var dropdownMenu = (function() {
var $listItems = $('ul.dropdown > li'),
$menuItems = $listItems.children('a'),
$body = $('body'),
current = -1;
function init(){
$menuItems.on('click touchstart', open);
$listItems.on('click touchstart', function(event){
event.stopPropagation();
});
}
function open(event){
if(current !== -1) {
$listItems.eq(current).removeClass('is-open');
}
var $item = $(event.currentTarget).parent('li'),
idx = $item.index();
if(current === idx) {
$item.removeClass('is-open');
current = -1;
}
else {
$item.addClass('is-open');
current = idx;
$body.off('click touchstart').on('click touchstart', close);
}
return false;
}
function close(event) {
$listItems.eq(current).removeClass('is-open');
current = -1;
}
return {
init : init
};
})();
$(function() {
dropdownMenu.init();
});
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.