datatables.net-select 1.6.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! Select for DataTables 1.6.2
1
+ /*! Select for DataTables 1.7.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
@@ -18,7 +18,7 @@
18
18
  }
19
19
  };
20
20
 
21
- if (typeof window !== 'undefined') {
21
+ if (typeof window === 'undefined') {
22
22
  module.exports = function (root, $) {
23
23
  if ( ! root ) {
24
24
  // CommonJS environments without a window global must pass a
@@ -52,9 +52,9 @@ var DataTable = $.fn.dataTable;
52
52
  // Version information for debugger
53
53
  DataTable.select = {};
54
54
 
55
- DataTable.select.version = '1.6.2';
55
+ DataTable.select.version = '1.7.0';
56
56
 
57
- DataTable.select.init = function ( dt ) {
57
+ DataTable.select.init = function (dt) {
58
58
  var ctx = dt.settings()[0];
59
59
 
60
60
  if (ctx._select) {
@@ -63,58 +63,55 @@ DataTable.select.init = function ( dt ) {
63
63
 
64
64
  var savedSelected = dt.state.loaded();
65
65
 
66
- var selectAndSave = function(e, settings, data) {
67
- if(data === null || data.select === undefined) {
66
+ var selectAndSave = function (e, settings, data) {
67
+ if (data === null || data.select === undefined) {
68
68
  return;
69
69
  }
70
70
 
71
71
  // Clear any currently selected rows, before restoring state
72
72
  // None will be selected on first initialisation
73
- if (dt.rows({selected: true}).any()) {
73
+ if (dt.rows({ selected: true }).any()) {
74
74
  dt.rows().deselect();
75
75
  }
76
76
  if (data.select.rows !== undefined) {
77
77
  dt.rows(data.select.rows).select();
78
78
  }
79
79
 
80
- if (dt.columns({selected: true}).any()) {
80
+ if (dt.columns({ selected: true }).any()) {
81
81
  dt.columns().deselect();
82
82
  }
83
83
  if (data.select.columns !== undefined) {
84
84
  dt.columns(data.select.columns).select();
85
85
  }
86
86
 
87
- if (dt.cells({selected: true}).any()) {
87
+ if (dt.cells({ selected: true }).any()) {
88
88
  dt.cells().deselect();
89
89
  }
90
90
  if (data.select.cells !== undefined) {
91
- for(var i = 0; i < data.select.cells.length; i++) {
91
+ for (var i = 0; i < data.select.cells.length; i++) {
92
92
  dt.cell(data.select.cells[i].row, data.select.cells[i].column).select();
93
93
  }
94
94
  }
95
95
 
96
96
  dt.state.save();
97
- }
98
-
99
- dt
100
- .on('stateSaveParams', function(e, settings, data) {
101
- data.select = {};
102
- data.select.rows = dt.rows({selected:true}).ids(true).toArray();
103
- data.select.columns = dt.columns({selected:true})[0];
104
- data.select.cells = dt.cells({selected:true})[0].map(function(coords) {
105
- return {row: dt.row(coords.row).id(true), column: coords.column}
106
- });
107
- })
97
+ };
98
+
99
+ dt.on('stateSaveParams', function (e, settings, data) {
100
+ data.select = {};
101
+ data.select.rows = dt.rows({ selected: true }).ids(true).toArray();
102
+ data.select.columns = dt.columns({ selected: true })[0];
103
+ data.select.cells = dt.cells({ selected: true })[0].map(function (coords) {
104
+ return { row: dt.row(coords.row).id(true), column: coords.column };
105
+ });
106
+ })
108
107
  .on('stateLoadParams', selectAndSave)
109
- .one('init', function() {
108
+ .one('init', function () {
110
109
  selectAndSave(undefined, undefined, savedSelected);
111
110
  });
112
111
 
113
112
  var init = ctx.oInit.select;
114
113
  var defaults = DataTable.defaults.select;
115
- var opts = init === undefined ?
116
- defaults :
117
- init;
114
+ var opts = init === undefined ? defaults : init;
118
115
 
119
116
  // Set defaults
120
117
  var items = 'row';
@@ -129,32 +126,32 @@ DataTable.select.init = function ( dt ) {
129
126
  ctx._select = {};
130
127
 
131
128
  // Initialisation customisations
132
- if ( opts === true ) {
129
+ if (opts === true) {
133
130
  style = 'os';
134
131
  setStyle = true;
135
132
  }
136
- else if ( typeof opts === 'string' ) {
133
+ else if (typeof opts === 'string') {
137
134
  style = opts;
138
135
  setStyle = true;
139
136
  }
140
- else if ( $.isPlainObject( opts ) ) {
141
- if ( opts.blurable !== undefined ) {
137
+ else if ($.isPlainObject(opts)) {
138
+ if (opts.blurable !== undefined) {
142
139
  blurable = opts.blurable;
143
140
  }
144
-
145
- if ( opts.toggleable !== undefined ) {
141
+
142
+ if (opts.toggleable !== undefined) {
146
143
  toggleable = opts.toggleable;
147
144
  }
148
145
 
149
- if ( opts.info !== undefined ) {
146
+ if (opts.info !== undefined) {
150
147
  info = opts.info;
151
148
  }
152
149
 
153
- if ( opts.items !== undefined ) {
150
+ if (opts.items !== undefined) {
154
151
  items = opts.items;
155
152
  }
156
153
 
157
- if ( opts.style !== undefined ) {
154
+ if (opts.style !== undefined) {
158
155
  style = opts.style;
159
156
  setStyle = true;
160
157
  }
@@ -163,40 +160,43 @@ DataTable.select.init = function ( dt ) {
163
160
  setStyle = true;
164
161
  }
165
162
 
166
- if ( opts.selector !== undefined ) {
163
+ if (opts.selector !== undefined) {
167
164
  selector = opts.selector;
168
165
  }
169
166
 
170
- if ( opts.className !== undefined ) {
167
+ if (opts.className !== undefined) {
171
168
  className = opts.className;
172
169
  }
173
170
  }
174
171
 
175
- dt.select.selector( selector );
176
- dt.select.items( items );
177
- dt.select.style( style );
178
- dt.select.blurable( blurable );
179
- dt.select.toggleable( toggleable );
180
- dt.select.info( info );
172
+ dt.select.selector(selector);
173
+ dt.select.items(items);
174
+ dt.select.style(style);
175
+ dt.select.blurable(blurable);
176
+ dt.select.toggleable(toggleable);
177
+ dt.select.info(info);
181
178
  ctx._select.className = className;
182
179
 
183
-
184
180
  // Sort table based on selected rows. Requires Select Datatables extension
185
- $.fn.dataTable.ext.order['select-checkbox'] = function ( settings, col ) {
186
- return this.api().column( col, {order: 'index'} ).nodes().map( function ( td ) {
187
- if ( settings._select.items === 'row' ) {
188
- return $( td ).parent().hasClass( settings._select.className );
189
- } else if ( settings._select.items === 'cell' ) {
190
- return $( td ).hasClass( settings._select.className );
191
- }
192
- return false;
193
- });
181
+ $.fn.dataTable.ext.order['select-checkbox'] = function (settings, col) {
182
+ return this.api()
183
+ .column(col, { order: 'index' })
184
+ .nodes()
185
+ .map(function (td) {
186
+ if (settings._select.items === 'row') {
187
+ return $(td).parent().hasClass(settings._select.className);
188
+ }
189
+ else if (settings._select.items === 'cell') {
190
+ return $(td).hasClass(settings._select.className);
191
+ }
192
+ return false;
193
+ });
194
194
  };
195
195
 
196
196
  // If the init options haven't enabled select, but there is a selectable
197
197
  // class name, then enable
198
- if ( ! setStyle && $( dt.table().node() ).hasClass( 'selectable' ) ) {
199
- dt.select.style( 'os' );
198
+ if (!setStyle && $(dt.table().node()).hasClass('selectable')) {
199
+ dt.select.style('os');
200
200
  }
201
201
  };
202
202
 
@@ -264,7 +264,6 @@ handler that will select the items using the API methods.
264
264
 
265
265
  */
266
266
 
267
-
268
267
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
269
268
  * Local functions
270
269
  */
@@ -277,84 +276,87 @@ handler that will select the items using the API methods.
277
276
  * in the visible grid rather than by index in sequence. For example, if you
278
277
  * click first in cell 1-1 and then shift click in 2-2 - cells 1-2 and 2-1
279
278
  * should also be selected (and not 1-3, 1-4. etc)
280
- *
279
+ *
281
280
  * @param {DataTable.Api} dt DataTable
