Skip to content

Instantly share code, notes, and snippets.

@waako
Last active August 29, 2015 14:01
Show Gist options
  • Save waako/f2c3e98ddb9e898edea0 to your computer and use it in GitHub Desktop.
Save waako/f2c3e98ddb9e898edea0 to your computer and use it in GitHub Desktop.
<?php
/*
* Bootstrap override
* make dropdown menus do dropdown on hover,
* and allow parent link to be clickable
*/
// place this in your styles
ul.nav li.dropdown:hover > ul.dropdown-menu{
display: block !important;
}
ul.nav li.dropdown ul.dropdown-menu {
margin-top: 0;
}
/*
* in bootstrap subtheme, add the following functions
*/
function BOOTSTRAP-SUBTHEME_menu_link(array $variables) {
$element = $variables['element'];
$sub_menu = '';
if ($element['#below']) {
// Prevent dropdown functions from being added to management menu so it
// does not affect the navbar module.
if (($element['#original_link']['menu_name'] == 'management') && (module_exists('navbar'))) {
$sub_menu = drupal_render($element['#below']);
}
elseif ((!empty($element['#original_link']['depth'])) && ($element['#original_link']['depth'] == 1)) {
// Add our own wrapper.
unset($element['#below']['#theme_wrappers']);
$sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
// Generate as standard dropdown.
$element['#title'] .= ' <span class="caret"></span>';
$element['#attributes']['class'][] = 'dropdown';
$element['#localized_options']['html'] = TRUE;
// Set dropdown trigger element to # to prevent inadvertant page loading
// when a submenu link is clicked.
$element['#localized_options']['attributes']['data-target'] = '#';
$element['#localized_options']['attributes']['class'][] = 'dropdown-toggle disabled';
$element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
}
}
// On primary navigation menu, class 'active' is not set on active menu item.
// @see https://drupal.org/node/1896674
if (($element['#href'] == $_GET['q'] || ($element['#href'] == '<front>' && drupal_is_front_page())) && (empty($element['#localized_options']['language']))) {
$element['#attributes']['class'][] = 'active';
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment