Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / toolbar / js / toolbar.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal, drupalSettings) {
9   var options = $.extend({
10     breakpoints: {
11       'toolbar.narrow': '',
12       'toolbar.standard': '',
13       'toolbar.wide': ''
14     }
15   }, drupalSettings.toolbar, {
16     strings: {
17       horizontal: Drupal.t('Horizontal orientation'),
18       vertical: Drupal.t('Vertical orientation')
19     }
20   });
21
22   Drupal.behaviors.toolbar = {
23     attach: function attach(context) {
24       if (!window.matchMedia('only screen').matches) {
25         return;
26       }
27
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()
33         });
34
35         Drupal.toolbar.models.toolbarModel = model;
36
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;
41
42           mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
43
44           Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
45         });
46
47         Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
48           el: this,
49           model: model,
50           strings: options.strings
51         });
52         Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({
53           el: this,
54           model: model,
55           strings: options.strings
56         });
57         Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({
58           el: this,
59           model: model
60         });
61
62         model.trigger('change:isFixed', model, model.get('isFixed'));
63         model.trigger('change:activeTray', model, model.get('activeTray'));
64
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),
69           model: menuModel,
70           strings: options.strings
71         });
72
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));
77
78           model.set('areSubtreesLoaded', true);
79         });
80
81         Drupal.toolbar.views.toolbarVisualView.loadSubtrees();
82
83         $(document).on('drupalViewportOffsetChange.toolbar', function (event, offsets) {
84           model.set('offsets', offsets);
85         });
86
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);
93         });
94
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)
98           });
99         }
100
101         $(window).on({
102           'dialog:aftercreate': function dialogAftercreate(event, dialog, $element, settings) {
103             var $toolbar = $('#toolbar-bar');
104             $toolbar.css('margin-top', '0');
105
106             if (settings.drupalOffCanvasPosition === 'top') {
107               var height = Drupal.offCanvas.getContainer($element).outerHeight();
108               $toolbar.css('margin-top', height + 'px');
109
110               $element.on('dialogContentResize.off-canvas', function () {
111                 var newHeight = Drupal.offCanvas.getContainer($element).outerHeight();
112                 $toolbar.css('margin-top', newHeight + 'px');
113               });
114             }
115           },
116           'dialog:beforeclose': function dialogBeforeclose() {
117             $('#toolbar-bar').css('margin-top', '0');
118           }
119         });
120       });
121     }
122   };
123
124   Drupal.toolbar = {
125     views: {},
126
127     models: {},
128
129     mql: {},
130
131     setSubtrees: new $.Deferred(),
132
133     mediaQueryChangeHandler: function mediaQueryChangeHandler(model, label, mql) {
134       switch (label) {
135         case 'toolbar.narrow':
136           model.set({
137             isOriented: mql.matches,
138             isTrayToggleVisible: false
139           });
140
141           if (!mql.matches || !model.get('orientation')) {
142             model.set({ orientation: 'vertical' }, { validate: true });
143           }
144           break;
145
146         case 'toolbar.standard':
147           model.set({
148             isFixed: mql.matches
149           });
150           break;
151
152         case 'toolbar.wide':
153           model.set({
154             orientation: mql.matches && !model.get('locked') ? 'horizontal' : 'vertical'
155           }, { validate: true });
156
157           model.set({
158             isTrayToggleVisible: mql.matches
159           });
160           break;
161
162         default:
163           break;
164       }
165     }
166   };
167
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>';
170   };
171
172   Drupal.AjaxCommands.prototype.setToolbarSubtrees = function (ajax, response, status) {
173     Drupal.toolbar.setSubtrees.resolve(response.subtrees);
174   };
175 })(jQuery, Drupal, drupalSettings);