3 function ContextMenuManager() {}
5 /* builds a new menu and stores it */
6 ContextMenuManager.prototype.buildMenu = function(name) {
9 this.menus = new Array();
10 /* here we hijack the body onclick to
11 hide menus that may be visible */
12 getDocument().body.onclick = function() {
13 globalMenuManager.hideAll();
17 if(name == null) name = new Date().getTime();
18 this.menus[name] = new ContextMenu(name);
19 return this.menus[name];
22 /* returns the menu with the given name */
23 ContextMenuManager.prototype.getMenu = function(name) {
24 return this.menus[name];
27 /* hides all visible menus and brings the
28 selected menu to the front */
29 ContextMenuManager.prototype.toggle = function(name, evt) {
32 var win = getAppWindow();
35 if(!win.event) win.event = evt;
36 if(!IE) win.event.preventDefault();
37 else win.event.cancellBubble = true;
42 debug("Toggling context menu " + name );
43 this.getMenu(name).toggle();
46 /* hides all menues */
47 ContextMenuManager.prototype.hideAll = function() {
48 for( var index in this.menus) {
49 this.menus[index].hideMe();
53 /* sets a context object for the given menu. When a user clicks
54 in the context area, the menu appears */
55 ContextMenuManager.prototype.setContext = function(node, menu) {
58 node.oncontextmenu = function(evt) {
60 var win = getAppWindow();
61 if(!win.event) win.event = evt;
62 if(!IE) win.event.preventDefault();
63 else win.event.cancellBubble = true;
65 obj.toggle(menu.name);