Skip to content
Snippets Groups Projects

Integrate with better_exposed_filters for AJAX

Files
25
+ 34
11
@@ -19,7 +19,7 @@
*/
Drupal.facets.makeCheckboxes = function (context) {
// Find all checkbox facet links and give them a checkbox.
var $checkboxWidgets = $('.js-facets-checkbox-links', context)
var $checkboxWidgets = $('.js-facets-checkbox-links, .js-facets-links', context)
.once('facets-checkbox-transform');
if ($checkboxWidgets.length > 0) {
@@ -54,24 +54,47 @@
var description = $link.html();
var href = $link.attr('href');
var id = $link.data('drupal-facet-item-id');
var type = $link.data('drupal-facet-widget-element-class');
var checkbox = $('<input type="checkbox" class="facets-checkbox">')
var checkbox = $('<input type="checkbox">')
.attr('id', id)
.attr('name', $link.data('drupal-facet-filter-key') + '[]')
.addClass(type)
.val($link.data('drupal-facet-filter-value'))
.data($link.data())
.data('facetsredir', href);
var label = $('<label for="' + id + '">' + description + '</label>');
checkbox.on('change.facets', function (e) {
e.preventDefault();
var single_selection_group = $(this).data('drupal-facet-single-selection-group');
if (single_selection_group) {
checkbox.addClass(single_selection_group);
}
var $widget = $(this).closest('.js-facets-widget');
if (type === 'facets-link') {
checkbox.hide();
}
Drupal.facets.disableFacet($widget);
$widget.trigger('facets_filter', [ href ]);
var label = $('<label for="' + id + '">' + description + '</label>');
checkbox.on('change.facets', function (e) {
if ($link.data('drupal-facet-ajax') == 0) {
e.preventDefault();
var $widget = $(this).closest('.js-facets-widget');
Drupal.facets.disableFacet($widget);
$widget.trigger('facets_filter', [href]);
}
else {
var current = $(this);
if (current.is(':checked') && current.hasClass(single_selection_group)) {
var $widget = current.closest('.js-facets-widget');
$widget.find('input.' + single_selection_group + ':not(#' + current.attr('id') + ')').prop('checked', false);
}
}
});
if (active) {
checkbox.attr('checked', true);
checkbox.prop('checked', true);
label.find('.js-facet-deactivate').remove();
}
@@ -87,8 +110,8 @@
*/
Drupal.facets.disableFacet = function ($facet) {
$facet.addClass('facets-disabled');
$('input.facets-checkbox', $facet).click(Drupal.facets.preventDefault);
$('input.facets-checkbox', $facet).attr('disabled', true);
$('input.facets-checkbox, input.facets-link', $facet).click(Drupal.facets.preventDefault);
$('input.facets-checkbox, input.facets-link', $facet).attr('disabled', true);
};
/**
Loading