4 function openMenu(anchor, menu, align) {
5 var anchorPosition = anchor.offset();
10 } else if (align == "right") {
11 offset = menu.outerWidth() - anchor.outerWidth();
17 top: anchorPosition.top + anchor.outerHeight(),
18 left: anchorPosition.left - offset
25 function closeMenu(menu) {
26 clearTimeout(menu.timer);
31 * Callback called when the mouse enters a menu anchor.
33 function enterMenuAnchor(event, anchor, menu, delay, align) {
34 if (!anchor.hasClass("disabled")) {
35 clearTimeout(menu.timer);
38 menu.timer = setTimeout(function () { openMenu(anchor, menu, align); }, delay);
40 openMenu(event, menu, align);
46 * Callback called when the mouse leaves a menu anchor.
48 function leaveMenuAnchor(event, anchor, menu) {
49 var to = event.relatedTarget;
51 if (!menu.is(to) && menu.has(to).length === 0) {
55 clearTimeout(menu.timer);
59 * Callback called when the mouse leaves a menu.
61 function leaveMenu(event, anchor, menu) {
62 var to = event.relatedTarget;
64 if (!anchor.is(to) && menu.has(to).length === 0) {
68 clearTimeout(menu.timer);
72 * Setup a menu, triggered by hovering over an anchor for a given time.
74 function createMenu(anchorid, menuid, delay, align) {
75 var anchor = $("#" + anchorid);
76 var menu = $("#" + menuid);
78 anchor.mouseup(function (event) { closeMenu(menu); });
79 anchor.mouseover(function (event) { enterMenuAnchor(anchor, anchor, menu, delay, align); });
80 anchor.mouseout(function (event) { leaveMenuAnchor(event, anchor, menu); });
81 menu.mouseup(function (event) { closeMenu(menu); });
82 menu.mouseout(function (event) { leaveMenu(event, anchor, menu); });