Skip to content

Instantly share code, notes, and snippets.

@boborchard
Created October 16, 2013 18:10
Show Gist options
  • Select an option

  • Save boborchard/7012227 to your computer and use it in GitHub Desktop.

Select an option

Save boborchard/7012227 to your computer and use it in GitHub Desktop.
Reformat the Online-Access Pagepilot navigation to support Bootstrap 3.0's navigation menu
function addMenuSupport($parent, level) {
// add a parent class to the ul
$parent.addClass('navbar-nav');
// fetch all the li's that are direct children of the ul
var $children = $parent.children('li');
// add a child class to the li
$children.addClass('level-'+level);
// for each anchor, add class & attribute.
$children.has('ul').children('a').addClass('dropdown-toggle').attr( "data-toggle", "dropdown" );
// loop trough each li
$children.each(function() {
// get the ul that is a direct child of the li
var $sublist = $(this).children('ul');
// for each UL, add class
$(this).children('ul').addClass('dropdown-menu');
// if an ul was found
if ($sublist.length > 0) {
// add a class to the current li indicating there is a sub list
$(this).addClass('dropdown');
// repeat the process for the sublist, but with the level one higher
// = recursive function call
addLevelClass($sublist, level+1);
}
});
}
// call the function to add level classes on the upper most ul
addMenuSupport($('.navbar ul.nav'), 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment