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..9f75dee --- /dev/null +++ b/js/dropdown-widget.js @@ -0,0 +1,67 @@ +/** + * @file + * Transforms links into a dropdown list. + */ + +(function ($) { + + 'use strict'; + + + Drupal.facets = {}; + Drupal.behaviors.facetsDropdownWidget = { + attach: function (context, settings) { + Drupal.facets.makeDropdown(); + } + }; + + /** + * Turns all facet links into options. + */ + Drupal.facets.makeDropdown = function () { + // Find all dropdown facet links and turn them into an option. + $('.js-facets-dropdown-links').once('facets-dropdown-transform').each(function () { + var $links = $(this).find('.facet-item a'); + var $dropdown = $('