vendredi 28 novembre 2014

Foundation 2010: add additional menu levels using spf-dropdown.js



This spf-dropdown.js script works fine adding a sub level drop down feature to the top link bar, but I need to add another level. Any menu item with "-- " in front of it gets inserted into a new ul dynamically appended to its parent li.


I'd like to also have items with "---- " inserted into a new ul attached to the first sub item li and triggered by a hover on the sub item. (If that makes sense).


So it would look like this:

Top level site

-- Sub item

---- Sub sub item


Here's the jQuery that's used - if anything else is needed, please let me know:



var namespace = namespace || {
init :
function () {
with (namespace) {
spfDropdowns();
}
},
spfDropdowns :
function () {
// get drop-down menu items
var dropDownItems = jQuery('.s4-tn li.static');

// tag submenu items as submenu items
dropDownItems.filter(':contains("-- ")').addClass('spfDropdowns-submenuitem');
dropDownItems.filter(':contains("---- ")').addClass('spfDropdowns-submenuitem2');


// move submenu items into a dynamically created submenus
dropDownItems.each(function(i,val) {
// hi, i'm the menu item
var $me = jQuery(this);
if ($me.hasClass('spfDropdowns-submenuitem')) {
// i don't need to tell you i'm a submenu item again, do i?!
this.innerHTML = this.innerHTML.replace('---- ','');
this.innerHTML = this.innerHTML.replace('-- ','');


// look back at the nav items before me, until you find my parent
var $parent = $me.prev(':not(.spfDropdowns-submenuitem)');
// my parent holds me in a submenu, so make sure it has one!
if(! $parent.hasClass('spfDropdowns-haschildren')) {
$parent.addClass('spfDropdowns-haschildren').append('<ul class="spfDropdowns-dynamic"></ul>');
}
// I give up and go to live with my $parent :)
$me.remove().appendTo($parent.children('ul.spfDropdowns-dynamic'));
$me.removeClass('static').children().removeClass('static');
$me.addClass('dynamic').children().addClass('dynamic');
}
});
jQuery('.s4-tn').addClass('processed'); // .s4-tn should now be hidden unless it has the .processed class
},

}
//queue for DOM load
jQuery(namespace.init);







0 commentaires:

Enregistrer un commentaire