core/modules/toolbar/js/toolbar.js | 48 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index 610ae2f..dcf3dd5 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -26,7 +26,7 @@ var options = $.extend({ * Returns an orientation based on the orientation lock. * * Orientation is locked to the vertical position when a user changes a - * horizontal tray to a vertical try using the tray orientation toggle button. + * horizontal tray to a vertical tray using the tray orientation toggle button. * * @param String orientation * The value can be either 'horizontal' or 'vertical'. @@ -51,8 +51,9 @@ function checkOrientationLock (orientation) { * Modules register tabs with hook_toolbar(). */ Drupal.behaviors.toolbar = { + attach: function (context) { - // Verify that the sser agent understands media queries. Complex admin + // Verify that the user agent understands media queries. Complex admin // toolbar layouts require media query support. if (!window.matchMedia('only screen').matches) { return; @@ -60,7 +61,7 @@ Drupal.behaviors.toolbar = { // Process the administrative toolbar. $(context).find('#toolbar-administration').once('toolbar', function () { - // Establishe the toolbar models and views. + // 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'))) @@ -123,6 +124,7 @@ Drupal.behaviors.toolbar = { .on('drupalOverlayClose.toolbar', function () { model.set('isViewportOverflowConstrained', false); }); + // Broadcast model changes to other modules. model .on('change:orientation', function (model, orientation) { @@ -134,10 +136,12 @@ Drupal.behaviors.toolbar = { .on('change:activeTray', function (model, tray) { $(document).trigger('drupalToolbarTrayChange', tray); }); + // Call displace to get the initial placement of offset elements. Drupal.displace(); }); } + }; /** @@ -203,8 +207,8 @@ Drupal.toolbar = { // Represents whether a tray is open or not. Stored as a DOM element, not // a jQuery set. activeTray: null, - // Indicates whether the toolbar is display in an oriented fashion, either - // horizontal or vertical. + // Indicates whether the toolbar is displayed in an oriented fashion, + // either horizontal or vertical. isOriented: false, // Indicated whether the toolbar is positioned absolute (false) or fixed // (true). @@ -240,7 +244,7 @@ Drupal.toolbar = { ToolbarAuralView: Backbone.View.extend({ /** - * Implements Backbone.View.prototype.initialize(). + * {@inheritdoc} */ initialize: function (options) { this.strings = options.strings; @@ -256,7 +260,7 @@ Drupal.toolbar = { * @param String orientation * The new value of the orientation attribute in the model. */ - onOrientationChange: function(model, orientation) { + onOrientationChange: function (model, orientation) { Drupal.announce(Drupal.t('Tray orientation changed to @orientation.', { '@orientation': orientation })); @@ -269,7 +273,7 @@ Drupal.toolbar = { * @param Element orientation * The new value of the tray attribute in the model. */ - onActiveTrayChange: function(model, tray) { + onActiveTrayChange: function (model, tray) { var relevantTray = (tray === null) ? model.previous('activeTray') : tray; var state = (tray === null) ? this.strings.closed : this.strings.opened; Drupal.announce(Drupal.t('"@tray" tray @state.', { @@ -283,10 +287,12 @@ Drupal.toolbar = { * Backbone view for the toolbar element. */ ToolbarVisualView: Backbone.View.extend({ + events: { 'click .toolbar-bar .toolbar-tab': 'onTabClick', 'click .toolbar-toggle-orientation button': 'onOrientationToggleClick' }, + /** * {@inheritdoc} */ @@ -315,13 +321,9 @@ Drupal.toolbar = { * {@inheritdoc} */ render: function (model) { - // Update the display of the tabs. - this.refreshTabs(); - // Adjust the orientation of the active tray. - this.setTrayOrientation(); - // Adjust the attributes of the toolbar bar. - this.renderBar(); - + this.updateTabs(); + this.updateTrayOrientation(); + this.updateBarAttributes(); return this; }, @@ -333,7 +335,7 @@ Drupal.toolbar = { onTabClick: function (event) { // If this tab has a tray associated with it, it is considered an // activatable tab. - if ($(event.target).attr('data-toolbar-tray')) { + if (event.target.hasAttribute('data-toolbar-tray')) { var tab = this.model.get('activeTab'); // Set the event target as the active item if it is not already. this.model.set('activeTab', (!tab || event.target !== tab) ? event.target : null); @@ -371,9 +373,9 @@ Drupal.toolbar = { }, /** - * Toggles a toolbar tab and the associated tray. + * Updates the display of the tabs: toggles a tab and the associated tray. */ - refreshTabs: function () { + updateTabs: function () { var $tab = $(this.model.get('activeTab')); var $tray = $(); // Deactivate the previous tab. @@ -415,9 +417,9 @@ Drupal.toolbar = { }, /** - * Sets attributs on the toolbar bar element. + * Update the attributes of the toolbar bar element. */ - renderBar: function () { + updateBarAttributes: function () { var isOriented = this.model.get('isOriented'); if (isOriented) { this.$el.find('.toolbar-bar').attr('data-offset-top', ''); @@ -431,9 +433,9 @@ Drupal.toolbar = { }, /** - * Change the orientation of the tray between vertical and horizontal. + * Updates the orientation of the active tray if necessary. */ - setTrayOrientation: function () { + updateTrayOrientation: function () { var orientation = this.checkOrientationLock(this.model.get('orientation')); // The antiOrientation is used to render the view of action buttons like // the tray orientation toggle. @@ -556,7 +558,7 @@ Drupal.toolbar = { .toggleClass('toolbar-vertical', (orientation === 'vertical')) .toggleClass('toolbar-horizontal', (isOriented && orientation === 'horizontal')) .toggleClass('toolbar-paneled', (isViewportOverflowConstrained || this.model.get('isPaneled'))) - // Toggle the toolbar-tray-open class on the body elment. The class is + // Toggle the toolbar-tray-open class on the body element. The class is // applied when a toolbar tray is active. .toggleClass('toolbar-tray-open', !!this.model.get('activeTray')) // Apply padding to the top of the body to offset the placement of the