mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Restore hover menu on reload
Remember the hovered menu and restore it on each reload. fixes #8969
This commit is contained in:
parent
15ec564bc5
commit
2541b0eba4
@ -16,11 +16,12 @@
|
|||||||
this.on('mouseleave', 'li.dropdown', this.dropdownLeave, this);
|
this.on('mouseleave', 'li.dropdown', this.dropdownLeave, this);
|
||||||
this.on('mouseenter', '#menu > nav > ul > li', this.menuTitleHovered, this);
|
this.on('mouseenter', '#menu > nav > ul > li', this.menuTitleHovered, this);
|
||||||
this.on('mouseleave', '#sidebar', this.leaveSidebar, this);
|
this.on('mouseleave', '#sidebar', this.leaveSidebar, this);
|
||||||
this.on('rendered', this.onRendered);
|
this.on('rendered', this.onRendered, this);
|
||||||
};
|
};
|
||||||
Navigation.prototype = new Icinga.EventListener();
|
Navigation.prototype = new Icinga.EventListener();
|
||||||
|
|
||||||
Navigation.prototype.onRendered = function(evt) {
|
Navigation.prototype.onRendered = function(evt) {
|
||||||
|
var self = evt.data.self;
|
||||||
// get original source element of the rendered-event
|
// get original source element of the rendered-event
|
||||||
var el = evt.target;
|
var el = evt.target;
|
||||||
if (activeMenuId) {
|
if (activeMenuId) {
|
||||||
@ -50,14 +51,23 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// restore hovered menu after auto-reload
|
||||||
|
if (self.hovered) {
|
||||||
|
var hovered = self.icinga.utils.getElementByDomPath(self.hovered);
|
||||||
|
if (hovered) {
|
||||||
|
self.hoverElement($(hovered));
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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 $li;
|
var $li;
|
||||||
var icinga = event.data.self.icinga;
|
var self = event.data.self;
|
||||||
|
var icinga = self.icinga;
|
||||||
|
|
||||||
|
self.hovered = null;
|
||||||
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:
|
||||||
@ -88,7 +98,7 @@
|
|||||||
Navigation.prototype.setActiveByUrl = function(url) {
|
Navigation.prototype.setActiveByUrl = function(url) {
|
||||||
this.resetActive();
|
this.resetActive();
|
||||||
this.setActive($('#menu [href="' + url + '"]'));
|
this.setActive($('#menu [href="' + url + '"]'));
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the active menu element
|
* Change the active menu element
|
||||||
@ -96,7 +106,6 @@
|
|||||||
* @param $el {jQuery} A selector pointing to the active element
|
* @param $el {jQuery} A selector pointing to the active element
|
||||||
*/
|
*/
|
||||||
Navigation.prototype.setActive = function($el) {
|
Navigation.prototype.setActive = function($el) {
|
||||||
|
|
||||||
$el.closest('li').addClass('active');
|
$el.closest('li').addClass('active');
|
||||||
$el.parents('li').addClass('active');
|
$el.parents('li').addClass('active');
|
||||||
activeMenuId = $el.closest('li').attr('id');
|
activeMenuId = $el.closest('li').attr('id');
|
||||||
@ -112,6 +121,7 @@
|
|||||||
delay = 800,
|
delay = 800,
|
||||||
self = event.data.self;
|
self = event.data.self;
|
||||||
|
|
||||||
|
self.hovered = null;
|
||||||
if ($li.hasClass('active')) {
|
if ($li.hasClass('active')) {
|
||||||
$li.siblings().removeClass('hover');
|
$li.siblings().removeClass('hover');
|
||||||
return;
|
return;
|
||||||
@ -170,11 +180,17 @@
|
|||||||
$li.removeClass('hover');
|
$li.removeClass('hover');
|
||||||
$('#layout').removeClass('hoveredmenu');
|
$('#layout').removeClass('hoveredmenu');
|
||||||
}, 500);
|
}, 500);
|
||||||
|
self.hovered = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.hoverElement = function ($li) {
|
Navigation.prototype.hoverElement = function ($li) {
|
||||||
$('#layout').addClass('hoveredmenu');
|
$('#layout').addClass('hoveredmenu');
|
||||||
$li.addClass('hover');
|
$li.addClass('hover');
|
||||||
|
if ($li[0]) {
|
||||||
|
this.hovered = this.icinga.utils.getDomPath($li[0]);
|
||||||
|
} else {
|
||||||
|
this.hovered = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Navigation.prototype.dropdownHover = function () {
|
Navigation.prototype.dropdownHover = function () {
|
||||||
@ -192,6 +208,7 @@
|
|||||||
}
|
}
|
||||||
} catch(e) { /* Bypass because if IE8 */ }
|
} catch(e) { /* Bypass because if IE8 */ }
|
||||||
}, 300);
|
}, 300);
|
||||||
|
self.hovered = null;
|
||||||
};
|
};
|
||||||
Icinga.Behaviors.Navigation = Navigation;
|
Icinga.Behaviors.Navigation = Navigation;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user