comparison core/modules/toolbar/js/toolbar.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 = 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()
33 });
34
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);
39
40 mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
41
42 Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
43 }
44 }
45
46 Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
47 el: this,
48 model: model,
49 strings: options.strings
50 });
51 Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({
52 el: this,
53 model: model,
54 strings: options.strings
55 });
56 Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({
57 el: this,
58 model: model
59 });
60
61 model.trigger('change:isFixed', model, model.get('isFixed'));
62 model.trigger('change:activeTray', model, model.get('activeTray'));
63
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),
67 model: menuModel,
68 strings: options.strings
69 });
70
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));
75
76 model.set('areSubtreesLoaded', true);
77 });
78
79 Drupal.toolbar.views.toolbarVisualView.loadSubtrees();
80
81 $(document).on('drupalViewportOffsetChange.toolbar', function (event, offsets) {
82 model.set('offsets', offsets);
83 });
84
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);
91 });
92
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)
96 });
97 }
98 });
99 }
100 };
101
102 Drupal.toolbar = {
103 views: {},
104
105 models: {},
106
107 mql: {},
108
109 setSubtrees: new $.Deferred(),
110
111 mediaQueryChangeHandler: function mediaQueryChangeHandler(model, label, mql) {
112 switch (label) {
113 case 'toolbar.narrow':
114 model.set({
115 isOriented: mql.matches,
116 isTrayToggleVisible: false
117 });
118
119 if (!mql.matches || !model.get('orientation')) {
120 model.set({ orientation: 'vertical' }, { validate: true });
121 }
122 break;
123
124 case 'toolbar.standard':
125 model.set({
126 isFixed: mql.matches
127 });
128 break;
129
130 case 'toolbar.wide':
131 model.set({
132 orientation: mql.matches && !model.get('locked') ? 'horizontal' : 'vertical'
133 }, { validate: true });
134
135 model.set({
136 isTrayToggleVisible: mql.matches
137 });
138 break;
139
140 default:
141 break;
142 }
143 }
144 };
145
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>';
148 };
149
150 Drupal.AjaxCommands.prototype.setToolbarSubtrees = function (ajax, response, status) {
151 Drupal.toolbar.setSubtrees.resolve(response.subtrees);
152 };
153 })(jQuery, Drupal, drupalSettings);