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