Hide other submenus when opening a new one
This commit is contained in:
@ -1,22 +1,27 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
var subMenusSelector = 'ul.dropdown-menu [data-toggle=dropdown]';
|
||||||
|
|
||||||
function openSubMenu(event) {
|
function openSubMenu(event) {
|
||||||
if (this.pathname === '/') {
|
if (this.pathname === '/') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
$(subMenusSelector).parent().removeClass('open');
|
||||||
$(this).parent().addClass('open');
|
$(this).parent().addClass('open');
|
||||||
|
|
||||||
var menu = $(this).parent().find("ul");
|
var menu = $(this).parent().find("ul");
|
||||||
var menupos = menu.offset();
|
var menupos = menu.offset();
|
||||||
|
|
||||||
|
var newPos;
|
||||||
if ((menupos.left + menu.width()) + 30 > $(window).width()) {
|
if ((menupos.left + menu.width()) + 30 > $(window).width()) {
|
||||||
var newpos = -menu.width();
|
newPos = -menu.width();
|
||||||
} else {
|
} else {
|
||||||
var newpos = $(this).parent().width();
|
newPos = $(this).parent().width();
|
||||||
}
|
}
|
||||||
menu.css({left: newpos});
|
menu.css({left: newPos});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', openSubMenu).on('mouseenter', openSubMenu);
|
$(subMenusSelector).on('click', openSubMenu).on('mouseenter', openSubMenu);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user