Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, Drupal) { Chris@0: Drupal.behaviors.tableSelect = { Chris@0: attach: function attach(context, settings) { Chris@0: $(context).find('th.select-all').closest('table').once('table-select').each(Drupal.tableSelect); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.tableSelect = function () { Chris@0: if ($(this).find('td input[type="checkbox"]').length === 0) { Chris@0: return; Chris@0: } Chris@0: Chris@0: var table = this; Chris@0: var checkboxes = void 0; Chris@0: var lastChecked = void 0; Chris@0: var $table = $(table); Chris@0: var strings = { Chris@0: selectAll: Drupal.t('Select all rows in this table'), Chris@0: selectNone: Drupal.t('Deselect all rows in this table') Chris@0: }; Chris@0: var updateSelectAll = function updateSelectAll(state) { Chris@0: $table.prev('table.sticky-header').addBack().find('th.select-all input[type="checkbox"]').each(function () { Chris@0: var $checkbox = $(this); Chris@0: var stateChanged = $checkbox.prop('checked') !== state; Chris@0: Chris@0: $checkbox.attr('title', state ? strings.selectNone : strings.selectAll); Chris@0: Chris@0: if (stateChanged) { Chris@0: $checkbox.prop('checked', state).trigger('change'); Chris@0: } Chris@0: }); Chris@0: }; Chris@0: Chris@0: $table.find('th.select-all').prepend($('').attr('title', strings.selectAll)).on('click', function (event) { Chris@0: if ($(event.target).is('input[type="checkbox"]')) { Chris@0: checkboxes.each(function () { Chris@0: var $checkbox = $(this); Chris@0: var stateChanged = $checkbox.prop('checked') !== event.target.checked; Chris@0: Chris@0: if (stateChanged) { Chris@0: $checkbox.prop('checked', event.target.checked).trigger('change'); Chris@0: } Chris@0: Chris@0: $checkbox.closest('tr').toggleClass('selected', this.checked); Chris@0: }); Chris@0: Chris@0: updateSelectAll(event.target.checked); Chris@0: } Chris@0: }); Chris@0: Chris@0: checkboxes = $table.find('td input[type="checkbox"]:enabled').on('click', function (e) { Chris@0: $(this).closest('tr').toggleClass('selected', this.checked); Chris@0: Chris@0: if (e.shiftKey && lastChecked && lastChecked !== e.target) { Chris@0: Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked); Chris@0: } Chris@0: Chris@0: updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length); Chris@0: Chris@0: lastChecked = e.target; Chris@0: }); Chris@0: Chris@0: updateSelectAll(checkboxes.length === checkboxes.filter(':checked').length); Chris@0: }; Chris@0: Chris@0: Drupal.tableSelectRange = function (from, to, state) { Chris@0: var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling'; Chris@0: Chris@0: for (var i = from[mode]; i; i = i[mode]) { Chris@14: var $i = $(i); Chris@0: Chris@0: if (i.nodeType !== 1) { Chris@0: continue; Chris@0: } Chris@0: Chris@0: $i.toggleClass('selected', state); Chris@0: $i.find('input[type="checkbox"]').prop('checked', state); Chris@0: Chris@0: if (to.nodeType) { Chris@0: if (i === to) { Chris@0: break; Chris@0: } Chris@0: } else if ($.filter(to, [i]).r.length) { Chris@0: break; Chris@0: } Chris@0: } Chris@0: }; Chris@0: })(jQuery, Drupal);