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";
12 /* add mouseover effects */
14 this.div.onmouseover = function() {
15 add_css_class(div,"context_menu_item_hover");
17 this.div.onmouseout = function() {
18 remove_css_class(div,"context_menu_item_hover");
24 /* returns the DOM object (div) this item sits in */
25 ContextMenuItem.prototype.getNode = function() {
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 )
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";
45 this.items = new Array();
49 /* onclick is an actual function(){...} function */
50 ContextMenu.prototype.addItem = function(text,onclick) {
51 var item = new ContextMenuItem(text, onclick);
53 this.div.appendChild(item.getNode());
56 /* returns the DOM object (div) this menu sits in */
57 ContextMenu.prototype.getNode = function() {
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");
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");
76 /* if hidden, displays, and vice versa */
77 ContextMenu.prototype.toggle = function() {
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");
86 debug("After Toggling menu " + this.name + " : " + this.div.className);
89 /* returns the menu as an HTML string */
90 ContextMenu.prototype.toSring = function() {
91 return this.wrapperDiv.innerHTML;
94 /* returns an array of ContextMenuItem objects */
95 ContextMenu.prototype.getItems = function() {