31e0582c18993e5a5393d22e06e170ab26ef9440
[yaffs-website] / web / core / modules / filter / filter.admin.js
1 /**
2  * @file
3  * Attaches administration-specific behavior for the Filter module.
4  */
5
6 (function ($, Drupal) {
7
8   'use strict';
9
10   /**
11    * Displays and updates the status of filters on the admin page.
12    *
13    * @type {Drupal~behavior}
14    *
15    * @prop {Drupal~behaviorAttach} attach
16    *   Attaches behaviors to the filter admin view.
17    */
18   Drupal.behaviors.filterStatus = {
19     attach: function (context, settings) {
20       var $context = $(context);
21       $context.find('#filters-status-wrapper input.form-checkbox').once('filter-status').each(function () {
22         var $checkbox = $(this);
23         // Retrieve the tabledrag row belonging to this filter.
24         var $row = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-weight')).closest('tr');
25         // Retrieve the vertical tab belonging to this filter.
26         var $filterSettings = $context.find('#' + $checkbox.attr('id').replace(/-status$/, '-settings'));
27         var filterSettingsTab = $filterSettings.data('verticalTab');
28
29         // Bind click handler to this checkbox to conditionally show and hide
30         // the filter's tableDrag row and vertical tab pane.
31         $checkbox.on('click.filterUpdate', function () {
32           if ($checkbox.is(':checked')) {
33             $row.show();
34             if (filterSettingsTab) {
35               filterSettingsTab.tabShow().updateSummary();
36             }
37             else {
38               // On very narrow viewports, Vertical Tabs are disabled.
39               $filterSettings.show();
40             }
41           }
42           else {
43             $row.hide();
44             if (filterSettingsTab) {
45               filterSettingsTab.tabHide().updateSummary();
46             }
47             else {
48               // On very narrow viewports, Vertical Tabs are disabled.
49               $filterSettings.hide();
50             }
51           }
52           // Restripe table after toggling visibility of table row.
53           Drupal.tableDrag['filter-order'].restripeTable();
54         });
55
56         // Attach summary for configurable filters (only for screen readers).
57         if (filterSettingsTab) {
58           filterSettingsTab.details.drupalSetSummary(function (tabContext) {
59             return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
60           });
61         }
62
63         // Trigger our bound click handler to update elements to initial state.
64         $checkbox.triggerHandler('click.filterUpdate');
65       });
66     }
67   };
68
69 })(jQuery, Drupal);