Total Complexity | 491 |
Complexity/F | 5.34 |
Lines of Code | 2178 |
Function Count | 92 |
Duplicated Lines | 1472 |
Ratio | 67.58 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like api/js/egw_action/test/js/dhtmlxmenu.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | //v.2.6 build 100722 |
||
13 | function dhtmlXMenuObject(baseId, skin) { |
||
14 | var main_self = this; |
||
15 | |||
16 | this.addBaseIdAsContextZone = null; |
||
17 | |||
18 | this.isDhtmlxMenuObject = true; |
||
19 | |||
20 | // skin settings |
||
21 | this.skin = (skin!=null?skin:"dhx_skyblue"); |
||
22 | this.imagePath = ""; |
||
23 | |||
24 | // iframe |
||
25 | this._isIE6 = false; |
||
26 | if (_isIE) this._isIE6 = (window.XMLHttpRequest==null?true:false); |
||
27 | |||
28 | if (baseId == null) { |
||
29 | this.base = document.body; |
||
30 | } else { |
||
31 | if (document.getElementById(baseId) != null) { |
||
32 | this.base = document.getElementById(baseId); |
||
33 | while (this.base.childNodes.length > 0) { this.base.removeChild(this.base.childNodes[0]); } |
||
34 | this.base.className += " dhtmlxMenu_"+this.skin+"_Middle dir_left"; |
||
35 | this.base._autoSkinUpdate = true; |
||
36 | // preserv default oncontextmenu for future restorin in case of context menu |
||
37 | if (this.base.oncontextmenu) this.base._oldContextMenuHandler = this.base.oncontextmenu; |
||
38 | // |
||
39 | this.addBaseIdAsContextZone = baseId; |
||
40 | this.base.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; } |
||
41 | this.base.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; } |
||
42 | } else { |
||
43 | this.base = document.body; |
||
44 | } |
||
45 | } |
||
46 | // this.topId = topId; |
||
47 | this.topId = "dhxWebMenuTopId"; |
||
48 | |||
49 | // |
||
50 | if (!this.extendedModule) { |
||
51 | // add notify for menu |
||
52 | var t = function(){alert(this.i18n.dhxmenuextalert);}; |
||
53 | var extMethods = new Array("setItemEnabled", "setItemDisabled", "isItemEnabled", "_changeItemState", "getItemText", "setItemText", |
||
54 | "loadFromHTML", "hideItem", "showItem", "isItemHidden", "_changeItemVisible", "setUserData", "getUserData", |
||
55 | "setOpenMode", "setWebModeTimeout", "enableDynamicLoading", "_updateLoaderIcon", "getItemImage", "setItemImage", |
||
56 | "clearItemImage", "setAutoShowMode", "setAutoHideMode", "setContextMenuHideAllMode", "getContextMenuHideAllMode", |
||
57 | "setVisibleArea", "setTooltip", "getTooltip", "setHotKey", "getHotKey", "setItemSelected", "setTopText", "setRTL", |
||
58 | "setAlign", "setHref", "clearHref", "getCircuit", "_clearAllSelectedSubItemsInPolygon", "_checkArrowsState", |
||
59 | "_addUpArrow", "_addDownArrow", "_removeUpArrow", "_removeDownArrow", "_isArrowExists", "_doScrollUp", "_doScrollDown", |
||
60 | "_countPolygonItems", "setOverflowHeight", "_getRadioImgObj", "_setRadioState", "_radioOnClickHandler", |
||
61 | "getRadioChecked", "setRadioChecked", "addRadioButton", "_getCheckboxState", "_setCheckboxState", "_readLevel", |
||
62 | "_updateCheckboxImage", "_checkboxOnClickHandler", "setCheckboxState", "getCheckboxState", "addCheckbox", "serialize"); |
||
63 | for (var q=0; q<extMethods.length; q++) if (!this[extMethods[q]]) this[extMethods[q]] = t; |
||
64 | extMethods = null; |
||
65 | } |
||
66 | |||
67 | // should be used for frameset in IE |
||
68 | this.fixedPosition = false; |
||
69 | |||
70 | this.menuSelected = -1; |
||
71 | this.menuLastClicked = -1; |
||
72 | this.idPrefix = ""; |
||
73 | this.itemTagName = "item"; |
||
74 | this.itemTextTagName = "itemtext"; |
||
75 | this.userDataTagName = "userdata"; |
||
76 | this.itemTipTagName = "tooltip"; |
||
77 | this.itemHotKeyTagName = "hotkey"; |
||
78 | this.itemHrefTagName = "href"; |
||
79 | this.dirTopLevel = "bottom"; |
||
80 | this.dirSubLevel = "right"; |
||
81 | this.menuX1 = null; |
||
82 | this.menuX2 = null; |
||
83 | this.menuY1 = null; |
||
84 | this.menuY2 = null; |
||
85 | this.menuMode = "web"; |
||
86 | this.menuTimeoutMsec = 400; |
||
87 | this.menuTimeoutHandler = null; |
||
88 | this.idPull = {}; |
||
89 | this.itemPull = {}; |
||
90 | this.userData = {}; |
||
91 | this.radio = {}; |
||
92 | // |
||
93 | this._rtl = false; |
||
94 | this._align = "left"; |
||
95 | // |
||
96 | this.menuTouched = false; |
||
97 | // |
||
98 | this.zIndInit = 1200; |
||
99 | this.zInd = this.zIndInit; |
||
100 | this.zIndStep = 50; |
||
101 | // |
||
102 | this.menuModeTopLevelTimeout = true; // shows sublevel polygons from toplevel items with delay |
||
103 | this.menuModeTopLevelTimeoutTime = 200; // msec |
||
104 | // |
||
105 | // default skin |
||
106 | // this.skin = "Standard"; |
||
107 | |||
108 | // skin-based params |
||
109 | this._topLevelBottomMargin = 1; |
||
110 | this._topLevelRightMargin = 0; |
||
111 | this._topLevelOffsetLeft = 1; |
||
112 | this._arrowFFFix = (_isIE?(document.compatMode=="BackCompat"?0:-4):-4); // border fixer for FF for arrows polygons |
||
113 | |||
114 | /** |
||
115 | * @desc: changes menu skin |
||
116 | * @param: skin - skin name |
||
117 | * @type: public |
||
118 | */ |
||
119 | View Code Duplication | this.setSkin = function(skin) { |
|
120 | var oldSkin = this.skin; |
||
121 | this.skin = skin; |
||
122 | switch (this.skin){ |
||
123 | case "dhx_black": |
||
124 | case "dhx_blue": |
||
125 | case "dhx_skyblue": |
||
126 | case "dhx_web": |
||
127 | this._topLevelBottomMargin = 2; |
||
128 | this._topLevelRightMargin = 1; |
||
129 | this._topLevelOffsetLeft = 1; |
||
130 | this._arrowFFFix = (_isIE?(document.compatMode=="BackCompat"?0:-4):-4); |
||
131 | break; |
||
132 | case "dhx_web": |
||
133 | this._arrowFFFix = 0; |
||
134 | break; |
||
135 | } |
||
136 | if (this.base._autoSkinUpdate) { |
||
137 | this.base.className = this.base.className.replace("dhtmlxMenu_"+oldSkin+"_Middle", "")+" dhtmlxMenu_"+this.skin+"_Middle"; |
||
138 | } |
||
139 | |||
140 | for (var a in this.idPull) { |
||
141 | this.idPull[a].className = String(this.idPull[a].className).replace(oldSkin, this.skin); |
||
142 | |||
143 | } |
||
144 | } |
||
145 | this.setSkin(this.skin); |
||
146 | // |
||
147 | this.dLoad = false; |
||
148 | this.dLoadUrl = ""; |
||
149 | this.dLoadSign = "?"; |
||
150 | this.loaderIcon = false; |
||
151 | this.limit = 0; |
||
152 | // |
||
153 | this._scrollUpTM = null; |
||
154 | this._scrollUpTMTime = 20; |
||
155 | this._scrollUpTMStep = 3; |
||
156 | this._scrollDownTM = null; |
||
157 | this._scrollDownTMTime = 20; |
||
158 | this._scrollDownTMStep = 3; |
||
159 | /* context menu */ |
||
160 | this.context = false; |
||
161 | this.contextZones = {}; |
||
162 | this.contextMenuZoneId = false; |
||
163 | this.contextAutoShow = true; /* default open action */ |
||
164 | this.contextAutoHide = true; /* default close action */ |
||
165 | this.contextHideAllMode = true; /* true will hide all opened contextual menu polygons on mouseout, false - all except topleft */ |
||
166 | /* dac params */ |
||
167 | this.sxDacProc = null; |
||
168 | this.dacSpeed = 10; |
||
169 | this.dacCycles = []; |
||
170 | for (var q=0; q<10; q++) { this.dacCycles[q] = q; } |
||
171 | /* |
||
172 | this.dacSpeedIE = 60; |
||
173 | this.dacCyclesIE = []; |
||
174 | for (var q=0; q<3; q++) { this.dacCyclesIE[q] = q*2+1; } |
||
175 | */ |
||
176 | this.dacSpeedIE = 10; |
||
177 | this.dacCyclesIE = []; |
||
178 | for (var q=0; q<10; q++) { this.dacCyclesIE[q] = q; } |
||
179 | |||
180 | /* version 0.2 features: selected items and polygond for quick deselect */ |
||
181 | /* sxDac feature, implemented in version 0.4 */ |
||
182 | this._enableDacSupport = function(dac) { |
||
183 | this.sxDacProc = dac; |
||
184 | } |
||
185 | this._selectedSubItems = new Array(); |
||
186 | this._openedPolygons = new Array(); |
||
187 | this._addSubItemToSelected = function(item, polygon) { |
||
188 | var t = true; |
||
189 | for (var q=0; q<this._selectedSubItems.length; q++) { if ((this._selectedSubItems[q][0] == item) && (this._selectedSubItems[q][1] == polygon)) { t = false; } } |
||
190 | if (t == true) { this._selectedSubItems.push(new Array(item, polygon)); } |
||
191 | return t; |
||
192 | } |
||
193 | View Code Duplication | this._removeSubItemFromSelected = function(item, polygon) { |
|
194 | var m = new Array(); |
||
195 | var t = false; |
||
196 | for (var q=0; q<this._selectedSubItems.length; q++) { if ((this._selectedSubItems[q][0] == item) && (this._selectedSubItems[q][1] == polygon)) { t = true; } else { m[m.length] = this._selectedSubItems[q]; } } |
||
197 | if (t == true) { this._selectedSubItems = m; } |
||
198 | return t; |
||
199 | } |
||
200 | View Code Duplication | this._getSubItemToDeselectByPolygon = function(polygon) { |
|
201 | var m = new Array(); |
||
202 | for (var q=0; q<this._selectedSubItems.length; q++) { |
||
203 | if (this._selectedSubItems[q][1] == polygon) { |
||
204 | m[m.length] = this._selectedSubItems[q][0]; |
||
205 | m = m.concat(this._getSubItemToDeselectByPolygon(this._selectedSubItems[q][0])); |
||
206 | var t = true; |
||
207 | for (var w=0; w<this._openedPolygons.length; w++) { if (this._openedPolygons[w] == this._selectedSubItems[q][0]) { t = false; } } |
||
208 | if (t == true) { this._openedPolygons[this._openedPolygons.length] = this._selectedSubItems[q][0]; } |
||
209 | this._selectedSubItems[q][0] = -1; |
||
210 | this._selectedSubItems[q][1] = -1; |
||
211 | } |
||
212 | } |
||
213 | return m; |
||
214 | } |
||
215 | /* end */ |
||
216 | /* define polygon's position for dinamic content rendering and shows it, added in version 0.3 */ |
||
217 | this._hidePolygon = function(id) { |
||
218 | if (this.idPull["polygon_" + id] != null) { |
||
219 | if ((this.sxDacProc != null) && (this.idPull["sxDac_" + id] != null)) { |
||
220 | this.idPull["sxDac_"+id]._hide(); |
||
221 | } else { |
||
222 | // already hidden |
||
223 | if (this.idPull["polygon_"+id].style.display == "none") return; |
||
224 | // |
||
225 | this.idPull["polygon_"+id].style.display = "none"; |
||
226 | if (this.idPull["arrowup_"+id] != null) { this.idPull["arrowup_"+id].style.display = "none"; } |
||
227 | if (this.idPull["arrowdown_"+id] != null) { this.idPull["arrowdown_"+id].style.display = "none"; } |
||
228 | this._updateItemComplexState(id, true, false); |
||
229 | // hide ie6 cover |
||
230 | if (this._isIE6) { if (this.idPull["polygon_"+id+"_ie6cover"] != null) { this.idPull["polygon_"+id+"_ie6cover"].style.display = "none"; } } |
||
231 | // call event |
||
232 | id = String(id).replace(this.idPrefix, ""); |
||
233 | if (id == this.topId) id = null; |
||
234 | this.callEvent("onHide", [id]); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | this._showPolygon = function(id, openType) { |
||
239 | var itemCount = this._countVisiblePolygonItems(id); |
||
240 | if (itemCount == 0) return; |
||
241 | var pId = "polygon_"+id; |
||
242 | if ((this.idPull[pId] != null) && (this.idPull[id] != null)) { |
||
243 | if (this.menuModeTopLevelTimeout && this.menuMode == "web" && !this.context) { |
||
244 | if (!this.idPull[id]._mouseOver && openType == this.dirTopLevel) return; |
||
245 | } |
||
246 | |||
247 | // detect visible area |
||
248 | if (!this.fixedPosition) this._autoDetectVisibleArea(); |
||
249 | |||
250 | // show arrows |
||
251 | var arrUpH = 0; |
||
252 | var arrDownH = 0; |
||
253 | // |
||
254 | var arrowUp = null; |
||
255 | var arrowDown = null; |
||
256 | //#menu_overflow:06062008#{ |
||
257 | View Code Duplication | if (this.limit > 0 && this.limit < itemCount) { |
|
258 | var auId = "arrowup_"+id; |
||
259 | var adId = "arrowdown_"+id; |
||
260 | |||
261 | // add overflow arrows if they not exists |
||
262 | if (this.idPull["arrowup_"+id] == null) this._addUpArrow(String(id).replace(this.idPrefix,"")); |
||
263 | if (this.idPull["arrowdown_"+id] == null) this._addDownArrow(String(id).replace(this.idPrefix,"")); |
||
264 | |||
265 | // configure up arrow |
||
266 | arrowUp = this.idPull["arrowup_"+id]; |
||
267 | arrowUp.style.visibility = "hidden"; |
||
268 | arrowUp.style.display = ""; |
||
269 | arrowUp.style.zIndex = this.zInd; |
||
270 | arrUpH = arrowUp.offsetHeight; |
||
271 | |||
272 | // configure bottom arrow |
||
273 | arrowDown = this.idPull["arrowdown_"+id]; |
||
274 | arrowDown.style.visibility = "hidden"; |
||
275 | arrowDown.style.display = ""; |
||
276 | arrowDown.style.zIndex = this.zInd; |
||
277 | arrDownH = arrowDown.offsetHeight; |
||
278 | } |
||
279 | //#} |
||
280 | // show polygon |
||
281 | this.idPull[pId].style.visibility = "hidden"; |
||
282 | this.idPull[pId].style.left = "0px"; |
||
283 | this.idPull[pId].style.top = "0px"; |
||
284 | this.idPull[pId].style.display = ""; |
||
285 | this.idPull[pId].style.zIndex = this.zInd; |
||
286 | // |
||
287 | if (this.limit > 0) { |
||
288 | if (this.limit < itemCount) { |
||
289 | // set fixed size |
||
290 | // this.idPull[pId].style.height = this.idPull[pId].tbd.childNodes[0].offsetHeight*this.limit+"px";// + arrUpH + arrDownH; |
||
291 | this.idPull[pId].style.height = 24*this.limit+"px"; |
||
292 | this.idPull[pId].scrollTop = 0; |
||
293 | } else { |
||
294 | // remove fixed size |
||
295 | this.idPull[pId].style.height = ""; |
||
296 | } |
||
297 | } |
||
298 | // |
||
299 | this.zInd += this.zIndStep; |
||
300 | // |
||
301 | // console.log(this.idPull) |
||
302 | if (this.itemPull[id] != null) { |
||
303 | var parPoly = "polygon_"+this.itemPull[id]["parent"]; |
||
304 | } else if (this.context) { |
||
305 | var parPoly = this.idPull[this.idPrefix+this.topId]; |
||
306 | } |
||
307 | /* |
||
308 | // debug info |
||
309 | if (parPoly == null) { |
||
310 | alert("Implementation error. Please report [email protected]"); |
||
311 | } |
||
312 | */ |
||
313 | // |
||
314 | // |
||
315 | // define position |
||
316 | var srcX = (this.idPull[id].tagName != null ? getAbsoluteLeft(this.idPull[id]) : this.idPull[id][0]); |
||
317 | var srcY = (this.idPull[id].tagName != null ? getAbsoluteTop(this.idPull[id]) : this.idPull[id][1]); |
||
318 | var srcW = (this.idPull[id].tagName != null ? this.idPull[id].offsetWidth : 0); |
||
319 | var srcH = (this.idPull[id].tagName != null ? this.idPull[id].offsetHeight + arrUpH + arrDownH : 0); |
||
320 | |||
321 | var x = 0; |
||
322 | var y = 0; |
||
323 | var w = this.idPull[pId].offsetWidth; |
||
324 | var h = this.idPull[pId].offsetHeight; |
||
325 | |||
326 | //console.log(srcY,h,window.innerHeight,document.body.scrollTop) |
||
327 | /* |
||
328 | var bottomOverflow = (srcY+h > window.innerHeight+document.body.scrollTop); |
||
329 | if (bottomOverflow) { |
||
330 | if (openType == "bottom") openType = "top"; |
||
331 | if (openType == "right" || openType == "left") { |
||
332 | srcY = srcY-h; |
||
333 | } |
||
334 | } |
||
335 | */ |
||
336 | // pos |
||
337 | View Code Duplication | if (openType == "bottom") { |
|
338 | if (this._rtl) { |
||
339 | x = srcX + (srcW!=null?srcW:0) - w; |
||
340 | } else { |
||
341 | if (this._align == "right") { |
||
342 | x = srcX + srcW - w; |
||
343 | } else { |
||
344 | x = srcX - 1 + (openType==this.dirTopLevel?this._topLevelRightMargin:0); |
||
345 | } |
||
346 | } |
||
347 | y = srcY - 1 + srcH - arrUpH - arrDownH + this._topLevelBottomMargin; |
||
348 | } |
||
349 | if (openType == "right") { x = srcX + srcW - 1; y = srcY + 2; } |
||
350 | if (openType == "left") { x = srcX - this.idPull[pId].offsetWidth + 2; y = srcY + 2; } |
||
351 | if (openType == "top") { x = srcX - 1; y = srcY - h + 2; } |
||
352 | |||
353 | // overflow check |
||
354 | View Code Duplication | if (this.fixedPosition) { |
|
355 | // use fixed document.body/window dimension if required |
||
356 | var mx = 65536; |
||
357 | var my = 65536; |
||
358 | } else { |
||
359 | var mx = (this.menuX2!=null?this.menuX2:0); |
||
360 | var my = (this.menuY2!=null?this.menuY2:0); |
||
361 | |||
362 | if (mx == 0) { |
||
363 | if (window.innerWidth) { |
||
364 | mx = window.innerWidth; |
||
365 | my = window.innerHeight; |
||
366 | } else { |
||
367 | mx = document.body.offsetWidth; |
||
368 | my = document.body.scrollHeight; |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | if (x+w > mx && !this._rtl) { |
||
373 | // no space on right, open to left |
||
374 | x = srcX - w + 2; |
||
375 | } |
||
376 | if (x < this.menuX1 && this._rtl) { |
||
377 | // no space on left, open to right |
||
378 | x = srcX + srcW - 2; |
||
379 | } |
||
380 | if (x < 0) { |
||
381 | // menu floats left |
||
382 | x = 0; |
||
383 | } |
||
384 | if (y+h > my && this.menuY2 != null) { |
||
385 | y = srcY + srcH - h + 2; |
||
386 | // open from top level |
||
387 | if (this.itemPull[id] != null && !this.context) { |
||
388 | if (this.itemPull[id]["parent"] == this.idPrefix+this.topId) y = y - this.base.offsetHeight; |
||
389 | } |
||
390 | } |
||
391 | // |
||
392 | this.idPull[pId].style.left = x+"px"; |
||
393 | this.idPull[pId].style.top = y+arrUpH+"px"; |
||
394 | // |
||
395 | if ((this.sxDacProc != null) && (this.idPull["sxDac_" + id] != null)) { |
||
396 | this.idPull["sxDac_"+id]._show(); |
||
397 | } else { |
||
398 | this.idPull[pId].style.visibility = ""; |
||
399 | //#menu_overflow:06062008#{ |
||
400 | View Code Duplication | if (this.limit > 0 && this.limit < itemCount) { |
|
401 | // this.idPull[pId].scrollTop = 0; |
||
402 | arrowUp.style.left = x+"px"; |
||
403 | arrowUp.style.top = y+"px"; |
||
404 | arrowUp.style.width = w+this._arrowFFFix+"px"; |
||
405 | arrowUp.style.visibility = ""; |
||
406 | // |
||
407 | arrowDown.style.left = x+"px"; |
||
408 | arrowDown.style.top = y+arrUpH+h+"px"; |
||
409 | arrowDown.style.width = w+this._arrowFFFix+"px"; |
||
410 | arrowDown.style.visibility = ""; |
||
411 | // |
||
412 | this._checkArrowsState(id); |
||
413 | } |
||
414 | //#} |
||
415 | // show ie6 cover |
||
416 | if (this._isIE6) { |
||
417 | var pIdIE6 = pId+"_ie6cover"; |
||
418 | if (this.idPull[pIdIE6] == null) { |
||
419 | var ifr = document.createElement("IFRAME"); |
||
420 | ifr.className = "dhtmlxMenu_IE6CoverFix_"+this.skin; |
||
421 | ifr.frameBorder = 0; |
||
422 | ifr.setAttribute("src", "javascript:false;"); |
||
423 | document.body.insertBefore(ifr, document.body.firstChild); |
||
424 | this.idPull[pIdIE6] = ifr; |
||
425 | } |
||
426 | this.idPull[pIdIE6].style.left = this.idPull[pId].style.left; |
||
427 | this.idPull[pIdIE6].style.top = this.idPull[pId].style.top; |
||
428 | this.idPull[pIdIE6].style.width = this.idPull[pId].offsetWidth+"px"; |
||
429 | this.idPull[pIdIE6].style.height = this.idPull[pId].offsetHeight+"px"; |
||
430 | this.idPull[pIdIE6].style.zIndex = this.idPull[pId].style.zIndex-1; |
||
431 | this.idPull[pIdIE6].style.display = ""; |
||
432 | } |
||
433 | id = String(id).replace(this.idPrefix, ""); |
||
434 | if (id == this.topId) id = null; |
||
435 | this.callEvent("onShow", [id]); |
||
436 | // this.callEvent("_onPolyShow",[id.replace(this.idPrefix,"")]); |
||
437 | } |
||
438 | } |
||
439 | } |
||
440 | /* redistrib sublevel selection: select id and deselect other, added in version 0.3 */ |
||
441 | View Code Duplication | this._redistribSubLevelSelection = function(id, parentId) { |
|
442 | // clear previosly selected items |
||
443 | while (this._openedPolygons.length > 0) this._openedPolygons.pop(); |
||
444 | // this._openedPolygons = new Array(); |
||
445 | var i = this._getSubItemToDeselectByPolygon(parentId); |
||
446 | this._removeSubItemFromSelected(-1, -1); |
||
447 | for (var q=0; q<i.length; q++) { if ((this.idPull[i[q]] != null) && (i[q] != id)) { if (this.itemPull[i[q]]["state"] == "enabled") { this.idPull[i[q]].className = "sub_item"; } } } |
||
448 | // hide polygons |
||
449 | for (var q=0; q<this._openedPolygons.length; q++) { if (this._openedPolygons[q] != parentId) { this._hidePolygon(this._openedPolygons[q]); } } |
||
450 | // add new selection into list new |
||
451 | if (this.itemPull[id]["state"] == "enabled") { |
||
452 | this.idPull[id].className = "sub_item_selected"; |
||
453 | if (this.itemPull[id]["complex"] && this.dLoad && (this.itemPull[id]["loaded"]=="no")) { |
||
454 | if (this.loaderIcon == true) { this._updateLoaderIcon(id, true); } |
||
455 | var xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window); |
||
456 | this.itemPull[id]["loaded"] = "get"; |
||
457 | this.callEvent("onXLS", []); |
||
458 | xmlLoader.loadXML(this.dLoadUrl+this.dLoadSign+"action=loadMenu&parentId="+id.replace(this.idPrefix,"")+"&etc="+new Date().getTime()); |
||
459 | } |
||
460 | // show |
||
461 | if (this.itemPull[id]["complex"] || (this.dLoad && (this.itemPull[id]["loaded"] == "yes"))) { |
||
462 | // make arrow over |
||
463 | if ((this.itemPull[id]["complex"]) && (this.idPull["polygon_" + id] != null)) { |
||
464 | this._updateItemComplexState(id, true, true); |
||
465 | this._showPolygon(id, this.dirSubLevel); |
||
466 | } |
||
467 | } |
||
468 | this._addSubItemToSelected(id, parentId); |
||
469 | this.menuSelected = id; |
||
470 | } |
||
471 | } |
||
472 | /* onClickMenu action (click on any end item to perform some actions) |
||
473 | optimized in version 0.3 added type feature (click on disabled items, click on complex nodes) |
||
474 | attachEvent feature from 0.4 */ |
||
475 | View Code Duplication | this._doOnClick = function(id, type, casState) { |
|
476 | this.menuLastClicked = id; |
||
477 | // href |
||
478 | if (this.itemPull[this.idPrefix+id]["href_link"] != null) { |
||
479 | var form = document.createElement("FORM"); |
||
480 | var k = String(this.itemPull[this.idPrefix+id]["href_link"]).split("?"); |
||
481 | form.action = k[0]; |
||
482 | if (k[1] != null) { |
||
483 | var p = String(k[1]).split("&"); |
||
484 | for (var q=0; q<p.length; q++) { |
||
485 | var j = String(p[q]).split("="); |
||
486 | var m = document.createElement("INPUT"); |
||
487 | m.type = "hidden"; |
||
488 | m.name = (j[0]||""); |
||
489 | m.value = (j[1]||""); |
||
490 | form.appendChild(m); |
||
491 | } |
||
492 | } |
||
493 | if (this.itemPull[this.idPrefix+id]["href_target"] != null) { form.target = this.itemPull[this.idPrefix+id]["href_target"]; } |
||
494 | form.style.display = "none"; |
||
495 | document.body.appendChild(form); |
||
496 | form.submit(); |
||
497 | if (form != null) { |
||
498 | document.body.removeChild(form); |
||
499 | form = null; |
||
500 | } |
||
501 | return; |
||
502 | } |
||
503 | // |
||
504 | // some fixes |
||
505 | if (type.charAt(0)=="c") return; // can't click on complex item |
||
506 | if (type.charAt(1)=="d") return; // can't click on disabled item |
||
507 | if (type.charAt(2)=="s") return; // can't click on separator |
||
508 | // |
||
509 | if (this.checkEvent("onClick")) { |
||
510 | // this.callEvent("onClick", [id, type, this.contextMenuZoneId]); |
||
511 | this._clearAndHide(); |
||
512 | if (this._isContextMenuVisible() && this.contextAutoHide) this._hideContextMenu(); |
||
513 | this.callEvent("onClick", [id, this.contextMenuZoneId, casState]); |
||
514 | } else { |
||
515 | if ((type.charAt(1) == "d") || (this.menuMode == "win" && type.charAt(2) == "t")) return; |
||
516 | this._clearAndHide(); |
||
517 | if (this._isContextMenuVisible() && this.contextAutoHide) this._hideContextMenu(); |
||
518 | } |
||
519 | } |
||
520 | /* onTouchMenu action (select topLevel item), attachEvent added in 0.4 */ |
||
521 | this._doOnTouchMenu = function(id) { |
||
522 | if (this.menuTouched == false) { |
||
523 | this.menuTouched = true; |
||
524 | if (this.checkEvent("onTouch")) { |
||
525 | this.callEvent("onTouch", [id]); |
||
526 | } |
||
527 | } |
||
528 | } |
||
529 | // this._onTouchHandler = function(id) { } |
||
530 | // this._setOnTouchHandler = function(handler) { this._onTouchHandler = function(id) { handler(id); } } |
||
531 | /* return menu array of all nested objects */ |
||
532 | View Code Duplication | this._searchMenuNode = function(node, menu) { |
|
533 | var m = new Array(); |
||
534 | for (var q=0; q<menu.length; q++) { |
||
535 | if (typeof(menu[q]) == "object") { |
||
536 | if (menu[q].length == 5) { if (typeof(menu[q][0]) != "object") { if ((menu[q][0].replace(this.idPrefix, "") == node) && (q == 0)) { m = menu; } } } |
||
537 | var j = this._searchMenuNode(node, menu[q]); |
||
538 | if (j.length > 0) { m = j; } |
||
539 | } |
||
540 | } |
||
541 | return m; |
||
542 | } |
||
543 | /* return array of subitems for single menu object */ |
||
544 | /* modified in version 0.3 */ |
||
545 | this._getMenuNodes = function(node) { |
||
546 | var m = new Array; |
||
547 | for (var a in this.itemPull) { if (this.itemPull[a]["parent"] == node) { m[m.length] = a; } } |
||
548 | return m; |
||
549 | } |
||
550 | /* generate random string with specified length */ |
||
551 | this._genStr = function(w) { |
||
552 | var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
||
553 | for (var q=0; q<w; q++) s += z.charAt(Math.round(Math.random() * (z.length-1))); |
||
554 | return s; |
||
555 | } |
||
556 | /** |
||
557 | * @desc: return item type by id |
||
558 | * @param: id |
||
559 | * @type: public |
||
560 | */ |
||
561 | this.getItemType = function(id) { |
||
562 | id = this.idPrefix+id; |
||
563 | if (this.itemPull[id] == null) { return null; } |
||
564 | return this.itemPull[id]["type"]; |
||
565 | } |
||
566 | /* |
||
567 | * @desc: iterator, calls user-defined handler for each existing item and pass item id into it |
||
568 | * @param: handler - user-defined handler |
||
569 | * @type: public |
||
570 | */ |
||
571 | this.forEachItem = function(handler) { |
||
572 | for (var a in this.itemPull) { handler(String(a).replace(this.idPrefix, "")); } |
||
573 | } |
||
574 | /* clear selection and hide menu on onbody click event, optimized in version 0.3 */ |
||
575 | View Code Duplication | this._clearAndHide = function() { |
|
576 | main_self.menuSelected = -1; |
||
577 | main_self.menuLastClicked = -1; |
||
578 | while (main_self._openedPolygons.length > 0) { main_self._openedPolygons.pop(); } |
||
579 | for (var q=0; q<main_self._selectedSubItems.length; q++) { |
||
580 | var id = main_self._selectedSubItems[q][0]; |
||
581 | // clear all selection |
||
582 | if (main_self.idPull[id] != null) { |
||
583 | if (main_self.itemPull[id]["state"] == "enabled") { |
||
584 | if (main_self.idPull[id].className == "sub_item_selected") main_self.idPull[id].className = "sub_item"; |
||
585 | if (main_self.idPull[id].className == "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Selected") { |
||
586 | // main_self.idPull[id].className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal"; |
||
587 | // custom css |
||
588 | // console.log(main_self.itemPull[this.id]) |
||
589 | if (main_self.itemPull[id]["cssNormal"] != null) { |
||
590 | // alert(1) |
||
591 | main_self.idPull[id].className = main_self.itemPull[id]["cssNormal"]; |
||
592 | } else { |
||
593 | // default css |
||
594 | main_self.idPull[id].className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal"; |
||
595 | } |
||
596 | } |
||
597 | } |
||
598 | } |
||
599 | main_self._hidePolygon(id); |
||
600 | } |
||
601 | // added in 0.4 |
||
602 | // main_self._hidePolygon(main_self.idPrefix+main_self.topId); |
||
603 | main_self.menuTouched = false; |
||
604 | // |
||
605 | // hide all contextmenu polygons on mouseout |
||
606 | if (main_self.context) { |
||
607 | if (main_self.contextHideAllMode) { |
||
608 | main_self._hidePolygon(main_self.idPrefix+main_self.topId); |
||
609 | main_self.zInd = main_self.zIndInit; |
||
610 | } else { |
||
611 | main_self.zInd = main_self.zIndInit+main_self.zIndStep; |
||
612 | } |
||
613 | } |
||
614 | } |
||
615 | /* loading and parsing through xml, optimized in version 0.3 */ |
||
616 | this._doOnLoad = function() {} |
||
617 | /** |
||
618 | * @desc: loads menu data from an xml file and calls onLoadFunction when loading is done |
||
619 | * @param: xmlFile - an xml file with webmenu data |
||
620 | * @param: onLoadFunction - a function that is called after loading is done |
||
621 | * @type: public |
||
622 | */ |
||
623 | this.loadXML = function(xmlFile, onLoadFunction) { |
||
624 | if (onLoadFunction) this._doOnLoad = function() { onLoadFunction(); }; |
||
625 | this.callEvent("onXLS", []); |
||
626 | this._xmlLoader.loadXML(xmlFile); |
||
627 | } |
||
628 | /** |
||
629 | * @desc: loads menu data from an xml string and calls onLoadFunction when loading is done |
||
630 | * @param: xmlFile - an xml string with webmenu data |
||
631 | * @param: onLoadFunction - function that is called after loading is done |
||
632 | * @type: public |
||
633 | */ |
||
634 | this.loadXMLString = function(xmlString, onLoadFunction) { |
||
635 | if (onLoadFunction) this._doOnLoad = function() { onLoadFunction(); }; |
||
636 | this._xmlLoader.loadXMLString(xmlString); |
||
637 | } |
||
638 | View Code Duplication | this._buildMenu = function(t, parentId) { |
|
639 | // if (parentId==null) { parentId = this.topId;} |
||
640 | var u = 0; |
||
641 | for (var q=0; q<t.childNodes.length; q++) { |
||
642 | if (t.childNodes[q].tagName == this.itemTagName) { |
||
643 | var r = t.childNodes[q]; |
||
644 | var item = {}; |
||
645 | // basic |
||
646 | item["id"] = this.idPrefix+(r.getAttribute("id")||this._genStr(24)); |
||
647 | item["title"] = r.getAttribute("text")||""; |
||
648 | // images |
||
649 | item["imgen"] = r.getAttribute("img")||""; |
||
650 | item["imgdis"] = r.getAttribute("imgdis")||""; |
||
651 | item["tip"] = ""; |
||
652 | item["hotkey"] = ""; |
||
653 | // custom css |
||
654 | if (r.getAttribute("cssNormal") != null) { item["cssNormal"] = r.getAttribute("cssNormal"); } |
||
655 | // type |
||
656 | item["type"] = r.getAttribute("type")||"item"; |
||
657 | //#menu_checks:06062008{ |
||
658 | if (item["type"] == "checkbox") { |
||
659 | item["checked"] = (r.getAttribute("checked")!=null); |
||
660 | // set classname |
||
661 | item["imgen"] = "chbx_"+(item["checked"]?"1":"0"); |
||
662 | item["imgdis"] = item["imgen"]; |
||
663 | } |
||
664 | //#} |
||
665 | //#menu_radio:06062008{ |
||
666 | if (item["type"] == "radio") { |
||
667 | item["checked"] = (r.getAttribute("checked")!=null); |
||
668 | item["imgen"] = "rdbt_"+(item["checked"]?"1":"0"); |
||
669 | item["imgdis"] = item["imgen"]; |
||
670 | item["group"] = r.getAttribute("group")||this._genStr(24); |
||
671 | if (this.radio[item["group"]]==null) { this.radio[item["group"]] = new Array(); } |
||
672 | this.radio[item["group"]][this.radio[item["group"]].length] = item["id"]; |
||
673 | } |
||
674 | //#} |
||
675 | // enable/disable |
||
676 | item["state"] = (r.getAttribute("enabled")!=null||r.getAttribute("disabled")!=null?(r.getAttribute("enabled")=="false"||r.getAttribute("disabled")=="true"?"disabled":"enabled"):"enabled"); |
||
677 | item["parent"] = (parentId!=null?parentId:this.idPrefix+this.topId); |
||
678 | // item["complex"] = (((this.dLoad)&&(parentId!=null))?(r.getAttribute("complex")!=null?true:false):(this._buildMenu(r,item["id"])>0)); |
||
679 | item["complex"] = (this.dLoad?(r.getAttribute("complex")!=null?true:false):(this._buildMenu(r,item["id"])>0)); |
||
680 | if (this.dLoad && item["complex"]) { item["loaded"] = "no"; } |
||
681 | this.itemPull[item["id"]] = item; |
||
682 | // check for user data |
||
683 | for (var w=0; w<r.childNodes.length; w++) { |
||
684 | // added in 0.4 |
||
685 | var tagNm = r.childNodes[w].tagName; |
||
686 | if (tagNm != null) { tagNm = tagNm.toLowerCase(); } |
||
687 | // |
||
688 | if (tagNm == this.userDataTagName) { |
||
689 | var d = r.childNodes[w]; |
||
690 | if (d.getAttribute("name")!=null) { this.userData[item["id"]+"_"+d.getAttribute("name")] = (d.firstChild.nodeValue!=null?d.firstChild.nodeValue:""); } |
||
691 | } |
||
692 | // extended text, added in 0.4 |
||
693 | if (tagNm == this.itemTextTagName) { item["title"] = r.childNodes[w].firstChild.nodeValue; } |
||
694 | // tooltips, added in 0.4 |
||
695 | if (tagNm == this.itemTipTagName) { item["tip"] = r.childNodes[w].firstChild.nodeValue; } |
||
696 | // hotkeys, added in 0.4 |
||
697 | if (tagNm == this.itemHotKeyTagName) { item["hotkey"] = r.childNodes[w].firstChild.nodeValue; } |
||
698 | // hrefs |
||
699 | if (tagNm == this.itemHrefTagName && item["type"] == "item") { |
||
700 | item["href_link"] = r.childNodes[w].firstChild.nodeValue; |
||
701 | if (r.childNodes[w].getAttribute("target") != null) { item["href_target"] = r.childNodes[w].getAttribute("target"); } |
||
702 | } |
||
703 | } |
||
704 | u++; |
||
705 | } |
||
706 | } |
||
707 | return u; |
||
708 | } |
||
709 | /* parse incoming xml */ |
||
710 | View Code Duplication | this._xmlParser = function() { |
|
711 | if (main_self.dLoad) { |
||
712 | var t = this.getXMLTopNode("menu"); |
||
713 | parentId = (t.getAttribute("parentId")!=null?t.getAttribute("parentId"):null); |
||
714 | if (parentId == null) { |
||
715 | // alert(1) |
||
716 | // main_self.idPrefix = main_self._genStr(12); |
||
717 | main_self._buildMenu(t, null); |
||
718 | main_self._initTopLevelMenu(); |
||
719 | } else { |
||
720 | main_self._buildMenu(t, main_self.idPrefix+parentId); |
||
721 | main_self._addSubMenuPolygon(main_self.idPrefix+parentId, main_self.idPrefix+parentId);//, main_self.idPull[main_self.idPrefix+parentId]); |
||
722 | if (main_self.menuSelected == main_self.idPrefix+parentId) { |
||
723 | var pId = main_self.idPrefix+parentId; |
||
724 | var isTop = main_self.itemPull[main_self.idPrefix+parentId]["parent"]==main_self.idPrefix+main_self.topId; |
||
725 | var level = ((isTop&&(!main_self.context))?main_self.dirTopLevel:main_self.dirSubLevel); |
||
726 | var isShow = false; |
||
727 | if (isTop && main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) { |
||
728 | var item = main_self.idPull[main_self.idPrefix+parentId]; |
||
729 | if (item._mouseOver == true) { |
||
730 | var delay = main_self.menuModeTopLevelTimeoutTime - (new Date().getTime()-item._dynLoadTM); |
||
731 | if (delay > 1) { |
||
732 | item._menuOpenTM = window.setTimeout(function(){ main_self._showPolygon(pId, level); }, delay); |
||
733 | isShow = true; |
||
734 | } |
||
735 | } |
||
736 | } |
||
737 | if (!isShow) { main_self._showPolygon(pId, level); } |
||
738 | } |
||
739 | main_self.itemPull[main_self.idPrefix+parentId]["loaded"] = "yes"; |
||
740 | // console.log(main_self.loaderIcon) |
||
741 | if (main_self.loaderIcon == true) { main_self._updateLoaderIcon(main_self.idPrefix+parentId, false); } |
||
742 | } |
||
743 | this.destructor(); |
||
744 | main_self.callEvent("onXLE",[]); |
||
745 | } else { |
||
746 | var t = this.getXMLTopNode("menu"); |
||
747 | // alert(3) |
||
748 | // main_self.idPrefix = main_self._genStr(12); |
||
749 | main_self._buildMenu(t, null); |
||
750 | main_self.init(); |
||
751 | main_self.callEvent("onXLE",[]); |
||
752 | main_self._doOnLoad(); |
||
753 | } |
||
754 | } |
||
755 | this._xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window); |
||
756 | /* show sublevel item */ |
||
757 | View Code Duplication | this._showSubLevelItem = function(id,back) { |
|
758 | if (document.getElementById("arrow_" + this.idPrefix + id) != null) { document.getElementById("arrow_" + this.idPrefix + id).style.display = (back?"none":""); } |
||
759 | if (document.getElementById("image_" + this.idPrefix + id) != null) { document.getElementById("image_" + this.idPrefix + id).style.display = (back?"none":""); } |
||
760 | if (document.getElementById(this.idPrefix + id) != null) { document.getElementById(this.idPrefix + id).style.display = (back?"":"none"); } |
||
761 | } |
||
762 | /* hide sublevel item */ |
||
763 | this._hideSubLevelItem = function(id) { |
||
764 | this._showSubLevelItem(id,true) |
||
765 | } |
||
766 | // generating id prefix |
||
767 | this.idPrefix = this._genStr(12); |
||
768 | |||
769 | /* attach body events */ |
||
770 | this._bodyClick = function(e) { |
||
771 | e = e||event; |
||
772 | if (e.button == 2 || (_isOpera && e.ctrlKey == true)) return; |
||
773 | if (main_self.context) { |
||
774 | if (main_self.contextAutoHide && (!_isOpera || (main_self._isContextMenuVisible() && _isOpera))) main_self._hideContextMenu(); |
||
775 | } else { |
||
776 | main_self._clearAndHide(); |
||
777 | } |
||
778 | } |
||
779 | this._bodyContext = function(e) { |
||
780 | e = e||event; |
||
781 | var t = (e.srcElement||e.target).className; |
||
782 | if (t.search("dhtmlxMenu") != -1 && t.search("SubLevelArea") != -1) return; |
||
783 | var toHide = true; |
||
784 | var testZone = e.target || e.srcElement; |
||
785 | if (testZone.id != null) if (main_self.isContextZone(testZone.id)) toHide = false; |
||
786 | if (testZone == document.body) toHide = false; |
||
787 | if (toHide) main_self.hideContextMenu(); |
||
788 | } |
||
789 | |||
790 | if (_isIE) { |
||
791 | document.body.attachEvent("onclick", this._bodyClick); |
||
792 | document.body.attachEvent("oncontextmenu", this._bodyContext); |
||
793 | } else { |
||
794 | window.addEventListener("click", this._bodyClick, false); |
||
795 | window.addEventListener("contextmenu", this._bodyContext, false); |
||
796 | } |
||
797 | |||
798 | // add menu to global store |
||
799 | this._UID = this._genStr(32); |
||
800 | dhtmlxMenuObjectLiveInstances[this._UID] = this; |
||
801 | |||
802 | /* events */ |
||
803 | dhtmlxEventable(this); |
||
804 | // |
||
805 | return this; |
||
806 | } |
||
807 | dhtmlXMenuObject.prototype.init = function() { |
||
808 | if (this._isInited == true) return; |
||
809 | if (this.dLoad) { |
||
810 | this.callEvent("onXLS", []); |
||
811 | // this._xmlLoader.loadXML(this.dLoadUrl+"?action=loadMenu&parentId="+this.topId+"&topId="+this.topId); |
||
812 | this._xmlLoader.loadXML(this.dLoadUrl+this.dLoadSign+"action=loadMenu&etc="+new Date().getTime()); // &&parentId=topId&"+this.topId+"&topId="+this.topId); |
||
813 | } else { |
||
814 | this._initTopLevelMenu(); |
||
815 | this._isInited = true; |
||
816 | } |
||
817 | } |
||
818 | View Code Duplication | dhtmlXMenuObject.prototype._countVisiblePolygonItems = function(id) { |
|
819 | /* |
||
820 | var count = 0; |
||
821 | if ((this.idPull["polygon_"+id] != null) && (this.idPull[id] != null)) { |
||
822 | for (var q=0; q<this.idPull["polygon_"+id].childNodes.length; q++) { |
||
823 | var node = this.idPull["polygon_"+id].childNodes[q]; |
||
824 | count += (((node.style.display=="none")||(node.className=="dhtmlxMenu_SubLevelArea_Separator"))?0:1); |
||
825 | } |
||
826 | } |
||
827 | */ |
||
828 | /* updated in 0.4 */ |
||
829 | var count = 0; |
||
830 | // console.log(this.idPull) |
||
831 | for (var a in this.itemPull) { |
||
832 | //console.log(a) |
||
833 | var par = this.itemPull[a]["parent"]; |
||
834 | var tp = this.itemPull[a]["type"]; |
||
835 | if (this.idPull[a] != null) { |
||
836 | // console.log(this.idPull[a]) |
||
837 | // alert(1111) |
||
838 | if (par == id && (tp == "item" || tp == "radio" || tp == "checkbox") && this.idPull[a].style.display != "none") { |
||
839 | count++; |
||
840 | } |
||
841 | } |
||
842 | } |
||
843 | return count; |
||
844 | } |
||
845 | View Code Duplication | dhtmlXMenuObject.prototype._redefineComplexState = function(id) { |
|
846 | // alert(id) |
||
847 | if (this.idPrefix+this.topId == id) { return; } |
||
848 | if ((this.idPull["polygon_"+id] != null) && (this.idPull[id] != null)) { |
||
849 | var u = this._countVisiblePolygonItems(id); |
||
850 | if ((u > 0) && (!this.itemPull[id]["complex"])) { this._updateItemComplexState(id, true, false); } |
||
851 | if ((u == 0) && (this.itemPull[id]["complex"])) { this._updateItemComplexState(id, false, false); } |
||
852 | } |
||
853 | } |
||
854 | /* complex arrow manipulations, over added in 0.4 */ |
||
855 | View Code Duplication | dhtmlXMenuObject.prototype._updateItemComplexState = function(id, state, over) { |
|
856 | // 0.2 FIX :: topLevel's items can have complex items with arrow |
||
857 | if ((!this.context) && (this._getItemLevelType(id.replace(this.idPrefix,"")) == "TopLevel")) { |
||
858 | // 30.06.2008 fix > complex state for top level item, state only, no arrow |
||
859 | this.itemPull[id]["complex"] = state; |
||
860 | return; |
||
861 | } |
||
862 | if ((this.idPull[id] == null) || (this.itemPull[id] == null)) { return; } |
||
863 | // 0.2 FIX :: end |
||
864 | this.itemPull[id]["complex"] = state; |
||
865 | // fixed in 0.4 for context |
||
866 | if (id == this.idPrefix+this.topId) return; |
||
867 | // end fix |
||
868 | // try to retrieve arrow img object |
||
869 | var arrowObj = null; |
||
870 | |||
871 | |||
872 | var item = this.idPull[id].childNodes[this._rtl?0:2]; |
||
873 | if (item.childNodes[0]) if (String(item.childNodes[0].className).search("complex_arrow") === 0) arrowObj = item.childNodes[0]; |
||
874 | |||
875 | if (this.itemPull[id]["complex"]) { |
||
876 | // create arrow |
||
877 | if (arrowObj == null) { |
||
878 | arrowObj = document.createElement("DIV"); |
||
879 | arrowObj.className = "complex_arrow"; |
||
880 | arrowObj.id = "arrow_"+id; |
||
881 | while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]); |
||
882 | item.appendChild(arrowObj); |
||
883 | } |
||
884 | // over state added in 0.4 |
||
885 | |||
886 | if (this.dLoad && (this.itemPull[id]["loaded"] == "get") && this.loaderIcon) { |
||
887 | // change arrow to loader |
||
888 | if (arrowObj.className != "complex_arrow_loading") arrowObj.className = "complex_arrow_loading"; |
||
889 | } else { |
||
890 | arrowObj.className = "complex_arrow"; |
||
891 | } |
||
892 | |||
893 | return; |
||
894 | } |
||
895 | |||
896 | if ((!this.itemPull[id]["complex"]) && (arrowObj!=null)) { |
||
897 | item.removeChild(arrowObj); |
||
898 | if (this.itemPull[id]["hotkey_backup"] != null && this.setHotKey) { this.setHotKey(id.replace(this.idPrefix, ""), this.itemPull[id]["hotkey_backup"]); } |
||
899 | } |
||
900 | |||
901 | } |
||
902 | |||
903 | /* return css-part level type */ |
||
904 | dhtmlXMenuObject.prototype._getItemLevelType = function(id) { |
||
905 | return (this.itemPull[this.idPrefix+id]["parent"]==this.idPrefix+this.topId?"TopLevel":"SubLevelArea"); |
||
906 | } |
||
907 | /****************************************************************************************************************************************************/ |
||
908 | /* "TOPLEVEL" LOW-LEVEL RENDERING */ |
||
909 | /* redistrib selection in case of top node in real-time mode */ |
||
910 | View Code Duplication | dhtmlXMenuObject.prototype._redistribTopLevelSelection = function(id, parent) { |
|
911 | // kick polygons and decelect before selected menues |
||
912 | var i = this._getSubItemToDeselectByPolygon("parent"); |
||
913 | this._removeSubItemFromSelected(-1, -1); |
||
914 | for (var q=0; q<i.length; q++) { |
||
915 | if (i[q] != id) { this._hidePolygon(i[q]); } |
||
916 | if ((this.idPull[i[q]] != null) && (i[q] != id)) { this.idPull[i[q]].className = this.idPull[i[q]].className.replace(/Selected/g, "Normal"); } |
||
917 | } |
||
918 | // check if enabled |
||
919 | if (this.itemPull[this.idPrefix+id]["state"] == "enabled") { |
||
920 | this.idPull[this.idPrefix+id].className = "dhtmlxMenu_"+this.skin+"_TopLevel_Item_Selected"; |
||
921 | // |
||
922 | this._addSubItemToSelected(this.idPrefix+id, "parent"); |
||
923 | this.menuSelected = (this.menuMode=="win"?(this.menuSelected!=-1?id:this.menuSelected):id); |
||
924 | if ((this.itemPull[this.idPrefix+id]["complex"]) && (this.menuSelected != -1)) { this._showPolygon(this.idPrefix+id, this.dirTopLevel); } |
||
925 | } |
||
926 | } |
||
927 | View Code Duplication | dhtmlXMenuObject.prototype._initTopLevelMenu = function() { |
|
928 | // console.log(this.idPull); |
||
929 | this.dirTopLevel = "bottom"; |
||
930 | this.dirSubLevel = (this._rtl?"left":"right"); |
||
931 | if (this.context) { |
||
932 | this.idPull[this.idPrefix+this.topId] = new Array(0,0); |
||
933 | this._addSubMenuPolygon(this.idPrefix+this.topId, this.idPrefix+this.topId); |
||
934 | } else { |
||
935 | var m = this._getMenuNodes(this.idPrefix + this.topId); |
||
936 | for (var q=0; q<m.length; q++) { |
||
937 | if (this.itemPull[m[q]]["type"] == "item") this._renderToplevelItem(m[q], null); |
||
938 | if (this.itemPull[m[q]]["type"] == "separator") this._renderSeparator(m[q], null); |
||
939 | } |
||
940 | } |
||
941 | } |
||
942 | /* add top menu item, complex define that submenues are in presence */ |
||
943 | View Code Duplication | dhtmlXMenuObject.prototype._renderToplevelItem = function(id, pos) { |
|
944 | var main_self = this; |
||
945 | var m = document.createElement("DIV"); |
||
946 | m.id = id; |
||
947 | // custom css |
||
948 | if (this.itemPull[id]["state"] == "enabled" && this.itemPull[id]["cssNormal"] != null) { |
||
949 | m.className = this.itemPull[id]["cssNormal"]; |
||
950 | } else { |
||
951 | m.className = "dhtmlxMenu_"+this.skin+"_TopLevel_Item_"+(this.itemPull[id]["state"]=="enabled"?"Normal":"Disabled"); |
||
952 | } |
||
953 | |||
954 | // text |
||
955 | if (this.itemPull[id]["title"] != "") { |
||
956 | var t1 = document.createElement("DIV"); |
||
957 | t1.className = "top_level_text"; |
||
958 | t1.innerHTML = this.itemPull[id]["title"]; |
||
959 | m.appendChild(t1); |
||
960 | } |
||
961 | // tooltip |
||
962 | if (this.itemPull[id]["tip"].length > 0) m.title = this.itemPull[id]["tip"]; |
||
963 | // |
||
964 | // image in top level |
||
965 | if ((this.itemPull[id]["imgen"]!="")||(this.itemPull[id]["imgdis"]!="")) { |
||
966 | var imgTop=this.itemPull[id][(this.itemPull[id]["state"]=="enabled")?"imgen":"imgdis"]; |
||
967 | if (imgTop) { |
||
968 | var img = document.createElement("IMG"); |
||
969 | img.border = "0"; |
||
970 | img.id = "image_"+id; |
||
971 | img.src= this.imagePath+imgTop; |
||
972 | img.className = "dhtmlxMenu_TopLevel_Item_Icon"; |
||
973 | if (m.childNodes.length > 0 && !this._rtl) m.insertBefore(img, m.childNodes[0]); else m.appendChild(img); |
||
974 | } |
||
975 | } |
||
976 | m.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; } |
||
977 | m.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; } |
||
978 | // add container for top-level items if not exists yet |
||
979 | if (!this.cont) { |
||
980 | this.cont = document.createElement("DIV"); |
||
981 | this.cont.dir = "ltr"; |
||
982 | this.cont.className = (this._align=="right"?"align_right":"align_left"); |
||
983 | this.base.appendChild(this.cont); |
||
984 | } |
||
985 | // insert |
||
986 | /* |
||
987 | if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.base.childNodes.length - 1) pos = null; } |
||
988 | if (pos != null) this.base.insertBefore(m, this.base.childNodes[pos]); else this.base.appendChild(m); |
||
989 | */ |
||
990 | if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.cont.childNodes.length - 1) pos = null; } |
||
991 | if (pos != null) this.cont.insertBefore(m, this.cont.childNodes[pos]); else this.cont.appendChild(m); |
||
992 | |||
993 | |||
994 | // |
||
995 | this.idPull[m.id] = m; |
||
996 | // create submenues |
||
997 | if (this.itemPull[id]["complex"] && (!this.dLoad)) this._addSubMenuPolygon(this.itemPull[id]["id"], this.itemPull[id]["id"]); |
||
998 | // events |
||
999 | m.onmouseover = function() { |
||
1000 | if (main_self.menuMode == "web") { window.clearTimeout(main_self.menuTimeoutHandler); } |
||
1001 | // kick polygons and decelect before selected menues |
||
1002 | var i = main_self._getSubItemToDeselectByPolygon("parent"); |
||
1003 | main_self._removeSubItemFromSelected(-1, -1); |
||
1004 | for (var q=0; q<i.length; q++) { |
||
1005 | if (i[q] != this.id) { main_self._hidePolygon(i[q]); } |
||
1006 | if ((main_self.idPull[i[q]] != null) && (i[q] != this.id)) { |
||
1007 | // custom css |
||
1008 | if (main_self.itemPull[i[q]]["cssNormal"] != null) { |
||
1009 | main_self.idPull[i[q]].className = main_self.itemPull[i[q]]["cssNormal"]; |
||
1010 | } else { |
||
1011 | if (main_self.idPull[i[q]].className == "sub_item_selected") main_self.idPull[i[q]].className = "sub_item"; |
||
1012 | main_self.idPull[i[q]].className = main_self.idPull[i[q]].className.replace(/Selected/g, "Normal"); |
||
1013 | } |
||
1014 | } |
||
1015 | } |
||
1016 | // check if enabled |
||
1017 | if (main_self.itemPull[this.id]["state"] == "enabled") { |
||
1018 | this.className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Selected"; |
||
1019 | // |
||
1020 | main_self._addSubItemToSelected(this.id, "parent"); |
||
1021 | main_self.menuSelected = (main_self.menuMode=="win"?(main_self.menuSelected!=-1?this.id:main_self.menuSelected):this.id); |
||
1022 | if (main_self.dLoad && (main_self.itemPull[this.id]["loaded"]=="no")) { |
||
1023 | if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) { |
||
1024 | this._mouseOver = true; |
||
1025 | this._dynLoadTM = new Date().getTime(); |
||
1026 | } |
||
1027 | var xmlLoader = new dtmlXMLLoaderObject(main_self._xmlParser, window); |
||
1028 | main_self.itemPull[this.id]["loaded"] = "get"; |
||
1029 | main_self.callEvent("onXLS", []); |
||
1030 | xmlLoader.loadXML(main_self.dLoadUrl+main_self.dLoadSign+"action=loadMenu&parentId="+this.id.replace(main_self.idPrefix,"")+"&etc="+new Date().getTime()); |
||
1031 | } |
||
1032 | if ((!main_self.dLoad) || (main_self.dLoad && (main_self.itemPull[this.id]["loaded"]=="yes"))) { |
||
1033 | if ((main_self.itemPull[this.id]["complex"]) && (main_self.menuSelected != -1)) { |
||
1034 | if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) { |
||
1035 | this._mouseOver = true; |
||
1036 | var showItemId = this.id; |
||
1037 | this._menuOpenTM = window.setTimeout(function(){main_self._showPolygon(showItemId, main_self.dirTopLevel);}, main_self.menuModeTopLevelTimeoutTime); |
||
1038 | } else { |
||
1039 | main_self._showPolygon(this.id, main_self.dirTopLevel); |
||
1040 | } |
||
1041 | } |
||
1042 | } |
||
1043 | } |
||
1044 | main_self._doOnTouchMenu(this.id.replace(main_self.idPrefix, "")); |
||
1045 | } |
||
1046 | m.onmouseout = function() { |
||
1047 | if (!((main_self.itemPull[this.id]["complex"]) && (main_self.menuSelected != -1)) && (main_self.itemPull[this.id]["state"]=="enabled")) { |
||
1048 | // custom css |
||
1049 | // console.log(main_self.itemPull[this.id]) |
||
1050 | if (main_self.itemPull[this.id]["cssNormal"] != null) { |
||
1051 | // alert(1) |
||
1052 | m.className = main_self.itemPull[this.id]["cssNormal"]; |
||
1053 | } else { |
||
1054 | // default css |
||
1055 | m.className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal"; |
||
1056 | } |
||
1057 | } |
||
1058 | if (main_self.menuMode == "web") { |
||
1059 | window.clearTimeout(main_self.menuTimeoutHandler); |
||
1060 | main_self.menuTimeoutHandler = window.setTimeout(function(){main_self._clearAndHide();}, main_self.menuTimeoutMsec, "JavaScript"); |
||
1061 | } |
||
1062 | if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) { |
||
1063 | this._mouseOver = false; |
||
1064 | window.clearTimeout(this._menuOpenTM); |
||
1065 | } |
||
1066 | } |
||
1067 | m.onclick = function(e) { |
||
1068 | if (main_self.menuMode == "web") { window.clearTimeout(main_self.menuTimeoutHandler); } |
||
1069 | // fix, added in 0.4 |
||
1070 | if (main_self.menuMode != "web" && main_self.itemPull[this.id]["state"] == "disabled") { return; } |
||
1071 | // |
||
1072 | e = e || event; |
||
1073 | e.cancelBubble = true; |
||
1074 | e.returnValue = false; |
||
1075 | |||
1076 | if (main_self.menuMode == "win") { |
||
1077 | if (main_self.itemPull[this.id]["complex"]) { |
||
1078 | if (main_self.menuSelected == this.id) { main_self.menuSelected = -1; var s = false; } else { main_self.menuSelected = this.id; var s = true; } |
||
1079 | if (s) { main_self._showPolygon(this.id, main_self.dirTopLevel); } else { main_self._hidePolygon(this.id); } |
||
1080 | } |
||
1081 | } |
||
1082 | var tc = (main_self.itemPull[this.id]["complex"]?"c":"-"); |
||
1083 | var td = (main_self.itemPull[this.id]["state"]!="enabled"?"d":"-"); |
||
1084 | var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey}; |
||
1085 | main_self._doOnClick(this.id.replace(main_self.idPrefix, ""), tc+td+"t", cas); |
||
1086 | return false; |
||
1087 | } |
||
1088 | } |
||
1089 | /****************************************************************************************************************************************************/ |
||
1090 | /** |
||
1091 | * @desc: empty function, now more used from 90226 |
||
1092 | * @type: public |
||
1093 | */ |
||
1094 | dhtmlXMenuObject.prototype.setImagePath = function() { /* no more used */ } |
||
1095 | /** |
||
1096 | * @desc: defines an url where necessary user embedded icons are located |
||
1097 | * @param: path - url to images |
||
1098 | * @type: public |
||
1099 | */ |
||
1100 | dhtmlXMenuObject.prototype.setIconsPath = function(path) { this.imagePath = path; } |
||
1101 | /** |
||
1102 | * @desc: alias for setIconsPath |
||
1103 | * @type: public |
||
1104 | */ |
||
1105 | dhtmlXMenuObject.prototype.setIconPath = dhtmlXMenuObject.prototype.setIconsPath; |
||
1106 | /* real-time update icon in menu */ |
||
1107 | View Code Duplication | dhtmlXMenuObject.prototype._updateItemImage = function(id, levelType) { |
|
1108 | // search existsing image |
||
1109 | |||
1110 | id = this.idPrefix+id; |
||
1111 | var isTopLevel = (this.itemPull[id]["parent"] == this.idPrefix+this.topId && !this.context); |
||
1112 | |||
1113 | // search existing image |
||
1114 | var imgObj = null; |
||
1115 | if (isTopLevel) { |
||
1116 | for (var q=0; q<this.idPull[id].childNodes.length; q++) { |
||
1117 | try { if (this.idPull[id].childNodes[q].className == "dhtmlxMenu_TopLevel_Item_Icon") imgObj = this.idPull[id].childNodes[q]; } catch(e) {} |
||
1118 | } |
||
1119 | } else { |
||
1120 | try { var imgObj = this.idPull[id].childNodes[this._rtl?2:0].childNodes[0]; } catch(e) { } |
||
1121 | } |
||
1122 | |||
1123 | if (this.itemPull[id]["type"] == "radio") { |
||
1124 | var imgSrc = this.itemPull[id][(this.itemPull[id]["state"]=="enabled"?"imgen":"imgdis")]; |
||
1125 | // console.log(this.itemPull[this.idPrefix+id]) |
||
1126 | } else { |
||
1127 | var imgSrc = this.itemPull[id][(this.itemPull[id]["state"]=="enabled"?"imgen":"imgdis")]; |
||
1128 | } |
||
1129 | |||
1130 | if (imgSrc.length > 0) { |
||
1131 | if (imgObj != null) { |
||
1132 | imgObj.src = this.imagePath+imgSrc; |
||
1133 | } else { |
||
1134 | if (isTopLevel) { |
||
1135 | var imgObj = document.createElement("IMG"); |
||
1136 | imgObj.className = "dhtmlxMenu_TopLevel_Item_Icon"; |
||
1137 | imgObj.src = this.imagePath+imgSrc; |
||
1138 | imgObj.border = "0"; |
||
1139 | imgObj.id = "image_"+id; |
||
1140 | if (!this._rtl && this.idPull[id].childNodes.length > 0) this.idPull[id].insertBefore(imgObj,this.idPull[id].childNodes[0]); else this.idPull[id].appendChild(imgObj); |
||
1141 | |||
1142 | } else { |
||
1143 | |||
1144 | var imgObj = document.createElement("IMG"); |
||
1145 | imgObj.className = "sub_icon"; |
||
1146 | imgObj.src = this.imagePath+imgSrc; |
||
1147 | imgObj.border = "0"; |
||
1148 | imgObj.id = "image_"+id; |
||
1149 | var item = this.idPull[id].childNodes[this._rtl?2:0]; |
||
1150 | while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]); |
||
1151 | item.appendChild(imgObj); |
||
1152 | |||
1153 | } |
||
1154 | } |
||
1155 | } else { |
||
1156 | if (imgObj != null) imgObj.parentNode.removeChild(imgObj); |
||
1157 | } |
||
1158 | } |
||
1159 | /** |
||
1160 | * @desc: removes an item from the menu with all nested sublevels |
||
1161 | * @param: id - id of the item for removing |
||
1162 | * @type: public |
||
1163 | */ |
||
1164 | View Code Duplication | dhtmlXMenuObject.prototype.removeItem = function(id, _isTId, _recCall) { |
|
1165 | if (!_isTId) id = this.idPrefix + id; |
||
1166 | |||
1167 | var pId = null; |
||
1168 | |||
1169 | if (id != this.idPrefix+this.topId) { |
||
1170 | |||
1171 | if (this.itemPull[id] == null) return; |
||
1172 | |||
1173 | // separator top |
||
1174 | var t = this.itemPull[id]["type"]; |
||
1175 | |||
1176 | if (t == "separator") { |
||
1177 | var item = this.idPull["separator_"+id]; |
||
1178 | if (this.itemPull[id]["parent"] == this.idPrefix+this.topId) { |
||
1179 | item.onclick = null; |
||
1180 | item.onselectstart = null; |
||
1181 | item.id = null; |
||
1182 | item.parentNode.removeChild(item); |
||
1183 | } else { |
||
1184 | item.childNodes[0].childNodes[0].onclick = null; |
||
1185 | item.childNodes[0].childNodes[0].onselectstart = null; |
||
1186 | item.childNodes[0].childNodes[0].id = null; |
||
1187 | item.childNodes[0].removeChild(item.childNodes[0].childNodes[0]); |
||
1188 | item.removeChild(item.childNodes[0]); |
||
1189 | item.parentNode.removeChild(item); |
||
1190 | } |
||
1191 | this.idPull["separator_"+id] = null; |
||
1192 | this.itemPull[id] = null; |
||
1193 | delete this.idPull["separator_"+id]; |
||
1194 | delete this.itemPull[id]; |
||
1195 | item = null; |
||
1196 | } else { |
||
1197 | // item checkbox radio |
||
1198 | pId = this.itemPull[id]["parent"]; |
||
1199 | var item = this.idPull[id]; |
||
1200 | item.onclick = null; |
||
1201 | item.oncontextmenu = null; |
||
1202 | item.onmouseover = null; |
||
1203 | item.onmouseout = null; |
||
1204 | item.onselectstart = null; |
||
1205 | item.id = null; |
||
1206 | while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]); |
||
1207 | item.parentNode.removeChild(item); |
||
1208 | this.idPull[id] = null; |
||
1209 | this.itemPull[id] = null; |
||
1210 | delete this.idPull[id]; |
||
1211 | delete this.itemPull[id]; |
||
1212 | item = null; |
||
1213 | |||
1214 | } |
||
1215 | t = null; |
||
1216 | } |
||
1217 | |||
1218 | // clear nested items |
||
1219 | for (var a in this.itemPull) if (this.itemPull[a]["parent"] == id) this.removeItem(a, true, true); |
||
1220 | |||
1221 | // check if empty polygon left |
||
1222 | var p2 = new Array(id); |
||
1223 | if (pId != null && !_recCall) { |
||
1224 | if (this.idPull["polygon_"+pId] != null) { |
||
1225 | if (this.idPull["polygon_"+pId].tbd.childNodes.length == 0) { |
||
1226 | p2.push(pId); |
||
1227 | this._updateItemComplexState(pId, false, false); |
||
1228 | } |
||
1229 | } |
||
1230 | } |
||
1231 | |||
1232 | // delete nested polygons and parent's if any |
||
1233 | for (var q=0; q<p2.length; q++) { |
||
1234 | if (this.idPull["polygon_"+p2[q]]) { |
||
1235 | var p = this.idPull["polygon_"+p2[q]]; |
||
1236 | p.onclick = null; |
||
1237 | p.oncontextmenu = null; |
||
1238 | p.tbl.removeChild(p.tbd); |
||
1239 | p.tbd = null; |
||
1240 | p.removeChild(p.tbl); |
||
1241 | p.tbl = null; |
||
1242 | p.id = null; |
||
1243 | p.parentNode.removeChild(p); |
||
1244 | p = null; |
||
1245 | if (this._isIE6) { |
||
1246 | var pc = "polygon_"+p2[q]+"_ie6cover"; |
||
1247 | if (this.idPull[pc] != null) { document.body.removeChild(this.idPull[pc]); delete this.idPull[pc]; } |
||
1248 | } |
||
1249 | if (this.idPull["arrowup_"+id] != null && this._removeArrow) this._removeArrow("arrowup_"+id); |
||
1250 | if (this.idPull["arrowdown_"+id] != null && this._removeArrow) this._removeArrow("arrowdown_"+id); |
||
1251 | // |
||
1252 | this.idPull["polygon_"+p2[q]] = null; |
||
1253 | delete this.idPull["polygon_"+p2[q]]; |
||
1254 | } |
||
1255 | } |
||
1256 | p2 = null; |
||
1257 | |||
1258 | |||
1259 | /* |
||
1260 | // get parent |
||
1261 | var parentId = this.itemPull[id]["parent"]; |
||
1262 | // separator |
||
1263 | if (this.itemPull[id]["type"] == "separator") { |
||
1264 | this.idPull["separator_"+id].parentNode.removeChild(this.idPull["separator_"+id]); |
||
1265 | this.idPull["separator_"+id] = null; |
||
1266 | this.itemPull[id] = null; |
||
1267 | delete this.idPull["separator_"+id]; |
||
1268 | delete this.itemPull[id]; |
||
1269 | // return; |
||
1270 | } else { |
||
1271 | // complex/single item |
||
1272 | if (this.itemPull[id]["complex"]) { |
||
1273 | var items = this._getAllParents(id); |
||
1274 | items[items.length] = id; |
||
1275 | var polygons = new Array(); |
||
1276 | for (var q=0; q<items.length; q++) { |
||
1277 | if (this.itemPull[items[q]]["type"] == "separator") { |
||
1278 | this.removeItem(items[q].replace(this.idPrefix,"")); |
||
1279 | } else { |
||
1280 | if (this.itemPull[items[q]]["complex"]) { polygons[polygons.length] = items[q]; } |
||
1281 | this.idPull[items[q]].parentNode.removeChild(this.idPull[items[q]]); |
||
1282 | this.idPull[items[q]] = null; |
||
1283 | this.itemPull[items[q]] = null; |
||
1284 | delete this.idPull[items[q]]; |
||
1285 | delete this.itemPull[items[q]]; |
||
1286 | } |
||
1287 | } |
||
1288 | for (var q=0; q<polygons.length; q++) { |
||
1289 | this.idPull["polygon_"+polygons[q]].parentNode.removeChild(this.idPull["polygon_"+polygons[q]]); |
||
1290 | if (this._isIE6) { |
||
1291 | var pId = "polygon_"+polygons[q]+"_ie6cover"; |
||
1292 | if (this.idPull[pId] != null) { document.body.removeChild(this.idPull[pId]); delete this.idPull[pId]; } |
||
1293 | } |
||
1294 | this.idPull["polygon_"+polygons[q]] = null; |
||
1295 | this.itemPull[polygons[q]] = null; |
||
1296 | delete this.idPull["polygon_"+polygons[q]]; |
||
1297 | delete this.itemPull[polygons[q]]; |
||
1298 | } |
||
1299 | } else { |
||
1300 | this.idPull[id].parentNode.removeChild(this.idPull[id]); |
||
1301 | this.idPull[id] = null; |
||
1302 | this.itemPull[id] = null; |
||
1303 | delete this.idPull[id]; |
||
1304 | delete this.itemPull[id]; |
||
1305 | } |
||
1306 | } |
||
1307 | // checking existing empty polygon |
||
1308 | if (this.idPull["polygon_"+parentId] != null) { |
||
1309 | var p = this.idPull["polygon_"+parentId]; |
||
1310 | if (p.tbd.childNodes.length == 0) { |
||
1311 | p.tbd.parentNode.removeChild(p.tbd); |
||
1312 | p.tbl.parentNode.removeChild(p.tbl); |
||
1313 | document.body.removeChild(p); |
||
1314 | p = null; |
||
1315 | if (this._isIE6) { |
||
1316 | var pId = "polygon_"+parentId+"_ie6cover"; |
||
1317 | if (this.idPull[pId] != null) { |
||
1318 | document.body.removeChild(this.idPull[pId]); |
||
1319 | this.idPull[pId] = null; |
||
1320 | delete this.idPull[pId]; |
||
1321 | } |
||
1322 | } |
||
1323 | this.idPull["polygon_"+parentId] = null; |
||
1324 | delete this.idPull["polygon_"+parentId]; |
||
1325 | this._updateItemComplexState(parentId, false, false); |
||
1326 | } |
||
1327 | } |
||
1328 | */ |
||
1329 | } |
||
1330 | /* collect parents for remove complex item */ |
||
1331 | View Code Duplication | dhtmlXMenuObject.prototype._getAllParents = function(id) { |
|
1332 | var parents = new Array(); |
||
1333 | for (var a in this.itemPull) { |
||
1334 | if (this.itemPull[a]["parent"] == id) { |
||
1335 | parents[parents.length] = this.itemPull[a]["id"]; |
||
1336 | if (this.itemPull[a]["complex"]) { |
||
1337 | var t = this._getAllParents(this.itemPull[a]["id"]); |
||
1338 | for (var q=0; q<t.length; q++) { parents[parents.length] = t[q]; } |
||
1339 | } |
||
1340 | } |
||
1341 | } |
||
1342 | return parents; |
||
1343 | } |
||
1344 | |||
1345 | //#menu_context:06062008{ |
||
1346 | |||
1347 | /****************************************************************************************************************************************************/ |
||
1348 | /* CONTEXT STUFF */ |
||
1349 | /* render dhtmlxMenu as context menu of base object */ |
||
1350 | /** |
||
1351 | * @desc: renders menu as contextual |
||
1352 | * @type: public |
||
1353 | */ |
||
1354 | dhtmlXMenuObject.prototype.renderAsContextMenu = function() { |
||
1355 | this.context = true; |
||
1356 | if (this.base._autoSkinUpdate == true) { |
||
1357 | this.base.className = this.base.className.replace("dhtmlxMenu_"+this.skin+"_Middle",""); |
||
1358 | this.base._autoSkinUpdate = false; |
||
1359 | } |
||
1360 | if (this.addBaseIdAsContextZone != null) { this.addContextZone(this.addBaseIdAsContextZone); } |
||
1361 | } |
||
1362 | /** |
||
1363 | * @desc: adds a contextual zone to a contextual menu |
||
1364 | * @param: zoneId - id of the object on page to render as a contextual zone |
||
1365 | * @type: public |
||
1366 | */ |
||
1367 | View Code Duplication | dhtmlXMenuObject.prototype.addContextZone = function(zoneId) { |
|
1368 | if (zoneId == document.body) { |
||
1369 | zoneId = "document.body."+this.idPrefix; |
||
1370 | var zone = document.body; |
||
1371 | } else { |
||
1372 | var zone = document.getElementById(zoneId); |
||
1373 | } |
||
1374 | var zoneExists = false; |
||
1375 | for (var a in this.contextZones) { zoneExists = zoneExists || (a == zoneId) || (this.contextZones[a] == zone); } |
||
1376 | if (zoneExists == true) return false; |
||
1377 | this.contextZones[zoneId] = zone; |
||
1378 | var main_self = this; |
||
1379 | if (_isOpera) { |
||
1380 | this.operaContext = function(e){ main_self._doOnContextMenuOpera(e, main_self); } |
||
1381 | zone.addEventListener("mouseup", this.operaContext, false); |
||
1382 | // |
||
1383 | } else { |
||
1384 | if (zone.oncontextmenu != null && !zone._oldContextMenuHandler) zone._oldContextMenuHandler = zone.oncontextmenu; |
||
1385 | zone.oncontextmenu = function(e) { |
||
1386 | // autoclose any other opened context menues |
||
1387 | for (var q in dhtmlxMenuObjectLiveInstances) { |
||
1388 | if (q != main_self._UID) { |
||
1389 | if (dhtmlxMenuObjectLiveInstances[q].context) { |
||
1390 | dhtmlxMenuObjectLiveInstances[q]._hideContextMenu(); |
||
1391 | } |
||
1392 | } |
||
1393 | } |
||
1394 | // |
||
1395 | e = e||event; |
||
1396 | e.cancelBubble = true; |
||
1397 | e.returnValue = false; |
||
1398 | main_self._doOnContextBeforeCall(e, this); |
||
1399 | return false; |
||
1400 | } |
||
1401 | } |
||
1402 | } |
||
1403 | dhtmlXMenuObject.prototype._doOnContextMenuOpera = function(e, main_self) { |
||
1404 | // autoclose any other opened context menues |
||
1405 | for (var q in dhtmlxMenuObjectLiveInstances) { |
||
1406 | if (q != main_self._UID) { |
||
1407 | if (dhtmlxMenuObjectLiveInstances[q].context) { |
||
1408 | dhtmlxMenuObjectLiveInstances[q]._hideContextMenu(); |
||
1409 | } |
||
1410 | } |
||
1411 | } |
||
1412 | // |
||
1413 | e.cancelBubble = true; |
||
1414 | e.returnValue = false; |
||
1415 | if (e.button == 0 && e.ctrlKey == true) { main_self._doOnContextBeforeCall(e, this); } |
||
1416 | return false; |
||
1417 | } |
||
1418 | /** |
||
1419 | * @desc: removes an object from contextual zones list |
||
1420 | * @param: zoneId - id of a contextual zone |
||
1421 | * @type: public |
||
1422 | */ |
||
1423 | View Code Duplication | dhtmlXMenuObject.prototype.removeContextZone = function(zoneId) { |
|
1424 | if (!this.isContextZone(zoneId)) return false; |
||
1425 | if (zoneId == document.body) zoneId = "document.body."+this.idPrefix; |
||
1426 | var zone = this.contextZones[zoneId]; |
||
1427 | if (_isOpera) { |
||
1428 | zone.removeEventListener("mouseup", this.operaContext, false); |
||
1429 | } else { |
||
1430 | zone.oncontextmenu = (zone._oldContextMenuHandler!=null?zone._oldContextMenuHandler:null); |
||
1431 | zone._oldContextMenuHandler = null; |
||
1432 | } |
||
1433 | try { |
||
1434 | this.contextZones[zoneId] = null; |
||
1435 | delete this.contextZones[zoneId]; |
||
1436 | } catch(e){} |
||
1437 | return true; |
||
1438 | } |
||
1439 | /** |
||
1440 | * @desc: returns true if an object is used as a contextual zone for the menu |
||
1441 | * @param: zoneId - id of the object to check |
||
1442 | * @type: public |
||
1443 | */ |
||
1444 | dhtmlXMenuObject.prototype.isContextZone = function(zoneId) { |
||
1445 | if (zoneId == document.body && this.contextZones["document.body."+this.idPrefix] != null) return true; |
||
1446 | var isZone = false; |
||
1447 | if (this.contextZones[zoneId] != null) { if (this.contextZones[zoneId] == document.getElementById(zoneId)) isZone = true; } |
||
1448 | return isZone; |
||
1449 | } |
||
1450 | dhtmlXMenuObject.prototype._isContextMenuVisible = function() { |
||
1451 | if (this.idPull["polygon_"+this.idPrefix+this.topId] == null) return false; |
||
1452 | return (this.idPull["polygon_"+this.idPrefix+this.topId].style.display == ""); |
||
1453 | } |
||
1454 | dhtmlXMenuObject.prototype._showContextMenu = function(x, y, zoneId) { |
||
1455 | // hide any opened context menu/polygons |
||
1456 | this._clearAndHide(); |
||
1457 | // this._hideContextMenu(); |
||
1458 | // open |
||
1459 | if (this.idPull["polygon_"+this.idPrefix+this.topId] == null) return false; |
||
1460 | window.clearTimeout(this.menuTimeoutHandler); |
||
1461 | this.idPull[this.idPrefix+this.topId] = new Array(x, y); |
||
1462 | this._showPolygon(this.idPrefix+this.topId, "bottom"); |
||
1463 | this.callEvent("onContextMenu", [zoneId]); |
||
1464 | } |
||
1465 | dhtmlXMenuObject.prototype._hideContextMenu = function() { |
||
1466 | if (this.idPull["polygon_"+this.idPrefix+this.topId] == null) return false; |
||
1467 | this._clearAndHide(); |
||
1468 | this._hidePolygon(this.idPrefix+this.topId); |
||
1469 | this.zInd = this.zIndInit; |
||
1470 | } |
||
1471 | /****************************************************************************************************************************************************/ |
||
1472 | View Code Duplication | dhtmlXMenuObject.prototype._doOnContextBeforeCall = function(e, cZone) { |
|
1473 | this.contextMenuZoneId = cZone.id; |
||
1474 | this._clearAndHide(); |
||
1475 | this._hideContextMenu(); |
||
1476 | |||
1477 | // scroll settings |
||
1478 | var p = (e.srcElement||e.target); |
||
1479 | var px = (_isIE||_isOpera||_KHTMLrv?e.offsetX:e.layerX); |
||
1480 | var py = (_isIE||_isOpera||_KHTMLrv?e.offsetY:e.layerY); |
||
1481 | var mx = getAbsoluteLeft(p)+px; |
||
1482 | var my = getAbsoluteTop(p)+py; |
||
1483 | |||
1484 | if (this.checkEvent("onBeforeContextMenu")) { |
||
1485 | if (this.callEvent("onBeforeContextMenu", [cZone.id])) { |
||
1486 | if (this.contextAutoShow) { |
||
1487 | this._showContextMenu(mx, my); |
||
1488 | this.callEvent("onAfterContextMenu", [cZone.id]); |
||
1489 | } |
||
1490 | } |
||
1491 | } else { |
||
1492 | if (this.contextAutoShow) { |
||
1493 | this._showContextMenu(mx, my); |
||
1494 | this.callEvent("onAfterContextMenu", [cZone.id]); |
||
1495 | } |
||
1496 | } |
||
1497 | } |
||
1498 | /* public: user call for show/hide context menu */ |
||
1499 | /** |
||
1500 | * @desc: usercall to show a contextual menu |
||
1501 | * @param: x - position of the menu on x axis |
||
1502 | * @param: y - position of the menu on y axis |
||
1503 | * @type: public |
||
1504 | */ |
||
1505 | dhtmlXMenuObject.prototype.showContextMenu = function(x, y) { |
||
1506 | this._showContextMenu(x, y, false); |
||
1507 | } |
||
1508 | /** |
||
1509 | * @desc: usercall to hide a contextual menu |
||
1510 | * @type: public |
||
1511 | */ |
||
1512 | dhtmlXMenuObject.prototype.hideContextMenu = function() { |
||
1513 | this._hideContextMenu(); |
||
1514 | } |
||
1515 | dhtmlXMenuObject.prototype._autoDetectVisibleArea = function() { |
||
1516 | if (this._isVisibleArea) return; |
||
1517 | // |
||
1518 | this.menuX1 = document.body.scrollLeft; |
||
1519 | this.menuX2 = this.menuX1+(window.innerWidth||document.body.clientWidth); |
||
1520 | this.menuY1 = Math.max((_isIE?document.documentElement:document.getElementsByTagName("html")[0]).scrollTop, document.body.scrollTop); |
||
1521 | // this.menuY2 = this.menuY1+(_isIE?(document.documentElement?Math.max(document.documentElement.clientHeight:document.body.clientHeight):window.innerHeight); |
||
1522 | this.menuY2 = this.menuY1+(_isIE?Math.max(document.documentElement.clientHeight||0,document.documentElement.offsetHeight||0,document.body.clientHeight||0):window.innerHeight); |
||
1523 | |||
1524 | } |
||
1525 | /* inner - returns true if prognozided polygon layout off the visible area */ |
||
1526 | /*dhtmlXMenuObject.prototype._isInVisibleArea = function(x, y, w, h) { |
||
1527 | return ((x >= this.menuX1) && (x+w<=this.menuX2) && (y >= this.menuY1) && (y+h <= this.menuY2)); |
||
1528 | }*/ |
||
1529 | |||
1530 | |||
1531 | //#} |
||
1532 | |||
1533 | /** |
||
1534 | * @desc: returns item's position in the current polygon |
||
1535 | * @param: id - the item |
||
1536 | * @type: public |
||
1537 | */ |
||
1538 | View Code Duplication | dhtmlXMenuObject.prototype.getItemPosition = function(id) { |
|
1539 | id = this.idPrefix+id; |
||
1540 | var pos = -1; |
||
1541 | if (this.itemPull[id] == null) return pos; |
||
1542 | var parent = this.itemPull[id]["parent"]; |
||
1543 | // var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.base); |
||
1544 | var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.cont); |
||
1545 | for (var q=0; q<obj.childNodes.length; q++) { if (obj.childNodes[q]==this.idPull["separator_"+id]||obj.childNodes[q]==this.idPull[id]) { pos = q; } } |
||
1546 | return pos; |
||
1547 | } |
||
1548 | |||
1549 | /** |
||
1550 | * @desc: sets new item's position in the current polygon (moves an item inside the single level) |
||
1551 | * @param: id - the item |
||
1552 | * @param: pos - the position (int) |
||
1553 | * @type: public |
||
1554 | */ |
||
1555 | View Code Duplication | dhtmlXMenuObject.prototype.setItemPosition = function(id, pos) { |
|
1556 | id = this.idPrefix+id; |
||
1557 | if (this.idPull[id] == null) { return; } |
||
1558 | // added in 0.4 |
||
1559 | var isOnTopLevel = (this.itemPull[id]["parent"] == this.idPrefix+this.topId); |
||
1560 | // |
||
1561 | var itemData = this.idPull[id]; |
||
1562 | var itemPos = this.getItemPosition(id.replace(this.idPrefix,"")); |
||
1563 | var parent = this.itemPull[id]["parent"]; |
||
1564 | // var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.base); |
||
1565 | var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.cont); |
||
1566 | obj.removeChild(obj.childNodes[itemPos]); |
||
1567 | if (pos < 0) pos = 0; |
||
1568 | // added in 0.4 |
||
1569 | if (isOnTopLevel && pos < 1) { pos = 1; } |
||
1570 | // |
||
1571 | if (pos < obj.childNodes.length) { obj.insertBefore(itemData, obj.childNodes[pos]); } else { obj.appendChild(itemData); } |
||
1572 | } |
||
1573 | |||
1574 | /** |
||
1575 | * @desc: returns parent's id |
||
1576 | * @param: id - the item |
||
1577 | * @type: public |
||
1578 | */ |
||
1579 | dhtmlXMenuObject.prototype.getParentId = function(id) { |
||
1580 | id = this.idPrefix+id; |
||
1581 | if (this.itemPull[id] == null) { return null; } |
||
1582 | return ((this.itemPull[id]["parent"]!=null?this.itemPull[id]["parent"]:this.topId).replace(this.idPrefix,"")); |
||
1583 | } |
||
1584 | /* public: add item */ |
||
1585 | |||
1586 | /** |
||
1587 | * @desc: adds a new sibling item |
||
1588 | * @param: nextToId - id of the element after which a new one will be inserted |
||
1589 | * @param: itemId - id of a new item |
||
1590 | * @param: itemText - text of a new item |
||
1591 | * @param: disabled - true|false, whether the item is disabled or not |
||
1592 | * @param: img - image for the enabled item |
||
1593 | * @param: imgDis - image for the disabled item |
||
1594 | * @type: public |
||
1595 | */ |
||
1596 | dhtmlXMenuObject.prototype.addNewSibling = function(nextToId, itemId, itemText, disabled, imgEnabled, imgDisabled) { |
||
1597 | var id = this.idPrefix+(itemId!=null?itemId:this._genStr(24)); |
||
1598 | var parentId = this.idPrefix+(nextToId!=null?this.getParentId(nextToId):this.topId); |
||
1599 | // console.log(id, parentId) |
||
1600 | // console.log(id, ",", parentId) |
||
1601 | this._addItemIntoGlobalStrorage(id, parentId, itemText, "item", disabled, imgEnabled, imgDisabled); |
||
1602 | if ((parentId == this.idPrefix+this.topId) && (!this.context)) { |
||
1603 | this._renderToplevelItem(id, this.getItemPosition(nextToId)); |
||
1604 | } else { |
||
1605 | this._renderSublevelItem(id, this.getItemPosition(nextToId)); |
||
1606 | } |
||
1607 | } |
||
1608 | |||
1609 | /** |
||
1610 | * @desc: adds a new child item |
||
1611 | * @param: parentId - the item which will contain a new item in the sublevel |
||
1612 | * @param: position - the position of a new item |
||
1613 | * @param: itemId - id of a new item |
||
1614 | * @param: itemText - text of a new item |
||
1615 | * @param: disabled - true|false, whether the item is disabled or not |
||
1616 | * @param: img - image for the enabled item |
||
1617 | * @param: imgDis - image for the disabled item |
||
1618 | * @type: public |
||
1619 | */ |
||
1620 | View Code Duplication | dhtmlXMenuObject.prototype.addNewChild = function(parentId, pos, itemId, itemText, disabled, imgEnabled, imgDisabled) { |
|
1621 | if (parentId == null) { |
||
1622 | if (this.context) { |
||
1623 | parentId = this.topId; |
||
1624 | } else { |
||
1625 | this.addNewSibling(parentId, itemId, itemText, disabled, imgEnabled, imgDisabled); |
||
1626 | if (pos != null) this.setItemPosition(itemId, pos); |
||
1627 | return; |
||
1628 | } |
||
1629 | } |
||
1630 | itemId = this.idPrefix+(itemId!=null?itemId:this._genStr(24)); |
||
1631 | // remove hotkey, added in 0.4 |
||
1632 | if (this.setHotKey) this.setHotKey(parentId, ""); |
||
1633 | // |
||
1634 | parentId = this.idPrefix+parentId; |
||
1635 | this._addItemIntoGlobalStrorage(itemId, parentId, itemText, "item", disabled, imgEnabled, imgDisabled); |
||
1636 | if (this.idPull["polygon_"+parentId] == null) { this._renderSublevelPolygon(parentId, parentId); } |
||
1637 | this._renderSublevelItem(itemId, pos-1); |
||
1638 | // console.log(parentId) |
||
1639 | this._redefineComplexState(parentId); |
||
1640 | } |
||
1641 | |||
1642 | /* add item to storage */ |
||
1643 | View Code Duplication | dhtmlXMenuObject.prototype._addItemIntoGlobalStrorage = function(itemId, itemParentId, itemText, itemType, disabled, img, imgDis) { |
|
1644 | var item = { |
||
1645 | id: itemId, |
||
1646 | title: itemText, |
||
1647 | imgen: (img!=null?img:""), |
||
1648 | imgdis: (imgDis!=null?imgDis:""), |
||
1649 | type: itemType, |
||
1650 | state: (disabled==true?"disabled":"enabled"), |
||
1651 | parent: itemParentId, |
||
1652 | complex:false, |
||
1653 | hotkey: "", |
||
1654 | tip: ""}; |
||
1655 | this.itemPull[item.id] = item; |
||
1656 | } |
||
1657 | /* recursively creates and adds submenu polygon */ |
||
1658 | View Code Duplication | dhtmlXMenuObject.prototype._addSubMenuPolygon = function(id, parentId) { |
|
1659 | var s = this._renderSublevelPolygon(id, parentId); |
||
1660 | var j = this._getMenuNodes(parentId); |
||
1661 | for (q=0; q<j.length; q++) { if (this.itemPull[j[q]]["type"] == "separator") { this._renderSeparator(j[q], null); } else { this._renderSublevelItem(j[q], null); } } |
||
1662 | if (id == parentId) { var level = "topLevel"; } else { var level = "subLevel"; } |
||
1663 | for (var q=0; q<j.length; q++) { if (this.itemPull[j[q]]["complex"]) { this._addSubMenuPolygon(id, this.itemPull[j[q]]["id"]); } } |
||
1664 | } |
||
1665 | /* inner: add single subpolygon/item/separator */ |
||
1666 | View Code Duplication | dhtmlXMenuObject.prototype._renderSublevelPolygon = function(id, parentId) { |
|
1667 | var s = document.createElement("DIV"); |
||
1668 | s.className = "dhtmlxMenu_"+this.skin+"_SubLevelArea_Polygon "+(this._rtl?"dir_right":""); |
||
1669 | s.dir = "ltr"; |
||
1670 | s.oncontextmenu = function(e) { e = e||event; e.returnValue = false; e.cancelBubble = true; return false; } |
||
1671 | s.id = "polygon_" + parentId; |
||
1672 | s.onclick = function(e) { e = e || event; e.cancelBubble = true; } |
||
1673 | s.style.display = "none"; |
||
1674 | document.body.insertBefore(s, document.body.firstChild); |
||
1675 | // |
||
1676 | var tbl = document.createElement("TABLE"); |
||
1677 | tbl.className = "dhtmlxMebu_SubLevelArea_Tbl"; |
||
1678 | tbl.cellSpacing = 0; |
||
1679 | tbl.cellPadding = 0; |
||
1680 | tbl.border = 0; |
||
1681 | var tbd = document.createElement("TBODY"); |
||
1682 | tbl.appendChild(tbd); |
||
1683 | s.appendChild(tbl); |
||
1684 | s.tbl = tbl; |
||
1685 | s.tbd = tbd; |
||
1686 | // polygon |
||
1687 | this.idPull[s.id] = s; |
||
1688 | if (this.sxDacProc != null) { |
||
1689 | this.idPull["sxDac_" + parentId] = new this.sxDacProc(s, s.className); |
||
1690 | if (_isIE) { |
||
1691 | this.idPull["sxDac_" + parentId]._setSpeed(this.dacSpeedIE); |
||
1692 | this.idPull["sxDac_" + parentId]._setCustomCycle(this.dacCyclesIE); |
||
1693 | } else { |
||
1694 | this.idPull["sxDac_" + parentId]._setSpeed(this.dacSpeed); |
||
1695 | this.idPull["sxDac_" + parentId]._setCustomCycle(this.dacCycles); |
||
1696 | } |
||
1697 | } |
||
1698 | return s; |
||
1699 | } |
||
1700 | View Code Duplication | dhtmlXMenuObject.prototype._renderSublevelItem = function(id, pos) { |
|
1701 | var main_self = this; |
||
1702 | |||
1703 | var tr = document.createElement("TR"); |
||
1704 | tr.className = (this.itemPull[id]["state"]=="enabled"?"sub_item":"sub_item_dis"); |
||
1705 | |||
1706 | // icon |
||
1707 | var t1 = document.createElement("TD"); |
||
1708 | t1.className = "sub_item_icon"; |
||
1709 | var icon = this.itemPull[id][(this.itemPull[id]["state"]=="enabled"?"imgen":"imgdis")]; |
||
1710 | if (icon != "") { |
||
1711 | var tp = this.itemPull[id]["type"]; |
||
1712 | if (tp=="checkbox"||tp=="radio") { |
||
1713 | var img = document.createElement("DIV"); |
||
1714 | img.id = "image_"+this.itemPull[id]["id"]; |
||
1715 | img.className = "sub_icon "+icon; |
||
1716 | t1.appendChild(img); |
||
1717 | } |
||
1718 | if (!(tp=="checkbox"||tp=="radio")) { |
||
1719 | var img = document.createElement("IMG"); |
||
1720 | img.id = "image_"+this.itemPull[id]["id"]; |
||
1721 | img.className = "sub_icon"; |
||
1722 | img.src = this.imagePath+icon; |
||
1723 | t1.appendChild(img); |
||
1724 | } |
||
1725 | } |
||
1726 | |||
1727 | // text |
||
1728 | var t2 = document.createElement("TD"); |
||
1729 | t2.className = "sub_item_text"; |
||
1730 | if (this.itemPull[id]["title"] != "") { |
||
1731 | var t2t = document.createElement("DIV"); |
||
1732 | t2t.className = "sub_item_text"; |
||
1733 | t2t.innerHTML = this.itemPull[id]["title"]; |
||
1734 | t2.appendChild(t2t); |
||
1735 | } else { |
||
1736 | t2.innerHTML = " "; |
||
1737 | } |
||
1738 | |||
1739 | // hotkey/sublevel arrow |
||
1740 | var t3 = document.createElement("TD"); |
||
1741 | t3.className = "sub_item_hk"; |
||
1742 | if (this.itemPull[id]["complex"]) { |
||
1743 | |||
1744 | var arw = document.createElement("DIV"); |
||
1745 | arw.className = "complex_arrow"; |
||
1746 | arw.id = "arrow_"+this.itemPull[id]["id"]; |
||
1747 | t3.appendChild(arw); |
||
1748 | |||
1749 | } else { |
||
1750 | if (this.itemPull[id]["hotkey"].length > 0 && !this.itemPull[id]["complex"]) { |
||
1751 | var t3t = document.createElement("DIV"); |
||
1752 | t3t.className = "sub_item_hk"; |
||
1753 | t3t.innerHTML = this.itemPull[id]["hotkey"]; |
||
1754 | t3.appendChild(t3t); |
||
1755 | } else { |
||
1756 | t3.innerHTML = " "; |
||
1757 | } |
||
1758 | } |
||
1759 | tr.appendChild(this._rtl?t3:t1); |
||
1760 | tr.appendChild(t2); |
||
1761 | tr.appendChild(this._rtl?t1:t3); |
||
1762 | |||
1763 | |||
1764 | // |
||
1765 | tr.id = this.itemPull[id]["id"]; |
||
1766 | tr.parent = this.itemPull[id]["parent"]; |
||
1767 | // tooltip, added in 0.4 |
||
1768 | if (this.itemPull[id]["tip"].length > 0) tr.title = this.itemPull[id]["tip"]; |
||
1769 | // |
||
1770 | tr.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; } |
||
1771 | tr.onmouseover = function() { |
||
1772 | if (main_self.menuMode == "web") window.clearTimeout(main_self.menuTimeoutHandler); |
||
1773 | main_self._redistribSubLevelSelection(this.id, this.parent); |
||
1774 | } |
||
1775 | if (main_self.menuMode == "web") { |
||
1776 | tr.onmouseout = function() { |
||
1777 | window.clearTimeout(main_self.menuTimeoutHandler); |
||
1778 | main_self.menuTimeoutHandler = window.setTimeout(function(){main_self._clearAndHide();}, main_self.menuTimeoutMsec, "JavaScript"); |
||
1779 | } |
||
1780 | } |
||
1781 | tr.onclick = function(e) { |
||
1782 | // added in 0.4, preven complex closing if user event not defined |
||
1783 | if (!main_self.checkEvent("onClick") && main_self.itemPull[this.id]["complex"]) return; |
||
1784 | // |
||
1785 | e = e || event; e.cancelBubble = true; |
||
1786 | e.returnValue = false; |
||
1787 | tc = (main_self.itemPull[this.id]["complex"]?"c":"-"); |
||
1788 | td = (main_self.itemPull[this.id]["state"]=="enabled"?"-":"d"); |
||
1789 | var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey}; |
||
1790 | switch (main_self.itemPull[this.id]["type"]) { |
||
1791 | case "checkbox": |
||
1792 | main_self._checkboxOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas); |
||
1793 | break; |
||
1794 | case "radio": |
||
1795 | main_self._radioOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas); |
||
1796 | break; |
||
1797 | case "item": |
||
1798 | main_self._doOnClick(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas); |
||
1799 | break; |
||
1800 | } |
||
1801 | return false; |
||
1802 | } |
||
1803 | // add |
||
1804 | var polygon = this.idPull["polygon_"+this.itemPull[id]["parent"]]; |
||
1805 | if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > polygon.tbd.childNodes.length - 1) pos = null; } |
||
1806 | if (pos != null && polygon.tbd.childNodes[pos] != null) polygon.tbd.insertBefore(tr, polygon.tbd.childNodes[pos]); else polygon.tbd.appendChild(tr); |
||
1807 | this.idPull[tr.id] = tr; |
||
1808 | } |
||
1809 | /****************************************************************************************************************************************************/ |
||
1810 | /* SEPARATOR */ |
||
1811 | View Code Duplication | dhtmlXMenuObject.prototype._renderSeparator = function(id, pos) { |
|
1812 | var level = (this.context?"SubLevelArea":(this.itemPull[id]["parent"]==this.idPrefix+this.topId?"TopLevel":"SubLevelArea")); |
||
1813 | if (level == "TopLevel" && this.context) return; |
||
1814 | |||
1815 | var main_self = this; |
||
1816 | |||
1817 | if (level != "TopLevel") { |
||
1818 | var tr = document.createElement("TR"); |
||
1819 | tr.className = "sub_sep"; |
||
1820 | var td = document.createElement("TD"); |
||
1821 | td.colSpan = "3"; |
||
1822 | tr.appendChild(td); |
||
1823 | } |
||
1824 | |||
1825 | var k = document.createElement("DIV"); |
||
1826 | k.id = "separator_"+id; |
||
1827 | k.className = (level=="TopLevel"?"top_sep":"sub_sep"); |
||
1828 | k.onselectstart = function(e) { e = e || event; e.returnValue = false; } |
||
1829 | k.onclick = function(e) { |
||
1830 | e = e || event; e.cancelBubble = true; |
||
1831 | var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey}; |
||
1832 | main_self._doOnClick(this.id.replace("separator_" + main_self.idPrefix, ""), "--s", cas); |
||
1833 | } |
||
1834 | if (level == "TopLevel") { |
||
1835 | if (pos != null) { |
||
1836 | pos++; if (pos < 0) { pos = 0; } |
||
1837 | // if (this.base.childNodes[pos] != null) { this.base.insertBefore(k, this.base.childNodes[pos]); } else { this.base.appendChild(k); } |
||
1838 | if (this.cont.childNodes[pos] != null) { this.cont.insertBefore(k, this.cont.childNodes[pos]); } else { this.cont.appendChild(k); } |
||
1839 | } else { |
||
1840 | // add as a last item |
||
1841 | // var last = this.base.childNodes[this.base.childNodes.length-1]; |
||
1842 | var last = this.cont.childNodes[this.cont.childNodes.length-1]; |
||
1843 | // if (String(last).search("TopLevel_Text") == -1) { this.base.appendChild(k); } else { this.base.insertBefore(k, last); } |
||
1844 | if (String(last).search("TopLevel_Text") == -1) { this.cont.appendChild(k); } else { this.cont.insertBefore(k, last); } |
||
1845 | } |
||
1846 | this.idPull[k.id] = k; |
||
1847 | } else { |
||
1848 | var polygon = this.idPull["polygon_"+this.itemPull[id]["parent"]]; |
||
1849 | if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > polygon.tbd.childNodes.length - 1) pos = null; } |
||
1850 | if (pos != null && polygon.tbd.childNodes[pos] != null) polygon.tbd.insertBefore(tr, polygon.tbd.childNodes[pos]); else polygon.tbd.appendChild(tr); |
||
1851 | td.appendChild(k); |
||
1852 | this.idPull[k.id] = tr; |
||
1853 | } |
||
1854 | } |
||
1855 | /** |
||
1856 | * @desc: add a new separator |
||
1857 | * @param: nextToId - id of the element after which a new separator will be inserted |
||
1858 | * @param: itemId - id of a new separator |
||
1859 | * @type: public |
||
1860 | */ |
||
1861 | dhtmlXMenuObject.prototype.addNewSeparator = function(nextToId, itemId) { //, disabled) { |
||
1862 | itemId = this.idPrefix+(itemId!=null?itemId:this._genStr(24)); |
||
1863 | var parentId = this.idPrefix+this.getParentId(nextToId); |
||
1864 | // if ((parentId == this.idPrefix+this.topId) && (!this.context)) { return; } |
||
1865 | // this._addItemIntoGlobalStrorage(itemId, parentId, "", "item", disabled, "", ""); |
||
1866 | // this._addItemIntoGlobalStrorage(itemId, parentId, "", "item", false, "", ""); |
||
1867 | this._addItemIntoGlobalStrorage(itemId, parentId, "", "separator", false, "", ""); |
||
1868 | this._renderSeparator(itemId, this.getItemPosition(nextToId)); |
||
1869 | } |
||
1870 | /****************************************************************************************************************************************************/ |
||
1871 | // hide any opened polygons |
||
1872 | /** |
||
1873 | * @desc: hides any open menu polygons |
||
1874 | * @type: public |
||
1875 | */ |
||
1876 | dhtmlXMenuObject.prototype.hide = function() { |
||
1877 | this._clearAndHide(); |
||
1878 | } |
||
1879 | /** |
||
1880 | * @desc: clear all loaded items |
||
1881 | * @type: public |
||
1882 | */ |
||
1883 | dhtmlXMenuObject.prototype.clearAll = function() { |
||
1884 | /* |
||
1885 | for (var a in this.itemPull) { |
||
1886 | if (this.itemPull[a]["parent"] == this.idPrefix+this.topId) { |
||
1887 | this.removeItem(String(a).replace(this.idPrefix,"")); |
||
1888 | } |
||
1889 | } |
||
1890 | */ |
||
1891 | this.removeItem(this.idPrefix+this.topId, true); |
||
1892 | this._isInited = false; |
||
1893 | this.idPrefix = this._genStr(12); |
||
1894 | } |
||
1895 | /****************************************************************************************************************************************************/ |
||
1896 | /** |
||
1897 | * @desc: unloads menu from page (destructor) |
||
1898 | * @type: public |
||
1899 | */ |
||
1900 | View Code Duplication | dhtmlXMenuObject.prototype.unload = function() { |
|
1901 | |||
1902 | if (_isIE) { |
||
1903 | document.body.detachEvent("onclick", this._bodyClick); |
||
1904 | document.body.detachEvent("oncontextmenu", this._bodyContext); |
||
1905 | } else { |
||
1906 | window.removeEventListener("click", this._bodyClick, false); |
||
1907 | window.removeEventListener("contextmenu", this._bodyContext, false); |
||
1908 | } |
||
1909 | this._bodyClick = null; |
||
1910 | this._bodyContext = null; |
||
1911 | |||
1912 | // will recursively remove all items |
||
1913 | this.removeItem(this.idPrefix+this.topId, true); |
||
1914 | |||
1915 | this.itemPull = null; |
||
1916 | this.idPull = null; |
||
1917 | |||
1918 | // clear context zones |
||
1919 | if (this.context) for (var a in this.contextZones) this.removeContextZone(a); |
||
1920 | |||
1921 | if (this.cont != null) { |
||
1922 | this.cont.className = ""; |
||
1923 | this.cont.parentNode.removeChild(this.cont); |
||
1924 | this.cont = null; |
||
1925 | } |
||
1926 | |||
1927 | if (this.base != null) { |
||
1928 | this.base.className = ""; |
||
1929 | if (!this.context) this.base.oncontextmenu = (this.base._oldContextMenuHandler||null); |
||
1930 | this.base.onselectstart = null; |
||
1931 | this.base = null; |
||
1932 | } |
||
1933 | this.setSkin = null; |
||
1934 | |||
1935 | this.detachAllEvents(); |
||
1936 | |||
1937 | if (this._xmlLoader) { |
||
1938 | this._xmlLoader.destructor(); |
||
1939 | this._xmlLoader = null; |
||
1940 | } |
||
1941 | |||
1942 | this._align = null; |
||
1943 | this._arrowFFFix = null; |
||
1944 | this._isIE6 = null; |
||
1945 | this._isInited = null; |
||
1946 | this._rtl = null; |
||
1947 | this._scrollDownTMStep = null; |
||
1948 | this._scrollDownTMTime = null; |
||
1949 | this._scrollUpTMStep = null; |
||
1950 | this._scrollUpTMTime = null; |
||
1951 | this._topLevelBottomMargin = null; |
||
1952 | this._topLevelOffsetLeft = null; |
||
1953 | this._topLevelBottomMargin = null; |
||
1954 | this._topLevelRightMargin = null; |
||
1955 | this.addBaseIdAsContextZone = null; |
||
1956 | this.context = null; |
||
1957 | this.contextAutoHide = null; |
||
1958 | this.contextAutoShow = null; |
||
1959 | this.contextHideAllMode = null; |
||
1960 | this.contextMenuZoneId = null; |
||
1961 | this.dLoad = null; |
||
1962 | this.dLoadSign = null; |
||
1963 | this.dLoadUrl = null; |
||
1964 | this.loaderIcon = null; |
||
1965 | this.fixedPosition = null; |
||
1966 | this.dirSubLevel = null; |
||
1967 | this.dirTopLevel = null; |
||
1968 | this.limit = null; |
||
1969 | this.menuSelected = null; |
||
1970 | this.menuLastClicked = null; |
||
1971 | this.idPrefix = null; |
||
1972 | this.imagePath = null; |
||
1973 | this.menuMode = null; |
||
1974 | this.menuModeTopLevelTimeout = null; |
||
1975 | this.menuModeTopLevelTimeoutTime = null; |
||
1976 | this.menuTimeoutHandler = null; |
||
1977 | this.menuTimeoutMsec = null; |
||
1978 | this.menuTouched = null; |
||
1979 | this.isDhtmlxMenuObject = null; |
||
1980 | this.itemHotKeyTagName = null; |
||
1981 | this.itemHrefTagName = null; |
||
1982 | this.itemTagName = null; |
||
1983 | this.itemTextTagName = null; |
||
1984 | this.itemTipTagName = null; |
||
1985 | this.userDataTagName = null; |
||
1986 | this.skin = null; |
||
1987 | this.topId = null; |
||
1988 | this.dacCycles = null; |
||
1989 | this.dacCyclesIE = null; |
||
1990 | this.dacSpeed = null; |
||
1991 | this.dacSpeedIE = null; |
||
1992 | this.zInd = null; |
||
1993 | this.zIndInit = null; |
||
1994 | this.zIndStep = null; |
||
1995 | |||
1996 | // |
||
1997 | // unload basic methods |
||
1998 | |||
1999 | this._enableDacSupport = null; |
||
2000 | this._selectedSubItems = null; |
||
2001 | this._openedPolygons = null; |
||
2002 | this._addSubItemToSelected = null; |
||
2003 | this._removeSubItemFromSelected = null; |
||
2004 | this._getSubItemToDeselectByPolygon = null; |
||
2005 | this._hidePolygon = null; |
||
2006 | this._showPolygon = null; |
||
2007 | this._redistribSubLevelSelection = null; |
||
2008 | this._doOnClick = null; |
||
2009 | this._doOnTouchMenu = null; |
||
2010 | this._searchMenuNode = null; |
||
2011 | this._getMenuNodes = null; |
||
2012 | this._genStr = null; |
||
2013 | this._clearAndHide = null; |
||
2014 | this._doOnLoad = null; |
||
2015 | this.getItemType = null; |
||
2016 | this.forEachItem = null; |
||
2017 | this.init = null; |
||
2018 | this.loadXML = null; |
||
2019 | this.loadXMLString = null; |
||
2020 | this._buildMenu = null; |
||
2021 | this._xmlParser = null; |
||
2022 | this._showSubLevelItem = null; |
||
2023 | this._hideSubLevelItem = null; |
||
2024 | this._countVisiblePolygonItems = null; |
||
2025 | this._redefineComplexState = null; |
||
2026 | this._updateItemComplexState = null; |
||
2027 | this._getItemLevelType = null; |
||
2028 | this._redistribTopLevelSelection = null; |
||
2029 | this._initTopLevelMenu = null; |
||
2030 | this._renderToplevelItem = null; |
||
2031 | this.setImagePath = null; |
||
2032 | this.setIconsPath = null; |
||
2033 | this.setIconPath = null; |
||
2034 | this._updateItemImage = null; |
||
2035 | this.removeItem = null; |
||
2036 | this._getAllParents = null; |
||
2037 | this.renderAsContextMenu = null; |
||
2038 | this.addContextZone = null; |
||
2039 | this.removeContextZone = null; |
||
2040 | this.isContextZone = null; |
||
2041 | this._isContextMenuVisible = null; |
||
2042 | this._showContextMenu = null; |
||
2043 | this._doOnContextBeforeCall = null; |
||
2044 | this._autoDetectVisibleArea = null; |
||
2045 | this._addItemIntoGlobalStrorage = null; |
||
2046 | this._addSubMenuPolygon = null; |
||
2047 | this._renderSublevelPolygon = null; |
||
2048 | this._renderSublevelItem = null; |
||
2049 | this._renderSeparator = null; |
||
2050 | this._hideContextMenu = null; |
||
2051 | this.clearAll = null; |
||
2052 | this.getItemPosition = null; |
||
2053 | this.setItemPosition = null; |
||
2054 | this.getParentId = null; |
||
2055 | this.addNewSibling = null; |
||
2056 | this.addNewChild = null; |
||
2057 | this.addNewSeparator = null; |
||
2058 | this.attachEvent = null; |
||
2059 | this.callEvent = null; |
||
2060 | this.checkEvent = null; |
||
2061 | this.eventCatcher = null; |
||
2062 | this.detachEvent = null; |
||
2063 | this.dhx_Event = null; |
||
2064 | this.unload = null; |
||
2065 | this.items = null; |
||
2066 | this.radio = null; |
||
2067 | this.detachAllEvents = null; |
||
2068 | this.hide = null; |
||
2069 | this.showContextMenu = null; |
||
2070 | this.hideContextMenu = null; |
||
2071 | |||
2072 | |||
2073 | // unload extended methods |
||
2074 | this._changeItemState = null; |
||
2075 | this._changeItemVisible = null; |
||
2076 | this._updateLoaderIcon = null; |
||
2077 | this._clearAllSelectedSubItemsInPolygon = null; |
||
2078 | this._checkArrowsState = null; |
||
2079 | this._addUpArrow = null; |
||
2080 | this._addDownArrow = null; |
||
2081 | this._removeUpArrow = null; |
||
2082 | this._removeDownArrow = null; |
||
2083 | this._isArrowExists = null; |
||
2084 | this._doScrollUp = null; |
||
2085 | this._doScrollDown = null; |
||
2086 | this._countPolygonItems = null; |
||
2087 | this._getRadioImgObj = null; |
||
2088 | this._setRadioState = null; |
||
2089 | this._radioOnClickHandler = null; |
||
2090 | this._getCheckboxState = null; |
||
2091 | this._setCheckboxState = null; |
||
2092 | this._readLevel = null; |
||
2093 | this._updateCheckboxImage = null; |
||
2094 | this._checkboxOnClickHandler = null; |
||
2095 | this._removeArrow = null; |
||
2096 | this.setItemEnabled = null; |
||
2097 | this.setItemDisabled = null; |
||
2098 | this.isItemEnabled = null; |
||
2099 | this.getItemText = null; |
||
2100 | this.setItemText = null; |
||
2101 | this.loadFromHTML = null; |
||
2102 | this.hideItem = null; |
||
2103 | this.showItem = null; |
||
2104 | this.isItemHidden = null; |
||
2105 | this.setUserData = null; |
||
2106 | this.getUserData = null; |
||
2107 | this.setOpenMode = null; |
||
2108 | this.setWebModeTimeout = null; |
||
2109 | this.enableDynamicLoading = null; |
||
2110 | this.getItemImage = null; |
||
2111 | this.setItemImage = null; |
||
2112 | this.clearItemImage = null; |
||
2113 | this.setAutoShowMode = null; |
||
2114 | this.setAutoHideMode = null; |
||
2115 | this.setContextMenuHideAllMode = null; |
||
2116 | this.getContextMenuHideAllMode = null; |
||
2117 | this.setVisibleArea = null; |
||
2118 | this.setTooltip = null; |
||
2119 | this.getTooltip = null; |
||
2120 | this.setHotKey = null; |
||
2121 | this.getHotKey = null; |
||
2122 | this.setItemSelected = null; |
||
2123 | this.setTopText = null; |
||
2124 | this.setRTL = null; |
||
2125 | this.setAlign = null; |
||
2126 | this.setHref = null; |
||
2127 | this.clearHref = null; |
||
2128 | this.getCircuit = null; |
||
2129 | this.contextZones = null; |
||
2130 | this.setOverflowHeight = null; |
||
2131 | this.userData = null; |
||
2132 | this.getRadioChecked = null; |
||
2133 | this.setRadioChecked = null; |
||
2134 | this.addRadioButton = null; |
||
2135 | this.setCheckboxState = null; |
||
2136 | this.getCheckboxState = null; |
||
2137 | this.addCheckbox = null; |
||
2138 | this.serialize = null; |
||
2139 | |||
2140 | |||
2141 | this.extendedModule = null; |
||
2142 | |||
2143 | // remove menu from global store |
||
2144 | dhtmlxMenuObjectLiveInstances[this._UID] = null; |
||
2145 | try { delete dhtmlxMenuObjectLiveInstances[this._UID]; } catch(e) {} |
||
2146 | this._UID = null; |
||
2147 | |||
2148 | } |
||
2149 | // dhtmlxmenu global store |
||
2150 | var dhtmlxMenuObjectLiveInstances = {}; |
||
2151 | |||
2152 | dhtmlXMenuObject.prototype.i18n = { |
||
2153 | dhxmenuextalert: "dhtmlxmenu_ext.js required" |
||
2154 | }; |
||
2155 | |||
2156 | //menu |
||
2157 | View Code Duplication | (function(){ |
|
2158 | dhtmlx.extend_api("dhtmlXMenuObject",{ |
||
2159 | _init:function(obj){ |
||
2160 | return [obj.parent, obj.skin]; |
||
2161 | }, |
||
2162 | align:"setAlign", |
||
2163 | top_text:"setTopText", |
||
2164 | context:"renderAsContextMenu", |
||
2165 | icon_path:"setIconsPath", |
||
2166 | open_mode:"setOpenMode", |
||
2167 | rtl:"setRTL", |
||
2168 | skin:"setSkin", |
||
2169 | dynamic:"enableDynamicLoading", |
||
2170 | xml:"loadXML", |
||
2171 | items:"items", |
||
2172 | overflow:"setOverflowHeight" |
||
2173 | },{ |
||
2174 | items:function(arr,parent){ |
||
2175 | var pos = 100000; |
||
2176 | var lastItemId = null; |
||
2177 | for (var i=0; i < arr.length; i++) { |
||
2178 | var item=arr[i]; |
||
2179 | if (item.type == "separator") { |
||
2180 | this.addNewSeparator(lastItemId, pos, item.id); |
||
2181 | lastItemId = item.id; |
||
2182 | } else { |
||
2183 | this.addNewChild(parent, pos, item.id, item.text, item.disabled, item.img, item.img_disabled); |
||
2184 | lastItemId = item.id; |
||
2185 | if (item.items) this.items(item.items,item.id); |
||
2186 | } |
||
2187 | } |
||
2188 | } |
||
2189 | }); |
||
2190 | })(); |