diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index b323488..29b2195 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -332,11 +332,9 @@ Drupal.toolbar = { this.updateTabs(); this.updateTrayOrientation(); this.updateBarAttributes(); - // Load the subtrees if the toolbar tray is in a vertical orientation - // and if they have been loaded yet. There is no other attribute in the - // model with the value of vertical, so just check for it and whether - // the subtrees have been loaded yet to know when to make an AJAX call - // to get them. + // Load the subtrees if the toolbar tray is in a vertical orientation. + // There is no other attribute in the model with the value of vertical + // that could be confused with the orientation attribute. if (value && value === 'vertical') { this.loadSubtrees(); } @@ -511,20 +509,21 @@ Drupal.toolbar = { * Calls the endpoint URI that will return rendered subtrees with JSONP. */ loadSubtrees: function () { - if(!this.model.get('areSubtreesLoaded')) { + if (!this.model.get('areSubtreesLoaded')) { var endpoint = drupalSettings.toolbar.subtreesPath; var cachedEndpoint = localStorage.getItem('Drupal.toolbar.subtreesPath'); var cachedSubtrees = JSON.parse(localStorage.getItem('Drupal.toolbar.subtrees')); + var isVertical = this.model.get('orientation') === 'vertical'; // If we have the subtrees in localStorage and the endpoint url -- // including the hash of the subtrees -- has not changed, then use // the cached data. - if (endpoint === cachedEndpoint && cachedSubtrees) { + if (isVertical && endpoint === cachedEndpoint && cachedSubtrees) { Drupal.toolbar.setSubtrees.resolve(cachedSubtrees); this.model.set('areSubtreesLoaded', true); } // Only make the call to get the subtrees if the orientation of the // toolbar is vertical. - else if (this.model.get('orientation') === 'vertical') { + else if (isVertical) { // Remove the cached menu information. localStorage.removeItem('Drupal.toolbar.subtreesPath'); localStorage.removeItem('Drupal.toolbar.subtrees'); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index be08ccc..11a4962 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -441,9 +441,8 @@ function toolbar_toolbar() { // To conserve bandwidth, we only include the top-level links in the HTML. // The subtrees are fetched through a JSONP script. Here we - // add that JSONP script url. We add it as a path because it is not a file + // add that JSONP script URL. We add it as a path because it is not a file // available via a stream wrapper. - // @todo, cache the subtrees in the browser. // @see toolbar_subtrees_jsonp() $menu['toolbar_administration']['#attached']['js'][] = array( 'type' => 'setting', @@ -561,34 +560,6 @@ function toolbar_get_rendered_subtrees() { } /** - * Checks whether an item is in the active trail. - * - * Useful when using a menu generated by menu_tree_all_data() which does - * not set the 'in_active_trail' flag on items. - * - * @return - * TRUE when path is in the active trail, FALSE if not. - * - * @todo - * Look at migrating to a menu system level function. - */ -function toolbar_in_active_trail($path) { - $active_paths = &drupal_static(__FUNCTION__); - - // Gather active paths. - if (!isset($active_paths)) { - $active_paths = array(); - $trail = menu_get_active_trail(); - foreach ($trail as $item) { - if (!empty($item['href'])) { - $active_paths[] = $item['href']; - } - } - } - return in_array($path, $active_paths); -} - -/** * Implements hook_library_info(). */ function toolbar_library_info() { @@ -643,7 +614,7 @@ function toolbar_library_info() { * The hash of the admin_menu subtrees. */ function _toolbar_get_subtree_hash() { - $uid = \Drupal::currentUser()->id();; + $uid = \Drupal::currentUser()->id(); $cid = _toolbar_get_user_cid($uid); if ($cache = cache('toolbar')->get($cid)) { $hash = $cache->data;