Merge branch 'bugfix/always-use-the-jquery-find-method-w/-node-context-10704'

fixes #10704
This commit is contained in:
Eric Lippmann 2016-12-08 17:15:02 +01:00
commit 626afbd5ec
2 changed files with 17 additions and 32 deletions

View File

@ -49,7 +49,7 @@ EOT;
* @var string
*/
private $closeTpl = <<< 'EOT'
<li class="dropdown" style="float: right;">
<li style="float: right;">
<a href="#" title="{TITLE}" aria-label="{TITLE}" class="close-container-control">
<i aria-hidden="true" class="icon-cancel"></i>
</a>

View File

@ -10,11 +10,9 @@
Icinga.EventListener.call(this, icinga);
this.on('click', '#menu a', this.linkClicked, this);
this.on('click', '#menu tr[href]', this.linkClicked, this);
this.on('mouseenter', 'li.dropdown', this.dropdownHover, this);
this.on('mouseleave', 'li.dropdown', this.dropdownLeave, this);
this.on('mouseenter', '#menu > nav > ul > li', this.menuTitleHovered, this);
this.on('mouseleave', '#sidebar', this.leaveSidebar, this);
this.on('rendered', this.onRendered, this);
this.on('rendered', '#menu', this.onRendered, this);
/**
* The DOM-Path of the active item
@ -35,9 +33,11 @@
this.hovered = null;
/**
* @type {HTMLElement}
* The menu
*
* @type {jQuery}
*/
this.element = null;
this.$menu = null;
};
Navigation.prototype = new Icinga.EventListener();
@ -49,16 +49,18 @@
Navigation.prototype.onRendered = function(e) {
var _this = e.data.self;
this.element = e.target;
if (! _this.$menu) {
_this.$menu = $(e.target);
}
if (! _this.active) {
// There is no stored menu item, therefore it is assumed that this is the first rendering
// of the navigation after the page has been opened.
// initialise the menu selected by the backend as active.
var $menus = $('#menu li.active', e.target);
if ($menus.length) {
$menus.each(function() {
var $active = _this.$menu.find('li.active');
if ($active.length) {
$active.each(function() {
_this.setActive($(this));
});
} else {
@ -147,17 +149,17 @@
Navigation.prototype.setActiveByUrl = function(url) {
// try to active the first item that has an exact URL match
this.setActive($('#menu [href="' + url + '"]'));
this.setActive(this.$menu.find('[href="' + url + '"]'));
// the url may point to the search field, which must be activated too
if (! this.active) {
this.setActive($('#menu form[action="' + this.icinga.utils.parseUrl(url).path + '"]'));
this.setActive(this.$menu.find('form[action="' + this.icinga.utils.parseUrl(url).path + '"]'));
}
// some urls may have custom filters which won't match any menu item, in that case search
// for a menu item that points to the base action without any filters
if (! this.active) {
this.setActive($('#menu [href="' + this.icinga.utils.parseUrl(url).path + '"]').first());
this.setActive(this.$menu.find('[href="' + this.icinga.utils.parseUrl(url).path + '"]').first());
}
};
@ -179,10 +181,10 @@
*/
Navigation.prototype.clear = function() {
// menu items
$('#menu li.active', this.element).removeClass('active');
this.$menu.find('li.active').removeClass('active');
// search fields
$('#menu input.active', this.element).removeClass('active');
this.$menu.find('input.active').removeClass('active');
};
/**
@ -350,23 +352,6 @@
}
};
Navigation.prototype.dropdownHover = function () {
$(this).addClass('hover');
};
Navigation.prototype.dropdownLeave = function (event) {
var $li = $(this),
_this = event.data.self;
setTimeout(function () {
// TODO: make this behave well together with keyboard navigation
try {
if (!$li.is('li:hover') /*&& ! $li.find('a:focus')*/) {
$li.removeClass('hover');
}
} catch(e) { /* Bypass because if IE8 */ }
}, 300);
_this.hovered = null;
};
Icinga.Behaviors.Navigation = Navigation;
}) (Icinga, jQuery);