3 * Attaches administration-specific behavior for the Filter module.
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);
19 .find('#filters-status-wrapper input.form-checkbox')
20 .once('filter-status')
22 const $checkbox = $(this);
23 // Retrieve the tabledrag row belonging to this filter.
25 .find(`#${$checkbox.attr('id').replace(/-status$/, '-weight')}`)
27 // Retrieve the vertical tab belonging to this filter.
28 const $filterSettings = $context.find(
29 `#${$checkbox.attr('id').replace(/-status$/, '-settings')}`,
31 const filterSettingsTab = $filterSettings.data('verticalTab');
33 // Bind click handler to this checkbox to conditionally show and hide
34 // the filter's tableDrag row and vertical tab pane.
35 $checkbox.on('click.filterUpdate', () => {
36 if ($checkbox.is(':checked')) {
38 if (filterSettingsTab) {
39 filterSettingsTab.tabShow().updateSummary();
41 // On very narrow viewports, Vertical Tabs are disabled.
42 $filterSettings.show();
46 if (filterSettingsTab) {
47 filterSettingsTab.tabHide().updateSummary();
49 // On very narrow viewports, Vertical Tabs are disabled.
50 $filterSettings.hide();
53 // Restripe table after toggling visibility of table row.
54 Drupal.tableDrag['filter-order'].restripeTable();
57 // Attach summary for configurable filters (only for screen readers).
58 if (filterSettingsTab) {
59 filterSettingsTab.details.drupalSetSummary(
61 $checkbox.is(':checked')
63 : Drupal.t('Disabled'),
67 // Trigger our bound click handler to update elements to initial state.
68 $checkbox.triggerHandler('click.filterUpdate');