core/misc/drupal.js | 3 ++ core/modules/toolbar/js/toolbar.js | 48 ++++++++++++++++++---- core/modules/toolbar/js/views/ToolbarVisualView.js | 7 ++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 75f85bb..a8d50c6 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -3,6 +3,8 @@ * Defines the Drupal JS API. */ +console.time('parse to attaching behaviors'); + /** * A jQuery object. * @@ -192,6 +194,7 @@ if (window.jQuery) { * @throws {Drupal~DrupalBehaviorError} */ Drupal.attachBehaviors = function (context, settings) { + console.timeEnd('parse to attaching behaviors'); context = context || document; settings = settings || drupalSettings; var errors = []; diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index ed4068c..664d0e0 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -3,6 +3,9 @@ * Defines the behavior of the Drupal administration toolbar. */ +//console.timeStamp('toolbar.js parse'); +console.time('parse to start toolbar behavior'); + (function ($, Drupal, drupalSettings) { "use strict"; @@ -38,38 +41,67 @@ */ Drupal.behaviors.toolbar = { attach: function (context) { + console.timeEnd('parse to start toolbar behavior'); + console.time('initial offsets'); + console.time('toolbar behavior'); + +// console.time('test'); +// $(context).find('#toolbar-administration') +// console.timeEnd('test'); +// console.time('test2'); +// $(context).find('#toolbar-administration').once('foo'); +// console.timeEnd('test2'); +// console.time('test3'); +// $(context).find('#toolbar-administration').once('bar').each(function() { +// console.timeEnd('test3'); +// }); +// console.time('test4'); +// $(context).find('#toolbar-administration').each(function() { +// console.timeEnd('test4'); +// }); + + + debugger; // Verify that the user agent understands media queries. Complex admin // toolbar layouts require media query support. if (!window.matchMedia('only screen').matches) { return; } // Process the administrative toolbar. - $(context).find('#toolbar-administration').once('toolbar').each(function () { + var $toolbar = $(context).find('#toolbar-administration').once('toolbar'); + if (!$toolbar.length) { + return; + } + console.timeEnd('toolbar behavior'); +debugger; // Establish the toolbar models and views. var model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({ locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')) || false, activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))) }); Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({ - el: this, + el: $toolbar.get(0), model: model, strings: options.strings }); Drupal.toolbar.views.toolbarAuralView = new Drupal.toolbar.ToolbarAuralView({ - el: this, + el: $toolbar.get(0), model: model, strings: options.strings }); Drupal.toolbar.views.bodyVisualView = new Drupal.toolbar.BodyVisualView({ - el: this, + el: $toolbar.get(0), model: model }); +// model.set('offsets', JSON.parse(localStorage.getItem('Drupal.toolbar.offsets')) || {top:0, bottom:0, left:0, right:0}); + console.timeEnd('initial offsets'); + // Render collapsible menus. var menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel(); Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({ - el: $(this).find('.toolbar-menu-administration').get(0), + el: $toolbar.find('.toolbar-menu-administration').get(0), model: menuModel, strings: options.strings }); @@ -84,7 +116,7 @@ // Indicate on the toolbarModel that subtrees are now loaded. model.set('areSubtreesLoaded', true); }); - +debugger; // Attach a listener to the configured media query breakpoints. for (var label in options.breakpoints) { if (options.breakpoints.hasOwnProperty(label)) { @@ -112,6 +144,7 @@ // Update the model when the viewport offset changes. .on('drupalViewportOffsetChange.toolbar', function (event, offsets) { model.set('offsets', offsets); + localStorage.setItem('Drupal.toolbar.offsets', offsets); }); // Broadcast model changes to other modules. @@ -134,7 +167,6 @@ 'activeTab': $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0) }); } - }); } }; @@ -245,4 +277,6 @@ Drupal.toolbar.setSubtrees.resolve(response.subtrees); }; +// Drupal.behaviors.toolbar.attach(document); + }(jQuery, Drupal, drupalSettings)); diff --git a/core/modules/toolbar/js/views/ToolbarVisualView.js b/core/modules/toolbar/js/views/ToolbarVisualView.js index 2645f52..91ebc8d 100644 --- a/core/modules/toolbar/js/views/ToolbarVisualView.js +++ b/core/modules/toolbar/js/views/ToolbarVisualView.js @@ -60,6 +60,7 @@ * @return {Drupal.toolbar.ToolbarVisualView} */ render: function () { +// console.profile(); this.updateTabs(); this.updateTrayOrientation(); this.updateBarAttributes(); @@ -81,10 +82,16 @@ // Trigger a recalculation of viewport displacing elements. Use setTimeout // to ensure this recalculation happens after changes to visual elements // have processed. + debugger; window.setTimeout(function () { + debugger; +// console.log('displaced'); +// console.profile(); Drupal.displace(true); }, 0); +// console.profileEnd(); return this; + }, /**