2015-08-17 17:00:26 -07:00
/ * *
2018-11-23 12:29:20 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2015-08-17 17:00:26 -07:00
( function ( $ , Drupal ) {
Drupal . behaviors . tableSelect = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context , settings ) {
2015-08-17 17:00:26 -07:00
$ ( context ) . find ( 'th.select-all' ) . closest ( 'table' ) . once ( 'table-select' ) . each ( Drupal . tableSelect ) ;
}
} ;
Drupal . tableSelect = function ( ) {
if ( $ ( this ) . find ( 'td input[type="checkbox"]' ) . length === 0 ) {
return ;
}
var table = this ;
2018-11-23 12:29:20 +00:00
var checkboxes = void 0 ;
var lastChecked = void 0 ;
2015-08-17 17:00:26 -07:00
var $table = $ ( table ) ;
2015-09-04 13:20:09 -07:00
var strings = {
selectAll : Drupal . t ( 'Select all rows in this table' ) ,
selectNone : Drupal . t ( 'Deselect all rows in this table' )
} ;
2018-11-23 12:29:20 +00:00
var updateSelectAll = function updateSelectAll ( state ) {
2015-08-17 17:00:26 -07:00
$table . prev ( 'table.sticky-header' ) . addBack ( ) . find ( 'th.select-all input[type="checkbox"]' ) . each ( function ( ) {
2016-01-06 16:31:26 -08:00
var $checkbox = $ ( this ) ;
var stateChanged = $checkbox . prop ( 'checked' ) !== state ;
$checkbox . attr ( 'title' , state ? strings . selectNone : strings . selectAll ) ;
2015-08-17 17:00:26 -07:00
2016-01-06 16:31:26 -08:00
if ( stateChanged ) {
$checkbox . prop ( 'checked' , state ) . trigger ( 'change' ) ;
}
2015-08-17 17:00:26 -07:00
} ) ;
} ;
$table . find ( 'th.select-all' ) . prepend ( $ ( '<input type="checkbox" class="form-checkbox" />' ) . attr ( 'title' , strings . selectAll ) ) . on ( 'click' , function ( event ) {
if ( $ ( event . target ) . is ( 'input[type="checkbox"]' ) ) {
checkboxes . each ( function ( ) {
2016-01-06 16:31:26 -08:00
var $checkbox = $ ( this ) ;
var stateChanged = $checkbox . prop ( 'checked' ) !== event . target . checked ;
2015-08-17 17:00:26 -07:00
2016-01-06 16:31:26 -08:00
if ( stateChanged ) {
$checkbox . prop ( 'checked' , event . target . checked ) . trigger ( 'change' ) ;
}
2015-08-17 17:00:26 -07:00
2016-01-06 16:31:26 -08:00
$checkbox . closest ( 'tr' ) . toggleClass ( 'selected' , this . checked ) ;
2015-08-17 17:00:26 -07:00
} ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
updateSelectAll ( event . target . checked ) ;
}
} ) ;
checkboxes = $table . find ( 'td input[type="checkbox"]:enabled' ) . on ( '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 ) ;
}
2018-11-23 12:29:20 +00:00
updateSelectAll ( checkboxes . length === checkboxes . filter ( ':checked' ) . length ) ;
2015-08-17 17:00:26 -07:00
lastChecked = e . target ;
} ) ;
2018-11-23 12:29:20 +00:00
updateSelectAll ( checkboxes . length === checkboxes . filter ( ':checked' ) . length ) ;
2015-08-17 17:00:26 -07:00
} ;
Drupal . tableSelectRange = function ( from , to , state ) {
var mode = from . rowIndex > to . rowIndex ? 'previousSibling' : 'nextSibling' ;
for ( var i = from [ mode ] ; i ; i = i [ mode ] ) {
2018-11-23 12:29:20 +00:00
var $i = $ ( i ) ;
2015-08-17 17:00:26 -07:00
if ( i . nodeType !== 1 ) {
continue ;
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
$i . toggleClass ( 'selected' , state ) ;
$i . find ( 'input[type="checkbox"]' ) . prop ( 'checked' , state ) ;
if ( to . nodeType ) {
if ( i === to ) {
break ;
}
2018-11-23 12:29:20 +00:00
} else if ( $ . filter ( to , [ i ] ) . r . length ) {
break ;
}
2015-08-17 17:00:26 -07:00
}
} ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal ) ;