From 232c10dc0460d6b4eaeb327077e4b197a64ed1f2 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 18 Nov 2014 22:51:10 +0000 Subject: [PATCH] Issue #1850164 by Tom Verhaeghe: Default state of toolbar should show menu tray in non-narrow viewports --- core/modules/toolbar/js/toolbar.js | 24 +++++++++++++++++------- core/modules/toolbar/toolbar.module | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index b99e0c72e505..e5b244cbfe2b 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -29,8 +29,8 @@ /** * Registers tabs with the toolbar. * - * The Drupal toolbar allows modules to register top-level tabs. These may point - * directly to a resource or toggle the visibility of a tray. + * The Drupal toolbar allows modules to register top-level tabs. These may + * point directly to a resource or toggle the visibility of a tray. * * Modules register tabs with hook_toolbar(). */ @@ -88,8 +88,8 @@ if (options.breakpoints.hasOwnProperty(label)) { var mq = options.breakpoints[label]; var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq); - // Curry the model and the label of the media query breakpoint to the - // mediaQueryChangeHandler function. + // Curry the model and the label of the media query breakpoint to + // the mediaQueryChangeHandler function. mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); // Fire the mediaQueryChangeHandler for each configured breakpoint // so that they process once. @@ -102,8 +102,8 @@ // process. The toolbar starts in the vertical orientation by default, // unless the viewport is wide enough to accommodate a horizontal // orientation. Thus we give the Toolbar a chance to determine if it - // should be set to horizontal orientation before attempting to load menu - // subtrees. + // should be set to horizontal orientation before attempting to load + // menu subtrees. Drupal.toolbar.views.toolbarVisualView.loadSubtrees(); $(document) @@ -123,6 +123,15 @@ .on('change:activeTray', function (model, tray) { $(document).trigger('drupalToolbarTrayChange', tray); }); + + // If the toolbar's orientation is horizontal and no active tab is + // defined then show the tray of the first toolbar tab by default (but + // not the first 'Home' toolbar tab). + if (Drupal.toolbar.models.toolbarModel.get('orientation') === 'horizontal' && Drupal.toolbar.models.toolbarModel.get('activeTab') === null){ + Drupal.toolbar.models.toolbarModel.set({ + 'activeTab': $('.toolbar-bar .toolbar-tab:not(.home-toolbar-tab) a').get(0) + }); + } }); } }; @@ -177,7 +186,8 @@ model.set({ 'orientation': ((mql.matches) ? 'horizontal' : 'vertical') }, {validate: true}); - // The tray orientation toggle visibility does not need to be validated. + // The tray orientation toggle visibility does not need to be + // validated. model.set({ 'isTrayToggleVisible': mql.matches }); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 9a7914b5ebbc..f95a890f3b16 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -133,7 +133,7 @@ function toolbar_toolbar() { ), ), '#wrapper_attributes' => array( - 'class' => array('hidden'), + 'class' => array('hidden', 'home-toolbar-tab'), ), '#attached' => array( 'library' => array( -- GitLab