X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/13289d404188bd397ee72852f66c415a2bb87066..5cb9f2b022ba1c829ae5f4d980f27c7aad694ff6:/app/assets/javascripts/menu.js?ds=inline diff --git a/app/assets/javascripts/menu.js b/app/assets/javascripts/menu.js index 8db1be4b9..a01fc39cc 100644 --- a/app/assets/javascripts/menu.js +++ b/app/assets/javascripts/menu.js @@ -19,65 +19,31 @@ function openMenu(anchor, menu, align) { }); } -/* - * Close a menu. - */ -function closeMenu(menu) { - clearTimeout(menu.timer); - menu.hide(); -} - -/* - * Callback called when the mouse enters a menu anchor. - */ -function enterMenuAnchor(event, anchor, menu, delay, align) { - if (!anchor.hasClass("disabled")) { - clearTimeout(menu.timer); - - if (delay > 0) { - menu.timer = setTimeout(function () { openMenu(anchor, menu, align) }, delay); - } else { - openMenu(event, menu, align); - } - } -} - -/* - * Callback called when the mouse leaves a menu anchor. - */ -function leaveMenuAnchor(event, anchor, menu) { - var to = event.relatedTarget; - - if (!menu.is(to) && menu.has(to).length == 0) { - menu.hide(); - } - - clearTimeout(menu.timer); -} - -/* - * Callback called when the mouse leaves a menu. - */ -function leaveMenu(event, anchor, menu) { - var to = event.relatedTarget; - - if (!anchor.is(to) && menu.has(to).length == 0) { - menu.hide(); - } - - clearTimeout(menu.timer); -} - /* * Setup a menu, triggered by hovering over an anchor for a given time. */ -function createMenu(anchorid, menuid, delay, align) { - var anchor = $("#" + anchorid); - var menu = $("#" + menuid); +function createMenu(anchorid, menuid, align) { + var $anchor = $("#" + anchorid); + var $arrow = $("#" + anchorid + " .menuicon"); + var $menu = $("#" + menuid); + var $page = $(":not(#" + menuid + ", #" + anchorid + ")"); + + function hide() { + $menu.hide(); + $page.off("click", hide); + } - anchor.mouseup(function (event) { closeMenu(menu) }); - anchor.mouseover(function (event) { enterMenuAnchor(anchor, anchor, menu, delay, align) }); - anchor.mouseout(function (event) { leaveMenuAnchor(event, anchor, menu) }); - menu.mouseup(function (event) { closeMenu(menu) }); - menu.mouseout(function (event) { leaveMenu(event, anchor, menu) }); + $arrow.click(function(e) { + if ($anchor.is(":not(.disabled)")) { + e.stopPropagation(); + e.preventDefault(); + if ($menu.is(":visible")) { + $menu.hide(); + $page.off("click", hide); + } else { + openMenu($anchor, $menu.show(), align); + $page.on("click", hide); + } + } + }); }