The template provides a plugin to display multi-level menus like touch devices, with sliding parts. It can also load content via AJAX, automatically
To enable this feature, simply wrap the desired menu into an element with the class navigable:
<section class="navigable"> ... menu ... </section>
This example shows a section, but you can use a div as well. The navigable wrapper may be used anywhere, including inside another menu.
Sub-levels should be embedded within their parent element:
<section class="navigable"> <ul class="big-menu"> <li class="with-right-arrow"> <span><span class="list-count">3</span>Root element</span> <ul class="big-menu"> <li><a href="#">Children element</a></li> <li><a href="#">Children element</a></li> <li><a href="#">Children element</a></li> <li class="with-right-arrow"> <span>Children with subs</span> <ul class="big-menu"> <li><a href="#">Children element</a></li> <li><a href="#">Children element</a></li> <li><a href="#">Children element</a></li> </ul> </li> </ul> </li> ... </ul> </section>
Here is an example result:
Since v1.4, the back button will display the text of the parent element. If you want to set a custom text instead, you may do one of the following:
// Change default (affect all menus) $.template.navigable.backText = 'Back';
<!-- Set an inline option --> <section class="navigable" data-navigable-options='{"backText":"Back"}'>
If you want to menu to be open at startup to show a specific element (for instance, the current page), add the class navigable-current to this element:
<section class="navigable"> ... <li><a href="#" class="navigable-current">Current element</a></li> ... </section>
From version 1.4, you can now reset the menu to its main level by calling this on the menu:
$('.navigable').navigableReset();
To speed up loading, you may want to include only root elements, and load their content via AJAX. This is really simple with this plugin, just set the menu as a link with the content URL as href and add the class navigable-ajax - for instance:
<section class="navigable"> <ul class="big-menu"> <li class="with-right-arrow"> <a href="path-to-content" class="navigable-ajax">With ajax sub-menu</a> </li> ... </ul> </section>
Note that instead of a link, you may use a span with a special data attribute:
<section class="navigable"> <ul class="big-menu"> <li class="with-right-arrow"> <span data-navigable-url="path-to-content" class="navigable-ajax">With ajax sub-menu</span> </li> ... </ul> </section>
Here is a demo:
The plugin will display a loading animation, and when the content is loaded, append it to the clicked element as a sub-menu. Note that the loaded content should be an already formatted output, the plugin won't perform any transformation on it.
If loading fails, a message is displayed using the notification plugin (if available).