Skip to content
Snippets Groups Projects

Draft: Issue #3052574: Facets with AJAX not working in most of situations

1 file
+ 32
3
Compare changes
  • Side-by-side
  • Inline
  • 15989978
    Issue #3052574 by Eduardo Morales Alberti, jefuri, matiasmiranda, lukasss,... · 15989978
    Florian Wust authored
    Issue #3052574 by Eduardo Morales Alberti, jefuri, matiasmiranda, lukasss, MPetkovFFW, Mschudders, balis_m, p-neyens, raman.b, ctrlADel, KarlShea, dabbor, yuraosn, czigor, orom, amoebanath, Oleksiy, dealancer, silajit, allaprishchepa, kamalbvg, bedlam: Facets with AJAX not working in most of situations
+ 32
3
@@ -38,9 +38,12 @@
// Update view on range slider stop event.
if (typeof settings.facets !== "undefined" && settings.facets.sliders && settings.facets.sliders[facetId]) {
settings.facets.sliders[facetId].change = function (values, handle, unencoded, tap, positions, noUiSlider) {
settings.facets.sliders[facetId].stop = function (event, ui) {
if ("undefined" === typeof ui) {
return;
}
const sliderSettings = settings.facets.sliders[facetId];
var href = sliderSettings.url.replace('__range_slider_min__', Math.round(unencoded[0])).replace('__range_slider_max__', Math.round(unencoded[1]));
var href = sliderSettings.url.replace('__range_slider_min__', Math.round(ui.values[0])).replace('__range_slider_max__', Math.round(ui.values[1]));
// Update facet query params on the request.
var currentHref = window.location.href;
@@ -86,13 +89,14 @@
}
}
href = '/' + Drupal.Views.getPath(href) + '?' + $.param(queryParams);
href = settings.path.baseUrl + Drupal.Views.getPath(href) + '?' + $.param(queryParams);
updateFacetsView(href, current_dom_id, view_path);
};
}
else if (facetId == 'facets_summary_ajax_summary' || facetId == 'facets_summary_ajax_summary_count') {
if (updateFacetsSummaryBlock()) {
$(once(facetId, '[data-drupal-facets-summary-id=' + facetSettings.facets_summary_id + '] ul li')).click(function (e) {
e.preventDefault();
var facetLink = $(this).find('a');
@@ -149,6 +153,31 @@
}
});
const formId = 'form#views-exposed-form-' + views_settings.view_name.replace(/_/g, '-') + '-' + views_settings.view_display_id.replace(/_/g, '-'),
$form = $(formId);
if ($form.length) {
// Remove all old facets inputs in exposed form.
$('input[type="hidden"][name^="f["]', $form).remove();
const hashes = href.slice(href.indexOf('?') + 1).split('&');
// Create hidden inputs to preserve facets in exposed form.
for (let i = 0; i < hashes.length; i++) {
const hash = hashes[i].split('='),
hashKey = window.decodeURIComponent(hash[0]);
if (hashKey.substr(0, 2) === 'f[') {
const input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', hashKey);
input.setAttribute('value', window.decodeURIComponent(hash[1]));
$form.append(input);
}
}
}
// Refresh facets blocks.
updateFacetsBlocks(href);
}
Loading