]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/widgets/menu/ContextMenuManager.js
removing old opac images and css
[working/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, evt) {
30
31         if(evt) {
32                 var win = getAppWindow();
33                 win.event = evt;
34                 /*
35                 if(!win.event) win.event = evt;
36                 if(!IE) win.event.preventDefault();
37                 else win.event.cancellBubble = true;
38                 */
39         }
40
41         this.hideAll();
42         debug("Toggling context menu " + name );
43         this.getMenu(name).toggle();
44 }
45
46 /* hides all menues */
47 ContextMenuManager.prototype.hideAll = function() {
48         for( var index in this.menus) {
49                 this.menus[index].hideMe();
50         }
51 }
52
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) {
56
57         var obj = this;
58         node.oncontextmenu = function(evt) {
59
60                 var win = getAppWindow();
61                 if(!win.event) win.event = evt;
62                 if(!IE) win.event.preventDefault();
63                 else win.event.cancellBubble = true;
64
65                 obj.toggle(menu.name);
66                 return false;
67         }
68         
69 }