diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index 8cbd9c5..0f2a274 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -17,9 +17,10 @@ */ Drupal.behaviors.toolbar = { attach: function (context) { + var defaults = this.defaults; $(context).find('#toolbar-administration').once('toolbar', function () { - var options = $.extend(Drupal.behaviors.toolbar.defaults, drupalSettings.toolbar); - + // Create a reference to the defaults in this function scope. + var options = $.extend(defaults, drupalSettings.toolbar); // Set up switching between the vertical and horizontal presentation // of the toolbar trays based on a breakpoint. var mql = window.matchMedia(options.breakpoints['module.toolbar.wide']); @@ -42,11 +43,10 @@ Drupal.behaviors.toolbar = { }); // Respond to toolbar events. - Drupal.toolbar.model = model; $(document) - .on('drupalToolbarDimensionsChanged.toolbar', Drupal.toolbar.dimensionsChangeHandler) - .on('drupalToolbarOrientationChanged.toolbar', Drupal.toolbar.orientationChangeHandler) - .on('drupalToolbarTrayChanged.toolbar', Drupal.toolbar.trayChangeHandler); + .on('drupalToolbarDimensionsChanged.toolbar', dimensionsChangeHandler) + .on('drupalToolbarOrientationChanged.toolbar', orientationChangeHandler) + .on('drupalToolbarTrayChanged.toolbar', trayChangeHandler); // Broadcast model changes to other modules. model @@ -98,71 +98,40 @@ Drupal.behaviors.toolbar = { }; // Expose a limited public API. -Drupal.toolbar = Drupal.toolbar || { - - model: null, - - /** - * Accepts a list of subtree menu elements. - * - * A deferred object that is resolved by an inlined JavaScript callback. - * - * JSONP callback. - * @see toolbar_subtrees_jsonp(). - */ - setSubtrees: new $.Deferred(), + Drupal.toolbar = Drupal.toolbar || { + /** + * Accepts a list of subtree menu elements. + * + * A deferred object that is resolved by an inlined JavaScript callback. + * + * JSONP callback. + * @see toolbar_subtrees_jsonp(). + */ + setSubtrees: new $.Deferred(), - /** - * - */ - setActiveItem: function (element) { - var item; - if (typeof element === 'object') { - // Check if the element is a DOM element. - if ('tagName' in element) { + /** + * + */ + setActiveItem: function (element) { + var item; + if (typeof element === 'object') { + // Check if the element is a DOM element. + if ('tagName' in element) { + item = element; + } + // Check if the element is a jQuery set. + if ('jquery' in element) { + item = element.get(0); + } + } + else if (!element) { item = element; } - // Check if the element is a jQuery set. - if ('jquery' in element) { - item = element.get(0); + if (this.model && item) { + this.model.set('activeTab', item); } } - else if (!element) { - item = element; - } - if (this.model && item) { - this.model.set('activeTab', item); - } - }, - - /** - * - */ - dimensionsChangeHandler: function (event, height) { - // Alter the padding on the top of the body element. - $('body') - .css('padding-top', height); - $(document) - .trigger('offsettopchange', height); - }, - - /** - * - */ - orientationChangeHandler: function (event, orientation) { - $('body') - .toggleClass('toolbar-vertical', orientation === 'vertical') - .toggleClass('toolbar-horizontal', orientation === 'horizontal'); - }, - - /** - * - */ - trayChangeHandler: function (event, tray) { - $('body') - .toggleClass('toolbar-tray-open', !!tray); - } -}; + }; /** * Backbone model for the toolbar. @@ -462,15 +431,45 @@ var MenuView = Backbone.View.extend({ } } // Render the main menu as a nested, collapsible accordion. - if ('toolbarMenu' in $.fn) { + if ('drupalToolbarMenu' in $.fn) { this.$el .find('> .menu') - .toolbarMenu(); + .drupalToolbarMenu(); } } }); + + +/** + * + */ +function dimensionsChangeHandler (event, height) { + // Alter the padding on the top of the body element. + $('body') + .css('padding-top', height); + $(document) + .trigger('offsettopchange', height); +} + +/** + * + */ +function orientationChangeHandler (event, orientation) { + $('body') + .toggleClass('toolbar-vertical', orientation === 'vertical') + .toggleClass('toolbar-horizontal', orientation === 'horizontal'); +} + +/** + * + */ +function trayChangeHandler (event, tray) { + $('body') + .toggleClass('toolbar-tray-open', !!tray); +} + /** * Theme function for the toolbar orientation toggle. * diff --git a/core/modules/toolbar/js/toolbar.menu.js b/core/modules/toolbar/js/toolbar.menu.js index aba195d..46c2143 100644 --- a/core/modules/toolbar/js/toolbar.menu.js +++ b/core/modules/toolbar/js/toolbar.menu.js @@ -2,7 +2,7 @@ * Builds a nested accordion widget. * * Invoke on an HTML list element with the jQuery plugin pattern. - * - For example, $('.menu').toolbarMenu(); + * - For example, $('.menu').drupalToolbarMenu(); */ (function ($, Drupal, drupalSettings) { @@ -14,7 +14,7 @@ */ var activeItem = drupalSettings.basePath + Drupal.encodePath(drupalSettings.currentPath); - $.fn.toolbarMenu = function () { + $.fn.drupalToolbarMenu = function () { var ui = { 'handleOpen': Drupal.t('Extend'),