2306 |
22 May 06 |
jari |
/* $Id$ |
417 |
19 Apr 05 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Gregory Vincic |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Nicklas Nordborg |
417 |
19 Apr 05 |
nicklas |
6 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
417 |
19 Apr 05 |
nicklas |
9 |
|
417 |
19 Apr 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
417 |
19 Apr 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
417 |
19 Apr 05 |
nicklas |
of the License, or (at your option) any later version. |
417 |
19 Apr 05 |
nicklas |
14 |
|
417 |
19 Apr 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
417 |
19 Apr 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
417 |
19 Apr 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
417 |
19 Apr 05 |
nicklas |
GNU General Public License for more details. |
417 |
19 Apr 05 |
nicklas |
19 |
|
417 |
19 Apr 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
417 |
19 Apr 05 |
nicklas |
22 |
------------------------------------------------------------------ |
417 |
19 Apr 05 |
nicklas |
23 |
|
417 |
19 Apr 05 |
nicklas |
JavaScript functions for the Menu taglib. |
417 |
19 Apr 05 |
nicklas |
25 |
|
417 |
19 Apr 05 |
nicklas |
@author Nicklas |
417 |
19 Apr 05 |
nicklas |
@version 2.0 |
417 |
19 Apr 05 |
nicklas |
28 |
*/ |
7419 |
03 Nov 17 |
nicklas |
'use strict'; |
417 |
19 Apr 05 |
nicklas |
30 |
|
6201 |
07 Nov 12 |
nicklas |
var Menu = function() |
417 |
19 Apr 05 |
nicklas |
32 |
{ |
6201 |
07 Nov 12 |
nicklas |
var menu = {}; |
6201 |
07 Nov 12 |
nicklas |
var internal = {}; |
6201 |
07 Nov 12 |
nicklas |
var visibleMenus = []; |
714 |
02 Jun 05 |
nicklas |
36 |
|
6201 |
07 Nov 12 |
nicklas |
37 |
/** |
6201 |
07 Nov 12 |
nicklas |
Show a top-level menu at the given position. |
6201 |
07 Nov 12 |
nicklas |
@param menuDiv A menu object or ID |
6201 |
07 Nov 12 |
nicklas |
@param x,y The pixel coordinates for the top left/right corner of the menu |
6201 |
07 Nov 12 |
nicklas |
@param alignRight If set the x coordinate is counted from the right side of |
6201 |
07 Nov 12 |
nicklas |
the window and the right side of the menu is aligned to that pixel |
6201 |
07 Nov 12 |
nicklas |
43 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.showTopMenu = function(menuDiv, x, y, alignRight) |
714 |
02 Jun 05 |
nicklas |
45 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.hideAll(); |
6201 |
07 Nov 12 |
nicklas |
menuDiv = Doc.element(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
if (alignRight) |
714 |
02 Jun 05 |
nicklas |
49 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.right = (x)+'px'; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.left = 'auto'; |
714 |
02 Jun 05 |
nicklas |
52 |
} |
714 |
02 Jun 05 |
nicklas |
else |
714 |
02 Jun 05 |
nicklas |
54 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.left = (x)+'px'; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.right = 'auto'; |
714 |
02 Jun 05 |
nicklas |
57 |
} |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.top = (y)+'px'; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.display = 'block'; |
7943 |
04 May 21 |
nicklas |
menuDiv.style.zIndex = '999'; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.canHide = true; |
6201 |
07 Nov 12 |
nicklas |
internal.registerVisible(menuDiv); |
714 |
02 Jun 05 |
nicklas |
63 |
} |
714 |
02 Jun 05 |
nicklas |
64 |
|
6201 |
07 Nov 12 |
nicklas |
65 |
/** |
6201 |
07 Nov 12 |
nicklas |
Toggle a top-level menu. If the menu is not visible it is shown, |
6201 |
07 Nov 12 |
nicklas |
otherwise it is hidden. |
6201 |
07 Nov 12 |
nicklas |
@param menuDiv A menu object or ID |
6201 |
07 Nov 12 |
nicklas |
@param x,y The pixel coordinates for the top left corner of the menu |
6201 |
07 Nov 12 |
nicklas |
70 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.toggleTopMenu = function(menuDiv, x, y, alignRight) |
5808 |
17 Oct 11 |
nicklas |
72 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuDiv = Doc.element(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
if (menuDiv.style.display == 'none') |
417 |
19 Apr 05 |
nicklas |
75 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.showTopMenu(menuDiv, x, y, alignRight); |
417 |
19 Apr 05 |
nicklas |
77 |
} |
472 |
27 Apr 05 |
nicklas |
else |
472 |
27 Apr 05 |
nicklas |
79 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(menuDiv, true); |
472 |
27 Apr 05 |
nicklas |
81 |
} |
417 |
19 Apr 05 |
nicklas |
82 |
} |
472 |
27 Apr 05 |
nicklas |
83 |
|
6201 |
07 Nov 12 |
nicklas |
84 |
/** |
6201 |
07 Nov 12 |
nicklas |
Hide all visible menus and their submenus. |
6201 |
07 Nov 12 |
nicklas |
86 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.hideAll = function() |
417 |
19 Apr 05 |
nicklas |
88 |
{ |
6201 |
07 Nov 12 |
nicklas |
var i = 0; |
6201 |
07 Nov 12 |
nicklas |
while (visibleMenus.length > 0 && i < 10) |
6201 |
07 Nov 12 |
nicklas |
91 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(visibleMenus[0], true); |
6201 |
07 Nov 12 |
nicklas |
i++; |
6201 |
07 Nov 12 |
nicklas |
94 |
} |
5808 |
17 Oct 11 |
nicklas |
95 |
} |
5808 |
17 Oct 11 |
nicklas |
96 |
|
6201 |
07 Nov 12 |
nicklas |
97 |
/** |
6201 |
07 Nov 12 |
nicklas |
Get the menu that the given menu-item belongs to. |
6201 |
07 Nov 12 |
nicklas |
99 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.getMenuOfMenuItem = function(menuItem) |
5808 |
17 Oct 11 |
nicklas |
101 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuItem = Doc.element(menuItem); |
6201 |
07 Nov 12 |
nicklas |
if (!menuItem.menu) |
6201 |
07 Nov 12 |
nicklas |
104 |
{ |
6201 |
07 Nov 12 |
nicklas |
var parent = menuItem.parentNode; |
6201 |
07 Nov 12 |
nicklas |
while (parent.tagName.toLowerCase() != 'div') |
6201 |
07 Nov 12 |
nicklas |
107 |
{ |
6201 |
07 Nov 12 |
nicklas |
parent = parent.parentNode; |
6201 |
07 Nov 12 |
nicklas |
109 |
} |
6201 |
07 Nov 12 |
nicklas |
menuItem.menu = parent; |
6201 |
07 Nov 12 |
nicklas |
111 |
} |
6201 |
07 Nov 12 |
nicklas |
return menuItem.menu; |
6201 |
07 Nov 12 |
nicklas |
113 |
} |
6201 |
07 Nov 12 |
nicklas |
114 |
|
6201 |
07 Nov 12 |
nicklas |
115 |
/** |
6201 |
07 Nov 12 |
nicklas |
Show a submenu. |
6201 |
07 Nov 12 |
nicklas |
@param menuItem The ID or document element of the menu-item that is linked with the submenu |
6201 |
07 Nov 12 |
nicklas |
@param subMenu The submenu object or ID to display |
6201 |
07 Nov 12 |
nicklas |
119 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.showSubMenu = function(menuItem, subMenu) |
6201 |
07 Nov 12 |
nicklas |
121 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuItem = Doc.element(menuItem); |
6201 |
07 Nov 12 |
nicklas |
subMenu = Doc.element(subMenu); |
6201 |
07 Nov 12 |
nicklas |
var menuDiv = menu.getMenuOfMenuItem(menuItem); |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(menuDiv); |
6400 |
27 Jan 14 |
nicklas |
var pos = Doc.getElementPosition(menuItem); |
6201 |
07 Nov 12 |
nicklas |
var vertical = Data.int(menuDiv, 'vertical'); |
6610 |
20 Nov 14 |
nicklas |
var dx = vertical ? pos.width : -1; // place submenu to the right of the parent menu |
6201 |
07 Nov 12 |
nicklas |
var dy = vertical ? 0 : pos.height; // place submenu below the parent menu |
6201 |
07 Nov 12 |
nicklas |
subMenu.style.left = (pos.left+dx)+'px'; |
6201 |
07 Nov 12 |
nicklas |
subMenu.style.right = 'auto'; |
6201 |
07 Nov 12 |
nicklas |
subMenu.style.top = (pos.top+dy)+'px'; |
6201 |
07 Nov 12 |
nicklas |
subMenu.style.display = 'block'; |
7943 |
04 May 21 |
nicklas |
subMenu.style.zIndex = parseInt(menuDiv.style.zIndex || '999')+1; |
6201 |
07 Nov 12 |
nicklas |
subMenu.canHide = true; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.activeSubMenu = subMenu; |
6201 |
07 Nov 12 |
nicklas |
internal.registerVisible(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
138 |
} |
6201 |
07 Nov 12 |
nicklas |
139 |
|
6201 |
07 Nov 12 |
nicklas |
140 |
|
6201 |
07 Nov 12 |
nicklas |
141 |
/** |
6201 |
07 Nov 12 |
nicklas |
Hide submenus that have been opened from the given |
6201 |
07 Nov 12 |
nicklas |
menu. |
6201 |
07 Nov 12 |
nicklas |
@param menuDiv A menu object or the ID |
6201 |
07 Nov 12 |
nicklas |
@param hideTopMenu If set, the top, level menu is hidden as well |
6201 |
07 Nov 12 |
nicklas |
146 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus = function(menuDiv, hideTopMenu) |
6201 |
07 Nov 12 |
nicklas |
148 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuDiv = Doc.element(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
var activeSubMenu = menuDiv.activeSubMenu; |
472 |
27 Apr 05 |
nicklas |
if (activeSubMenu) |
472 |
27 Apr 05 |
nicklas |
152 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(activeSubMenu, false); |
472 |
27 Apr 05 |
nicklas |
activeSubMenu.style.display = 'none'; |
6201 |
07 Nov 12 |
nicklas |
menuDiv.activeSubMenu = null; |
6201 |
07 Nov 12 |
nicklas |
internal.unregisterVisible(menuDiv); |
472 |
27 Apr 05 |
nicklas |
157 |
} |
6201 |
07 Nov 12 |
nicklas |
if (menuDiv.canHide && hideTopMenu) |
758 |
13 Jun 05 |
nicklas |
159 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuDiv.style.display = 'none'; |
6201 |
07 Nov 12 |
nicklas |
internal.unregisterVisible(menuDiv); |
758 |
13 Jun 05 |
nicklas |
162 |
} |
417 |
19 Apr 05 |
nicklas |
163 |
} |
472 |
27 Apr 05 |
nicklas |
164 |
|
6201 |
07 Nov 12 |
nicklas |
165 |
/** |
6201 |
07 Nov 12 |
nicklas |
Toggle the visibility of a submenu. If the given |
6201 |
07 Nov 12 |
nicklas |
submenu is the currently active submenu, it is hidden, |
6201 |
07 Nov 12 |
nicklas |
otherwise it is shown. |
6201 |
07 Nov 12 |
nicklas |
@param menuItem The ID or document element of the menu-item that is linked with the submenu |
6201 |
07 Nov 12 |
nicklas |
@param subMenu The submenu object or ID to display |
6201 |
07 Nov 12 |
nicklas |
171 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.toggleSubMenu = function(menuItem, subMenu) |
5808 |
17 Oct 11 |
nicklas |
173 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuItem = Doc.element(menuItem); |
6201 |
07 Nov 12 |
nicklas |
subMenu = Doc.element(subMenu); |
6201 |
07 Nov 12 |
nicklas |
var menuDiv = menu.getMenuOfMenuItem(menuItem); |
6201 |
07 Nov 12 |
nicklas |
if (menuDiv.activeSubMenu == subMenu) |
6201 |
07 Nov 12 |
nicklas |
178 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
180 |
} |
6201 |
07 Nov 12 |
nicklas |
else |
6201 |
07 Nov 12 |
nicklas |
182 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.showSubMenu(menuItem, subMenu); |
6201 |
07 Nov 12 |
nicklas |
184 |
} |
5808 |
17 Oct 11 |
nicklas |
185 |
} |
5808 |
17 Oct 11 |
nicklas |
186 |
|
6201 |
07 Nov 12 |
nicklas |
187 |
/** |
6201 |
07 Nov 12 |
nicklas |
Open the given URL. |
6201 |
07 Nov 12 |
nicklas |
189 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.openUrl = function(url, target) |
417 |
19 Apr 05 |
nicklas |
191 |
{ |
6201 |
07 Nov 12 |
nicklas |
var targetWindow = (target == null ? window : window.top.frames[target]); |
6201 |
07 Nov 12 |
nicklas |
if (targetWindow != null) |
417 |
19 Apr 05 |
nicklas |
194 |
{ |
6201 |
07 Nov 12 |
nicklas |
targetWindow.location = url; |
7894 |
08 Dec 20 |
nicklas |
var content = document.getElementsByClassName('content'); |
7894 |
08 Dec 20 |
nicklas |
setTimeout(Forms.pleaseWait, 1000, content.length == 1 ? content[0] : null); |
417 |
19 Apr 05 |
nicklas |
198 |
} |
417 |
19 Apr 05 |
nicklas |
else |
417 |
19 Apr 05 |
nicklas |
200 |
{ |
6201 |
07 Nov 12 |
nicklas |
window.open(url, target); |
417 |
19 Apr 05 |
nicklas |
202 |
} |
417 |
19 Apr 05 |
nicklas |
203 |
} |
472 |
27 Apr 05 |
nicklas |
204 |
|
6201 |
07 Nov 12 |
nicklas |
205 |
/** |
6201 |
07 Nov 12 |
nicklas |
Add a click event handler to the menuitem unless it is disabled. |
6201 |
07 Nov 12 |
nicklas |
The menuItem is either the ID or a document element |
6201 |
07 Nov 12 |
nicklas |
208 |
*/ |
6201 |
07 Nov 12 |
nicklas |
menu.addClickHandler = function(menuItem, handler) |
417 |
19 Apr 05 |
nicklas |
210 |
{ |
6201 |
07 Nov 12 |
nicklas |
menuItem = Doc.element(menuItem); |
6201 |
07 Nov 12 |
nicklas |
if (!menuItem) return; |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(menuItem, 'click', handler); |
472 |
27 Apr 05 |
nicklas |
214 |
} |
472 |
27 Apr 05 |
nicklas |
215 |
|
6201 |
07 Nov 12 |
nicklas |
216 |
/** |
6201 |
07 Nov 12 |
nicklas |
Add the given menu to the list of visible menus |
6201 |
07 Nov 12 |
nicklas |
218 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.registerVisible = function(menuDiv) |
472 |
27 Apr 05 |
nicklas |
220 |
{ |
6201 |
07 Nov 12 |
nicklas |
visibleMenus[visibleMenus.length] = menuDiv; |
6201 |
07 Nov 12 |
nicklas |
222 |
} |
6201 |
07 Nov 12 |
nicklas |
223 |
|
6201 |
07 Nov 12 |
nicklas |
224 |
/** |
6201 |
07 Nov 12 |
nicklas |
Remove the given menu from the list of visible menus. |
6201 |
07 Nov 12 |
nicklas |
226 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.unregisterVisible = function(menuDiv) |
6201 |
07 Nov 12 |
nicklas |
228 |
{ |
6201 |
07 Nov 12 |
nicklas |
for (var i = visibleMenus.length-1; i >= 0; i--) |
417 |
19 Apr 05 |
nicklas |
230 |
{ |
6201 |
07 Nov 12 |
nicklas |
if (visibleMenus[i] == menuDiv) |
6201 |
07 Nov 12 |
nicklas |
232 |
{ |
6201 |
07 Nov 12 |
nicklas |
visibleMenus.splice(i, 1); |
6201 |
07 Nov 12 |
nicklas |
return; |
6201 |
07 Nov 12 |
nicklas |
235 |
} |
417 |
19 Apr 05 |
nicklas |
236 |
} |
417 |
19 Apr 05 |
nicklas |
237 |
} |
417 |
19 Apr 05 |
nicklas |
238 |
|
6201 |
07 Nov 12 |
nicklas |
239 |
/** |
6201 |
07 Nov 12 |
nicklas |
Initialize menu items by adding event listeners to the menu items, etc. |
6201 |
07 Nov 12 |
nicklas |
This method handle the following auto-initializable elements: |
6201 |
07 Nov 12 |
nicklas |
* submenu: A menu-item that opens up a new submenu |
6201 |
07 Nov 12 |
nicklas |
* menuitem: A menu-item in a menu that has either a target url or an onclick (deprecated) handler |
6201 |
07 Nov 12 |
nicklas |
* menu-anchor: An element that open a new top-level menu |
6201 |
07 Nov 12 |
nicklas |
245 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.initMenuItems = function(element, autoInit) |
417 |
19 Apr 05 |
nicklas |
247 |
{ |
6201 |
07 Nov 12 |
nicklas |
if (autoInit == 'submenu') |
472 |
27 Apr 05 |
nicklas |
249 |
{ |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(element, 'click', internal.submenuOnClick); |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(element, 'mouseover', internal.submenuOnMouseOver); |
6201 |
07 Nov 12 |
nicklas |
252 |
} |
6201 |
07 Nov 12 |
nicklas |
else if (autoInit == 'menuitem') |
6201 |
07 Nov 12 |
nicklas |
254 |
{ |
6201 |
07 Nov 12 |
nicklas |
var url = Data.get(element, 'url'); |
6201 |
07 Nov 12 |
nicklas |
if (url) |
472 |
27 Apr 05 |
nicklas |
257 |
{ |
6415 |
05 Feb 14 |
nicklas |
element.addEventListener('click', Events.stopIfDisabled, true); |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(element, 'click', internal.menuItemWithUrlOnClick); |
472 |
27 Apr 05 |
nicklas |
260 |
} |
472 |
27 Apr 05 |
nicklas |
261 |
} |
6201 |
07 Nov 12 |
nicklas |
else if (autoInit == 'menu') |
6201 |
07 Nov 12 |
nicklas |
263 |
{ |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(element, 'mouseover', internal.menuOnMouseOver); |
6201 |
07 Nov 12 |
nicklas |
265 |
} |
6201 |
07 Nov 12 |
nicklas |
else if (autoInit == 'menu-anchor') |
6201 |
07 Nov 12 |
nicklas |
267 |
{ |
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(element, 'click', internal.menuAnchorOnClick); |
6201 |
07 Nov 12 |
nicklas |
269 |
} |
417 |
19 Apr 05 |
nicklas |
270 |
} |
6201 |
07 Nov 12 |
nicklas |
Doc.addElementInitializer(internal.initMenuItems); |
472 |
27 Apr 05 |
nicklas |
272 |
|
6201 |
07 Nov 12 |
nicklas |
273 |
/** |
6201 |
07 Nov 12 |
nicklas |
Click handler for menu items that has an 'data-url' attribute specified. |
6201 |
07 Nov 12 |
nicklas |
By default, the url is opened in the main window. If a 'data-target' |
6201 |
07 Nov 12 |
nicklas |
attribute is specified, the url is opened in the window named by the target. |
6201 |
07 Nov 12 |
nicklas |
If a 'data-popup' is specified, the url is opened in a popup window. |
6201 |
07 Nov 12 |
nicklas |
278 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.menuItemWithUrlOnClick = function(event) |
417 |
19 Apr 05 |
nicklas |
280 |
{ |
6201 |
07 Nov 12 |
nicklas |
var menuItem = event.currentTarget; |
6201 |
07 Nov 12 |
nicklas |
var url = Data.get(menuItem, 'url'); |
6401 |
28 Jan 14 |
nicklas |
var popup = Data.get(menuItem, 'popup'); |
6401 |
28 Jan 14 |
nicklas |
url = url.replace(/\$SESSION\-ID\$/, App.getSessionId()); |
6201 |
07 Nov 12 |
nicklas |
if (popup) |
472 |
27 Apr 05 |
nicklas |
286 |
{ |
6201 |
07 Nov 12 |
nicklas |
var options = popup.split(/[,\s]+/); |
6201 |
07 Nov 12 |
nicklas |
Dialogs.openPopup(url, options[0], options[1], options[2]); |
472 |
27 Apr 05 |
nicklas |
289 |
} |
6201 |
07 Nov 12 |
nicklas |
else |
6201 |
07 Nov 12 |
nicklas |
291 |
{ |
6201 |
07 Nov 12 |
nicklas |
Menu.openUrl(url, Data.get(menuItem, 'target')); |
6201 |
07 Nov 12 |
nicklas |
293 |
} |
417 |
19 Apr 05 |
nicklas |
294 |
} |
417 |
19 Apr 05 |
nicklas |
295 |
|
6201 |
07 Nov 12 |
nicklas |
296 |
/** |
6201 |
07 Nov 12 |
nicklas |
Event handler for mouse over events which hide all |
6201 |
07 Nov 12 |
nicklas |
submenus for the current menu. |
6201 |
07 Nov 12 |
nicklas |
299 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.menuItemOnMouseOver = function(event) |
6201 |
07 Nov 12 |
nicklas |
301 |
{ |
6201 |
07 Nov 12 |
nicklas |
var menuItem = event.currentTarget; |
6201 |
07 Nov 12 |
nicklas |
var menuDiv = menu.getMenuOfMenuItem(menuItem); |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(menuDiv); |
6201 |
07 Nov 12 |
nicklas |
305 |
} |
417 |
19 Apr 05 |
nicklas |
306 |
|
6201 |
07 Nov 12 |
nicklas |
307 |
/** |
6201 |
07 Nov 12 |
nicklas |
Event handler for mouse over events which hide all |
6201 |
07 Nov 12 |
nicklas |
submenus for the current menu. |
6201 |
07 Nov 12 |
nicklas |
310 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.menuOnMouseOver = function(event) |
417 |
19 Apr 05 |
nicklas |
312 |
{ |
6723 |
12 Feb 15 |
nicklas |
if (!event.target.classList.contains('menuitem')) return; |
6201 |
07 Nov 12 |
nicklas |
menu.hideSubMenus(event.currentTarget); |
6201 |
07 Nov 12 |
nicklas |
315 |
} |
6201 |
07 Nov 12 |
nicklas |
316 |
|
6201 |
07 Nov 12 |
nicklas |
317 |
/** |
6201 |
07 Nov 12 |
nicklas |
Event handler for a submenu-item that opens a submenu |
6201 |
07 Nov 12 |
nicklas |
automatically when the mouse is over the submenu-item. |
6201 |
07 Nov 12 |
nicklas |
320 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.submenuOnMouseOver = function(event) |
6201 |
07 Nov 12 |
nicklas |
322 |
{ |
6201 |
07 Nov 12 |
nicklas |
var menuItem = event.currentTarget; |
6201 |
07 Nov 12 |
nicklas |
var submenuId = Data.get(menuItem, 'submenu-id'); |
6201 |
07 Nov 12 |
nicklas |
var menuDiv = menu.getMenuOfMenuItem(menuItem); |
6201 |
07 Nov 12 |
nicklas |
var open = Data.get(menuDiv, 'open'); |
6201 |
07 Nov 12 |
nicklas |
if (open == 'enter') |
417 |
19 Apr 05 |
nicklas |
328 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.showSubMenu(menuItem, submenuId); |
417 |
19 Apr 05 |
nicklas |
330 |
} |
417 |
19 Apr 05 |
nicklas |
else |
417 |
19 Apr 05 |
nicklas |
332 |
{ |
6201 |
07 Nov 12 |
nicklas |
var subMenu = Doc.element(submenuId); |
6201 |
07 Nov 12 |
nicklas |
if (menuDiv.activeSubMenu && (menuDiv.activeSubMenu != subMenu)) |
6201 |
07 Nov 12 |
nicklas |
335 |
{ |
6201 |
07 Nov 12 |
nicklas |
menu.showSubMenu(menuItem, subMenu); |
6201 |
07 Nov 12 |
nicklas |
337 |
} |
417 |
19 Apr 05 |
nicklas |
338 |
} |
6201 |
07 Nov 12 |
nicklas |
event.stopPropagation(); |
417 |
19 Apr 05 |
nicklas |
340 |
} |
6201 |
07 Nov 12 |
nicklas |
341 |
|
6201 |
07 Nov 12 |
nicklas |
342 |
/** |
6201 |
07 Nov 12 |
nicklas |
Click handler for submenu-items that toggle the visibility of |
6201 |
07 Nov 12 |
nicklas |
the submenu. |
6201 |
07 Nov 12 |
nicklas |
345 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.submenuOnClick = function(event) |
6201 |
07 Nov 12 |
nicklas |
347 |
{ |
6201 |
07 Nov 12 |
nicklas |
var menuItem = event.currentTarget; |
6201 |
07 Nov 12 |
nicklas |
var submenuId = Data.get(menuItem, 'submenu-id'); |
6201 |
07 Nov 12 |
nicklas |
menu.toggleSubMenu(menuItem, submenuId); |
6201 |
07 Nov 12 |
nicklas |
event.stopPropagation(); |
6201 |
07 Nov 12 |
nicklas |
352 |
} |
6201 |
07 Nov 12 |
nicklas |
353 |
|
6201 |
07 Nov 12 |
nicklas |
354 |
/** |
6201 |
07 Nov 12 |
nicklas |
Event handler for an gui element that, when clicked, open a new |
6201 |
07 Nov 12 |
nicklas |
top-level menu. The menu id should be specified by the 'data-menu-id' |
6201 |
07 Nov 12 |
nicklas |
attribute. If 'data-align-right' is set, the right border of the menu |
6201 |
07 Nov 12 |
nicklas |
is aligned with the right side of the target element, otherwise the |
6201 |
07 Nov 12 |
nicklas |
left sides are aligned (the default). |
6201 |
07 Nov 12 |
nicklas |
360 |
*/ |
6201 |
07 Nov 12 |
nicklas |
internal.menuAnchorOnClick = function(event) |
6201 |
07 Nov 12 |
nicklas |
362 |
{ |
6201 |
07 Nov 12 |
nicklas |
var target = event.currentTarget; |
6201 |
07 Nov 12 |
nicklas |
var menuId = Data.get(target, 'menu-id'); |
6201 |
07 Nov 12 |
nicklas |
var alignRight = Data.int(target, 'align-right'); |
6201 |
07 Nov 12 |
nicklas |
366 |
|
6400 |
27 Jan 14 |
nicklas |
var pos = Doc.getElementPosition(target); |
6201 |
07 Nov 12 |
nicklas |
var x = pos.left; |
6201 |
07 Nov 12 |
nicklas |
var y = pos.top+pos.height; |
6201 |
07 Nov 12 |
nicklas |
if (alignRight) |
6201 |
07 Nov 12 |
nicklas |
371 |
{ |
6201 |
07 Nov 12 |
nicklas |
var winPos = App.getWindowPosition(); |
6201 |
07 Nov 12 |
nicklas |
x = winPos.width - pos.left - pos.width; |
6201 |
07 Nov 12 |
nicklas |
374 |
} |
6201 |
07 Nov 12 |
nicklas |
menu.toggleTopMenu(menuId, x, y, alignRight); |
6201 |
07 Nov 12 |
nicklas |
event.stopPropagation(); |
6201 |
07 Nov 12 |
nicklas |
377 |
} |
6201 |
07 Nov 12 |
nicklas |
378 |
|
6201 |
07 Nov 12 |
nicklas |
return menu; |
6201 |
07 Nov 12 |
nicklas |
380 |
}(); |
6201 |
07 Nov 12 |
nicklas |
381 |
|
6201 |
07 Nov 12 |
nicklas |
Events.addEventHandler(document, 'click', Menu.hideAll); |