add own logic
This commit is contained in:
commit
5cabe99d1e
64 changed files with 6031 additions and 0 deletions
113
js/advanced_search.admin.js
Normal file
113
js/advanced_search.admin.js
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
//# sourceURL=modules/contrib/advanced_search/js/islandora-advanced-search.admin.js
|
||||
/**
|
||||
* @file
|
||||
* Largely based on core/modules/blocks/js/blocks.js
|
||||
*
|
||||
* This file allows for moving rows between two regions in a table and have the
|
||||
* 'region' field update appropriately.
|
||||
*/
|
||||
(function ($, window, Drupal) {
|
||||
Drupal.behaviors.islandoraAdvancedSearchAdmin = {
|
||||
attach: function attach(context, settings) {
|
||||
if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag['advanced-search-fields'] === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
function checkEmptyRegions(table, rowObject) {
|
||||
table.find('tr.region-message').each(function () {
|
||||
var $this = $(this);
|
||||
|
||||
if ($this.prev('tr').get(0) === rowObject.element) {
|
||||
if (rowObject.method !== 'keyboard' || rowObject.direction === 'down') {
|
||||
rowObject.swap('after', this);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) {
|
||||
$this.removeClass('region-populated').addClass('region-empty');
|
||||
} else if ($this.is('.region-empty')) {
|
||||
$this.removeClass('region-empty').addClass('region-populated');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateLastPlaced(table, rowObject) {
|
||||
table.find('.color-success').removeClass('color-success');
|
||||
|
||||
var $rowObject = $(rowObject);
|
||||
if (!$rowObject.is('.drag-previous')) {
|
||||
table.find('.drag-previous').removeClass('drag-previous');
|
||||
$rowObject.addClass('drag-previous');
|
||||
}
|
||||
}
|
||||
|
||||
function updateFieldWeights(table, region) {
|
||||
var weight = -Math.round(table.find('.draggable').length / 2);
|
||||
|
||||
table.find('.region-' + region + '-message').nextUntil('.region-title').find('select.field-weight').val(function () {
|
||||
return ++weight;
|
||||
});
|
||||
}
|
||||
|
||||
var table = $('#advanced-search-fields');
|
||||
|
||||
var tableDrag = Drupal.tableDrag['advanced-search-fields'];
|
||||
|
||||
tableDrag.row.prototype.onSwap = function (swappedRow) {
|
||||
checkEmptyRegions(table, this);
|
||||
updateLastPlaced(table, this);
|
||||
};
|
||||
|
||||
tableDrag.onDrop = function () {
|
||||
var dragObject = this;
|
||||
var $rowElement = $(dragObject.rowObject.element);
|
||||
|
||||
var regionRow = $rowElement.prevAll('tr.region-message').get(0);
|
||||
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
|
||||
var regionField = $rowElement.find('select.field-display');
|
||||
|
||||
if (regionField.find('option[value=' + regionName + ']').length === 0) {
|
||||
window.alert(Drupal.t('The field cannot be placed in this region.'));
|
||||
|
||||
regionField.trigger('change');
|
||||
}
|
||||
|
||||
if (!regionField.is('.field-display-' + regionName)) {
|
||||
var weightField = $rowElement.find('select.field-weight');
|
||||
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*field-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
|
||||
regionField.removeClass('field-display-' + oldRegionName).addClass('field-display-' + regionName);
|
||||
weightField.removeClass('field-weight-' + oldRegionName).addClass('field-weight-' + regionName);
|
||||
regionField.val(regionName);
|
||||
}
|
||||
|
||||
updateFieldWeights(table, regionName);
|
||||
};
|
||||
|
||||
$(once('field-display', 'select.field-display', context)).on('change', function (event) {
|
||||
var row = $(this).closest('tr');
|
||||
var select = $(this);
|
||||
|
||||
tableDrag.rowObject = new tableDrag.row(row[0]);
|
||||
var regionMessage = table.find('.region-' + select[0].value + '-message');
|
||||
var regionItems = regionMessage.nextUntil('.region-message, .region-title');
|
||||
if (regionItems.length) {
|
||||
regionItems.last().after(row);
|
||||
} else {
|
||||
regionMessage.after(row);
|
||||
}
|
||||
updateFieldWeights(table, select[0].value);
|
||||
|
||||
checkEmptyRegions(table, tableDrag.rowObject);
|
||||
|
||||
updateLastPlaced(table, row);
|
||||
|
||||
if (!tableDrag.changed) {
|
||||
$(Drupal.theme('tableDragChangedWarning')).insertBefore(tableDrag.table).hide().fadeIn('slow');
|
||||
tableDrag.changed = true;
|
||||
}
|
||||
|
||||
select.trigger('blur');
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery, window, Drupal);
|
||||
39
js/advanced_search.entityFields.js
Normal file
39
js/advanced_search.entityFields.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
(function ($, Drupal, drupalSettings) {
|
||||
Drupal.behaviors.advanceSearchEntityFields = {
|
||||
attach: function attach(context, settings) {
|
||||
let $searchSelectElement = $('#edit-terms-0-search');
|
||||
let originalSearchSelectOptions = $searchSelectElement.find('option').clone();
|
||||
$(document).on('change', '.advanced-search-form-entity', function() {
|
||||
console.log('change');
|
||||
let id = $(this).attr('id');
|
||||
let i = id.substring(11, 12);
|
||||
let $select = $('#' + id);
|
||||
let searchSelectId = 'edit-terms-' + i + '-search';
|
||||
console.log(searchSelectId);
|
||||
let selector = "[id^='" + searchSelectId + "']";
|
||||
console.log(selector);
|
||||
let $searchSelect = $(selector);
|
||||
console.log($searchSelect);
|
||||
if ($select.val() === 'ba419826c9014f40126565bf413f7a59') { // Auktion
|
||||
$searchSelect.empty();
|
||||
$searchSelect.append('<option value="label">Titel</option>');
|
||||
$searchSelect.append('<option value="ff8fb361d19f1fb4030605f87cb995ff">Auktionshaus</option>');
|
||||
$searchSelect.append('<option value="f4394d15487b58f49c719cf850f57e3a">Auktionskatalog</option>');
|
||||
$searchSelect.append('<option value="fd76aa80d3352b4ad8733552c8a10e7a">involvierte Institutionen</option>');
|
||||
$searchSelect.append('<option value="fa809b28c4e8b22e6a8f77722b04fae1">involvierte Personen</option>');
|
||||
} else if ($select.val() === 'b1d559f7b6af224a3f6f3b9a12e6b161') { // Institution
|
||||
$searchSelect.empty();
|
||||
$searchSelect.append('<option value="f838846307ea61a3d408df5022d498ba">Name</option>');
|
||||
$searchSelect.append('<option value="f53c209f6575fb5a7a0e7e7f424f7abd">Alternative Namen</option>');
|
||||
$searchSelect.append('<option value="field_mit_institution_verbundene">verbundene Orte</option>');
|
||||
} else if ($select.val() === 'alles') {
|
||||
$searchSelect.empty();
|
||||
$.each(originalSearchSelectOptions, function(i, option) {
|
||||
$searchSelect.append(option);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
202
js/advanced_search.form.js
Normal file
202
js/advanced_search.form.js
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
//# sourceURL=modules/contrib/islandora/modules/advanced_search/js/islandora-advanced-search.form.js
|
||||
/**
|
||||
* @file
|
||||
* Handles Ajax submission / updating form action on url change, etc.
|
||||
*/
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
// Replace Results per page html h3 tag with strong tag
|
||||
jQuery('h3:contains("Results per page")').replaceWith(function(){
|
||||
return jQuery("<strong />", {html: jQuery(this).html()});
|
||||
});
|
||||
|
||||
|
||||
// Gets current parameters minus ones provided by the form.
|
||||
function getParams(query_parameter, recurse_parameter) {
|
||||
const url_search_params = new URLSearchParams(window.location.search);
|
||||
const params = Object.fromEntries(url_search_params.entries());
|
||||
// Remove Advanced Search Query Parameters.
|
||||
const param_match = "query\\[\\d+\\]\\[.+\\]".replace("query", query_parameter);
|
||||
const param_regex = new RegExp(param_match, "g");
|
||||
for (const param in params) {
|
||||
if (param.match(param_regex)) {
|
||||
delete params[param];
|
||||
}
|
||||
}
|
||||
// Remove Recurse parameter.
|
||||
delete params[recurse_parameter];
|
||||
// Remove the page if set as submitting the form should always take
|
||||
// the user to the first page (facets do the same).
|
||||
delete params["page"];
|
||||
return params;
|
||||
}
|
||||
|
||||
// Groups form inputs by search term.
|
||||
function getTerms(inputs) {
|
||||
const input_regex = /terms\[(?<index>\d+)\]\[(?<component>.*)\]/;
|
||||
const terms = [];
|
||||
for (const input in inputs) {
|
||||
const name = inputs[input].name;
|
||||
const value = inputs[input].value;
|
||||
const found = name.match(input_regex);
|
||||
if (found) {
|
||||
const index = parseInt(found.groups.index);
|
||||
const component = found.groups.component;
|
||||
if (typeof terms[index] !== 'object') {
|
||||
terms[index] = {};
|
||||
}
|
||||
terms[index][component] = value;
|
||||
}
|
||||
}
|
||||
return terms;
|
||||
}
|
||||
|
||||
// Checks if the form user has set recursive to true in the form.
|
||||
function getRecurse(inputs) {
|
||||
for (const input in inputs) {
|
||||
const name = inputs[input].name;
|
||||
const value = inputs[input].value;
|
||||
if (name == "recursive" && value == "1") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function url(inputs, settings) {
|
||||
const terms = getTerms(inputs);
|
||||
const recurse = getRecurse(inputs);
|
||||
const params = getParams(settings.query_parameter, settings.recurse_parameter);
|
||||
for (const index in terms) {
|
||||
const term = terms[index];
|
||||
// Do not include terms with no value.
|
||||
if (term.value.length != 0) {
|
||||
for (const component in term) {
|
||||
const value = term[component];
|
||||
const param = "query[index][component]"
|
||||
.replace("query", settings.query_parameter)
|
||||
.replace("index", index)
|
||||
.replace("component", settings.mapping[component]);
|
||||
params[param] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recurse) {
|
||||
params[settings.recurse_parameter] = '1';
|
||||
}
|
||||
return window.location.href.split("?")[0] + "?" + $.param(params);
|
||||
}
|
||||
|
||||
function updateParam(urlstring, param, value) {
|
||||
var url = new URL(urlstring);
|
||||
var search_params = url.searchParams;
|
||||
|
||||
search_params.set(param, value);
|
||||
|
||||
url.search = search_params.toString();
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
Drupal.behaviors.advanced_search_form = {
|
||||
attach: function (context, settings) {
|
||||
if (settings.advanced_search_form.id !== 'undefined') {
|
||||
const $form = $(once('search-form', 'form#' + settings.advanced_search_form.id));
|
||||
if ($form.length > 0) {
|
||||
window.addEventListener("pushstate", function (e) {
|
||||
$form.attr('action', window.location.pathname + window.location.search);
|
||||
});
|
||||
window.addEventListener("popstate", function (e) {
|
||||
if (e.state != null) {
|
||||
$form.attr('action', window.location.pathname + window.location.search);
|
||||
}
|
||||
});
|
||||
|
||||
/* digitalutsc added */
|
||||
$("input[name*='[value]']").each(function () {
|
||||
// enable enter key trigger submit searching
|
||||
$(this).on("keypress", function (e) {
|
||||
|
||||
if (e.keyCode == 13) {
|
||||
// Cancel the default action on keypress event
|
||||
e.preventDefault();
|
||||
$form.submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Prevent form submission and push state instead.
|
||||
//
|
||||
// Logic server side / client side should match to generate the
|
||||
// appropriate URL with javascript enabled or disable.
|
||||
//
|
||||
// If a route is set for the view display that this form is derived
|
||||
// from, and we are not on the same page as that route, rely on the
|
||||
// normal submit which will redirect to the appropriate page.
|
||||
if (!settings.advanced_search_form.redirect) {
|
||||
$form.submit(function (e) {
|
||||
//e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const inputs = $form.serializeArray();
|
||||
const href = url(inputs, settings.advanced_search_form);
|
||||
|
||||
/* digitalutsc added*/
|
||||
$("li.pager__item a.pager__itemsperpage").each(function( index ) {
|
||||
// update pager links - items per page
|
||||
var new_link = href;
|
||||
if (href.includes("items_per_page=") === false) {
|
||||
new_link = new_link + '&items_per_page=' + $(this).text().trim().toLowerCase();
|
||||
$( this ).attr("href", new_link);
|
||||
}
|
||||
else {
|
||||
// replace with new param
|
||||
new_link = updateParam(new_link, "items_per_page", $(this).text().trim().toLowerCase());
|
||||
$( this ).attr("href", new_link);
|
||||
}
|
||||
});
|
||||
|
||||
$("li.pager__item a.pager__display").each(function( index ) {
|
||||
// update pager links - display
|
||||
var new_link = href;
|
||||
if (href.includes("display=") === false) {
|
||||
new_link = new_link + '&display=' + $(this).text().trim().toLowerCase();
|
||||
$( this ).attr("href", new_link);
|
||||
}
|
||||
else {
|
||||
// replace with new param
|
||||
new_link = updateParam(new_link, "display", $(this).text().trim().toLowerCase());
|
||||
$( this ).attr("href", new_link);
|
||||
}
|
||||
});
|
||||
|
||||
window.history.pushState(null, document.title, href);
|
||||
});
|
||||
}
|
||||
// Reset should trigger refresh of AJAX Blocks / Views.
|
||||
$form.find('input[data-drupal-selector = "edit-reset"]').mousedown(function (e) {
|
||||
const inputs = [];
|
||||
const href = url(inputs, settings.advanced_search_form);
|
||||
window.history.pushState(null, document.title, href.split('?')[0] );
|
||||
|
||||
/* reset the url after reset button clicked */
|
||||
window.location.replace(href.split('?')[0]);
|
||||
});
|
||||
|
||||
// Handle the page summary
|
||||
$("#ajax-page-summary").hide();
|
||||
$( document ).ajaxComplete(function( event, request, settings ) {
|
||||
console.log('ajax complete');
|
||||
|
||||
$("#ajax-page-summary").hide();
|
||||
if (jQuery("#ajax-page-summary").length >0) {
|
||||
$(".pager__summary").html($("#ajax-page-summary").html());
|
||||
}
|
||||
else {
|
||||
$(".pager__summary").html("");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
265
js/facets/facets-views-ajax.js
Normal file
265
js/facets/facets-views-ajax.js
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
//# sourceURL=modules/contrib/islandora/modules/advanced_search/js/facets/facets-view.ajax.js
|
||||
/**
|
||||
* @file
|
||||
* Overrides the facets-view-ajax.js behavior from the 'facets' module.
|
||||
*/
|
||||
(function ($, Drupal) {
|
||||
"use strict";
|
||||
|
||||
// Generate events on push state.
|
||||
(function (history) {
|
||||
var pushState = history.pushState;
|
||||
history.pushState = function (state, title, url) {
|
||||
var ret = pushState.apply(this, arguments);
|
||||
var event = new Event("pushstate");
|
||||
window.dispatchEvent(event);
|
||||
return ret;
|
||||
};
|
||||
})(window.history);
|
||||
|
||||
function parseQueryString( queryString ) {
|
||||
var params = {}, queries, temp, i, l;
|
||||
|
||||
// Split into key/value pairs
|
||||
queries = queryString.split("&");
|
||||
|
||||
// Convert the array of strings into an object
|
||||
for ( i = 0, l = queries.length; i < l; i++ ) {
|
||||
temp = queries[i].split('=');
|
||||
params[temp[0]] = temp[1];
|
||||
}
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
function reload(url) {
|
||||
// Update View.
|
||||
if (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) {
|
||||
var view_path = drupalSettings.views.ajax_path;
|
||||
$.each(drupalSettings.views.ajaxViews, function (views_dom_id) {
|
||||
var views_parameters = Drupal.Views.parseQueryString(url);
|
||||
var views_arguments = Drupal.Views.parseViewArgs(url, "search");
|
||||
var views_settings = $.extend(
|
||||
{},
|
||||
Drupal.views.instances[views_dom_id].settings,
|
||||
views_arguments,
|
||||
views_parameters
|
||||
);
|
||||
var views_ajax_settings =
|
||||
Drupal.views.instances[views_dom_id].element_settings;
|
||||
views_ajax_settings.submit = views_settings;
|
||||
views_ajax_settings.url =
|
||||
view_path + "?" + $.param(Drupal.Views.parseQueryString(url));
|
||||
Drupal.ajax(views_ajax_settings).execute();
|
||||
});
|
||||
}
|
||||
|
||||
// Update items_per_page links in pager
|
||||
if (url.indexOf("items_per_page=") == -1) {
|
||||
// append items_per_page
|
||||
$("a.pager__itemsperpage").each(function( index ) {
|
||||
var newUrl = url + "&items_per_page=" + $(this).html();
|
||||
$(this).attr("href", newUrl);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// replace existed items_per_page
|
||||
var params = parseQueryString(url.split("?")[1]);
|
||||
var newParams = [];
|
||||
var existingDateQuery = false; // true if a date query already exists
|
||||
|
||||
var links = {};
|
||||
// update publication date in url if previously queried
|
||||
for (var key in params) {
|
||||
if (!params[key]) { // no search parameters in url
|
||||
break;
|
||||
}
|
||||
|
||||
// check for items_per_page query
|
||||
if (!key.startsWith("items_per_page")) {
|
||||
newParams.push(key + "=" + params[key]);
|
||||
}
|
||||
}
|
||||
var newParamsUrl = newParams.join('&');
|
||||
$("a.pager__itemsperpage").each(function( index ) {
|
||||
$(this).attr("href", url.split("?")[0] + '?' + newParamsUrl + "&items_per_page=" + $(this).html());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update display mode links in pager
|
||||
if (url.indexOf("display=") == -1) {
|
||||
// append items_per_page
|
||||
$("a.pager__display").each(function( index ) {
|
||||
var newUrl = url + "&display=" + $(this).find(".display-mode").html().toLowerCase();
|
||||
$(this).attr("href", newUrl);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// replace existed display
|
||||
var params = parseQueryString(url.split("?")[1]);
|
||||
var newParams = [];
|
||||
var existingDateQuery = false; // true if a date query already exists
|
||||
|
||||
var links = {};
|
||||
// update publication date in url if previously queried
|
||||
for (var key in params) {
|
||||
if (!params[key]) { // no search parameters in url
|
||||
break;
|
||||
}
|
||||
|
||||
// check for display query
|
||||
if (!key.startsWith("display")) {
|
||||
newParams.push(key + "=" + params[key]);
|
||||
}
|
||||
}
|
||||
var newParamsUrl = newParams.join('&');
|
||||
$("a.pager__display").each(function( index ) {
|
||||
|
||||
var value = $(this).find(".display-mode").html().toLowerCase();
|
||||
$(this).attr("href", url.split("?")[0] + '?' + newParamsUrl + "&display=" + value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Replace filter, pager, summary, and facet blocks.
|
||||
var blocks = {};
|
||||
$(
|
||||
"[class*='block-plugin-id--islandora-advanced-search-result-pager'], [class*='block-plugin-id--views-exposed-filter-block'], [class*='block-facets']"
|
||||
).each(function () {
|
||||
var id = $(this).attr("id");
|
||||
var block_id = id
|
||||
.slice("block-".length, id.length)
|
||||
.replace(/--.*$/g, "")
|
||||
.replace(/-/g, "_");
|
||||
blocks[block_id] = "#" + id;
|
||||
});
|
||||
Drupal.ajax({
|
||||
url: Drupal.url("islandora-advanced-search-ajax-blocks"),
|
||||
submit: {
|
||||
link: url,
|
||||
blocks: blocks,
|
||||
},
|
||||
}).execute();
|
||||
}
|
||||
|
||||
// On location change reload all the blocks / ajax view.
|
||||
window.addEventListener("pushstate", function (e) {
|
||||
reload(window.location.href);
|
||||
});
|
||||
|
||||
window.addEventListener("popstate", function (e) {
|
||||
if (e.state != null) {
|
||||
reload(window.location.href);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Push state on form/pager/facet change.
|
||||
*/
|
||||
Drupal.behaviors.islandoraAdvancedSearchViewsAjax = {
|
||||
attach: function (context, settings) {
|
||||
window.historyInitiated = true;
|
||||
// Remove existing behavior from form.
|
||||
if (settings && settings.views && settings.views.ajaxViews) {
|
||||
$.each(settings.views.ajaxViews, function (index, settings) {
|
||||
var exposed_form = $(
|
||||
"form#views-exposed-form-" +
|
||||
settings.view_name.replace(/_/g, "-") +
|
||||
"-" +
|
||||
settings.view_display_id.replace(/_/g, "-")
|
||||
);
|
||||
$(once('exposed-form',
|
||||
"form#views-exposed-form-" +
|
||||
settings.view_name.replace(/_/g, "-") +
|
||||
"-" +
|
||||
settings.view_display_id.replace(/_/g, "-")))
|
||||
.find("input[type=submit], input[type=image]")
|
||||
.not("[data-drupal-selector=edit-reset]")
|
||||
.each(function (index) {
|
||||
$(this).unbind("click");
|
||||
$(this).click(function (e) {
|
||||
// Let ctrl/cmd click open in a new window.
|
||||
if (e.shiftKey || e.ctrlKey || e.metaKey) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
var href = window.location.href;
|
||||
var params = Drupal.Views.parseQueryString(href);
|
||||
// Remove the page if set as submitting the form should always take
|
||||
// the user to the first page (facets do the same).
|
||||
delete params.page;
|
||||
// Include values from the form in the URL.
|
||||
$.each(exposed_form.serializeArray(), function () {
|
||||
params[this.name] = this.value;
|
||||
});
|
||||
href = href.split("?")[0] + "?" + $.param(params);
|
||||
window.history.pushState(null, document.title, href);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (window.location.search.includes("display=") === true) {
|
||||
|
||||
$("li.pager__item a.pager__display").each(function () {
|
||||
$(this).parent().removeClass("is-active");
|
||||
$(this).removeClass("pager__link--is-active");
|
||||
if ($(this).text().trim().toLowerCase() === getParam(window.location.search, "display").trim().toLowerCase()) {
|
||||
$(this).addClass("pager__link--is-active");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (window.location.search.includes("items_per_page=") === true) {
|
||||
$("li.pager__item a.pager__itemsperpage").each(function() {
|
||||
$(this).parent().removeClass("is-active");
|
||||
$(this).removeClass("pager__link--is-active");
|
||||
if ($(this).text().trim().toLowerCase() === getParam(window.location.search, "items_per_page").trim().toLowerCase()) {
|
||||
$(this).addClass("pager__link--is-active");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
function getParam(urlstring, param) {
|
||||
var searchparam = new URLSearchParams(urlstring);
|
||||
return searchparam.get(param);
|
||||
}
|
||||
|
||||
// Attach behavior to pager, summary, facet links.
|
||||
$(once("new-window", "[data-drupal-pager-id], [data-drupal-facets-summary-id], [data-drupal-facet-id]"))
|
||||
.find("a:not(.facet-item)")
|
||||
.click(function (e) {
|
||||
// Let ctrl/cmd click open in a new window.
|
||||
if (e.shiftKey || e.ctrlKey || e.metaKey) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
|
||||
// added to prevent page reload if a facet link is clicked (Ajax of view is enabled)
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
window.history.pushState(null, document.title, $(this).attr("href"));
|
||||
});
|
||||
|
||||
// Trigger on sort change.
|
||||
$(once('params-sort', '[data-drupal-pager-id] select[name="order"], .pager__sort select[name="order"]'))
|
||||
.change(function () {
|
||||
var href = window.location.href;
|
||||
var params = Drupal.Views.parseQueryString(href);
|
||||
|
||||
var selection = $(this).val();
|
||||
var option = selection.split('_');
|
||||
params.sort_order = option[option.length - 1].toUpperCase();
|
||||
params.sort_by = selection.replace("_" + option[option.length - 1], "");
|
||||
href = href.split("?")[0] + "?" + $.param(params);
|
||||
window.history.pushState(null, document.title, href);
|
||||
});
|
||||
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal);
|
||||
74
js/facets/soft-limit.js
Normal file
74
js/facets/soft-limit.js
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* @file
|
||||
* Provides the soft limit functionality.
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
'use strict';
|
||||
|
||||
Drupal.behaviors.facetSoftLimit = {
|
||||
attach: function (context, settings) {
|
||||
if (settings.facets.softLimit !== 'undefined') {
|
||||
$.each(settings.facets.softLimit, function (facet, limit) {
|
||||
Drupal.facets.applySoftLimit(facet, limit, settings);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Drupal.facets = Drupal.facets || {};
|
||||
|
||||
/**
|
||||
* Applies the soft limit UI feature to a specific facets list.
|
||||
*
|
||||
* @param {string} facet
|
||||
* The facet id.
|
||||
* @param {string} limit
|
||||
* The maximum amount of items to show.
|
||||
* @param {object} settings
|
||||
* Settings.
|
||||
*/
|
||||
Drupal.facets.applySoftLimit = function (facet, limit, settings) {
|
||||
var zero_based_limit = (limit - 1);
|
||||
var facet_id = facet;
|
||||
var facetsList = $('ul[data-drupal-facet-id="' + facet_id + '"]');
|
||||
|
||||
// In case of multiple instances of a facet, we need to key them.
|
||||
if (facetsList.length > 1) {
|
||||
facetsList.each(function (key, $value) {
|
||||
$(this).attr('data-drupal-facet-id', facet_id + '-' + key);
|
||||
});
|
||||
}
|
||||
|
||||
// Hide facets over the limit.
|
||||
facetsList.each(function () {
|
||||
$(once('applysoftlimit', $(this).children('li:gt(' + zero_based_limit + ')'))).hide();
|
||||
});
|
||||
|
||||
|
||||
// Add "Show more" / "Show less" links.
|
||||
facetsList.filter(function () {
|
||||
return ($(this).find('li').length > limit && $(this).parent().find('a.facets-soft-limit-link').length < 1);
|
||||
}).each(function () {
|
||||
var facet = $(this);
|
||||
var showLessLabel = settings.facets.softLimitSettings[facet_id].showLessLabel;
|
||||
var showMoreLabel = settings.facets.softLimitSettings[facet_id].showMoreLabel;
|
||||
$('<a href="#" class="facets-soft-limit-link"></a>')
|
||||
.text(showMoreLabel).attr("aria-expanded", "false")
|
||||
.on('click', function () {
|
||||
if (facet.find('li:hidden').length > 0) {
|
||||
facet.find('li:gt(' + zero_based_limit + ')').slideDown();
|
||||
facet.find('li:lt(' + (zero_based_limit + 2) + ') input').focus();
|
||||
$(this).addClass('open').text(showLessLabel).attr("aria-expanded", "true");
|
||||
}
|
||||
else {
|
||||
facet.find('li:gt(' + zero_based_limit + ')').slideUp();
|
||||
$(this).removeClass('open').text(showMoreLabel).attr("aria-expanded", "false");
|
||||
}
|
||||
return false;
|
||||
}).insertAfter($(this));
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
Loading…
Add table
Add a link
Reference in a new issue