]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/widgets/menu/ContextMenu.js
removing old opac images and css
[Evergreen.git] / Open-ILS / src / javascript / widgets / menu / ContextMenu.js
1 /*  */
2
3 /* menu item class */
4 function ContextMenuItem(text,onclick) {
5         this.onclick = onclick;
6         this.div = createAppElement("div");
7         this.div.appendChild(createAppTextNode(text));
8         this.div.onclick = this.onclick;
9         this.div.className = "context_menu_item";
10
11
12         /* add mouseover effects */
13         var div = this.div;
14         this.div.onmouseover = function() {
15                         add_css_class(div,"context_menu_item_hover");
16         }
17         this.div.onmouseout = function() {
18                 remove_css_class(div,"context_menu_item_hover");
19    }
20
21 }
22
23
24 /* returns the DOM object (div) this item sits in */
25 ContextMenuItem.prototype.getNode = function() {
26         return this.div;
27 }
28
29 /* put an image to the left of the menu item */
30 ContextMenuItem.prototype.addIcon= function(url) {
31         var img = createAppElement("img");
32         add_css_class( img, "context_menu_item_img");
33         img.setAttribute("src", url);
34         this.div.insertBefore( img, this.div.firstChild )
35 }
36
37
38 /* context menu class */
39 function ContextMenu(name) {
40         this.div = createAppElement("div");
41         this.wrapperDiv = createAppElement("div");
42         this.wrapperDiv.appendChild(this.div);
43         this.div.className = "context_menu hide_me";
44         this.name = name;
45         this.items = new Array();
46 }
47
48
49 /* onclick is an actual function(){...} function */
50 ContextMenu.prototype.addItem = function(text,onclick) {
51         var item = new ContextMenuItem(text, onclick);
52         this.items.push(item)
53         this.div.appendChild(item.getNode());
54 }
55
56 /* returns the DOM object (div) this menu sits in */
57 ContextMenu.prototype.getNode = function() {
58         return this.div;
59 }
60
61 /* hides this context menu */
62 ContextMenu.prototype.hideMe = function() {
63         if( this.div.className.indexOf("show_me") != -1 ) {
64                 swapClass(this.div,"show_me", "hide_me");
65         }
66 }
67
68 /* displays this context menu */
69 ContextMenu.prototype.showMe = function() {
70         if( this.div.className.indexOf("hide_me") != -1 ) {
71                 swapClass(this.div,"show_me", "hide_me");
72         }
73 }
74
75
76 /* if hidden, displays, and vice versa */
77 ContextMenu.prototype.toggle = function() {
78
79         var mousepos =  getMousePos();
80         this.div.style.position = "absolute";
81    this.div.style.left = mousepos[0];
82    this.div.style.top = mousepos[1];
83         debug("Toggling menu " + this.name + " : " + this.div.className);
84         swapClass(this.div,"show_me", "hide_me");
85
86         debug("After Toggling menu " + this.name + " : " + this.div.className);
87 }
88
89 /* returns the menu as an HTML string */
90 ContextMenu.prototype.toSring = function() {
91         return this.wrapperDiv.innerHTML;
92 }
93
94 /* returns an array of ContextMenuItem objects */
95 ContextMenu.prototype.getItems = function() {
96         return this.items;
97 }
98
99