diff --git a/facets.libraries.yml b/facets.libraries.yml index 62daaf3..23cbc63 100644 --- a/facets.libraries.yml +++ b/facets.libraries.yml @@ -28,3 +28,13 @@ drupal.facets.checkbox-widget: dependencies: - core/jquery - core/drupal + - core/jquery.once + +drupal.facets.dropdown-widget: + version: VERSION + js: + js/dropdown-widget.js: {} + dependencies: + - core/jquery + - core/drupal + - core/jquery.once \ No newline at end of file diff --git a/js/dropdown-widget.js b/js/dropdown-widget.js new file mode 100644 index 0000000..6a3aaa8 --- /dev/null +++ b/js/dropdown-widget.js @@ -0,0 +1,58 @@ +/** + * @file + * Transforms links into a dropdown list. + */ + +(function ($) { + + "use strict"; + + var $dropdown = ''; + + Drupal.facets = {}; + Drupal.behaviors.facetsDropdownWidget = { + attach: function (context, settings) { + Drupal.facets.makeDropdown(); + } + }; + + /** + * Turns all facet links into options. + */ + Drupal.facets.makeDropdown = function () { + var is_multiple = $('.js-facets-dropdown-links').data('multiple'); + + $dropdown = '