Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update advanced search for new Drupal "once" function #41

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions advanced_search.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ advanced.search.admin:
js/advanced_search.admin.js: {}
dependencies:
- core/drupal.tabledrag
- core/jquery
- core/once

advanced.search.form:
js:
Expand Down
2 changes: 1 addition & 1 deletion js/advanced_search.admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
updateFieldWeights(table, regionName);
};

$(context).find('select.field-display').once('field-display').on('change', function (event) {
$(once('field-display', 'select.field-display', context)).on('change', function (event) {
var row = $(this).closest('tr');
var select = $(this);

Expand Down
2 changes: 1 addition & 1 deletion js/advanced_search.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
Drupal.behaviors.advanced_search_form = {
attach: function (context, settings) {
if (settings.advanced_search_form.id !== 'undefined') {
const $form = $('form#' + settings.advanced_search_form.id).once();
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);
Expand Down
31 changes: 8 additions & 23 deletions js/facets/facets-views-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@
"-" +
settings.view_display_id.replace(/_/g, "-")
);
exposed_form
.once()
$(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) {
Expand Down Expand Up @@ -228,8 +231,7 @@
}

// Attach behavior to pager, summary, facet links.
$("[data-drupal-pager-id], [data-drupal-facets-summary-id], [data-drupal-facet-id]")
.once()
$(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.
Expand All @@ -244,37 +246,20 @@
window.history.pushState(null, document.title, $(this).attr("href"));
});

/* digitalutsc added */
$('.pager__sort select[name="order"]')
.once()
// 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_by = option[0];
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);
});


// Trigger on sort change.
$('[data-drupal-pager-id] select[name="order"]')
.once()
.change(function () {
var href = window.location.href;
var params = Drupal.Views.parseQueryString(href);
var selection = $(this).val();
var option = $('option[value="' + selection + '"]');
params.sort_order = option.data("sort_order");
params.sort_by = option.data("sort_by");
href = href.split("?")[0] + "?" + $.param(params);
window.history.pushState(null, document.title, href);
});
},
};
})(jQuery, Drupal);
2 changes: 1 addition & 1 deletion js/facets/soft-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

// Hide facets over the limit.
facetsList.each(function () {
$(this).children('li:gt(' + zero_based_limit + ')').once('applysoftlimit').hide();
$(once('applysoftlimit', $(this).children('li:gt(' + zero_based_limit + ')'))).hide();
});


Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AjaxBlocksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function respond(Request $request) {

// Rebuild the request and the current path, needed for facets.
$path = $request->request->get('link');
$blocks = $request->request->get('blocks');
$blocks = $request->request->all('blocks');

// Make sure we are not updating blocks multiple times.
$blocks = array_unique($blocks);
Expand Down