Well, I set out on same quest a few hours ago and I was hoping to find an answer here to help me out.
I've got it working now and I'll share what I've learned, though I'm new to bootstrap. Someone else feel free to chime in if you see rookie mistakes. Guess it's time to repay the community since many of my questions have been answered here.
Here goes:
Look at this jsFiddle to see my complete sample code and demo: http://jsfiddle.net/acterry/fMYpg/
You'll have play with the the vertical divider to see the nav change from one style to the other.
I wanted to use the same nav ul to drive both menus. But after looking through the source of Jquery.mmenu, I saw the following things that I knew would cause problems:
- mmenu wraps new containers (div by default) around your HTML
- mmenu modifies the menu ul in ways that would likely freak out bootstrap navbar
- mmenu had no function to destory itself and undo the DOM changes it caused
As a proof of concept, I was fine with using bootstraps predefined responsive breakpoints to determine which nav style was shown.
Here's the HTML for the menu portion
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="visible-desktop navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/">My Site</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse collapse">
<ul class="nav" id="mainSiteMenu">
<li><a href="#">Home</a>
</li>
<li><a href="#">Link 1</a>
</li>
<li><a href="#">Link 2</a>
</li>
<li><a href="#">Link 3</a>
</li>
</ul>
</div>
</div>
</div>
<div class="hidden-desktop navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" href="#mainSiteMenuMMenuNav">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/">My Site</a>
</div>
</div>
</div>
<nav id="mainSiteMenuMMenuNav"></nav>
Here's a quick breakdown of the steps:
- (not shown above) Wrap all of the HTML on your page in a div if it is not already in a single container. If you are using something other than a div, then set the pageNodetype in the mmenu config appropriately
- Define your nav ul as shown on the bootstrap component page. But, give the UL an ID so we can reference it later.
- Duplicate the navbar-inner div
- In the first navbar inner, add visible-desktop to the div's class parameter -- this is the navbar that will be shown to desktop users. Bootstrap will hide it below the desktop/tablet width breakpoint
- In the second navbar-inner, add hidden-desktop to the div's class parameter -- this is the navbar that will be shown to tablets/phones (or anything else with a browser width less than 940px by default)
- Add an empty nav container with an ID (I used mainSiteMenuNav) after the closing div of the navbar. This is where the UL for mmenu will be.
- In my code, notice the btn-navbar link in the second navbar-inner. That's the button that's going to open/close mmenu. The href anchor needs to match whatever ID you gave that empty nav container
Since I couldn't use the exact same UL for both menu's, I decided to use jQuery to programmatically duplicate the one used by the bootstrap navbar upon page load and stuff it into the empty nav container for mmenu to use.
It would probably be cleaner to just create the empty nav container programmatically. I'll probably do that tomorrow.
This javascript copies the UL, places it into the nav container and instantiates mmenu with the copied UL:
$(function () {
$("#mainSiteMenuMMenuNav").append($("#mainSiteMenu").clone().attr("id", "mainSiteMenuMMenu").attr("class", ""));
$("#mainSiteMenuMMenuNav").mmenu({
configuration: {
pageNodetype: "div"
}
});
});
That should do it. If you run into problems, please double-check everything. And again, I just figured this out a couple of hours ago .... so it might NOT be a fool proof solution.
If someone has a better way or sees issues, let me know.