diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index 56a9fde..99e521d 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -116,9 +116,6 @@ 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(); }); } }; @@ -312,9 +309,6 @@ Drupal.toolbar = { // Trigger an activeTab change so that listening scripts can respond on // page load. This will call render. this.model.trigger('change:activeTab'); - - // Invoke Drupal.displace() to get the current viewport offset values. - Drupal.displace(); }, /** @@ -324,6 +318,12 @@ Drupal.toolbar = { this.updateTabs(); this.updateTrayOrientation(); this.updateBarAttributes(); + // Trigger a recalculation of viewport displacing elements. Use setTimeout + // to ensure this recalculation happens after changes to visual elements + // have processed. + window.setTimeout(function () { + Drupal.displace(true); + }, 0); return this; }, @@ -468,8 +468,6 @@ Drupal.toolbar = { $trays.filter('.toolbar-tray-vertical.active').attr('data-offset-' + edge, ''); // If an active horizontal tray exists, mark it as an offset element. $trays.filter('.toolbar-tray-horizontal.active').attr('data-offset-top', ''); - // Trigger a recalculation of viewport displacing elements. - Drupal.displace(); }, /** diff --git a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module index 3ccbf0a..bc2ce99 100644 --- a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module +++ b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module @@ -25,6 +25,7 @@ function toolbar_test_toolbar() { ), ), 'tray' => array( + '#heading' => t('Test tray'), '#wrapper_attributes' => array( 'id' => 'toolbar-tray-testing', ), @@ -35,7 +36,6 @@ function toolbar_test_toolbar() { l(t('link 2'), '', array('attributes' => array('title' => 'Test link 2 title'))), l(t('link 3'), '', array('attributes' => array('title' => 'Test link 3 title'))), ), - '#prefix' => '

' . t('Test tray') . '

', '#attributes' => array( 'class' => array('menu'), ), diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 7f132e2..845ea9e 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -370,9 +370,13 @@ function theme_toolbar_tray_wrapper(&$variables) { * the tray. Properties used: #children and #heading. */ function theme_toolbar_tray_heading_wrapper(&$variables) { - if (!empty($variables['element']['#children'])) { - $element = $variables['element']; - return '

' . $element['#heading'] . '

' . $element['#children']; + $element = $variables['element']; + if (!empty($element['#children'])) { + $heading = ''; + if (!empty($element['#heading'])) { + $heading = '

' . $element['#heading'] . '

'; + } + return $heading . $element['#children']; } }