282
281
  * @param {object} idx Cell index to select to
283
282
  * @param {object} last Cell index to select from
284
283
  * @private
285
284
  */
286
- function cellRange( dt, idx, last )
287
- {
285
+ function cellRange(dt, idx, last) {
288
286
  var indexes;
289
287
  var columnIndexes;
290
288
  var rowIndexes;
291
- var selectColumns = function ( start, end ) {
292
- if ( start > end ) {
289
+ var selectColumns = function (start, end) {
290
+ if (start > end) {
293
291
  var tmp = end;
294
292
  end = start;
295
293
  start = tmp;
296
294
  }
297
-
295
+
298
296
  var record = false;
299
- return dt.columns( ':visible' ).indexes().filter( function (i) {
300
- if ( i === start ) {
301
- record = true;
302
- }
303
-
304
- if ( i === end ) { // not else if, as start might === end
305
- record = false;
306
- return true;
307
- }
297
+ return dt
298
+ .columns(':visible')
299
+ .indexes()
300
+ .filter(function (i) {
301
+ if (i === start) {
302
+ record = true;
303
+ }
308
304
 
309
- return record;
310
- } );
305
+ if (i === end) {
306
+ // not else if, as start might === end
307
+ record = false;
308
+ return true;
309
+ }
310
+
311
+ return record;
312
+ });
311
313
  };
312
314
 
313
- var selectRows = function ( start, end ) {
314
- var indexes = dt.rows( { search: 'applied' } ).indexes();
315
+ var selectRows = function (start, end) {
316
+ var indexes = dt.rows({ search: 'applied' }).indexes();
315
317
 
316
318
  // Which comes first - might need to swap
317
- if ( indexes.indexOf( start ) > indexes.indexOf( end ) ) {
319
+ if (indexes.indexOf(start) > indexes.indexOf(end)) {
318
320
  var tmp = end;
319
321
  end = start;
320
322
  start = tmp;
321
323
  }
322
324
 
323
325
  var record = false;
324
- return indexes.filter( function (i) {
325
- if ( i === start ) {
326
+ return indexes.filter(function (i) {
327
+ if (i === start) {
326
328
  record = true;
327
329
  }
328
-
329
- if ( i === end ) {
330
+
331
+ if (i === end) {
330
332
  record = false;
331
333
  return true;
332
334
  }
333
335
 
334
336
  return record;
335
- } );
337
+ });
336
338
  };
337
339
 
338
- if ( ! dt.cells( { selected: true } ).any() && ! last ) {
340
+ if (!dt.cells({ selected: true }).any() && !last) {
339
341
  // select from the top left cell to this one
340
- columnIndexes = selectColumns( 0, idx.column );
341
- rowIndexes = selectRows( 0 , idx.row );
342
+ columnIndexes = selectColumns(0, idx.column);
343
+ rowIndexes = selectRows(0, idx.row);
342
344
  }
343
345
  else {
344
346
  // Get column indexes between old and new
345
- columnIndexes = selectColumns( last.column, idx.column );
346
- rowIndexes = selectRows( last.row , idx.row );
347
+ columnIndexes = selectColumns(last.column, idx.column);
348
+ rowIndexes = selectRows(last.row, idx.row);
347
349
  }
348
350
 
349
- indexes = dt.cells( rowIndexes, columnIndexes ).flatten();
351
+ indexes = dt.cells(rowIndexes, columnIndexes).flatten();
350
352
 
351
- if ( ! dt.cells( idx, { selected: true } ).any() ) {
353
+ if (!dt.cells(idx, { selected: true }).any()) {
352
354
  // Select range
353
- dt.cells( indexes ).select();
355
+ dt.cells(indexes).select();
354
356
  }
355
357
  else {
356
358
  // Deselect range
357
- dt.cells( indexes ).deselect();
359
+ dt.cells(indexes).deselect();
358
360
  }
359
361
  }
360
362
 
@@ -364,17 +366,16 @@ function cellRange( dt, idx, last )
364
366
  * @param {DataTable.Api} dt DataTable to remove events from
365
367
  * @private
366
368
  */
367
- function disableMouseSelection( dt )
368
- {
369
+ function disableMouseSelection(dt) {
369
370
  var ctx = dt.settings()[0];
370
371
  var selector = ctx._select.selector;
371
372
 
372
- $( dt.table().container() )
373
- .off( 'mousedown.dtSelect', selector )
374
- .off( 'mouseup.dtSelect', selector )
375
- .off( 'click.dtSelect', selector );
373
+ $(dt.table().container())
374
+ .off('mousedown.dtSelect', selector)
375
+ .off('mouseup.dtSelect', selector)
376
+ .off('click.dtSelect', selector);
376
377
 
377
- $('body').off( 'click.dtSelect' + _safeId(dt.table().node()) );
378
+ $('body').off('click.dtSelect' + _safeId(dt.table().node()));
378
379
  }
379
380
 
380
381
  /**
@@ -383,47 +384,49 @@ function disableMouseSelection( dt )
383
384
  * @param {DataTable.Api} dt DataTable to remove events from
384
385
  * @private
385
386
  */
386
- function enableMouseSelection ( dt )
387
- {
388
- var container = $( dt.table().container() );
387
+ function enableMouseSelection(dt) {
388
+ var container = $(dt.table().container());
389
389
  var ctx = dt.settings()[0];
390
390
  var selector = ctx._select.selector;
391
391
  var matchSelection;
392
392
 
393
393
  container
394
- .on( 'mousedown.dtSelect', selector, function(e) {
394
+ .on('mousedown.dtSelect', selector, function (e) {
395
395
  // Disallow text selection for shift clicking on the table so multi
396
396
  // element selection doesn't look terrible!
397
- if ( e.shiftKey || e.metaKey || e.ctrlKey ) {
397
+ if (e.shiftKey || e.metaKey || e.ctrlKey) {
398
398
  container
399
- .css( '-moz-user-select', 'none' )
399
+ .css('-moz-user-select', 'none')
400
400
  .one('selectstart.dtSelect', selector, function () {
401
401
  return false;
402
- } );
402
+ });
403
403
  }
404
404
 
405
- if ( window.getSelection ) {
405
+ if (window.getSelection) {
406
406
  matchSelection = window.getSelection();
407
407
  }
408
- } )
409
- .on( 'mouseup.dtSelect', selector, function() {
408
+ })
409
+ .on('mouseup.dtSelect', selector, function () {
410
410
  // Allow text selection to occur again, Mozilla style (tested in FF
411
411
  // 35.0.1 - still required)
412
- container.css( '-moz-user-select', '' );
413
- } )
414
- .on( 'click.dtSelect', selector, function ( e ) {
412
+ container.css('-moz-user-select', '');
413
+ })
414
+ .on('click.dtSelect', selector, function (e) {
415
415
  var items = dt.select.items();
416
416
  var idx;
417
417
 
418
418
  // If text was selected (click and drag), then we shouldn't change
419
419
  // the row's selected state
420
- if ( matchSelection ) {
420
+ if (matchSelection) {
421
421
  var selection = window.getSelection();
422
422
 
423
423
  // If the element that contains the selection is not in the table, we can ignore it
424
424
  // This can happen if the developer selects text from the click event
425
- if ( ! selection.anchorNode || $(selection.anchorNode).closest('table')[0] === dt.table().node() ) {
426
- if ( selection !== matchSelection ) {
425
+ if (
426
+ !selection.anchorNode ||
427
+ $(selection.anchorNode).closest('table')[0] === dt.table().node()
428
+ ) {
429
+ if (selection !== matchSelection) {
427
430
  return;
428
431
  }
429
432
  }
@@ -433,71 +436,71 @@ function enableMouseSelection ( dt )
433
436
  var wrapperClass = dt.settings()[0].oClasses.sWrapper.trim().replace(/ +/g, '.');
434
437
 
435
438
  // Ignore clicks inside a sub-table
436
- if ( $(e.target).closest('div.'+wrapperClass)[0] != dt.table().container() ) {
439
+ if ($(e.target).closest('div.' + wrapperClass)[0] != dt.table().container()) {
437
440
  return;
438
441
  }
439
442
 
440
- var cell = dt.cell( $(e.target).closest('td, th') );
443
+ var cell = dt.cell($(e.target).closest('td, th'));
441
444
 
442
445
  // Check the cell actually belongs to the host DataTable (so child
443
446
  // rows, etc, are ignored)
444
- if ( ! cell.any() ) {
447
+ if (!cell.any()) {
445
448
  return;
446
449
  }
447
450
 
448
451
  var event = $.Event('user-select.dt');
449
- eventTrigger( dt, event, [ items, cell, e ] );
452
+ eventTrigger(dt, event, [items, cell, e]);
450
453
 
451
- if ( event.isDefaultPrevented() ) {
454
+ if (event.isDefaultPrevented()) {
452
455
  return;
453
456
  }
454
457
 
455
458
  var cellIndex = cell.index();
456
- if ( items === 'row' ) {
459
+ if (items === 'row') {
457
460
  idx = cellIndex.row;
458
- typeSelect( e, dt, ctx, 'row', idx );
461
+ typeSelect(e, dt, ctx, 'row', idx);
459
462
  }
460
- else if ( items === 'column' ) {
463
+ else if (items === 'column') {
461
464
  idx = cell.index().column;
462
- typeSelect( e, dt, ctx, 'column', idx );
465
+ typeSelect(e, dt, ctx, 'column', idx);
463
466
  }
464
- else if ( items === 'cell' ) {
467
+ else if (items === 'cell') {
465
468
  idx = cell.index();
466
- typeSelect( e, dt, ctx, 'cell', idx );
469
+ typeSelect(e, dt, ctx, 'cell', idx);
467
470
  }
468
471
 
469
472
  ctx._select_lastCell = cellIndex;
470
- } );
473
+ });
471
474
 
472
475
  // Blurable
473
- $('body').on( 'click.dtSelect' + _safeId(dt.table().node()), function ( e ) {
474
- if ( ctx._select.blurable ) {
476
+ $('body').on('click.dtSelect' + _safeId(dt.table().node()), function (e) {
477
+ if (ctx._select.blurable) {
475
478
  // If the click was inside the DataTables container, don't blur
476
- if ( $(e.target).parents().filter( dt.table().container() ).length ) {
479
+ if ($(e.target).parents().filter(dt.table().container()).length) {
477
480
  return;
478
481
  }
479
482
 
480
483
  // Ignore elements which have been removed from the DOM (i.e. paging
481
484
  // buttons)
482
- if ( $(e.target).parents('html').length === 0 ) {
483
- return;
485
+ if ($(e.target).parents('html').length === 0) {
486
+ return;
484
487
  }
485
488
 
486
489
  // Don't blur in Editor form
487
- if ( $(e.target).parents('div.DTE').length ) {
490
+ if ($(e.target).parents('div.DTE').length) {
488
491
  return;
489
492
  }
490
493
 
491
494
  var event = $.Event('select-blur.dt');
492
- eventTrigger( dt, event, [ e.target, e ] );
495
+ eventTrigger(dt, event, [e.target, e]);
493
496
 
494
- if ( event.isDefaultPrevented() ) {
497
+ if (event.isDefaultPrevented()) {
495
498
  return;
496
499
  }
497
500
 
498
- clear( ctx, true );
501
+ clear(ctx, true);
499
502
  }
500
- } );
503
+ });
501
504
  }
502
505
 
503
506
  /**
@@ -510,70 +513,72 @@ function enableMouseSelection ( dt )
510
513
  * triggering
511
514
  * @private
512
515
  */
513
- function eventTrigger ( api, type, args, any )
514
- {
515
- if ( any && ! api.flatten().length ) {
516
+ function eventTrigger(api, type, args, any) {
517
+ if (any && !api.flatten().length) {
516
518
  return;
517
519
  }
518
520
 
519
- if ( typeof type === 'string' ) {
520
- type = type +'.dt';
521
+ if (typeof type === 'string') {
522
+ type = type + '.dt';
521
523
  }
522
524
 
523
- args.unshift( api );
525
+ args.unshift(api);
524
526
 
525
- $(api.table().node()).trigger( type, args );
527
+ $(api.table().node()).trigger(type, args);
526
528
  }
527
529
 
528
530
  /**
529
531
  * Update the information element of the DataTable showing information about the
530
532
  * items selected. This is done by adding tags to the existing text
531
- *
533
+ *
532
534
  * @param {DataTable.Api} api DataTable to update
533
535
  * @private
534
536
  */
535
- function info ( api )
536
- {
537
+ function info(api) {
537
538
  var ctx = api.settings()[0];
538
539
 
539
- if ( ! ctx._select.info || ! ctx.aanFeatures.i ) {
540
+ if (!ctx._select.info || !ctx.aanFeatures.i) {
540
541
  return;
541
542
  }
542
543
 
543
- if ( api.select.style() === 'api' ) {
544
+ if (api.select.style() === 'api') {
544
545
  return;
545
546
  }
546
547
 
547
- var rows = api.rows( { selected: true } ).flatten().length;
548
- var columns = api.columns( { selected: true } ).flatten().length;
549
- var cells = api.cells( { selected: true } ).flatten().length;
550
-
551
- var add = function ( el, name, num ) {
552
- el.append( $('<span class="select-item"/>').append( api.i18n(
553
- 'select.'+name+'s',
554
- { _: '%d '+name+'s selected', 0: '', 1: '1 '+name+' selected' },
555
- num
556
- ) ) );
548
+ var rows = api.rows({ selected: true }).flatten().length;
549
+ var columns = api.columns({ selected: true }).flatten().length;
550
+ var cells = api.cells({ selected: true }).flatten().length;
551
+
552
+ var add = function (el, name, num) {
553
+ el.append(
554
+ $('<span class="select-item"/>').append(
555
+ api.i18n(
556
+ 'select.' + name + 's',
557
+ { _: '%d ' + name + 's selected', 0: '', 1: '1 ' + name + ' selected' },
558
+ num
559
+ )
560
+ )
561
+ );
557
562
  };
558
563
 
559
564
  // Internal knowledge of DataTables to loop over all information elements
560
- $.each( ctx.aanFeatures.i, function ( i, el ) {
565
+ $.each(ctx.aanFeatures.i, function (i, el) {
561
566
  el = $(el);
562
567
 
563
- var output = $('<span class="select-info"/>');
564
- add( output, 'row', rows );
565
- add( output, 'column', columns );
566
- add( output, 'cell', cells );
568
+ var output = $('<span class="select-info"/>');
569
+ add(output, 'row', rows);
570
+ add(output, 'column', columns);
571
+ add(output, 'cell', cells);
567
572
 
568
573
  var exisiting = el.children('span.select-info');
569
- if ( exisiting.length ) {
574
+ if (exisiting.length) {
570
575
  exisiting.remove();
571
576
  }
572
577
 
573
- if ( output.text() !== '' ) {
574
- el.append( output );
578
+ if (output.text() !== '') {
579
+ el.append(output);
575
580
  }
576
- } );
581
+ });
577
582
  }
578
583
 
579
584
  /**
@@ -586,41 +591,44 @@ function info ( api )
586
591
  * @param {DataTable.settings} ctx Settings object to operate on
587
592
  * @private
588
593
  */
589
- function init ( ctx ) {
590
- var api = new DataTable.Api( ctx );
594
+ function init(ctx) {
595
+ var api = new DataTable.Api(ctx);
591
596
  ctx._select_init = true;
592
597
 
593
598
  // Row callback so that classes can be added to rows and cells if the item
594
599
  // was selected before the element was created. This will happen with the
595
600
  // `deferRender` option enabled.
596
- //
601
+ //
597
602
  // This method of attaching to `aoRowCreatedCallback` is a hack until
598
603
  // DataTables has proper events for row manipulation If you are reviewing
599
604
  // this code to create your own plug-ins, please do not do this!
600
- ctx.aoRowCreatedCallback.push( {
601
- fn: function ( row, data, index ) {
605
+ ctx.aoRowCreatedCallback.push({
606
+ fn: function (row, data, index) {
602
607
  var i, ien;
603
- var d = ctx.aoData[ index ];
608
+ var d = ctx.aoData[index];
604
609
 
605
610
  // Row
606
- if ( d._select_selected ) {
607
- $( row ).addClass( ctx._select.className );
611
+ if (d._select_selected) {
612
+ $(row).addClass(ctx._select.className);
608
613
  }
609
614
 
610
615
  // Cells and columns - if separated out, we would need to do two
611
616
  // loops, so it makes sense to combine them into a single one
612
- for ( i=0, ien=ctx.aoColumns.length ; i<ien ; i++ ) {
613
- if ( ctx.aoColumns[i]._select_selected || (d._selected_cells && d._selected_cells[i]) ) {
614
- $(d.anCells[i]).addClass( ctx._select.className );
617
+ for (i = 0, ien = ctx.aoColumns.length; i < ien; i++) {
618
+ if (
619
+ ctx.aoColumns[i]._select_selected ||
620
+ (d._selected_cells && d._selected_cells[i])
621
+ ) {
622
+ $(d.anCells[i]).addClass(ctx._select.className);
615
623
  }
616
624
  }
617
625
  },
618
626
  sName: 'select-deferRender'
619
- } );
627
+ });
620
628
 
621
629
  // On Ajax reload we want to reselect all rows which are currently selected,
622
630
  // if there is an rowId (i.e. a unique value to identify each row with)
623
- api.on( 'preXhr.dt.dtSelect', function (e, settings) {
631
+ api.on('preXhr.dt.dtSelect', function (e, settings) {
624
632
  if (settings !== api.settings()[0]) {
625
633
  // Not triggered by our DataTable!
626
634
  return;
@@ -628,47 +636,52 @@ function init ( ctx ) {
628
636
 
629
637
  // note that column selection doesn't need to be cached and then
630
638
  // reselected, as they are already selected
631
- var rows = api.rows( { selected: true } ).ids( true ).filter( function ( d ) {
632
- return d !== undefined;
633
- } );
639
+ var rows = api
640
+ .rows({ selected: true })
641
+ .ids(true)
642
+ .filter(function (d) {
643
+ return d !== undefined;
644
+ });
634
645
 
635
- var cells = api.cells( { selected: true } ).eq(0).map( function ( cellIdx ) {
636
- var id = api.row( cellIdx.row ).id( true );
637
- return id ?
638
- { row: id, column: cellIdx.column } :
639
- undefined;
640
- } ).filter( function ( d ) {
641
- return d !== undefined;
642
- } );
646
+ var cells = api
647
+ .cells({ selected: true })
648
+ .eq(0)
649
+ .map(function (cellIdx) {
650
+ var id = api.row(cellIdx.row).id(true);
651
+ return id ? { row: id, column: cellIdx.column } : undefined;
652
+ })
653
+ .filter(function (d) {
654
+ return d !== undefined;
655
+ });
643
656
 
644
657
  // On the next draw, reselect the currently selected items
645
- api.one( 'draw.dt.dtSelect', function () {
646
- api.rows( rows ).select();
658
+ api.one('draw.dt.dtSelect', function () {
659
+ api.rows(rows).select();
647
660
 
648
661
  // `cells` is not a cell index selector, so it needs a loop
649
- if ( cells.any() ) {
650
- cells.each( function ( id ) {
651
- api.cells( id.row, id.column ).select();
652
- } );
662
+ if (cells.any()) {
663
+ cells.each(function (id) {
664
+ api.cells(id.row, id.column).select();
665
+ });
653
666
  }
654
- } );
655
- } );
667
+ });
668
+ });
656
669
 
657
670
  // Update the table information element with selected item summary
658
- api.on( 'draw.dtSelect.dt select.dtSelect.dt deselect.dtSelect.dt info.dt', function () {
659
- info( api );
671
+ api.on('draw.dtSelect.dt select.dtSelect.dt deselect.dtSelect.dt info.dt', function () {
672
+ info(api);
660
673
  api.state.save();
661
- } );
674
+ });
662
675
 
663
676
  // Clean up and release
664
- api.on( 'destroy.dtSelect', function () {
677
+ api.on('destroy.dtSelect', function () {
665
678
  // Remove class directly rather than calling deselect - which would trigger events
666
- $(api.rows({selected: true}).nodes()).removeClass(api.settings()[0]._select.className);
679
+ $(api.rows({ selected: true }).nodes()).removeClass(api.settings()[0]._select.className);
667
680
 
668
- disableMouseSelection( api );
669
- api.off( '.dtSelect' );
681
+ disableMouseSelection(api);
682
+ api.off('.dtSelect');
670
683
  $('body').off('.dtSelect' + _safeId(api.table().node()));
671
- } );
684
+ });
672
685
  }
673
686
 
674
687
  /**
@@ -681,38 +694,37 @@ function init ( ctx ) {
681
694
  * @param {object} last Item index to select from
682
695
  * @private
683
696
  */
684
- function rowColumnRange( dt, type, idx, last )
685
- {
697
+ function rowColumnRange(dt, type, idx, last) {
686
698
  // Add a range of rows from the last selected row to this one
687
- var indexes = dt[type+'s']( { search: 'applied' } ).indexes();
688
- var idx1 = $.inArray( last, indexes );
689
- var idx2 = $.inArray( idx, indexes );
699
+ var indexes = dt[type + 's']({ search: 'applied' }).indexes();
700
+ var idx1 = $.inArray(last, indexes);
701
+ var idx2 = $.inArray(idx, indexes);
690
702
 
691
- if ( ! dt[type+'s']( { selected: true } ).any() && idx1 === -1 ) {
703
+ if (!dt[type + 's']({ selected: true }).any() && idx1 === -1) {
692
704
  // select from top to here - slightly odd, but both Windows and Mac OS
693
705
  // do this
694
- indexes.splice( $.inArray( idx, indexes )+1, indexes.length );
706
+ indexes.splice($.inArray(idx, indexes) + 1, indexes.length);
695
707
  }
696
708
  else {
697
709
  // reverse so we can shift click 'up' as well as down
698
- if ( idx1 > idx2 ) {
710
+ if (idx1 > idx2) {
699
711
  var tmp = idx2;
700
712
  idx2 = idx1;
701
713
  idx1 = tmp;
702
714
  }
703
715
 
704
- indexes.splice( idx2+1, indexes.length );
705
- indexes.splice( 0, idx1 );
716
+ indexes.splice(idx2 + 1, indexes.length);
717
+ indexes.splice(0, idx1);
706
718
  }
707
719
 
708
- if ( ! dt[type]( idx, { selected: true } ).any() ) {
720
+ if (!dt[type](idx, { selected: true }).any()) {
709
721
  // Select range
710
- dt[type+'s']( indexes ).select();
722
+ dt[type + 's'](indexes).select();
711
723
  }
712
724
  else {
713
725
  // Deselect range - need to keep the clicked on row selected
714
- indexes.splice( $.inArray( idx, indexes ), 1 );
715
- dt[type+'s']( indexes ).deselect();
726
+ indexes.splice($.inArray(idx, indexes), 1);
727
+ dt[type + 's'](indexes).deselect();
716
728
  }
717
729
  }
718
730
 
@@ -724,14 +736,13 @@ function rowColumnRange( dt, type, idx, last )
724
736
  * of selection style
725
737
  * @private
726
738
  */
727
- function clear( ctx, force )
728
- {
729
- if ( force || ctx._select.style === 'single' ) {
730
- var api = new DataTable.Api( ctx );
731
-
732
- api.rows( { selected: true } ).deselect();
733
- api.columns( { selected: true } ).deselect();
734
- api.cells( { selected: true } ).deselect();
739
+ function clear(ctx, force) {
740
+ if (force || ctx._select.style === 'single') {
741
+ var api = new DataTable.Api(ctx);
742
+
743
+ api.rows({ selected: true }).deselect();
744
+ api.columns({ selected: true }).deselect();
745
+ api.cells({ selected: true }).deselect();
735
746
  }
736
747
  }
737
748
 
@@ -745,72 +756,74 @@ function clear( ctx, force )
745
756
  * @param {int|object} idx Index of the item to select
746
757
  * @private
747
758
  */
748
- function typeSelect ( e, dt, ctx, type, idx )
749
- {
759
+ function typeSelect(e, dt, ctx, type, idx) {
750
760
  var style = dt.select.style();
751
761
  var toggleable = dt.select.toggleable();
752
- var isSelected = dt[type]( idx, { selected: true } ).any();
753
-
754
- if ( isSelected && ! toggleable ) {
762
+ var isSelected = dt[type](idx, { selected: true }).any();
763
+
764
+ if (isSelected && !toggleable) {
755
765
  return;
756
766
  }
757
767
 
758
- if ( style === 'os' ) {
759
- if ( e.ctrlKey || e.metaKey ) {
768
+ if (style === 'os') {
769
+ if (e.ctrlKey || e.metaKey) {
760
770
  // Add or remove from the selection
761
- dt[type]( idx ).select( ! isSelected );
771
+ dt[type](idx).select(!isSelected);
762
772
  }
763
- else if ( e.shiftKey ) {
764
- if ( type === 'cell' ) {
765
- cellRange( dt, idx, ctx._select_lastCell || null );
773
+ else if (e.shiftKey) {
774
+ if (type === 'cell') {
775
+ cellRange(dt, idx, ctx._select_lastCell || null);
766
776
  }
767
777
  else {
768
- rowColumnRange( dt, type, idx, ctx._select_lastCell ?
769
- ctx._select_lastCell[type] :
770
- null
778
+ rowColumnRange(
779
+ dt,
780
+ type,
781
+ idx,
782
+ ctx._select_lastCell ? ctx._select_lastCell[type] : null
771
783
  );
772
784
  }
773
785
  }
774
786
  else {
775
787
  // No cmd or shift click - deselect if selected, or select
776
788
  // this row only
777
- var selected = dt[type+'s']( { selected: true } );
789
+ var selected = dt[type + 's']({ selected: true });
778
790
 
779
- if ( isSelected && selected.flatten().length === 1 ) {
780
- dt[type]( idx ).deselect();
791
+ if (isSelected && selected.flatten().length === 1) {
792
+ dt[type](idx).deselect();
781
793
  }
782
794
  else {
783
795
  selected.deselect();
784
- dt[type]( idx ).select();
796
+ dt[type](idx).select();
785
797
  }
786
798
  }
787
- } else if ( style == 'multi+shift' ) {
788
- if ( e.shiftKey ) {
789
- if ( type === 'cell' ) {
790
- cellRange( dt, idx, ctx._select_lastCell || null );
799
+ }
800
+ else if (style == 'multi+shift') {
801
+ if (e.shiftKey) {
802
+ if (type === 'cell') {
803
+ cellRange(dt, idx, ctx._select_lastCell || null);
791
804
  }
792
805
  else {
793
- rowColumnRange( dt, type, idx, ctx._select_lastCell ?
794
- ctx._select_lastCell[type] :
795
- null
806
+ rowColumnRange(
807
+ dt,
808
+ type,
809
+ idx,
810
+ ctx._select_lastCell ? ctx._select_lastCell[type] : null
796
811
  );
797
812
  }
798
813
  }
799
814
  else {
800
- dt[ type ]( idx ).select( ! isSelected );
815
+ dt[type](idx).select(!isSelected);
801
816
  }
802
817
  }
803
818
  else {
804
- dt[ type ]( idx ).select( ! isSelected );
819
+ dt[type](idx).select(!isSelected);
805
820
  }
806
821
  }
807
822
 
808
- function _safeId( node ) {
823
+ function _safeId(node) {
809
824
  return node.id.replace(/[^a-zA-Z0-9\-\_]/g, '-');
810
825
  }
811
826
 
812
-
813
-
814
827
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
815
828
  * DataTables selectors
816
829
  */
@@ -818,56 +831,62 @@ function _safeId( node ) {
818
831
  // row and column are basically identical just assigned to different properties
819
832
  // and checking a different array, so we can dynamically create the functions to
820
833
  // reduce the code size
821
- $.each( [
822
- { type: 'row', prop: 'aoData' },
823
- { type: 'column', prop: 'aoColumns' }
824
- ], function ( i, o ) {
825
- DataTable.ext.selector[ o.type ].push( function ( settings, opts, indexes ) {
826
- var selected = opts.selected;
827
- var data;
828
- var out = [];
829
-
830
- if ( selected !== true && selected !== false ) {
831
- return indexes;
832
- }
834
+ $.each(
835
+ [
836
+ { type: 'row', prop: 'aoData' },
837
+ { type: 'column', prop: 'aoColumns' }
838
+ ],
839
+ function (i, o) {
840
+ DataTable.ext.selector[o.type].push(function (settings, opts, indexes) {
841
+ var selected = opts.selected;
842
+ var data;
843
+ var out = [];
844
+
845
+ if (selected !== true && selected !== false) {
846
+ return indexes;
847
+ }
833
848
 
834
- for ( var i=0, ien=indexes.length ; i<ien ; i++ ) {
835
- data = settings[ o.prop ][ indexes[i] ];
849
+ for (var i = 0, ien = indexes.length; i < ien; i++) {
850
+ data = settings[o.prop][indexes[i]];
836
851
 
837
- if ( (selected === true && data._select_selected === true) ||
838
- (selected === false && ! data._select_selected )
839
- ) {
840
- out.push( indexes[i] );
852
+ if (
853
+ (selected === true && data._select_selected === true) ||
854
+ (selected === false && !data._select_selected)
855
+ ) {
856
+ out.push(indexes[i]);
857
+ }
841
858
  }
842
- }
843
859
 
844
- return out;
845
- } );
846
- } );
860
+ return out;
861
+ });
862
+ }
863
+ );
847
864
 
848
- DataTable.ext.selector.cell.push( function ( settings, opts, cells ) {
865
+ DataTable.ext.selector.cell.push(function (settings, opts, cells) {
849
866
  var selected = opts.selected;
850
867
  var rowData;
851
868
  var out = [];
852
869
 
853
- if ( selected === undefined ) {
870
+ if (selected === undefined) {
854
871
  return cells;
855
872
  }
856
873
 
857
- for ( var i=0, ien=cells.length ; i<ien ; i++ ) {
858
- rowData = settings.aoData[ cells[i].row ];
874
+ for (var i = 0, ien = cells.length; i < ien; i++) {
875
+ rowData = settings.aoData[cells[i].row];
859
876
 
860
- if ( (selected === true && rowData._selected_cells && rowData._selected_cells[ cells[i].column ] === true) ||
861
- (selected === false && ( ! rowData._selected_cells || ! rowData._selected_cells[ cells[i].column ] ) )
877
+ if (
878
+ (selected === true &&
879
+ rowData._selected_cells &&
880
+ rowData._selected_cells[cells[i].column] === true) ||
881
+ (selected === false &&
882
+ (!rowData._selected_cells || !rowData._selected_cells[cells[i].column]))
862
883
  ) {
863
- out.push( cells[i] );
884
+ out.push(cells[i]);
864
885
  }
865
886
  }
866
887
 
867
888
  return out;
868
- } );
869
-
870
-
889
+ });
871
890
 
872
891
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
873
892
  * DataTables API
@@ -880,67 +899,67 @@ DataTable.ext.selector.cell.push( function ( settings, opts, cells ) {
880
899
  var apiRegister = DataTable.Api.register;
881
900
  var apiRegisterPlural = DataTable.Api.registerPlural;
882
901
 
883
- apiRegister( 'select()', function () {
884
- return this.iterator( 'table', function ( ctx ) {
885
- DataTable.select.init( new DataTable.Api( ctx ) );
886
- } );
887
- } );
902
+ apiRegister('select()', function () {
903
+ return this.iterator('table', function (ctx) {
904
+ DataTable.select.init(new DataTable.Api(ctx));
905
+ });
906
+ });
888
907
 
889
- apiRegister( 'select.blurable()', function ( flag ) {
890
- if ( flag === undefined ) {
908
+ apiRegister('select.blurable()', function (flag) {
909
+ if (flag === undefined) {
891
910
  return this.context[0]._select.blurable;
892
911
  }
893
912
 
894
- return this.iterator( 'table', function ( ctx ) {
913
+ return this.iterator('table', function (ctx) {
895
914
  ctx._select.blurable = flag;
896
- } );
897
- } );
915
+ });
916
+ });
898
917
 
899
- apiRegister( 'select.toggleable()', function ( flag ) {
900
- if ( flag === undefined ) {
918
+ apiRegister('select.toggleable()', function (flag) {
919
+ if (flag === undefined) {
901
920
  return this.context[0]._select.toggleable;
902
921
  }
903
922
 
904
- return this.iterator( 'table', function ( ctx ) {
923
+ return this.iterator('table', function (ctx) {
905
924
  ctx._select.toggleable = flag;
906
- } );
907
- } );
925
+ });
926
+ });
908
927
 
909
- apiRegister( 'select.info()', function ( flag ) {
910
- if ( flag === undefined ) {
928
+ apiRegister('select.info()', function (flag) {
929
+ if (flag === undefined) {
911
930
  return this.context[0]._select.info;
912
931
  }
913
932
 
914
- return this.iterator( 'table', function ( ctx ) {
933
+ return this.iterator('table', function (ctx) {
915
934
  ctx._select.info = flag;
916
- } );
917
- } );
935
+ });
936
+ });
918
937
 
919
- apiRegister( 'select.items()', function ( items ) {
920
- if ( items === undefined ) {
938
+ apiRegister('select.items()', function (items) {
939
+ if (items === undefined) {
921
940
  return this.context[0]._select.items;
922
941
  }
923
942
 
924
- return this.iterator( 'table', function ( ctx ) {
943
+ return this.iterator('table', function (ctx) {
925
944
  ctx._select.items = items;
926
945
 
927
- eventTrigger( new DataTable.Api( ctx ), 'selectItems', [ items ] );
928
- } );
929
- } );
946
+ eventTrigger(new DataTable.Api(ctx), 'selectItems', [items]);
947
+ });
948
+ });
930
949
 
931
950
  // Takes effect from the _next_ selection. None disables future selection, but
932
951
  // does not clear the current selection. Use the `deselect` methods for that
933
- apiRegister( 'select.style()', function ( style ) {
934
- if ( style === undefined ) {
952
+ apiRegister('select.style()', function (style) {
953
+ if (style === undefined) {
935
954
  return this.context[0]._select.style;
936
955
  }
937
956
 
938
- return this.iterator( 'table', function ( ctx ) {
939
- if ( ! ctx._select ) {
940
- DataTable.select.init( new DataTable.Api(ctx) );
957
+ return this.iterator('table', function (ctx) {
958
+ if (!ctx._select) {
959
+ DataTable.select.init(new DataTable.Api(ctx));
941
960
  }
942
961
 
943
- if ( ! ctx._select_init ) {
962
+ if (!ctx._select_init) {
944
963
  init(ctx);
945
964
  }
946
965
 
@@ -948,144 +967,132 @@ apiRegister( 'select.style()', function ( style ) {
948
967
 
949
968
  // Add / remove mouse event handlers. They aren't required when only
950
969
  // API selection is available
951
- var dt = new DataTable.Api( ctx );
952
- disableMouseSelection( dt );
953
-
954
- if ( style !== 'api' ) {
955
- enableMouseSelection( dt );
970
+ var dt = new DataTable.Api(ctx);
971
+ disableMouseSelection(dt);
972
+
973
+ if (style !== 'api') {
974
+ enableMouseSelection(dt);
956
975
  }
957
976
 
958
- eventTrigger( new DataTable.Api( ctx ), 'selectStyle', [ style ] );
959
- } );
960
- } );
977
+ eventTrigger(new DataTable.Api(ctx), 'selectStyle', [style]);
978
+ });
979
+ });
961
980
 
962
- apiRegister( 'select.selector()', function ( selector ) {
963
- if ( selector === undefined ) {
981
+ apiRegister('select.selector()', function (selector) {
982
+ if (selector === undefined) {
964
983
  return this.context[0]._select.selector;
965
984
  }
966
985
 
967
- return this.iterator( 'table', function ( ctx ) {
968
- disableMouseSelection( new DataTable.Api( ctx ) );
986
+ return this.iterator('table', function (ctx) {
987
+ disableMouseSelection(new DataTable.Api(ctx));
969
988
 
970
989
  ctx._select.selector = selector;
971
990
 
972
- if ( ctx._select.style !== 'api' ) {
973
- enableMouseSelection( new DataTable.Api( ctx ) );
991
+ if (ctx._select.style !== 'api') {
992
+ enableMouseSelection(new DataTable.Api(ctx));
974
993
  }
975
- } );
976
- } );
977
-
994
+ });
995
+ });
978
996
 
979
-
980
- apiRegisterPlural( 'rows().select()', 'row().select()', function ( select ) {
997
+ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
981
998
  var api = this;
982
999
 
983
- if ( select === false ) {
1000
+ if (select === false) {
984
1001
  return this.deselect();
985
1002
  }
986
1003
 
987
- this.iterator( 'row', function ( ctx, idx ) {
988
- clear( ctx );
1004
+ this.iterator('row', function (ctx, idx) {
1005
+ clear(ctx);
989
1006
 
990
- ctx.aoData[ idx ]._select_selected = true;
991
- $( ctx.aoData[ idx ].nTr ).addClass( ctx._select.className );
992
- } );
1007
+ ctx.aoData[idx]._select_selected = true;
1008
+ $(ctx.aoData[idx].nTr).addClass(ctx._select.className);
1009
+ });
993
1010
 
994
- this.iterator( 'table', function ( ctx, i ) {
995
- eventTrigger( api, 'select', [ 'row', api[i] ], true );
996
- } );
1011
+ this.iterator('table', function (ctx, i) {
1012
+ eventTrigger(api, 'select', ['row', api[i]], true);
1013
+ });
997
1014
 
998
1015
  return this;
999
- } );
1016
+ });
1000
1017
 
1001
- apiRegister( 'row().selected()', function () {
1018
+ apiRegister('row().selected()', function () {
1002
1019
  var ctx = this.context[0];
1003
1020
 
1004
- if (
1005
- ctx &&
1006
- this.length &&
1007
- ctx.aoData[this[0]] &&
1008
- ctx.aoData[this[0]]._select_selected
1009
- ) {
1021
+ if (ctx && this.length && ctx.aoData[this[0]] && ctx.aoData[this[0]]._select_selected) {
1010
1022
  return true;
1011
1023
  }
1012
1024
 
1013
1025
  return false;
1014
- } );
1026
+ });
1015
1027
 
1016
- apiRegisterPlural( 'columns().select()', 'column().select()', function ( select ) {
1028
+ apiRegisterPlural('columns().select()', 'column().select()', function (select) {
1017
1029
  var api = this;
1018
1030
 
1019
- if ( select === false ) {
1031
+ if (select === false) {
1020
1032
  return this.deselect();
1021
1033
  }
1022
1034
 
1023
- this.iterator( 'column', function ( ctx, idx ) {
1024
- clear( ctx );
1035
+ this.iterator('column', function (ctx, idx) {
1036
+ clear(ctx);
1025
1037
 
1026
- ctx.aoColumns[ idx ]._select_selected = true;
1038
+ ctx.aoColumns[idx]._select_selected = true;
1027
1039
 
1028
- var column = new DataTable.Api( ctx ).column( idx );
1040
+ var column = new DataTable.Api(ctx).column(idx);
1029
1041
 
1030
- $( column.header() ).addClass( ctx._select.className );
1031
- $( column.footer() ).addClass( ctx._select.className );
1042
+ $(column.header()).addClass(ctx._select.className);
1043
+ $(column.footer()).addClass(ctx._select.className);
1032
1044
 
1033
- column.nodes().to$().addClass( ctx._select.className );
1034
- } );
1045
+ column.nodes().to$().addClass(ctx._select.className);
1046
+ });
1035
1047
 
1036
- this.iterator( 'table', function ( ctx, i ) {
1037
- eventTrigger( api, 'select', [ 'column', api[i] ], true );
1038
- } );
1048
+ this.iterator('table', function (ctx, i) {
1049
+ eventTrigger(api, 'select', ['column', api[i]], true);
1050
+ });
1039
1051
 
1040
1052
  return this;
1041
- } );
1053
+ });
1042
1054
 
1043
- apiRegister( 'column().selected()', function () {
1055
+ apiRegister('column().selected()', function () {
1044
1056
  var ctx = this.context[0];
1045
1057
 
1046
- if (
1047
- ctx &&
1048
- this.length &&
1049
- ctx.aoColumns[this[0]] &&
1050
- ctx.aoColumns[this[0]]._select_selected
1051
- ) {
1058
+ if (ctx && this.length && ctx.aoColumns[this[0]] && ctx.aoColumns[this[0]]._select_selected) {
1052
1059
  return true;
1053
1060
  }
1054
1061
 
1055
1062
  return false;
1056
- } );
1063
+ });
1057
1064
 
1058
- apiRegisterPlural( 'cells().select()', 'cell().select()', function ( select ) {
1065
+ apiRegisterPlural('cells().select()', 'cell().select()', function (select) {
1059
1066
  var api = this;
1060
1067
 
1061
- if ( select === false ) {
1068
+ if (select === false) {
1062
1069
  return this.deselect();
1063
1070
  }
1064
1071
 
1065
- this.iterator( 'cell', function ( ctx, rowIdx, colIdx ) {
1066
- clear( ctx );
1072
+ this.iterator('cell', function (ctx, rowIdx, colIdx) {
1073
+ clear(ctx);
1067
1074
 
1068
- var data = ctx.aoData[ rowIdx ];
1075
+ var data = ctx.aoData[rowIdx];
1069
1076
 
1070
- if ( data._selected_cells === undefined ) {
1077
+ if (data._selected_cells === undefined) {
1071
1078
  data._selected_cells = [];
1072
1079
  }
1073
1080
 
1074
- data._selected_cells[ colIdx ] = true;
1081
+ data._selected_cells[colIdx] = true;
1075
1082
 
1076
- if ( data.anCells ) {
1077
- $( data.anCells[ colIdx ] ).addClass( ctx._select.className );
1083
+ if (data.anCells) {
1084
+ $(data.anCells[colIdx]).addClass(ctx._select.className);
1078
1085
  }
1079
- } );
1086
+ });
1080
1087
 
1081
- this.iterator( 'table', function ( ctx, i ) {
1082
- eventTrigger( api, 'select', [ 'cell', api.cells(api[i]).indexes().toArray() ], true );
1083
- } );
1088
+ this.iterator('table', function (ctx, i) {
1089
+ eventTrigger(api, 'select', ['cell', api.cells(api[i]).indexes().toArray()], true);
1090
+ });
1084
1091
 
1085
1092
  return this;
1086
- } );
1093
+ });
1087
1094
 
1088
- apiRegister( 'cell().selected()', function () {
1095
+ apiRegister('cell().selected()', function () {
1089
1096
  var ctx = this.context[0];
1090
1097
 
1091
1098
  if (ctx && this.length) {
@@ -1097,110 +1104,109 @@ apiRegister( 'cell().selected()', function () {
1097
1104
  }
1098
1105
 
1099
1106
  return false;
1100
- } );
1101
-
1107
+ });
1102
1108
 
1103
- apiRegisterPlural( 'rows().deselect()', 'row().deselect()', function () {
1109
+ apiRegisterPlural('rows().deselect()', 'row().deselect()', function () {
1104
1110
  var api = this;
1105
1111
 
1106
- this.iterator( 'row', function ( ctx, idx ) {
1107
- ctx.aoData[ idx ]._select_selected = false;
1112
+ this.iterator('row', function (ctx, idx) {
1113
+ ctx.aoData[idx]._select_selected = false;
1108
1114
  ctx._select_lastCell = null;
1109
- $( ctx.aoData[ idx ].nTr ).removeClass( ctx._select.className );
1110
- } );
1115
+ $(ctx.aoData[idx].nTr).removeClass(ctx._select.className);
1116
+ });
1111
1117
 
1112
- this.iterator( 'table', function ( ctx, i ) {
1113
- eventTrigger( api, 'deselect', [ 'row', api[i] ], true );
1114
- } );
1118
+ this.iterator('table', function (ctx, i) {
1119
+ eventTrigger(api, 'deselect', ['row', api[i]], true);
1120
+ });
1115
1121
 
1116
1122
  return this;
1117
- } );
1123
+ });
1118
1124
 
1119
- apiRegisterPlural( 'columns().deselect()', 'column().deselect()', function () {
1125
+ apiRegisterPlural('columns().deselect()', 'column().deselect()', function () {
1120
1126
  var api = this;
1121
1127
 
1122
- this.iterator( 'column', function ( ctx, idx ) {
1123
- ctx.aoColumns[ idx ]._select_selected = false;
1128
+ this.iterator('column', function (ctx, idx) {
1129
+ ctx.aoColumns[idx]._select_selected = false;
1124
1130
 
1125
- var api = new DataTable.Api( ctx );
1126
- var column = api.column( idx );
1131
+ var api = new DataTable.Api(ctx);
1132
+ var column = api.column(idx);
1127
1133
 
1128
- $( column.header() ).removeClass( ctx._select.className );
1129
- $( column.footer() ).removeClass( ctx._select.className );
1134
+ $(column.header()).removeClass(ctx._select.className);
1135
+ $(column.footer()).removeClass(ctx._select.className);
1130
1136
 
1131
1137
  // Need to loop over each cell, rather than just using
1132
1138
  // `column().nodes()` as cells which are individually selected should
1133
1139
  // not have the `selected` class removed from them
1134
- api.cells( null, idx ).indexes().each( function (cellIdx) {
1135
- var data = ctx.aoData[ cellIdx.row ];
1136
- var cellSelected = data._selected_cells;
1137
-
1138
- if ( data.anCells && (! cellSelected || ! cellSelected[ cellIdx.column ]) ) {
1139
- $( data.anCells[ cellIdx.column ] ).removeClass( ctx._select.className );
1140
- }
1141
- } );
1142
- } );
1140
+ api.cells(null, idx)
1141
+ .indexes()
1142
+ .each(function (cellIdx) {
1143
+ var data = ctx.aoData[cellIdx.row];
1144
+ var cellSelected = data._selected_cells;
1145
+
1146
+ if (data.anCells && (!cellSelected || !cellSelected[cellIdx.column])) {
1147
+ $(data.anCells[cellIdx.column]).removeClass(ctx._select.className);
1148
+ }
1149
+ });
1150
+ });
1143
1151
 
1144
- this.iterator( 'table', function ( ctx, i ) {
1145
- eventTrigger( api, 'deselect', [ 'column', api[i] ], true );
1146
- } );
1152
+ this.iterator('table', function (ctx, i) {
1153
+ eventTrigger(api, 'deselect', ['column', api[i]], true);
1154
+ });
1147
1155
 
1148
1156
  return this;
1149
- } );
1157
+ });
1150
1158
 
1151
- apiRegisterPlural( 'cells().deselect()', 'cell().deselect()', function () {
1159
+ apiRegisterPlural('cells().deselect()', 'cell().deselect()', function () {
1152
1160
  var api = this;
1153
1161
 
1154
- this.iterator( 'cell', function ( ctx, rowIdx, colIdx ) {
1155
- var data = ctx.aoData[ rowIdx ];
1162
+ this.iterator('cell', function (ctx, rowIdx, colIdx) {
1163
+ var data = ctx.aoData[rowIdx];
1156
1164
 
1157
- if(data._selected_cells !== undefined) {
1158
- data._selected_cells[ colIdx ] = false;
1165
+ if (data._selected_cells !== undefined) {
1166
+ data._selected_cells[colIdx] = false;
1159
1167
  }
1160
1168
 
1161
1169
  // Remove class only if the cells exist, and the cell is not column
1162
1170
  // selected, in which case the class should remain (since it is selected
1163
1171
  // in the column)
1164
- if ( data.anCells && ! ctx.aoColumns[ colIdx ]._select_selected ) {
1165
- $( data.anCells[ colIdx ] ).removeClass( ctx._select.className );
1172
+ if (data.anCells && !ctx.aoColumns[colIdx]._select_selected) {
1173
+ $(data.anCells[colIdx]).removeClass(ctx._select.className);
1166
1174
  }
1167
- } );
1175
+ });
1168
1176
 
1169
- this.iterator( 'table', function ( ctx, i ) {
1170
- eventTrigger( api, 'deselect', [ 'cell', api[i] ], true );
1171
- } );
1177
+ this.iterator('table', function (ctx, i) {
1178
+ eventTrigger(api, 'deselect', ['cell', api[i]], true);
1179
+ });
1172
1180
 
1173
1181
  return this;
1174
- } );
1175
-
1176
-
1182
+ });
1177
1183
 
1178
1184
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1179
1185
  * Buttons
1180
1186
  */
1181
- function i18n( label, def ) {
1187
+ function i18n(label, def) {
1182
1188
  return function (dt) {
1183
- return dt.i18n( 'buttons.'+label, def );
1189
+ return dt.i18n('buttons.' + label, def);
1184
1190
  };
1185
1191
  }
1186
1192
 
1187
1193
  // Common events with suitable namespaces
1188
- function namespacedEvents ( config ) {
1194
+ function namespacedEvents(config) {
1189
1195
  var unique = config._eventNamespace;
1190
1196
 
1191
- return 'draw.dt.DT'+unique+' select.dt.DT'+unique+' deselect.dt.DT'+unique;
1197
+ return 'draw.dt.DT' + unique + ' select.dt.DT' + unique + ' deselect.dt.DT' + unique;
1192
1198
  }
1193
1199
 
1194
- function enabled ( dt, config ) {
1195
- if ( $.inArray( 'rows', config.limitTo ) !== -1 && dt.rows( { selected: true } ).any() ) {
1200
+ function enabled(dt, config) {
1201
+ if ($.inArray('rows', config.limitTo) !== -1 && dt.rows({ selected: true }).any()) {
1196
1202
  return true;
1197
1203
  }
1198
1204
 
1199
- if ( $.inArray( 'columns', config.limitTo ) !== -1 && dt.columns( { selected: true } ).any() ) {
1205
+ if ($.inArray('columns', config.limitTo) !== -1 && dt.columns({ selected: true }).any()) {
1200
1206
  return true;
1201
1207
  }
1202
1208
 
1203
- if ( $.inArray( 'cells', config.limitTo ) !== -1 && dt.cells( { selected: true } ).any() ) {
1209
+ if ($.inArray('cells', config.limitTo) !== -1 && dt.cells({ selected: true }).any()) {
1204
1210
  return true;
1205
1211
  }
1206
1212
 
@@ -1209,82 +1215,96 @@ function enabled ( dt, config ) {
1209
1215
 
1210
1216
  var _buttonNamespace = 0;
1211
1217
 
1212
- $.extend( DataTable.ext.buttons, {
1218
+ $.extend(DataTable.ext.buttons, {
1213
1219
  selected: {
1214
- text: i18n( 'selected', 'Selected' ),
1220
+ text: i18n('selected', 'Selected'),
1215
1221
  className: 'buttons-selected',
1216
- limitTo: [ 'rows', 'columns', 'cells' ],
1217
- init: function ( dt, node, config ) {
1222
+ limitTo: ['rows', 'columns', 'cells'],
1223
+ init: function (dt, node, config) {
1218
1224
  var that = this;
1219
- config._eventNamespace = '.select'+(_buttonNamespace++);
1225
+ config._eventNamespace = '.select' + _buttonNamespace++;
1220
1226
 
1221
1227
  // .DT namespace listeners are removed by DataTables automatically
1222
1228
  // on table destroy
1223
- dt.on( namespacedEvents(config), function () {
1224
- that.enable( enabled(dt, config) );
1225
- } );
1229
+ dt.on(namespacedEvents(config), function () {
1230
+ that.enable(enabled(dt, config));
1231
+ });
1226
1232
 
1227
1233
  this.disable();
1228
1234
  },
1229
- destroy: function ( dt, node, config ) {
1230
- dt.off( config._eventNamespace );
1235
+ destroy: function (dt, node, config) {
1236
+ dt.off(config._eventNamespace);
1231
1237
  }
1232
1238
  },
1233
1239
  selectedSingle: {
1234
- text: i18n( 'selectedSingle', 'Selected single' ),
1240
+ text: i18n('selectedSingle', 'Selected single'),
1235
1241
  className: 'buttons-selected-single',
1236
- init: function ( dt, node, config ) {
1242
+ init: function (dt, node, config) {
1237
1243
  var that = this;
1238
- config._eventNamespace = '.select'+(_buttonNamespace++);
1244
+ config._eventNamespace = '.select' + _buttonNamespace++;
1239
1245
 
1240
- dt.on( namespacedEvents(config), function () {
1241
- var count = dt.rows( { selected: true } ).flatten().length +
1242
- dt.columns( { selected: true } ).flatten().length +
1243
- dt.cells( { selected: true } ).flatten().length;
1246
+ dt.on(namespacedEvents(config), function () {
1247
+ var count =
1248
+ dt.rows({ selected: true }).flatten().length +
1249
+ dt.columns({ selected: true }).flatten().length +
1250
+ dt.cells({ selected: true }).flatten().length;
1244
1251
 
1245
- that.enable( count === 1 );
1246
- } );
1252
+ that.enable(count === 1);
1253
+ });
1247
1254
 
1248
1255
  this.disable();
1249
1256
  },
1250
- destroy: function ( dt, node, config ) {
1251
- dt.off( config._eventNamespace );
1257
+ destroy: function (dt, node, config) {
1258
+ dt.off(config._eventNamespace);
1252
1259
  }
1253
1260
  },
1254
1261
  selectAll: {
1255
- text: i18n( 'selectAll', 'Select all' ),
1262
+ text: i18n('selectAll', 'Select all'),
1256
1263
  className: 'buttons-select-all',
1257
- action: function () {
1264
+ action: function (e, dt, node, config) {
1258
1265
  var items = this.select.items();
1259
- this[ items+'s' ]().select();
1266
+ var mod = config.selectorModifier;
1267
+
1268
+ if (mod) {
1269
+ if (typeof mod === 'function') {
1270
+ mod = mod.call(dt, e, dt, node, config);
1271
+ }
1272
+
1273
+ this[items + 's'](mod).select();
1274
+ }
1275
+ else {
1276
+ this[items + 's']().select();
1277
+ }
1260
1278
  }
1279
+ // selectorModifier can be specified
1261
1280
  },
1262
1281
  selectNone: {
1263
- text: i18n( 'selectNone', 'Deselect all' ),
1282
+ text: i18n('selectNone', 'Deselect all'),
1264
1283
  className: 'buttons-select-none',
1265
1284
  action: function () {
1266
- clear( this.settings()[0], true );
1285
+ clear(this.settings()[0], true);
1267
1286
  },
1268
- init: function ( dt, node, config ) {
1287
+ init: function (dt, node, config) {
1269
1288
  var that = this;
1270
- config._eventNamespace = '.select'+(_buttonNamespace++);
1289
+ config._eventNamespace = '.select' + _buttonNamespace++;
1271
1290
 
1272
- dt.on( namespacedEvents(config), function () {
1273
- var count = dt.rows( { selected: true } ).flatten().length +
1274
- dt.columns( { selected: true } ).flatten().length +
1275
- dt.cells( { selected: true } ).flatten().length;
1291
+ dt.on(namespacedEvents(config), function () {
1292
+ var count =
1293
+ dt.rows({ selected: true }).flatten().length +
1294
+ dt.columns({ selected: true }).flatten().length +
1295
+ dt.cells({ selected: true }).flatten().length;
1276
1296
 
1277
- that.enable( count > 0 );
1278
- } );
1297
+ that.enable(count > 0);
1298
+ });
1279
1299
 
1280
1300
  this.disable();
1281
1301
  },
1282
- destroy: function ( dt, node, config ) {
1283
- dt.off( config._eventNamespace );
1302
+ destroy: function (dt, node, config) {
1303
+ dt.off(config._eventNamespace);
1284
1304
  }
1285
1305
  },
1286
1306
  showSelected: {
1287
- text: i18n( 'showSelected', 'Show only selected' ),
1307
+ text: i18n('showSelected', 'Show only selected'),
1288
1308
  className: 'buttons-show-selected',
1289
1309
  action: function (e, dt, node, conf) {
1290
1310
  // Works by having a filtering function which will reduce to the selected
@@ -1310,7 +1330,7 @@ $.extend( DataTable.ext.buttons, {
1310
1330
  let row = s.aoData[idx];
1311
1331
 
1312
1332
  return row._select_selected;
1313
- }
1333
+ };
1314
1334
 
1315
1335
  conf._filter = fn;
1316
1336
  DataTable.ext.search.push(fn);
@@ -1321,27 +1341,26 @@ $.extend( DataTable.ext.buttons, {
1321
1341
  dt.draw();
1322
1342
  }
1323
1343
  }
1324
- } );
1344
+ });
1325
1345
 
1326
- $.each( [ 'Row', 'Column', 'Cell' ], function ( i, item ) {
1346
+ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1327
1347
  var lc = item.toLowerCase();
1328
1348
 
1329
- DataTable.ext.buttons[ 'select'+item+'s' ] = {
1330
- text: i18n( 'select'+item+'s', 'Select '+lc+'s' ),
1331
- className: 'buttons-select-'+lc+'s',
1349
+ DataTable.ext.buttons['select' + item + 's'] = {
1350
+ text: i18n('select' + item + 's', 'Select ' + lc + 's'),
1351
+ className: 'buttons-select-' + lc + 's',
1332
1352
  action: function () {
1333
- this.select.items( lc );
1353
+ this.select.items(lc);
1334
1354
  },
1335
- init: function ( dt ) {
1355
+ init: function (dt) {
1336
1356
  var that = this;
1337
1357
 
1338
- dt.on( 'selectItems.dt.DT', function ( e, ctx, items ) {
1339
- that.active( items === lc );
1340
- } );
1358
+ dt.on('selectItems.dt.DT', function (e, ctx, items) {
1359
+ that.active(items === lc);
1360
+ });
1341
1361
  }
1342
1362
  };
1343
- } );
1344
-
1363
+ });
1345
1364
 
1346
1365
  $.fn.DataTable.select = DataTable.select;
1347
1366
 
@@ -1353,13 +1372,13 @@ $.fn.DataTable.select = DataTable.select;
1353
1372
  // this required that the table be in the document! If it isn't then something
1354
1373
  // needs to trigger this method unfortunately. The next major release of
1355
1374
  // DataTables will rework the events and address this.
1356
- $(document).on( 'preInit.dt.dtSelect', function (e, ctx) {
1357
- if ( e.namespace !== 'dt' ) {
1375
+ $(document).on('preInit.dt.dtSelect', function (e, ctx) {
1376
+ if (e.namespace !== 'dt') {
1358
1377
  return;
1359
1378
  }
1360
1379
 
1361
- DataTable.select.init( new DataTable.Api( ctx ) );
1362
- } );
1380
+ DataTable.select.init(new DataTable.Api(ctx));
1381
+ });
1363
1382
 
1364
1383
 
1365
1384
  return DataTable;