1/** 2 * @file 3 * Provides base widget behaviours. 4 */ 5 6(function ($, Drupal, once) { 7 /** 8 * Handles "facets_filter" event and triggers "facets_filtering". 9 * 10 * The facets module will listend and trigger defined events on elements with 11 * class: "js-facets-widget". 12 * 13 * Events are doing following: 14 * "facets_filter" - widget should trigger this event. 15 * "facets_filtering" - The facets module will trigger this event before 16 * filter is executed. 17 * 18 * This is an example how to trigger "facets_filter" event for your widget: 19 * $(once('my-custom-widget-on-change', '.my-custom-widget.js-facets-widget')) 20 * .on('change', function () { 21 * // In this example $(this).val() will provide needed URL. 22 * $(this).trigger('facets_filter', [ $(this).val(), false ]); 23 * }); 24 * 25 * The facets module will trigger "facets_filtering" before filter is 26 * executed. Widgets can listen on "facets_filtering" event and react before 27 * filter is executed. Most common use case is to disable widget. When you 28 * disable widget, a user will not be able to trigger new "facets_filter" 29 * event before initial filter request is finished. 30 * 31 * This is an example how to handle "facets_filtering": 32 * $(once('my-custom-widget-on-facets-filtering', '.my-custom-widget.js-facets-widget')) 33 * .on('facets_filtering.my_widget_module', function () { 34 * // Let's say, that widget can be simply disabled (fe. select). 35 * $(this).prop('disabled', true); 36 * }); 37 * 38 * You should namespace events for your module widgets. With namespaced events 39 * you have better control on your handlers and if it's needed, you can easier 40 * register/deregister them. 41 */ 42 Drupal.behaviors.facetsFilter = { 43 attach: (context) => { 44 $(once('js-facet-filter', '.js-facets-widget', context)).on( 45 'facets_filter.facets', 46 function (event, url) { 47 $('.js-facets-widget').trigger('facets_filtering'); 48 49 window.location = url; 50 }, 51 ); 52 }, 53 }; 54})(jQuery, Drupal, 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.