From d88336dc39e922eec006b8af3d9301c66b6504ba Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Wed, 26 Aug 2015 11:40:10 +0200 Subject: [PATCH] Fix activating search items in navigation Support activating search input fields in navigation.js, improve setActiveByUrl to recognize search input urls. refs #9761 --- public/js/icinga/behavior/navigation.js | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/public/js/icinga/behavior/navigation.js b/public/js/icinga/behavior/navigation.js index 2883dac8d..e614a95ff 100644 --- a/public/js/icinga/behavior/navigation.js +++ b/public/js/icinga/behavior/navigation.js @@ -83,7 +83,9 @@ * * fixes #7897 */ - $el.html($el.html()); + if ($el.is('li')) { + $el.html($el.html()); + } } // restore hovered menu to current hovered element @@ -145,6 +147,11 @@ // try to active the first item that has an exact URL match this.setActive($('#menu [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 + '"]')); + } + // 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) { @@ -175,7 +182,11 @@ * Remove all active elements */ Navigation.prototype.clear = function() { + // menu items $('#menu li.active', this.element).removeClass('active'); + + // search fields + $('#menu input.active', this.element).removeClass('active'); }; /** @@ -185,15 +196,20 @@ */ Navigation.prototype.select = function($item) { // support selecting the url of the menu entry + var $input = $item.find('input'); $item = $item.closest('li'); - // select the current item - var $selectedMenu = $item.addClass('active'); + if ($item.length) { + // select the current item + var $selectedMenu = $item.addClass('active'); - // unfold the containing menu - var $outerMenu = $selectedMenu.parent().closest('li'); - if ($outerMenu.size()) { - $outerMenu.addClass('active'); + // unfold the containing menu + var $outerMenu = $selectedMenu.parent().closest('li'); + if ($outerMenu.size()) { + $outerMenu.addClass('active'); + } + } else if ($input.length) { + $input.addClass('active'); } }; @@ -207,6 +223,8 @@ this.select($el); if ($el.closest('li')[0]) { this.active = this.icinga.utils.getDomPath($el.closest('li')[0]); + } else if ($el.find('input')[0]) { + this.active = this.icinga.utils.getDomPath($el[0]); } else { this.active = null; }