123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- (function ($) {
- Drupal.behaviors.tableSelect = {
- attach: function (context, settings) {
-
- $('th.select-all', context).closest('table').once('table-select', Drupal.tableSelect);
- }
- };
- Drupal.tableSelect = function () {
-
- if ($('td input:checkbox', this).length == 0) {
- return;
- }
-
- var table = this, checkboxes, lastChecked;
- var strings = { 'selectAll': Drupal.t('Select all rows in this table'), 'selectNone': Drupal.t('Deselect all rows in this table') };
- var updateSelectAll = function (state) {
-
- $(table).prev('table.sticky-header').andSelf().find('th.select-all input:checkbox').each(function() {
- $(this).attr('title', state ? strings.selectNone : strings.selectAll);
- this.checked = state;
- });
- };
-
- $('th.select-all', table).prepend($('<input type="checkbox" class="form-checkbox" />').attr('title', strings.selectAll)).click(function (event) {
- if ($(event.target).is('input:checkbox')) {
-
- checkboxes.each(function () {
- this.checked = event.target.checked;
-
- $(this).closest('tr').toggleClass('selected', this.checked);
- });
-
- updateSelectAll(event.target.checked);
- }
- });
-
- checkboxes = $('td input:checkbox:enabled', table).click(function (e) {
-
- $(this).closest('tr').toggleClass('selected', this.checked);
-
-
-
- if (e.shiftKey && lastChecked && lastChecked != e.target) {
-
- Drupal.tableSelectRange($(e.target).closest('tr')[0], $(lastChecked).closest('tr')[0], e.target.checked);
- }
-
- updateSelectAll((checkboxes.length == $(checkboxes).filter(':checked').length));
-
- lastChecked = e.target;
- });
-
-
- updateSelectAll((checkboxes.length == $(checkboxes).filter(':checked').length));
- };
- Drupal.tableSelectRange = function (from, to, state) {
-
- var mode = from.rowIndex > to.rowIndex ? 'previousSibling' : 'nextSibling';
-
- for (var i = from[mode]; i; i = i[mode]) {
-
- if (i.nodeType != 1) {
- continue;
- }
-
- $(i).toggleClass('selected', state);
- $('input:checkbox', i).each(function () {
- this.checked = state;
- });
- if (to.nodeType) {
-
- if (i == to) {
- break;
- }
- }
-
- else if ($.filter(to, [i]).r.length) {
- break;
- }
- }
- };
- })(jQuery);
|