Skip to content

Instantly share code, notes, and snippets.

@johnny5th
Created May 12, 2016 14:38
Show Gist options
  • Save johnny5th/e2e2ad61f58a32bbf6ab17a330d1e265 to your computer and use it in GitHub Desktop.
Save johnny5th/e2e2ad61f58a32bbf6ab17a330d1e265 to your computer and use it in GitHub Desktop.
Drupal subnav dropdown click code
$('.menu-button').click(function() {
$('.nav-bar .menu-block-wrapper').toggleClass('open');
});
var deep_links = $('.nav-bar .menu-block-wrapper li.is-expanded');
$('> a', deep_links).click(function() {
// Hide other open menus on desktop
if(isScreen("desktop")) {
$(this).parent().siblings().find('> a, ul').removeClass('activemenu');
}
$(this).siblings('ul').toggleClass('activemenu');
$(this).toggleClass('activemenu');
return false;
});
// Screen Helper
// Requires matchMedia
function isScreen(test_screen) {
var real_screen;
if(matchMedia('(max-width: 62.4375em)').matches) {
real_screen = "mobile";
} else {
real_screen = "desktop";
}
if(real_screen == test_screen) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment