36 var SimpleContextMenu = SimpleContextMenu || {};
38 if (typeof Debug ==
'undefined')
39 alert(
'ERROR: Debug is undefined! Must include Debug.js before SimpleContextMenu.js');
40 if (typeof Globals ==
'undefined')
41 alert(
'ERROR: Globals is undefined! Must include Globals.js before SimpleContextMenu.js');
42 if (typeof DesktopContent ==
'undefined' &&
43 typeof Desktop ==
'undefined')
44 alert(
'ERROR: DesktopContent is undefined! Must include DesktopContent.js before SimpleContextMenu.js');
57 SimpleContextMenu._popUpEl = 0;
58 SimpleContextMenu._menuItemHandlers = [];
59 SimpleContextMenu._primaryColor =
"";
60 SimpleContextMenu._secondaryColor =
"";
62 SimpleContextMenu._styleEl = 0;
67 SimpleContextMenu.createMenu =
function(menuItems,menuItemHandlers,
68 popupID,topLeftX,topLeftY, primaryColor, secondaryColor, useDefaultHighlightColors)
80 SimpleContextMenu._menuItemHandlers = menuItemHandlers;
81 SimpleContextMenu._primaryColor = primaryColor;
82 SimpleContextMenu._secondaryColor = secondaryColor;
83 SimpleContextMenu._useDefaultHighlightColors = useDefaultHighlightColors;
85 var body = document.getElementsByTagName(
"BODY")[0];
86 var el = SimpleContextMenu._popUpEl;
89 Debug.log(
"Can not create SimpleContextMenu if one already exists",
96 el = document.createElement(
"div");
97 el.setAttribute(
"id", popupID);
98 el.style.display =
"none";
99 el.onmousemove =
function(e){e.cancelBubble =
true;};
100 body.appendChild(el);
107 css +=
"#clearDiv {" +
112 css +=
"#" + popupID +
"" +
114 "position:absolute;" +
115 "left:" + topLeftX +
"px;" +
116 "top:" + topLeftY +
"px;" +
117 "z-index: 1000000;" +
118 "background-color: " + primaryColor +
";" +
120 "padding: 8px 0 8px 0;" +
121 "border-radius: 2px;" +
122 "box-shadow: inset rgba(255,254,255,0.6) 0 0 0 /*top-bottom glow*/," +
123 " inset rgba(0,0,0,0.35) 0 0 3px /* inner shadow */, " +
124 " rgb(150,150,150) 0 0 3px /* outer glow */," +
125 " rgb(175,175,175) 0 0 3px /* color border */," +
126 " rgba(0,0,0,0.7) -5px 5px 5px /* drop shadow */; " +
128 css +=
"#" + popupID +
" div" +
130 "padding: 0 10px 0 10px;" +
131 "color: " + secondaryColor +
";" +
132 "-webkit-user-select: none;" +
133 "-moz-user-select: none;" +
134 "user-select: none;" +
136 css +=
"#" + popupID +
" div:hover" +
138 "background-color: " + (useDefaultHighlightColors?
"rgb(91,148,240)":secondaryColor) +
";" +
139 "color: " + (useDefaultHighlightColors?
"white":primaryColor) +
";" +
142 css +=
"#" + popupID +
" *" +
149 var style = document.createElement(
'style');
151 if (style.styleSheet) {
152 style.styleSheet.cssText = css;
154 style.appendChild(document.createTextNode(css));
157 document.getElementsByTagName(
'head')[0].appendChild(style);
159 SimpleContextMenu._styleEl = style;
165 for(var i=0;i<menuItems.length;++i)
168 "<div class='SimpleContextMenu-menuItem' " +
169 "id='SimpleContextMenu-menuItem-" + i +
"' " +
170 "onmousemove='SimpleContextMenu.handleMouseOverMenuItem(event," + i +
");' " +
171 "onmousedown='event.stopPropagation();' " +
172 "onmouseup='SimpleContextMenu.callMenuItemHandler(event," + i +
");' " +
176 str +=
"<div id='clearDiv'></div>";
180 el.style.display =
"block";
182 SimpleContextMenu._popUpEl = el;
190 SimpleContextMenu.createMenuCallAsString =
function(menuItems,menuItemHandlers,
191 popupID, primaryColor, secondaryColor, useDefaultHighlightColors) {
194 str +=
"SimpleContextMenu.createMenu([";
197 for(j=0;j<menuItems.length;++j)
201 str +=
"\"" + menuItems[j] +
"\"";
207 for(j=0;j<menuItemHandlers.length;++j)
211 menuItemHandlers[j] = menuItemHandlers[j].replace(/\\\
"/g, "AAAAA
");
212 menuItemHandlers[j] = menuItemHandlers[j].replace(/"/g,
"\\\"");
213 menuItemHandlers[j] = menuItemHandlers[j].replace(/AAAAA/g,
"\\\\\\\"");
217 str +=
"\"" + menuItemHandlers[j] +
"\"";
218 if(j != menuItemHandlers.length-1)
222 ",\"" + popupID +
"\",event.pageX-1,event.pageY-1, " +
223 "\"" + primaryColor +
224 "\", \"" + secondaryColor +
225 "\", " + (useDefaultHighlightColors?1:0) +
");";
230 SimpleContextMenu._removePopupTimer = 0;
236 SimpleContextMenu.mouseMoveHandler =
function(e)
239 if(SimpleContextMenu._popUpEl && !SimpleContextMenu._removePopupTimer)
242 SimpleContextMenu._removePopupTimer = window.setTimeout(
245 SimpleContextMenu._removePopupTimer = 0;
248 SimpleContextMenu._popUpEl.parentNode.removeChild(SimpleContextMenu._popUpEl);
249 SimpleContextMenu._popUpEl = 0;
251 if(SimpleContextMenu._styleEl)
253 SimpleContextMenu._styleEl.parentNode.removeChild(SimpleContextMenu._styleEl);
254 SimpleContextMenu._styleEl = 0;
259 else if(!SimpleContextMenu._popUpEl) SimpleContextMenu._removePopupTimer = 0;
262 if(typeof DesktopContent ==
'undefined')
263 Desktop.mouseMoveSubscriber(SimpleContextMenu.mouseMoveHandler);
265 DesktopContent.mouseMoveSubscriber(SimpleContextMenu.mouseMoveHandler);
269 SimpleContextMenu.callMenuItemHandler =
function(event,index)
271 var handler = SimpleContextMenu._menuItemHandlers[index];
273 Debug.log(
"Removing SimpleContextMenu");
274 SimpleContextMenu._popUpEl.parentNode.removeChild(SimpleContextMenu._popUpEl);
275 SimpleContextMenu._popUpEl = 0;
277 if(SimpleContextMenu._styleEl)
279 SimpleContextMenu._styleEl.parentNode.removeChild(SimpleContextMenu._styleEl);
280 SimpleContextMenu._styleEl = 0;
283 event.cancelBubble =
true;
284 event.preventDefault();
285 event.stopPropagation();
288 if(handler && (typeof handler) ==
"string")
290 Debug.log(
"evaluateJS = " + handler);
296 handler(event, index);
303 SimpleContextMenu.handleMouseOverMenuItem =
function(event,index)
305 event.cancelBubble =
true;
308 if(SimpleContextMenu._removePopupTimer)
310 window.clearTimeout(SimpleContextMenu._removePopupTimer);
311 SimpleContextMenu._removePopupTimer = 0;
318 for(var i=0;i<SimpleContextMenu._menuItemHandlers.length;++i)
320 el = document.getElementById(
"SimpleContextMenu-menuItem-" + i);
323 el.style.backgroundColor = (SimpleContextMenu._useDefaultHighlightColors?
"rgb(91,148,240)":SimpleContextMenu._secondaryColor);
324 el.style.color = (SimpleContextMenu._useDefaultHighlightColors?
"white" :SimpleContextMenu._primaryColor);
328 el.style.backgroundColor = SimpleContextMenu._primaryColor;
329 el.style.color = SimpleContextMenu._secondaryColor;