2015-06-08 14:04:39 +00:00
/ * *
2017-05-19 22:12:53 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
2017-05-23 14:30:14 +00:00
* https : //www.drupal.org/node/2815083
2017-05-19 22:12:53 +00:00
* @ preserve
* * /
2015-06-08 14:04:39 +00:00
2012-09-26 18:26:15 +00:00
( function ( $ , Drupal , window ) {
2014-01-27 21:41:32 +00:00
Drupal . behaviors . tableResponsive = {
2017-05-19 22:12:53 +00:00
attach : function attach ( context , settings ) {
2014-01-27 21:41:32 +00:00
var $tables = $ ( context ) . find ( 'table.responsive-enabled' ) . once ( 'tableresponsive' ) ;
if ( $tables . length ) {
2015-04-19 15:30:43 +00:00
var il = $tables . length ;
for ( var i = 0 ; i < il ; i ++ ) {
2014-01-27 21:41:32 +00:00
TableResponsive . tables . push ( new TableResponsive ( $tables [ i ] ) ) ;
}
2012-09-26 18:26:15 +00:00
}
}
2014-01-27 21:41:32 +00:00
} ;
2012-09-26 18:26:15 +00:00
2014-01-27 21:41:32 +00:00
function TableResponsive ( table ) {
this . table = table ;
this . $table = $ ( table ) ;
this . showText = Drupal . t ( 'Show all columns' ) ;
2015-03-23 10:58:52 +00:00
this . hideText = Drupal . t ( 'Hide lower priority columns' ) ;
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
this . $headers = this . $table . find ( 'th' ) ;
2017-05-19 22:12:53 +00:00
this . $link = $ ( '<button type="button" class="link tableresponsive-toggle"></button>' ) . attr ( 'title' , Drupal . t ( 'Show table cells that were hidden to make the table fit within a small screen.' ) ) . on ( 'click' , $ . proxy ( this , 'eventhandlerToggleColumns' ) ) ;
2012-09-26 18:26:15 +00:00
2014-01-27 21:41:32 +00:00
this . $table . before ( $ ( '<div class="tableresponsive-toggle-columns"></div>' ) . append ( this . $link ) ) ;
2012-09-26 18:26:15 +00:00
2017-05-19 22:12:53 +00:00
$ ( window ) . on ( 'resize.tableresponsive' , $ . proxy ( this , 'eventhandlerEvaluateColumnVisibility' ) ) . trigger ( 'resize.tableresponsive' ) ;
2014-01-27 21:41:32 +00:00
}
2012-09-26 18:26:15 +00:00
2017-05-19 22:12:53 +00:00
$ . extend ( TableResponsive , {
2014-01-27 21:41:32 +00:00
tables : [ ]
} ) ;
2012-09-26 18:26:15 +00:00
2017-05-19 22:12:53 +00:00
$ . extend ( TableResponsive . prototype , {
eventhandlerEvaluateColumnVisibility : function eventhandlerEvaluateColumnVisibility ( e ) {
2014-01-27 21:41:32 +00:00
var pegged = parseInt ( this . $link . data ( 'pegged' ) , 10 ) ;
var hiddenLength = this . $headers . filter ( '.priority-medium:hidden, .priority-low:hidden' ) . length ;
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
if ( hiddenLength > 0 ) {
this . $link . show ( ) . text ( this . showText ) ;
}
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
if ( ! pegged && hiddenLength === 0 ) {
this . $link . hide ( ) . text ( this . hideText ) ;
}
} ,
2017-05-19 22:12:53 +00:00
eventhandlerToggleColumns : function eventhandlerToggleColumns ( e ) {
2014-01-27 21:41:32 +00:00
e . preventDefault ( ) ;
var self = this ;
var $hiddenHeaders = this . $headers . filter ( '.priority-medium:hidden, .priority-low:hidden' ) ;
this . $revealedCells = this . $revealedCells || $ ( ) ;
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
if ( $hiddenHeaders . length > 0 ) {
$hiddenHeaders . each ( function ( index , element ) {
var $header = $ ( this ) ;
var position = $header . prevAll ( 'th' ) . length ;
self . $table . find ( 'tbody tr' ) . each ( function ( ) {
2015-04-15 07:59:36 +00:00
var $cells = $ ( this ) . find ( 'td' ) . eq ( position ) ;
2014-01-27 21:41:32 +00:00
$cells . show ( ) ;
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
self . $revealedCells = $ ( ) . add ( self . $revealedCells ) . add ( $cells ) ;
} ) ;
$header . show ( ) ;
2017-05-19 22:12:53 +00:00
2014-01-27 21:41:32 +00:00
self . $revealedCells = $ ( ) . add ( self . $revealedCells ) . add ( $header ) ;
2012-09-26 18:26:15 +00:00
} ) ;
2014-01-27 21:41:32 +00:00
this . $link . text ( this . hideText ) . data ( 'pegged' , 1 ) ;
2017-05-19 22:12:53 +00:00
} else {
this . $revealedCells . hide ( ) ;
this . $revealedCells . each ( function ( index , element ) {
var $cell = $ ( this ) ;
var properties = $cell . attr ( 'style' ) . split ( ';' ) ;
var newProps = [ ] ;
var match = /^display\s*\:\s*none$/ ;
for ( var i = 0 ; i < properties . length ; i ++ ) {
var prop = properties [ i ] ;
prop . trim ( ) ;
var isDisplayNone = match . exec ( prop ) ;
if ( isDisplayNone ) {
continue ;
}
newProps . push ( prop ) ;
2014-01-27 21:41:32 +00:00
}
2017-05-19 22:12:53 +00:00
$cell . attr ( 'style' , newProps . join ( ';' ) ) ;
} ) ;
this . $link . text ( this . showText ) . data ( 'pegged' , 0 ) ;
$ ( window ) . trigger ( 'resize.tableresponsive' ) ;
}
2012-09-26 18:26:15 +00:00
}
2014-01-27 21:41:32 +00:00
} ) ;
2015-06-08 14:04:39 +00:00
2014-01-27 21:41:32 +00:00
Drupal . TableResponsive = TableResponsive ;
2017-05-19 22:12:53 +00:00
} ) ( jQuery , Drupal , window ) ;