Commit 1c1588cb authored by dragos-dumi's avatar dragos-dumi Committed by borisson_

Issue #2725383 by sudhanshug, dragos-dumi: Use drupalSettings instead of...

Issue #2725383 by sudhanshug, dragos-dumi: Use drupalSettings instead of data-attribute to pass config to js
parent ad3e8499
......@@ -10,22 +10,23 @@
Drupal.facets = Drupal.facets || {};
Drupal.behaviors.facetsDropdownWidget = {
attach: function (context, settings) {
Drupal.facets.makeDropdown();
Drupal.facets.makeDropdown(context, settings);
}
};
/**
* Turns all facet links into a dropdown with options for every link.
*/
Drupal.facets.makeDropdown = function () {
Drupal.facets.makeDropdown = function (context, settings) {
// Find all dropdown facet links and turn them into an option.
$('.js-facets-dropdown-links').once('facets-dropdown-transform').each(function () {
var $ul = $(this);
var $links = $ul.find('.facet-item a');
var $dropdown = $('<select class="facets-dropdown" />').data($ul.data());
var id = $(this).data('drupal-facet-id');
var default_option_label = settings.facets.dropdown_widget[id]['facet-default-option-label'];
// Add empty text option first.
var default_option_label = $ul.data('facet-default-option-label');
var $default_option = $('<option />')
.attr('value', '')
.text(default_option_label);
......
......@@ -32,7 +32,7 @@ class DropdownWidget extends WidgetPluginBase {
public function build(FacetInterface $facet) {
$build = parent::build($facet);
$build['#attributes']['class'][] = 'js-facets-dropdown-links';
$build['#attributes']['data-facet-default-option-label'] = $this->getConfiguration()['default_option_label'];
$build['#attached']['drupalSettings']['facets']['dropdown_widget'][$facet->id()]['facet-default-option-label'] = $this->getConfiguration()['default_option_label'];
$build['#attached']['library'][] = 'facets/drupal.facets.dropdown-widget';
return $build;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment