]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/widgets/menu/ContextMenuManager.js
menu and menu manager classes
[Evergreen.git] / Open-ILS / src / javascript / widgets / menu / ContextMenuManager.js
1 /* */
2
3 function ContextMenuManager() {}
4
5 /* builds a new menu and stores it */
6 ContextMenuManager.prototype.buildMenu = function(name) {
7
8         if(!this.menus) { 
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(); 
14                 }
15         }
16
17         if(name == null) name = new Date().getTime();
18         this.menus[name] = new ContextMenu(name);
19         return this.menus[name];
20 }
21
22 /* returns the menu with the given name */
23 ContextMenuManager.prototype.getMenu = function(name) {
24         return this.menus[name];
25 }
26
27 /* hides all visible menus and brings the 
28         selected menu to the front */
29 ContextMenuManager.prototype.toggle = function(name) {
30         this.hideAll();
31         this.getMenu(name).toggle();
32 }
33
34 /* hides all menues */
35 ContextMenuManager.prototype.hideAll = function() {
36         for( var index in this.menus) {
37                 this.menus[index].hideMe();
38         }
39 }
40
41 /* sets a context object for the given menu.  When a user clicks
42         in the context area, the menu appears */
43 ContextMenuManager.prototype.setContext = function(node, menu) {
44         var obj = this;
45         node.oncontextmenu = function(evt) {
46                 var win = getAppWindow();
47                 if(!win.event) win.event = evt;
48                 obj.toggle(menu.name);
49                 return false;
50         }
51 }