Skip to content

Instantly share code, notes, and snippets.

/components_block_title.js Secret

Created Jan 27, 2017
What would you like to do?
* @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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.