mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-29 08:44:10 +02:00
Only apply navigation link-click handlers to menu
This commit is contained in:
parent
e216ba6721
commit
0ec97eb934
@ -14,16 +14,14 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.apply = function(el) {
|
Navigation.prototype.apply = function(el) {
|
||||||
// restore menu state
|
// restore old menu state
|
||||||
if (activeMenuId) {
|
if (activeMenuId) {
|
||||||
$('[role="navigation"] li.active', el).removeClass('active');
|
$('[role="navigation"] li.active', el).removeClass('active');
|
||||||
|
var $selectedMenu = $('#' + activeMenuId, el).addClass('active');
|
||||||
var $selectedMenu = $('#' + activeMenuId, el);
|
|
||||||
var $outerMenu = $selectedMenu.parent().closest('li');
|
var $outerMenu = $selectedMenu.parent().closest('li');
|
||||||
if ($outerMenu.size()) {
|
if ($outerMenu.size()) {
|
||||||
$selectedMenu = $outerMenu;
|
$outerMenu.addClass('active');
|
||||||
}
|
}
|
||||||
$selectedMenu.addClass('active');
|
|
||||||
} else {
|
} else {
|
||||||
// store menu state
|
// store menu state
|
||||||
var $menus = $('[role="navigation"] li.active', el);
|
var $menus = $('[role="navigation"] li.active', el);
|
||||||
@ -34,8 +32,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.bind = function() {
|
Navigation.prototype.bind = function() {
|
||||||
$(document).on('click', 'a', { self: this }, this.linkClicked);
|
$(document).on('click', '#menu a', { self: this }, this.linkClicked);
|
||||||
$(document).on('click', 'tr[href]', { self: this }, this.linkClicked);
|
$(document).on('click', '#menu tr[href]', { self: this }, this.linkClicked);
|
||||||
$(document).on('mouseenter', 'li.dropdown', this.dropdownHover);
|
$(document).on('mouseenter', 'li.dropdown', this.dropdownHover);
|
||||||
$(document).on('mouseleave', 'li.dropdown', {self: this}, this.dropdownLeave);
|
$(document).on('mouseleave', 'li.dropdown', {self: this}, this.dropdownLeave);
|
||||||
$(document).on('mouseenter', '#menu > ul > li', { self: this }, this.menuTitleHovered);
|
$(document).on('mouseenter', '#menu > ul > li', { self: this }, this.menuTitleHovered);
|
||||||
@ -43,8 +41,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.unbind = function() {
|
Navigation.prototype.unbind = function() {
|
||||||
$(document).off('click', 'a', this.linkClicked);
|
$(document).off('click', '#menu a', this.linkClicked);
|
||||||
$(document).off('click', 'tr[href]', this.linkClicked);
|
$(document).off('click', '#menu tr[href]', this.linkClicked);
|
||||||
$(document).off('mouseenter', 'li.dropdown', this.dropdownHover);
|
$(document).off('mouseenter', 'li.dropdown', this.dropdownHover);
|
||||||
$(document).off('mouseleave', 'li.dropdown', this.dropdownLeave);
|
$(document).off('mouseleave', 'li.dropdown', this.dropdownLeave);
|
||||||
$(document).off('mouseenter', '#menu > ul > li', this.menuTitleHovered);
|
$(document).off('mouseenter', '#menu > ul > li', this.menuTitleHovered);
|
||||||
@ -53,14 +51,12 @@
|
|||||||
Navigation.prototype.linkClicked = function(event) {
|
Navigation.prototype.linkClicked = function(event) {
|
||||||
var $a = $(this);
|
var $a = $(this);
|
||||||
var href = $a.attr('href');
|
var href = $a.attr('href');
|
||||||
var isMenuLink = $a.closest('#menu').length > 0;
|
|
||||||
var $li;
|
var $li;
|
||||||
var icinga = event.data.self.icinga;
|
var icinga = event.data.self.icinga;
|
||||||
|
|
||||||
if (href.match(/#/)) {
|
if (href.match(/#/)) {
|
||||||
// ...it may be a menu section without a dedicated link.
|
// ...it may be a menu section without a dedicated link.
|
||||||
// Switch the active menu item:
|
// Switch the active menu item:
|
||||||
if (isMenuLink) {
|
|
||||||
$li = $a.closest('li');
|
$li = $a.closest('li');
|
||||||
$('#menu .active').removeClass('active');
|
$('#menu .active').removeClass('active');
|
||||||
$li.addClass('active');
|
$li.addClass('active');
|
||||||
@ -68,25 +64,21 @@
|
|||||||
if ($li.hasClass('hover')) {
|
if ($li.hasClass('hover')) {
|
||||||
$li.removeClass('hover');
|
$li.removeClass('hover');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (href === '#') {
|
if (href === '#') {
|
||||||
// Allow to access dropdown menu by keyboard
|
// Allow to access dropdown menu by keyboard
|
||||||
if ($a.hasClass('dropdown-toggle')) {
|
if ($a.hasClass('dropdown-toggle')) {
|
||||||
$a.closest('li').toggleClass('hover');
|
$a.closest('li').toggleClass('hover');
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isMenuLink) {
|
|
||||||
activeMenuId = $(event.target).closest('li').attr('id');
|
activeMenuId = $(event.target).closest('li').attr('id');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (isMenuLink) {
|
|
||||||
var $menu = $('#menu');
|
|
||||||
// update target url of the menu container to the clicked link
|
// update target url of the menu container to the clicked link
|
||||||
|
var $menu = $('#menu');
|
||||||
var menuDataUrl = icinga.utils.parseUrl($menu.data('icinga-url'));
|
var menuDataUrl = icinga.utils.parseUrl($menu.data('icinga-url'));
|
||||||
menuDataUrl = icinga.utils.addUrlParams(menuDataUrl.path, { url: href });
|
menuDataUrl = icinga.utils.addUrlParams(menuDataUrl.path, { url: href });
|
||||||
$menu.data('icinga-url', menuDataUrl);
|
$menu.data('icinga-url', menuDataUrl);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.menuTitleHovered = function(event) {
|
Navigation.prototype.menuTitleHovered = function(event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user