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 , drupalSettings ) {
2018-11-23 12:29:20 +00:00
var options = $ . extend ( {
breakpoints : {
'toolbar.narrow' : '' ,
'toolbar.standard' : '' ,
'toolbar.wide' : ''
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
} , drupalSettings . toolbar , {
strings : {
horizontal : Drupal . t ( 'Horizontal orientation' ) ,
vertical : Drupal . t ( 'Vertical orientation' )
}
} ) ;
2015-08-17 17:00:26 -07:00
Drupal . behaviors . toolbar = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context ) {
2015-08-17 17:00:26 -07:00
if ( ! window . matchMedia ( 'only screen' ) . matches ) {
return ;
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
$ ( context ) . find ( '#toolbar-administration' ) . once ( 'toolbar' ) . each ( function ( ) {
2018-11-23 12:29:20 +00:00
var model = new Drupal . toolbar . ToolbarModel ( {
locked : JSON . parse ( localStorage . getItem ( 'Drupal.toolbar.trayVerticalLocked' ) ) ,
activeTab : document . getElementById ( JSON . parse ( localStorage . getItem ( 'Drupal.toolbar.activeTabID' ) ) ) ,
height : $ ( '#toolbar-administration' ) . outerHeight ( )
} ) ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
Drupal . toolbar . models . toolbarModel = model ;
Object . keys ( options . breakpoints ) . forEach ( function ( label ) {
var mq = options . breakpoints [ label ] ;
var mql = window . matchMedia ( mq ) ;
Drupal . toolbar . mql [ label ] = mql ;
mql . addListener ( Drupal . toolbar . mediaQueryChangeHandler . bind ( null , model , label ) ) ;
Drupal . toolbar . mediaQueryChangeHandler . call ( null , model , label , mql ) ;
2015-08-17 17:00:26 -07:00
} ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
Drupal . toolbar . views . toolbarVisualView = new Drupal . toolbar . ToolbarVisualView ( {
el : this ,
model : model ,
strings : options . strings
} ) ;
Drupal . toolbar . views . toolbarAuralView = new Drupal . toolbar . ToolbarAuralView ( {
el : this ,
model : model ,
strings : options . strings
} ) ;
Drupal . toolbar . views . bodyVisualView = new Drupal . toolbar . BodyVisualView ( {
el : this ,
model : model
} ) ;
2018-11-23 12:29:20 +00:00
model . trigger ( 'change:isFixed' , model , model . get ( 'isFixed' ) ) ;
model . trigger ( 'change:activeTray' , model , model . get ( 'activeTray' ) ) ;
var menuModel = new Drupal . toolbar . MenuModel ( ) ;
Drupal . toolbar . models . menuModel = menuModel ;
2015-08-17 17:00:26 -07:00
Drupal . toolbar . views . menuVisualView = new Drupal . toolbar . MenuVisualView ( {
el : $ ( this ) . find ( '.toolbar-menu-administration' ) . get ( 0 ) ,
model : menuModel ,
strings : options . strings
} ) ;
Drupal . toolbar . setSubtrees . done ( function ( subtrees ) {
menuModel . set ( 'subtrees' , subtrees ) ;
2015-08-27 12:03:05 -07:00
var theme = drupalSettings . ajaxPageState . theme ;
localStorage . setItem ( 'Drupal.toolbar.subtrees.' + theme , JSON . stringify ( subtrees ) ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
model . set ( 'areSubtreesLoaded' , true ) ;
} ) ;
Drupal . toolbar . views . toolbarVisualView . loadSubtrees ( ) ;
2018-11-23 12:29:20 +00:00
$ ( document ) . on ( 'drupalViewportOffsetChange.toolbar' , function ( event , offsets ) {
model . set ( 'offsets' , offsets ) ;
} ) ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
model . on ( 'change:orientation' , function ( model , orientation ) {
$ ( document ) . trigger ( 'drupalToolbarOrientationChange' , orientation ) ;
} ) . on ( 'change:activeTab' , function ( model , tab ) {
$ ( document ) . trigger ( 'drupalToolbarTabChange' , tab ) ;
} ) . on ( 'change:activeTray' , function ( model , tray ) {
$ ( document ) . trigger ( 'drupalToolbarTrayChange' , tray ) ;
} ) ;
2015-08-17 17:00:26 -07:00
if ( Drupal . toolbar . models . toolbarModel . get ( 'orientation' ) === 'horizontal' && Drupal . toolbar . models . toolbarModel . get ( 'activeTab' ) === null ) {
Drupal . toolbar . models . toolbarModel . set ( {
2015-09-04 13:20:09 -07:00
activeTab : $ ( '.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a' ) . get ( 0 )
2015-08-17 17:00:26 -07:00
} ) ;
}
2018-11-23 12:29:20 +00:00
$ ( window ) . on ( {
'dialog:aftercreate' : function dialogAftercreate ( event , dialog , $element , settings ) {
var $toolbar = $ ( '#toolbar-bar' ) ;
$toolbar . css ( 'margin-top' , '0' ) ;
if ( settings . drupalOffCanvasPosition === 'top' ) {
var height = Drupal . offCanvas . getContainer ( $element ) . outerHeight ( ) ;
$toolbar . css ( 'margin-top' , height + 'px' ) ;
$element . on ( 'dialogContentResize.off-canvas' , function ( ) {
var newHeight = Drupal . offCanvas . getContainer ( $element ) . outerHeight ( ) ;
$toolbar . css ( 'margin-top' , newHeight + 'px' ) ;
} ) ;
}
} ,
'dialog:beforeclose' : function dialogBeforeclose ( ) {
$ ( '#toolbar-bar' ) . css ( 'margin-top' , '0' ) ;
}
} ) ;
2015-08-17 17:00:26 -07:00
} ) ;
}
} ;
Drupal . toolbar = {
views : { } ,
models : { } ,
mql : { } ,
setSubtrees : new $ . Deferred ( ) ,
2018-11-23 12:29:20 +00:00
mediaQueryChangeHandler : function mediaQueryChangeHandler ( model , label , mql ) {
2015-08-17 17:00:26 -07:00
switch ( label ) {
case 'toolbar.narrow' :
model . set ( {
2015-09-04 13:20:09 -07:00
isOriented : mql . matches ,
isTrayToggleVisible : false
2015-08-17 17:00:26 -07:00
} ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
if ( ! mql . matches || ! model . get ( 'orientation' ) ) {
2018-11-23 12:29:20 +00:00
model . set ( { orientation : 'vertical' } , { validate : true } ) ;
2015-08-17 17:00:26 -07:00
}
break ;
case 'toolbar.standard' :
model . set ( {
2015-09-04 13:20:09 -07:00
isFixed : mql . matches
2015-08-17 17:00:26 -07:00
} ) ;
break ;
case 'toolbar.wide' :
model . set ( {
2018-11-23 12:29:20 +00:00
orientation : mql . matches && ! model . get ( 'locked' ) ? 'horizontal' : 'vertical'
} , { validate : true } ) ;
2015-08-17 17:00:26 -07:00
model . set ( {
2015-09-04 13:20:09 -07:00
isTrayToggleVisible : mql . matches
2015-08-17 17:00:26 -07:00
} ) ;
break ;
default :
break ;
}
}
} ;
Drupal . theme . toolbarOrientationToggle = function ( ) {
2018-11-23 12:29:20 +00:00
return '<div class="toolbar-toggle-orientation"><div class="toolbar-lining">' + '<button class="toolbar-icon" type="button"></button>' + '</div></div>' ;
2015-08-17 17:00:26 -07:00
} ;
2015-08-27 12:03:05 -07:00
Drupal . AjaxCommands . prototype . setToolbarSubtrees = function ( ajax , response , status ) {
Drupal . toolbar . setSubtrees . resolve ( response . subtrees ) ;
} ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal , drupalSettings ) ;