3 * Attaches administration-specific behavior for the Filter module.
6 (function ($, Drupal) {
8 * Displays and updates the status of filters on the admin page.
10 * @type {Drupal~behavior}
12 * @prop {Drupal~behaviorAttach} attach
13 * Attaches behaviors to the filter admin view.
15 Drupal.behaviors.filterStatus = {
16 attach(context, settings) {
17 const $context = $(context);
18 $context.find('#filters-status-wrapper input.form-checkbox').once('filter-status').each(function () {
19 const $checkbox = $(this);
20 // Retrieve the tabledrag row belonging to this filter.
21 const $row = $context.find(`#${$checkbox.attr('id').replace(/-status$/, '-weight')}`).closest('tr');
22 // Retrieve the vertical tab belonging to this filter.
23 const $filterSettings = $context.find(`#${$checkbox.attr('id').replace(/-status$/, '-settings')}`);
24 const filterSettingsTab = $filterSettings.data('verticalTab');
26 // Bind click handler to this checkbox to conditionally show and hide
27 // the filter's tableDrag row and vertical tab pane.
28 $checkbox.on('click.filterUpdate', () => {
29 if ($checkbox.is(':checked')) {
31 if (filterSettingsTab) {
32 filterSettingsTab.tabShow().updateSummary();
35 // On very narrow viewports, Vertical Tabs are disabled.
36 $filterSettings.show();
41 if (filterSettingsTab) {
42 filterSettingsTab.tabHide().updateSummary();
45 // On very narrow viewports, Vertical Tabs are disabled.
46 $filterSettings.hide();
49 // Restripe table after toggling visibility of table row.
50 Drupal.tableDrag['filter-order'].restripeTable();
53 // Attach summary for configurable filters (only for screen readers).
54 if (filterSettingsTab) {
55 filterSettingsTab.details.drupalSetSummary(tabContext => $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled'));
58 // Trigger our bound click handler to update elements to initial state.
59 $checkbox.triggerHandler('click.filterUpdate');