X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/04a6c41be94cea2175e49aa290bf204e69c41a5c..9793e4fb7f6503beab0efe1576f3e13dbf350f30:/public/javascripts/menu.js?ds=inline diff --git a/public/javascripts/menu.js b/public/javascripts/menu.js index 7a0cbf419..261517756 100644 --- a/public/javascripts/menu.js +++ b/public/javascripts/menu.js @@ -1,25 +1,43 @@ /* * Open a menu. */ -function openMenu(anchor, menu) { - menu.style.display = "block"; +function openMenu(anchor, menu, align) { + var offset; + + if (align == "left") { + offset = 0; + } else if (align == "right") { + offset = anchor.getWidth() - menu.getWidth(); + } menu.clonePosition(anchor, { setLeft: true, setTop: true, setWidth: false, setHeight: false, - offsetLeft: 0, offsetTop: anchor.getHeight() + offsetLeft: offset, offsetTop: anchor.getHeight() }); + + menu.style.display = "block"; } /* - * Callback called when the mouse enters a menu anchor. + * Close a menu. */ -function enterMenuAnchor(event, anchor, menu, delay) { +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, align) { + 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, align) }, delay); + } else { + openMenu(event, menu, align); + } } } @@ -27,7 +45,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 +58,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"; @@ -52,11 +70,13 @@ function leaveMenu(event, anchor, menu) { /* * Setup a menu, triggered by hovering over an anchor for a given time. */ -function createMenu(anchorid, menuid, delay) { +function createMenu(anchorid, menuid, delay, align) { 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, align) }); + 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) }); }