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 ) {
function DropButton ( dropbutton , settings ) {
2018-11-23 12:29:20 +00:00
var options = $ . extend ( { title : Drupal . t ( 'List additional actions' ) } , settings ) ;
2015-08-17 17:00:26 -07:00
var $dropbutton = $ ( dropbutton ) ;
this . $dropbutton = $dropbutton ;
this . $list = $dropbutton . find ( '.dropbutton' ) ;
this . $actions = this . $list . find ( 'li' ) . addClass ( 'dropbutton-action' ) ;
if ( this . $actions . length > 1 ) {
var $primary = this . $actions . slice ( 0 , 1 ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
var $secondary = this . $actions . slice ( 1 ) ;
$secondary . addClass ( 'secondary-action' ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
$primary . after ( Drupal . theme ( 'dropbuttonToggle' , options ) ) ;
2018-11-23 12:29:20 +00:00
this . $dropbutton . addClass ( 'dropbutton-multiple' ) . on ( {
'mouseleave.dropbutton' : $ . proxy ( this . hoverOut , this ) ,
'mouseenter.dropbutton' : $ . proxy ( this . hoverIn , this ) ,
'focusout.dropbutton' : $ . proxy ( this . focusOut , this ) ,
'focusin.dropbutton' : $ . proxy ( this . focusIn , this )
} ) ;
} else {
2015-08-17 17:00:26 -07:00
this . $dropbutton . addClass ( 'dropbutton-single' ) ;
}
}
2018-11-23 12:29:20 +00:00
function dropbuttonClickHandler ( e ) {
e . preventDefault ( ) ;
$ ( e . target ) . closest ( '.dropbutton-wrapper' ) . toggleClass ( 'open' ) ;
}
Drupal . behaviors . dropButton = {
attach : function attach ( context , settings ) {
var $dropbuttons = $ ( context ) . find ( '.dropbutton-wrapper' ) . once ( 'dropbutton' ) ;
if ( $dropbuttons . length ) {
var $body = $ ( 'body' ) . once ( 'dropbutton-click' ) ;
if ( $body . length ) {
$body . on ( 'click' , '.dropbutton-toggle' , dropbuttonClickHandler ) ;
}
var il = $dropbuttons . length ;
for ( var i = 0 ; i < il ; i ++ ) {
DropButton . dropbuttons . push ( new DropButton ( $dropbuttons [ i ] , settings . dropbutton ) ) ;
}
}
}
} ;
$ . extend ( DropButton , {
2015-08-17 17:00:26 -07:00
dropbuttons : [ ]
} ) ;
2018-11-23 12:29:20 +00:00
$ . extend ( DropButton . prototype , {
toggle : function toggle ( show ) {
2015-08-17 17:00:26 -07:00
var isBool = typeof show === 'boolean' ;
show = isBool ? show : ! this . $dropbutton . hasClass ( 'open' ) ;
this . $dropbutton . toggleClass ( 'open' , show ) ;
} ,
2018-11-23 12:29:20 +00:00
hoverIn : function hoverIn ( ) {
2015-08-17 17:00:26 -07:00
if ( this . timerID ) {
window . clearTimeout ( this . timerID ) ;
}
} ,
2018-11-23 12:29:20 +00:00
hoverOut : function hoverOut ( ) {
2015-08-17 17:00:26 -07:00
this . timerID = window . setTimeout ( $ . proxy ( this , 'close' ) , 500 ) ;
} ,
2018-11-23 12:29:20 +00:00
open : function open ( ) {
2015-08-17 17:00:26 -07:00
this . toggle ( true ) ;
} ,
2018-11-23 12:29:20 +00:00
close : function close ( ) {
2015-08-17 17:00:26 -07:00
this . toggle ( false ) ;
} ,
2018-11-23 12:29:20 +00:00
focusOut : function focusOut ( e ) {
2015-08-17 17:00:26 -07:00
this . hoverOut . call ( this , e ) ;
} ,
2018-11-23 12:29:20 +00:00
focusIn : function focusIn ( e ) {
2015-08-17 17:00:26 -07:00
this . hoverIn . call ( this , e ) ;
}
} ) ;
2018-11-23 12:29:20 +00:00
$ . extend ( Drupal . theme , {
dropbuttonToggle : function dropbuttonToggle ( options ) {
2015-08-17 17:00:26 -07:00
return '<li class="dropbutton-toggle"><button type="button"><span class="dropbutton-arrow"><span class="visually-hidden">' + options . title + '</span></span></button></li>' ;
}
} ) ;
Drupal . DropButton = DropButton ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal ) ;