From a4eec499eed0ef826e061d11ed7c35d099397861 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Thu, 6 Dec 2012 09:46:15 +0100 Subject: [PATCH] SONAR-3972 Fix issue when clicking on already displayed menu --- .../main/webapp/javascripts/application.js | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index f2f152bc273..dab9e953d63 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -312,12 +312,42 @@ function supports_html5_storage() { } } -var hideDropdownMenus = function() { - $j('.dropdown-menu').hide(); - $j(document).unbind('mouseup', hideDropdownMenus); +//******************* HANDLING OF DROPDOWN MENUS [BEGIN] ******************* // + +var currentlyDisplayedDropdownMenu; + +var hideCurrentDropdownMenu = function() { + menu = $j('#' + currentlyDisplayedDropdownMenu); + if (menu) { + menu.hide(); + } + $j(document).unbind('mouseup', hideCurrentDropdownMenu); +} + +var clickOnDropdownMenuLink = function(event) { + var link = $j(event.target).children('a'); + if (link) { + var href = link.attr('href'); + if (href && href.length > 1) { + // there's a real link, not a href="#" + window.location = href; + } else { + // otherwise, this means that the link is handled with an onclick event (for Ajax calls) + link.click(); + } + } } function showDropdownMenu(menuId) { - $j(document).bind('mouseup', hideDropdownMenus); - $j('#' + menuId).show(); + if (menuId == currentlyDisplayedDropdownMenu) { + currentlyDisplayedDropdownMenu = ""; + } else { + currentlyDisplayedDropdownMenu = menuId; + $j(document).mouseup(hideCurrentDropdownMenu); + $j('#' + currentlyDisplayedDropdownMenu + ' li').unbind('click'); + $j('#' + currentlyDisplayedDropdownMenu + ' li').click(clickOnDropdownMenuLink); + $j('#' + currentlyDisplayedDropdownMenu).show(); + } } + +//******************* HANDLING OF DROPDOWN MENUS [END] ******************* // -- 2.39.5