X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/04a6c41be94cea2175e49aa290bf204e69c41a5c..2e5fa5848fe0343fcd99d628961f9c9e2921f2cd:/public/javascripts/menu.js diff --git a/public/javascripts/menu.js b/public/javascripts/menu.js index 7a0cbf419..5b4c3050e 100644 --- a/public/javascripts/menu.js +++ b/public/javascripts/menu.js @@ -10,16 +10,26 @@ function openMenu(anchor, menu) { }); } +/* + * Close a menu. + */ +function closeMenu(menu) { + clearTimeout(menu.timer); + menu.style.display = "none"; +} + /* * Callback called when the mouse enters a menu anchor. */ function enterMenuAnchor(event, anchor, menu, delay) { - clearTimeout(menu.timer); + if (!anchor.hasClassName("disabled")) { + clearTimeout(menu.timer); - if (delay > 0) { - menu.timer = setTimeout(function () { openMenu(anchor, menu) }, delay); - } else { - openMenu(event, menu); + if (delay > 0) { + menu.timer = setTimeout(function () { openMenu(anchor, menu) }, delay); + } else { + openMenu(event, menu); + } } } @@ -27,7 +37,7 @@ function enterMenuAnchor(event, anchor, menu, delay) { * Callback called when the mouse leaves a menu anchor. */ function leaveMenuAnchor(event, anchor, menu) { - var to = event.relatedTarget || event.toElement; + var to = event.relatedTarget; if (to != menu && !to.descendantOf(menu)) { menu.style.display = "none"; @@ -40,7 +50,7 @@ function leaveMenuAnchor(event, anchor, menu) { * Callback called when the mouse leaves a menu. */ function leaveMenu(event, anchor, menu) { - var to = event.relatedTarget || event.toElement; + var to = event.relatedTarget; if (to != anchor && !to.descendantOf(menu)) { menu.style.display = "none"; @@ -56,7 +66,9 @@ function createMenu(anchorid, menuid, delay) { var anchor = $(anchorid); var menu = $(menuid); - anchor.onmouseover = function (event) { enterMenuAnchor(anchor, anchor, menu, delay) }; - anchor.onmouseout = function (event) { leaveMenuAnchor(event, anchor, menu) }; - menu.onmouseout = function (event) { leaveMenu(event, anchor, menu) }; + anchor.observe("mouseup", function (event) { closeMenu(menu) }); + anchor.observe("mouseover", function (event) { enterMenuAnchor(anchor, anchor, menu, delay) }); + anchor.observe("mouseout", function (event) { leaveMenuAnchor(event, anchor, menu) }); + menu.observe("mouseup", function (event) { closeMenu(menu) }); + menu.observe("mouseout", function (event) { leaveMenu(event, anchor, menu) }); }