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 = 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 Drupal.toolbar.models.toolbarModel = model;
37 Object.keys(options.breakpoints).forEach(function (label) {
38 var mq = options.breakpoints[label];
39 var mql = window.matchMedia(mq);
40 Drupal.toolbar.mql[label] = mql;
42 mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
44 Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
47 Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
50 strings: options.strings
52 Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({
55 strings: options.strings
57 Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({
62 model.trigger('change:isFixed', model, model.get('isFixed'));
63 model.trigger('change:activeTray', model, model.get('activeTray'));
65 var menuModel = new Drupal.toolbar.MenuModel();
66 Drupal.toolbar.models.menuModel = menuModel;
67 Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
68 el: $(this).find('.toolbar-menu-administration').get(0),
70 strings: options.strings
73 Drupal.toolbar.setSubtrees.done(function (subtrees) {
74 menuModel.set('subtrees', subtrees);
75 var theme = drupalSettings.ajaxPageState.theme;
76 localStorage.setItem('Drupal.toolbar.subtrees.' + theme, JSON.stringify(subtrees));
78 model.set('areSubtreesLoaded', true);
81 Drupal.toolbar.views.toolbarVisualView.loadSubtrees();
83 $(document).on('drupalViewportOffsetChange.toolbar', function (event, offsets) {
84 model.set('offsets', offsets);
87 model.on('change:orientation', function (model, orientation) {
88 $(document).trigger('drupalToolbarOrientationChange', orientation);
89 }).on('change:activeTab', function (model, tab) {
90 $(document).trigger('drupalToolbarTabChange', tab);
91 }).on('change:activeTray', function (model, tray) {
92 $(document).trigger('drupalToolbarTrayChange', tray);
95 if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null) {
96 Drupal.toolbar.models.toolbarModel.set({
97 activeTab: $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0)
102 'dialog:aftercreate': function dialogAftercreate(event, dialog, $element, settings) {
103 var $toolbar = $('#toolbar-bar');
104 $toolbar.css('margin-top', '0');
106 if (settings.drupalOffCanvasPosition === 'top') {
107 var height = Drupal.offCanvas.getContainer($element).outerHeight();
108 $toolbar.css('margin-top', height + 'px');
110 $element.on('dialogContentResize.off-canvas', function () {
111 var newHeight = Drupal.offCanvas.getContainer($element).outerHeight();
112 $toolbar.css('margin-top', newHeight + 'px');
116 'dialog:beforeclose': function dialogBeforeclose() {
117 $('#toolbar-bar').css('margin-top', '0');
131 setSubtrees: new $.Deferred(),
133 mediaQueryChangeHandler: function mediaQueryChangeHandler(model, label, mql) {
135 case 'toolbar.narrow':
137 isOriented: mql.matches,
138 isTrayToggleVisible: false
141 if (!mql.matches || !model.get('orientation')) {
142 model.set({ orientation: 'vertical' }, { validate: true });
146 case 'toolbar.standard':
154 orientation: mql.matches && !model.get('locked') ? 'horizontal' : 'vertical'
155 }, { validate: true });
158 isTrayToggleVisible: mql.matches
168 Drupal.theme.toolbarOrientationToggle = function () {
169 return '<div class="toolbar-toggle-orientation"><div class="toolbar-lining">' + '<button class="toolbar-icon" type="button"></button>' + '</div></div>';
172 Drupal.AjaxCommands.prototype.setToolbarSubtrees = function (ajax, response, status) {
173 Drupal.toolbar.setSubtrees.resolve(response.subtrees);
175 })(jQuery, Drupal, drupalSettings);