2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, drupalSettings) {
9 var options = $.extend({
12 'toolbar.standard': '',
15 }, drupalSettings.toolbar, {
17 horizontal: Drupal.t('Horizontal orientation'),
18 vertical: Drupal.t('Vertical orientation')
22 Drupal.behaviors.toolbar = {
23 attach: function attach(context) {
24 if (!window.matchMedia('only screen').matches) {
28 $(context).find('#toolbar-administration').once('toolbar').each(function () {
29 var model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({
30 locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')),
31 activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))),
32 height: $('#toolbar-administration').outerHeight()
35 for (var label in options.breakpoints) {
36 if (options.breakpoints.hasOwnProperty(label)) {
37 var mq = options.breakpoints[label];
38 var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq);
40 mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
42 Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
46 Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
49 strings: options.strings
51 Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({
54 strings: options.strings
56 Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({
61 model.trigger('change:isFixed', model, model.get('isFixed'));
62 model.trigger('change:activeTray', model, model.get('activeTray'));
64 var menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
65 Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
66 el: $(this).find('.toolbar-menu-administration').get(0),
68 strings: options.strings
71 Drupal.toolbar.setSubtrees.done(function (subtrees) {
72 menuModel.set('subtrees', subtrees);
73 var theme = drupalSettings.ajaxPageState.theme;
74 localStorage.setItem('Drupal.toolbar.subtrees.' + theme, JSON.stringify(subtrees));
76 model.set('areSubtreesLoaded', true);
79 Drupal.toolbar.views.toolbarVisualView.loadSubtrees();
81 $(document).on('drupalViewportOffsetChange.toolbar', function (event, offsets) {
82 model.set('offsets', offsets);
85 model.on('change:orientation', function (model, orientation) {
86 $(document).trigger('drupalToolbarOrientationChange', orientation);
87 }).on('change:activeTab', function (model, tab) {
88 $(document).trigger('drupalToolbarTabChange', tab);
89 }).on('change:activeTray', function (model, tray) {
90 $(document).trigger('drupalToolbarTrayChange', tray);
93 if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null) {
94 Drupal.toolbar.models.toolbarModel.set({
95 activeTab: $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0)
109 setSubtrees: new $.Deferred(),
111 mediaQueryChangeHandler: function mediaQueryChangeHandler(model, label, mql) {
113 case 'toolbar.narrow':
115 isOriented: mql.matches,
116 isTrayToggleVisible: false
119 if (!mql.matches || !model.get('orientation')) {
120 model.set({ orientation: 'vertical' }, { validate: true });
124 case 'toolbar.standard':
132 orientation: mql.matches && !model.get('locked') ? 'horizontal' : 'vertical'
133 }, { validate: true });
136 isTrayToggleVisible: mql.matches
146 Drupal.theme.toolbarOrientationToggle = function () {
147 return '<div class="toolbar-toggle-orientation"><div class="toolbar-lining">' + '<button class="toolbar-icon" type="button"></button>' + '</div></div>';
150 Drupal.AjaxCommands.prototype.setToolbarSubtrees = function (ajax, response, status) {
151 Drupal.toolbar.setSubtrees.resolve(response.subtrees);
153 })(jQuery, Drupal, drupalSettings);