1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- (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;
- });
- };
- 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);
|