2015-06-08 14:04:39 +00:00
|
|
|
/**
|
2017-05-19 22:12:53 +00:00
|
|
|
* DO NOT EDIT THIS FILE.
|
|
|
|
* See the following change record for more information,
|
2017-05-23 14:30:14 +00:00
|
|
|
* https://www.drupal.org/node/2815083
|
2017-05-19 22:12:53 +00:00
|
|
|
* @preserve
|
|
|
|
**/
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2013-08-29 16:39:27 +00:00
|
|
|
(function ($, Drupal) {
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.behaviors.tableSelect = {
|
2017-05-19 22:12:53 +00:00
|
|
|
attach: function attach(context, settings) {
|
2015-03-23 10:29:17 +00:00
|
|
|
$(context).find('th.select-all').closest('table').once('table-select').each(Drupal.tableSelect);
|
2014-01-27 21:41:32 +00:00
|
|
|
}
|
2007-11-14 21:25:48 +00:00
|
|
|
};
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.tableSelect = function () {
|
|
|
|
if ($(this).find('td input[type="checkbox"]').length === 0) {
|
|
|
|
return;
|
2007-11-14 21:25:48 +00:00
|
|
|
}
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2015-04-19 15:30:43 +00:00
|
|
|
var table = this;
|
2020-01-30 09:08:38 +00:00
|
|
|
var checkboxes;
|
|
|
|
var lastChecked;
|
2014-01-27 21:41:32 +00:00
|
|
|
var $table = $(table);
|
2015-08-07 14:08:23 +00:00
|
|
|
var strings = {
|
|
|
|
selectAll: Drupal.t('Select all rows in this table'),
|
|
|
|
selectNone: Drupal.t('Deselect all rows in this table')
|
|
|
|
};
|
2020-01-30 09:08:38 +00:00
|
|
|
|
2017-05-19 22:12:53 +00:00
|
|
|
var updateSelectAll = function updateSelectAll(state) {
|
2014-01-27 21:41:32 +00:00
|
|
|
$table.prev('table.sticky-header').addBack().find('th.select-all input[type="checkbox"]').each(function () {
|
2016-01-04 05:58:16 +00:00
|
|
|
var $checkbox = $(this);
|
|
|
|
var stateChanged = $checkbox.prop('checked') !== state;
|
|
|
|
$checkbox.attr('title', state ? strings.selectNone : strings.selectAll);
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2016-01-04 05:58:16 +00:00
|
|
|
if (stateChanged) {
|
|
|
|
$checkbox.prop('checked', state).trigger('change');
|
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
|
|
|
};
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2019-09-20 23:18:38 +00:00
|
|
|
$table.find('th.select-all').prepend($(Drupal.theme('checkbox')).attr('title', strings.selectAll)).on('click', function (event) {
|
2014-01-27 21:41:32 +00:00
|
|
|
if ($(event.target).is('input[type="checkbox"]')) {
|
|
|
|
checkboxes.each(function () {
|
2016-01-04 05:58:16 +00:00
|
|
|
var $checkbox = $(this);
|
|
|
|
var stateChanged = $checkbox.prop('checked') !== event.target.checked;
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2016-01-04 05:58:16 +00:00
|
|
|
if (stateChanged) {
|
|
|
|
$checkbox.prop('checked', event.target.checked).trigger('change');
|
|
|
|
}
|
2015-06-08 14:04:39 +00:00
|
|
|
|
2016-01-04 05:58:16 +00:00
|
|
|
$checkbox.closest('tr').toggleClass('selected', this.checked);
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
|
|
|
updateSelectAll(event.target.checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
checkboxes = $table.find('td input[type="checkbox"]:enabled').on('click', function (e) {
|
|
|
|
$(this).closest('tr').toggleClass('selected', this.checked);
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (e.shiftKey && lastChecked && lastChecked !== e.target) {
|
|
|
|
Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
|
|
|
|
}
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2017-05-19 22:12:53 +00:00
|
|
|
updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length);
|
2014-01-27 21:41:32 +00:00
|
|
|
lastChecked = e.target;
|
|
|
|
});
|
2017-05-19 22:12:53 +00:00
|
|
|
updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length);
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2006-11-21 08:16:39 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
Drupal.tableSelectRange = function (from, to, state) {
|
|
|
|
var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
|
|
|
|
|
2015-04-19 15:30:43 +00:00
|
|
|
for (var i = from[mode]; i; i = i[mode]) {
|
2017-10-12 07:10:10 +00:00
|
|
|
var $i = $(i);
|
2017-05-19 22:12:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
if (i.nodeType !== 1) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-19 22:12:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
$i.toggleClass('selected', state);
|
|
|
|
$i.find('input[type="checkbox"]').prop('checked', state);
|
|
|
|
|
|
|
|
if (to.nodeType) {
|
|
|
|
if (i === to) {
|
|
|
|
break;
|
|
|
|
}
|
2017-05-19 22:12:53 +00:00
|
|
|
} else if ($.filter(to, [i]).r.length) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-21 08:16:39 +00:00
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
};
|
2017-05-19 22:12:53 +00:00
|
|
|
})(jQuery, Drupal);
|