Skip to content

Instantly share code, notes, and snippets.

Created January 27, 2017 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d82717f722e8dc0bebc54fb6b4c7104e to your computer and use it in GitHub Desktop.
Save anonymous/d82717f722e8dc0bebc54fb6b4c7104e to your computer and use it in GitHub Desktop.
/**
* @file
*/
/**
* Display the active parent menu item name above the sidebar subtree menu.
*/
(function($) {
"use strict";
Drupal.behaviors.ComponentsBlockTitle = {
attach: function (context) {
// Only run on pages with a sidebar submenu.
if ($('.region-sidebar-first #block-nama-d8-main-menu', context).length) {
// Get the parent menu item name.
var parentMenuItem = $('.region-primary-menu .menu-item--active-trail a', context).text();
// Add it above the sidebar menu.
$('<h2>' + parentMenuItem + '</h2>', context).insertBefore('.region-sidebar-first #block-nama-d8-main-menu');
}
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment