Skip to content

Instantly share code, notes, and snippets.

@evanmwillhite
Last active September 27, 2017 18:20
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 evanmwillhite/48352af03863270f0b7fe8869e058012 to your computer and use it in GitHub Desktop.
Save evanmwillhite/48352af03863270f0b7fe8869e058012 to your computer and use it in GitHub Desktop.
Simple Menu Javascript Example
/**
* @file
* A JavaScript file containing menu functionality (small/large screen)
*
*/
(function (Drupal) {
Drupal.behaviors.mainMenu = {
attach: function (context) {
var menu = context.getElementById('menu');
var expand_menu = menu.getElementsByClassName('expand-sub');
for (var i = 0; i < expand_menu.length; i++) {
expand_menu[i].addEventListener("click", function(e) {
var menu_item = e.currentTarget;
var sub_menu = menu_item.nextElementSibling;
menu_item.classList.toggle('menu--open');
sub_menu.classList.toggle('expand-sub--open');
});
}
}
};
})(Drupal);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment