1/** 2 * @file 3 * bef_links_use_ajax.js 4 * 5 * Allows to use ajax with Bef links. 6 */ 7 8(function (once) { 9 10 // This is only needed to provide ajax functionality 11 Drupal.behaviors.better_exposed_filters_select_as_links = { 12 attach: function (context) { 13 once('bef-links-use-ajax', '.bef-links.bef-links-use-ajax', context).forEach(function (element) { 14 const links_name = element.getAttribute('data-name'); 15 const links_multiple = element.getAttribute('data-multiple'); 16 const form = element.closest('form'); 17 18 element.querySelectorAll('a').forEach((el) => el.addEventListener('click', (event) => { 19 // Prevent following the link URL. 20 event.preventDefault(); 21 22 const target = event.currentTarget; 23 24 const link_value = target.getAttribute('data-bef-value'); 25 const base_name = links_name.replace(/\[]$/, ''); 26 const link_name = links_multiple ? base_name + '[' + link_value + ']' : links_name; 27 const filter = form.querySelector('input[name="' + link_name + '"]'); 28 const filters = form.querySelectorAll('input[name^="' + base_name + '"]'); 29 30 if (target.classList.contains('bef-link--selected')) { 31 // The previously selected link is selected again. Deselect it. 32 target.classList.remove('bef-link--selected'); 33 if (!links_multiple || link_value === 'All') { 34 filters.forEach((el) => el.remove()); 35 } 36 else { 37 filter.remove(); 38 } 39 } 40 else { 41 if (!links_multiple || link_value === 'All') { 42 element.querySelectorAll('.bef-link--selected').forEach((el) => el.classList.remove('bef-link--selected')); 43 } 44 target.classList.add('bef-link--selected'); 45 46 if (!filter) { 47 const newFilter = document.createElement("input"); 48 newFilter.type = "hidden"; 49 newFilter.name = link_name; 50 newFilter.value = link_value; 51 element.appendChild(newFilter); 52 } 53 else { 54 filter.value = link_value; 55 } 56 } 57 58 // Submit the form. 59 form.querySelector('.form-submit:not([data-drupal-selector*=edit-reset])').click(); 60 })); 61 }); 62 } 63 }; 64})(once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.