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 ( $ , Modernizr , Drupal ) {
function CollapsibleDetails ( node ) {
this . $node = $ ( node ) ;
this . $node . data ( 'details' , this ) ;
2018-11-23 12:29:20 +00:00
var anchor = window . location . hash && window . location . hash !== '#' ? ', ' + window . location . hash : '' ;
2015-08-17 17:00:26 -07:00
if ( this . $node . find ( '.error' + anchor ) . length ) {
this . $node . attr ( 'open' , true ) ;
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
this . setupSummary ( ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
this . setupLegend ( ) ;
}
2018-11-23 12:29:20 +00:00
$ . extend ( CollapsibleDetails , {
2015-08-17 17:00:26 -07:00
instances : [ ]
} ) ;
2018-11-23 12:29:20 +00:00
$ . extend ( CollapsibleDetails . prototype , {
setupSummary : function setupSummary ( ) {
2015-08-17 17:00:26 -07:00
this . $summary = $ ( '<span class="summary"></span>' ) ;
2018-11-23 12:29:20 +00:00
this . $node . on ( 'summaryUpdated' , $ . proxy ( this . onSummaryUpdated , this ) ) . trigger ( 'summaryUpdated' ) ;
2015-08-17 17:00:26 -07:00
} ,
2018-11-23 12:29:20 +00:00
setupLegend : function setupLegend ( ) {
2015-08-17 17:00:26 -07:00
var $legend = this . $node . find ( '> summary' ) ;
2018-11-23 12:29:20 +00:00
$ ( '<span class="details-summary-prefix visually-hidden"></span>' ) . append ( this . $node . attr ( 'open' ) ? Drupal . t ( 'Hide' ) : Drupal . t ( 'Show' ) ) . prependTo ( $legend ) . after ( document . createTextNode ( ' ' ) ) ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
$ ( '<a class="details-title"></a>' ) . attr ( 'href' , '#' + this . $node . attr ( 'id' ) ) . prepend ( $legend . contents ( ) ) . appendTo ( $legend ) ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
$legend . append ( this . $summary ) . on ( 'click' , $ . proxy ( this . onLegendClick , this ) ) ;
2015-08-17 17:00:26 -07:00
} ,
2018-11-23 12:29:20 +00:00
onLegendClick : function onLegendClick ( e ) {
2015-08-17 17:00:26 -07:00
this . toggle ( ) ;
e . preventDefault ( ) ;
} ,
2018-11-23 12:29:20 +00:00
onSummaryUpdated : function onSummaryUpdated ( ) {
2015-08-17 17:00:26 -07:00
var text = $ . trim ( this . $node . drupalGetSummary ( ) ) ;
this . $summary . html ( text ? ' (' + text + ')' : '' ) ;
} ,
2018-11-23 12:29:20 +00:00
toggle : function toggle ( ) {
var _this = this ;
2015-08-17 17:00:26 -07:00
var isOpen = ! ! this . $node . attr ( 'open' ) ;
var $summaryPrefix = this . $node . find ( '> summary span.details-summary-prefix' ) ;
if ( isOpen ) {
$summaryPrefix . html ( Drupal . t ( 'Show' ) ) ;
2018-11-23 12:29:20 +00:00
} else {
2015-08-17 17:00:26 -07:00
$summaryPrefix . html ( Drupal . t ( 'Hide' ) ) ;
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
setTimeout ( function ( ) {
2018-11-23 12:29:20 +00:00
_this . $node . attr ( 'open' , ! isOpen ) ;
} , 0 ) ;
2015-08-17 17:00:26 -07:00
}
} ) ;
Drupal . behaviors . collapse = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context ) {
2015-08-17 17:00:26 -07:00
if ( Modernizr . details ) {
return ;
}
var $collapsibleDetails = $ ( context ) . find ( 'details' ) . once ( 'collapse' ) . addClass ( 'collapse-processed' ) ;
if ( $collapsibleDetails . length ) {
for ( var i = 0 ; i < $collapsibleDetails . length ; i ++ ) {
CollapsibleDetails . instances . push ( new CollapsibleDetails ( $collapsibleDetails [ i ] ) ) ;
}
}
}
} ;
2018-11-23 12:29:20 +00:00
var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange ( e , $target ) {
$target . parents ( 'details' ) . not ( '[open]' ) . find ( '> summary' ) . trigger ( 'click' ) ;
} ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
$ ( 'body' ) . on ( 'formFragmentLinkClickOrHashChange.details' , handleFragmentLinkClickOrHashChange ) ;
Drupal . CollapsibleDetails = CollapsibleDetails ;
} ) ( jQuery , Modernizr , Drupal ) ;