Mercurial > hg > cmmr2012-drupal-site
comparison core/misc/tableselect.js @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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 = $(i); | |
78 | |
79 if (i.nodeType !== 1) { | |
80 continue; | |
81 } | |
82 | |
83 $i.toggleClass('selected', state); | |
84 $i.find('input[type="checkbox"]').prop('checked', state); | |
85 | |
86 if (to.nodeType) { | |
87 if (i === to) { | |
88 break; | |
89 } | |
90 } else if ($.filter(to, [i]).r.length) { | |
91 break; | |
92 } | |
93 } | |
94 }; | |
95 })(jQuery, Drupal); |