Security update for Core, with self-updated composer
[yaffs-website] / web / core / misc / tableselect.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal) {
9   Drupal.behaviors.tableSelect = {
10     attach: function attach(context, settings) {
11       $(context).find('th.select-all').closest('table').once('table-select').each(Drupal.tableSelect);
12     }
13   };
14
15   Drupal.tableSelect = function () {
16     if ($(this).find('td input[type="checkbox"]').length === 0) {
17       return;
18     }
19
20     var table = this;
21     var checkboxes = void 0;
22     var lastChecked = void 0;
23     var $table = $(table);
24     var strings = {
25       selectAll: Drupal.t('Select all rows in this table'),
26       selectNone: Drupal.t('Deselect all rows in this table')
27     };
28     var updateSelectAll = function updateSelectAll(state) {
29       $table.prev('table.sticky-header').addBack().find('th.select-all input[type="checkbox"]').each(function () {
30         var $checkbox = $(this);
31         var stateChanged = $checkbox.prop('checked') !== state;
32
33         $checkbox.attr('title', state ? strings.selectNone : strings.selectAll);
34
35         if (stateChanged) {
36           $checkbox.prop('checked', state).trigger('change');
37         }
38       });
39     };
40
41     $table.find('th.select-all').prepend($('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll)).on('click', function (event) {
42       if ($(event.target).is('input[type="checkbox"]')) {
43         checkboxes.each(function () {
44           var $checkbox = $(this);
45           var stateChanged = $checkbox.prop('checked') !== event.target.checked;
46
47           if (stateChanged) {
48             $checkbox.prop('checked', event.target.checked).trigger('change');
49           }
50
51           $checkbox.closest('tr').toggleClass('selected', this.checked);
52         });
53
54         updateSelectAll(event.target.checked);
55       }
56     });
57
58     checkboxes = $table.find('td input[type="checkbox"]:enabled').on('click', function (e) {
59       $(this).closest('tr').toggleClass('selected', this.checked);
60
61       if (e.shiftKey && lastChecked && lastChecked !== e.target) {
62         Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
63       }
64
65       updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length);
66
67       lastChecked = e.target;
68     });
69
70     updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length);
71   };
72
73   Drupal.tableSelectRange = function (from, to, state) {
74     var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
75
76     for (var i = from[mode]; i; i = i[mode]) {
77       var $i;
78
79       if (i.nodeType !== 1) {
80         continue;
81       }
82       $i = $(i);
83
84       $i.toggleClass('selected', state);
85       $i.find('input[type="checkbox"]').prop('checked', state);
86
87       if (to.nodeType) {
88         if (i === to) {
89           break;
90         }
91       } else if ($.filter(to, [i]).r.length) {
92           break;
93         }
94     }
95   };
96 })(jQuery, Drupal);