//v.2.6 build 100722
/*
Copyright DHTMLX LTD. http://www.dhtmlx.com
You allowed to use this component or parts of it under GPL terms
To use it on other terms or get Professional edition of the component please contact us at sales@dhtmlx.com
*/
/**
* @desc: a constructor, creates a new dhtmlxMenu object, baseId defines a base object for the top menu level
* @param: baseId - id of the html element to which a menu will be attached, in case of a contextual menu - if specified, will used as a contextual zone
* @type: public
*/
function dhtmlXMenuObject(baseId, skin) {
var main_self = this;
this.addBaseIdAsContextZone = null;
this.isDhtmlxMenuObject = true;
// skin settings
this.skin = (skin!=null?skin:"dhx_skyblue");
this.imagePath = "";
// iframe
this._isIE6 = false;
if (_isIE) this._isIE6 = (window.XMLHttpRequest==null?true:false);
if (baseId == null) {
this.base = document.body;
} else {
if (document.getElementById(baseId) != null) {
this.base = document.getElementById(baseId);
while (this.base.childNodes.length > 0) { this.base.removeChild(this.base.childNodes[0]); }
this.base.className += " dhtmlxMenu_"+this.skin+"_Middle dir_left";
this.base._autoSkinUpdate = true;
// preserv default oncontextmenu for future restorin in case of context menu
if (this.base.oncontextmenu) this.base._oldContextMenuHandler = this.base.oncontextmenu;
//
this.addBaseIdAsContextZone = baseId;
this.base.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; }
this.base.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; }
} else {
this.base = document.body;
}
}
// this.topId = topId;
this.topId = "dhxWebMenuTopId";
//
if (!this.extendedModule) {
// add notify for menu
var t = function(){alert(this.i18n.dhxmenuextalert);};
var extMethods = new Array("setItemEnabled", "setItemDisabled", "isItemEnabled", "_changeItemState", "getItemText", "setItemText",
"loadFromHTML", "hideItem", "showItem", "isItemHidden", "_changeItemVisible", "setUserData", "getUserData",
"setOpenMode", "setWebModeTimeout", "enableDynamicLoading", "_updateLoaderIcon", "getItemImage", "setItemImage",
"clearItemImage", "setAutoShowMode", "setAutoHideMode", "setContextMenuHideAllMode", "getContextMenuHideAllMode",
"setVisibleArea", "setTooltip", "getTooltip", "setHotKey", "getHotKey", "setItemSelected", "setTopText", "setRTL",
"setAlign", "setHref", "clearHref", "getCircuit", "_clearAllSelectedSubItemsInPolygon", "_checkArrowsState",
"_addUpArrow", "_addDownArrow", "_removeUpArrow", "_removeDownArrow", "_isArrowExists", "_doScrollUp", "_doScrollDown",
"_countPolygonItems", "setOverflowHeight", "_getRadioImgObj", "_setRadioState", "_radioOnClickHandler",
"getRadioChecked", "setRadioChecked", "addRadioButton", "_getCheckboxState", "_setCheckboxState", "_readLevel",
"_updateCheckboxImage", "_checkboxOnClickHandler", "setCheckboxState", "getCheckboxState", "addCheckbox", "serialize");
for (var q=0; q 0 && this.limit < itemCount) {
var auId = "arrowup_"+id;
var adId = "arrowdown_"+id;
// add overflow arrows if they not exists
if (this.idPull["arrowup_"+id] == null) this._addUpArrow(String(id).replace(this.idPrefix,""));
if (this.idPull["arrowdown_"+id] == null) this._addDownArrow(String(id).replace(this.idPrefix,""));
// configure up arrow
arrowUp = this.idPull["arrowup_"+id];
arrowUp.style.visibility = "hidden";
arrowUp.style.display = "";
arrowUp.style.zIndex = this.zInd;
arrUpH = arrowUp.offsetHeight;
// configure bottom arrow
arrowDown = this.idPull["arrowdown_"+id];
arrowDown.style.visibility = "hidden";
arrowDown.style.display = "";
arrowDown.style.zIndex = this.zInd;
arrDownH = arrowDown.offsetHeight;
}
//#}
// show polygon
this.idPull[pId].style.visibility = "hidden";
this.idPull[pId].style.left = "0px";
this.idPull[pId].style.top = "0px";
this.idPull[pId].style.display = "";
this.idPull[pId].style.zIndex = this.zInd;
//
if (this.limit > 0) {
if (this.limit < itemCount) {
// set fixed size
// this.idPull[pId].style.height = this.idPull[pId].tbd.childNodes[0].offsetHeight*this.limit+"px";// + arrUpH + arrDownH;
this.idPull[pId].style.height = 24*this.limit+"px";
this.idPull[pId].scrollTop = 0;
} else {
// remove fixed size
this.idPull[pId].style.height = "";
}
}
//
this.zInd += this.zIndStep;
//
// console.log(this.idPull)
if (this.itemPull[id] != null) {
var parPoly = "polygon_"+this.itemPull[id]["parent"];
} else if (this.context) {
var parPoly = this.idPull[this.idPrefix+this.topId];
}
/*
// debug info
if (parPoly == null) {
alert("Implementation error. Please report support@dhtmlx.com");
}
*/
//
//
// define position
var srcX = (this.idPull[id].tagName != null ? getAbsoluteLeft(this.idPull[id]) : this.idPull[id][0]);
var srcY = (this.idPull[id].tagName != null ? getAbsoluteTop(this.idPull[id]) : this.idPull[id][1]);
var srcW = (this.idPull[id].tagName != null ? this.idPull[id].offsetWidth : 0);
var srcH = (this.idPull[id].tagName != null ? this.idPull[id].offsetHeight + arrUpH + arrDownH : 0);
var x = 0;
var y = 0;
var w = this.idPull[pId].offsetWidth;
var h = this.idPull[pId].offsetHeight;
//console.log(srcY,h,window.innerHeight,document.body.scrollTop)
/*
var bottomOverflow = (srcY+h > window.innerHeight+document.body.scrollTop);
if (bottomOverflow) {
if (openType == "bottom") openType = "top";
if (openType == "right" || openType == "left") {
srcY = srcY-h;
}
}
*/
// pos
if (openType == "bottom") {
if (this._rtl) {
x = srcX + (srcW!=null?srcW:0) - w;
} else {
if (this._align == "right") {
x = srcX + srcW - w;
} else {
x = srcX - 1 + (openType==this.dirTopLevel?this._topLevelRightMargin:0);
}
}
y = srcY - 1 + srcH - arrUpH - arrDownH + this._topLevelBottomMargin;
}
if (openType == "right") { x = srcX + srcW - 1; y = srcY + 2; }
if (openType == "left") { x = srcX - this.idPull[pId].offsetWidth + 2; y = srcY + 2; }
if (openType == "top") { x = srcX - 1; y = srcY - h + 2; }
// overflow check
if (this.fixedPosition) {
// use fixed document.body/window dimension if required
var mx = 65536;
var my = 65536;
} else {
var mx = (this.menuX2!=null?this.menuX2:0);
var my = (this.menuY2!=null?this.menuY2:0);
if (mx == 0) {
if (window.innerWidth) {
mx = window.innerWidth;
my = window.innerHeight;
} else {
mx = document.body.offsetWidth;
my = document.body.scrollHeight;
}
}
}
if (x+w > mx && !this._rtl) {
// no space on right, open to left
x = srcX - w + 2;
}
if (x < this.menuX1 && this._rtl) {
// no space on left, open to right
x = srcX + srcW - 2;
}
if (x < 0) {
// menu floats left
x = 0;
}
if (y+h > my && this.menuY2 != null) {
y = srcY + srcH - h + 2;
// open from top level
if (this.itemPull[id] != null && !this.context) {
if (this.itemPull[id]["parent"] == this.idPrefix+this.topId) y = y - this.base.offsetHeight;
}
}
//
this.idPull[pId].style.left = x+"px";
this.idPull[pId].style.top = y+arrUpH+"px";
//
if ((this.sxDacProc != null) && (this.idPull["sxDac_" + id] != null)) {
this.idPull["sxDac_"+id]._show();
} else {
this.idPull[pId].style.visibility = "";
//#menu_overflow:06062008#{
if (this.limit > 0 && this.limit < itemCount) {
// this.idPull[pId].scrollTop = 0;
arrowUp.style.left = x+"px";
arrowUp.style.top = y+"px";
arrowUp.style.width = w+this._arrowFFFix+"px";
arrowUp.style.visibility = "";
//
arrowDown.style.left = x+"px";
arrowDown.style.top = y+arrUpH+h+"px";
arrowDown.style.width = w+this._arrowFFFix+"px";
arrowDown.style.visibility = "";
//
this._checkArrowsState(id);
}
//#}
// show ie6 cover
if (this._isIE6) {
var pIdIE6 = pId+"_ie6cover";
if (this.idPull[pIdIE6] == null) {
var ifr = document.createElement("IFRAME");
ifr.className = "dhtmlxMenu_IE6CoverFix_"+this.skin;
ifr.frameBorder = 0;
ifr.setAttribute("src", "javascript:false;");
document.body.insertBefore(ifr, document.body.firstChild);
this.idPull[pIdIE6] = ifr;
}
this.idPull[pIdIE6].style.left = this.idPull[pId].style.left;
this.idPull[pIdIE6].style.top = this.idPull[pId].style.top;
this.idPull[pIdIE6].style.width = this.idPull[pId].offsetWidth+"px";
this.idPull[pIdIE6].style.height = this.idPull[pId].offsetHeight+"px";
this.idPull[pIdIE6].style.zIndex = this.idPull[pId].style.zIndex-1;
this.idPull[pIdIE6].style.display = "";
}
id = String(id).replace(this.idPrefix, "");
if (id == this.topId) id = null;
this.callEvent("onShow", [id]);
// this.callEvent("_onPolyShow",[id.replace(this.idPrefix,"")]);
}
}
}
/* redistrib sublevel selection: select id and deselect other, added in version 0.3 */
this._redistribSubLevelSelection = function(id, parentId) {
// clear previosly selected items
while (this._openedPolygons.length > 0) this._openedPolygons.pop();
// this._openedPolygons = new Array();
var i = this._getSubItemToDeselectByPolygon(parentId);
this._removeSubItemFromSelected(-1, -1);
for (var q=0; q 0) { m = j; }
}
}
return m;
}
/* return array of subitems for single menu object */
/* modified in version 0.3 */
this._getMenuNodes = function(node) {
var m = new Array;
for (var a in this.itemPull) { if (this.itemPull[a]["parent"] == node) { m[m.length] = a; } }
return m;
}
/* generate random string with specified length */
this._genStr = function(w) {
var s = ""; var z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (var q=0; q 0) { main_self._openedPolygons.pop(); }
for (var q=0; q0));
item["complex"] = (this.dLoad?(r.getAttribute("complex")!=null?true:false):(this._buildMenu(r,item["id"])>0));
if (this.dLoad && item["complex"]) { item["loaded"] = "no"; }
this.itemPull[item["id"]] = item;
// check for user data
for (var w=0; w 1) {
item._menuOpenTM = window.setTimeout(function(){ main_self._showPolygon(pId, level); }, delay);
isShow = true;
}
}
}
if (!isShow) { main_self._showPolygon(pId, level); }
}
main_self.itemPull[main_self.idPrefix+parentId]["loaded"] = "yes";
// console.log(main_self.loaderIcon)
if (main_self.loaderIcon == true) { main_self._updateLoaderIcon(main_self.idPrefix+parentId, false); }
}
this.destructor();
main_self.callEvent("onXLE",[]);
} else {
var t = this.getXMLTopNode("menu");
// alert(3)
// main_self.idPrefix = main_self._genStr(12);
main_self._buildMenu(t, null);
main_self.init();
main_self.callEvent("onXLE",[]);
main_self._doOnLoad();
}
}
this._xmlLoader = new dtmlXMLLoaderObject(this._xmlParser, window);
/* show sublevel item */
this._showSubLevelItem = function(id,back) {
if (document.getElementById("arrow_" + this.idPrefix + id) != null) { document.getElementById("arrow_" + this.idPrefix + id).style.display = (back?"none":""); }
if (document.getElementById("image_" + this.idPrefix + id) != null) { document.getElementById("image_" + this.idPrefix + id).style.display = (back?"none":""); }
if (document.getElementById(this.idPrefix + id) != null) { document.getElementById(this.idPrefix + id).style.display = (back?"":"none"); }
}
/* hide sublevel item */
this._hideSubLevelItem = function(id) {
this._showSubLevelItem(id,true)
}
// generating id prefix
this.idPrefix = this._genStr(12);
/* attach body events */
this._bodyClick = function(e) {
e = e||event;
if (e.button == 2 || (_isOpera && e.ctrlKey == true)) return;
if (main_self.context) {
if (main_self.contextAutoHide && (!_isOpera || (main_self._isContextMenuVisible() && _isOpera))) main_self._hideContextMenu();
} else {
main_self._clearAndHide();
}
}
this._bodyContext = function(e) {
e = e||event;
var t = (e.srcElement||e.target).className;
if (t.search("dhtmlxMenu") != -1 && t.search("SubLevelArea") != -1) return;
var toHide = true;
var testZone = e.target || e.srcElement;
if (testZone.id != null) if (main_self.isContextZone(testZone.id)) toHide = false;
if (testZone == document.body) toHide = false;
if (toHide) main_self.hideContextMenu();
}
if (_isIE) {
document.body.attachEvent("onclick", this._bodyClick);
document.body.attachEvent("oncontextmenu", this._bodyContext);
} else {
window.addEventListener("click", this._bodyClick, false);
window.addEventListener("contextmenu", this._bodyContext, false);
}
// add menu to global store
this._UID = this._genStr(32);
dhtmlxMenuObjectLiveInstances[this._UID] = this;
/* events */
dhtmlxEventable(this);
//
return this;
}
dhtmlXMenuObject.prototype.init = function() {
if (this._isInited == true) return;
if (this.dLoad) {
this.callEvent("onXLS", []);
// this._xmlLoader.loadXML(this.dLoadUrl+"?action=loadMenu&parentId="+this.topId+"&topId="+this.topId);
this._xmlLoader.loadXML(this.dLoadUrl+this.dLoadSign+"action=loadMenu&etc="+new Date().getTime()); // &&parentId=topId&"+this.topId+"&topId="+this.topId);
} else {
this._initTopLevelMenu();
this._isInited = true;
}
}
dhtmlXMenuObject.prototype._countVisiblePolygonItems = function(id) {
/*
var count = 0;
if ((this.idPull["polygon_"+id] != null) && (this.idPull[id] != null)) {
for (var q=0; q 0) && (!this.itemPull[id]["complex"])) { this._updateItemComplexState(id, true, false); }
if ((u == 0) && (this.itemPull[id]["complex"])) { this._updateItemComplexState(id, false, false); }
}
}
/* complex arrow manipulations, over added in 0.4 */
dhtmlXMenuObject.prototype._updateItemComplexState = function(id, state, over) {
// 0.2 FIX :: topLevel's items can have complex items with arrow
if ((!this.context) && (this._getItemLevelType(id.replace(this.idPrefix,"")) == "TopLevel")) {
// 30.06.2008 fix > complex state for top level item, state only, no arrow
this.itemPull[id]["complex"] = state;
return;
}
if ((this.idPull[id] == null) || (this.itemPull[id] == null)) { return; }
// 0.2 FIX :: end
this.itemPull[id]["complex"] = state;
// fixed in 0.4 for context
if (id == this.idPrefix+this.topId) return;
// end fix
// try to retrieve arrow img object
var arrowObj = null;
var item = this.idPull[id].childNodes[this._rtl?0:2];
if (item.childNodes[0]) if (String(item.childNodes[0].className).search("complex_arrow") === 0) arrowObj = item.childNodes[0];
if (this.itemPull[id]["complex"]) {
// create arrow
if (arrowObj == null) {
arrowObj = document.createElement("DIV");
arrowObj.className = "complex_arrow";
arrowObj.id = "arrow_"+id;
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item.appendChild(arrowObj);
}
// over state added in 0.4
if (this.dLoad && (this.itemPull[id]["loaded"] == "get") && this.loaderIcon) {
// change arrow to loader
if (arrowObj.className != "complex_arrow_loading") arrowObj.className = "complex_arrow_loading";
} else {
arrowObj.className = "complex_arrow";
}
return;
}
if ((!this.itemPull[id]["complex"]) && (arrowObj!=null)) {
item.removeChild(arrowObj);
if (this.itemPull[id]["hotkey_backup"] != null && this.setHotKey) { this.setHotKey(id.replace(this.idPrefix, ""), this.itemPull[id]["hotkey_backup"]); }
}
}
/* return css-part level type */
dhtmlXMenuObject.prototype._getItemLevelType = function(id) {
return (this.itemPull[this.idPrefix+id]["parent"]==this.idPrefix+this.topId?"TopLevel":"SubLevelArea");
}
/****************************************************************************************************************************************************/
/* "TOPLEVEL" LOW-LEVEL RENDERING */
/* redistrib selection in case of top node in real-time mode */
dhtmlXMenuObject.prototype._redistribTopLevelSelection = function(id, parent) {
// kick polygons and decelect before selected menues
var i = this._getSubItemToDeselectByPolygon("parent");
this._removeSubItemFromSelected(-1, -1);
for (var q=0; q 0) m.title = this.itemPull[id]["tip"];
//
// image in top level
if ((this.itemPull[id]["imgen"]!="")||(this.itemPull[id]["imgdis"]!="")) {
var imgTop=this.itemPull[id][(this.itemPull[id]["state"]=="enabled")?"imgen":"imgdis"];
if (imgTop) {
var img = document.createElement("IMG");
img.border = "0";
img.id = "image_"+id;
img.src= this.imagePath+imgTop;
img.className = "dhtmlxMenu_TopLevel_Item_Icon";
if (m.childNodes.length > 0 && !this._rtl) m.insertBefore(img, m.childNodes[0]); else m.appendChild(img);
}
}
m.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; }
m.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; }
// add container for top-level items if not exists yet
if (!this.cont) {
this.cont = document.createElement("DIV");
this.cont.dir = "ltr";
this.cont.className = (this._align=="right"?"align_right":"align_left");
this.base.appendChild(this.cont);
}
// insert
/*
if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.base.childNodes.length - 1) pos = null; }
if (pos != null) this.base.insertBefore(m, this.base.childNodes[pos]); else this.base.appendChild(m);
*/
if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.cont.childNodes.length - 1) pos = null; }
if (pos != null) this.cont.insertBefore(m, this.cont.childNodes[pos]); else this.cont.appendChild(m);
//
this.idPull[m.id] = m;
// create submenues
if (this.itemPull[id]["complex"] && (!this.dLoad)) this._addSubMenuPolygon(this.itemPull[id]["id"], this.itemPull[id]["id"]);
// events
m.onmouseover = function() {
if (main_self.menuMode == "web") { window.clearTimeout(main_self.menuTimeoutHandler); }
// kick polygons and decelect before selected menues
var i = main_self._getSubItemToDeselectByPolygon("parent");
main_self._removeSubItemFromSelected(-1, -1);
for (var q=0; q 0) {
if (imgObj != null) {
imgObj.src = this.imagePath+imgSrc;
} else {
if (isTopLevel) {
var imgObj = document.createElement("IMG");
imgObj.className = "dhtmlxMenu_TopLevel_Item_Icon";
imgObj.src = this.imagePath+imgSrc;
imgObj.border = "0";
imgObj.id = "image_"+id;
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);
} else {
var imgObj = document.createElement("IMG");
imgObj.className = "sub_icon";
imgObj.src = this.imagePath+imgSrc;
imgObj.border = "0";
imgObj.id = "image_"+id;
var item = this.idPull[id].childNodes[this._rtl?2:0];
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item.appendChild(imgObj);
}
}
} else {
if (imgObj != null) imgObj.parentNode.removeChild(imgObj);
}
}
/**
* @desc: removes an item from the menu with all nested sublevels
* @param: id - id of the item for removing
* @type: public
*/
dhtmlXMenuObject.prototype.removeItem = function(id, _isTId, _recCall) {
if (!_isTId) id = this.idPrefix + id;
var pId = null;
if (id != this.idPrefix+this.topId) {
if (this.itemPull[id] == null) return;
// separator top
var t = this.itemPull[id]["type"];
if (t == "separator") {
var item = this.idPull["separator_"+id];
if (this.itemPull[id]["parent"] == this.idPrefix+this.topId) {
item.onclick = null;
item.onselectstart = null;
item.id = null;
item.parentNode.removeChild(item);
} else {
item.childNodes[0].childNodes[0].onclick = null;
item.childNodes[0].childNodes[0].onselectstart = null;
item.childNodes[0].childNodes[0].id = null;
item.childNodes[0].removeChild(item.childNodes[0].childNodes[0]);
item.removeChild(item.childNodes[0]);
item.parentNode.removeChild(item);
}
this.idPull["separator_"+id] = null;
this.itemPull[id] = null;
delete this.idPull["separator_"+id];
delete this.itemPull[id];
item = null;
} else {
// item checkbox radio
pId = this.itemPull[id]["parent"];
var item = this.idPull[id];
item.onclick = null;
item.oncontextmenu = null;
item.onmouseover = null;
item.onmouseout = null;
item.onselectstart = null;
item.id = null;
while (item.childNodes.length > 0) item.removeChild(item.childNodes[0]);
item.parentNode.removeChild(item);
this.idPull[id] = null;
this.itemPull[id] = null;
delete this.idPull[id];
delete this.itemPull[id];
item = null;
}
t = null;
}
// clear nested items
for (var a in this.itemPull) if (this.itemPull[a]["parent"] == id) this.removeItem(a, true, true);
// check if empty polygon left
var p2 = new Array(id);
if (pId != null && !_recCall) {
if (this.idPull["polygon_"+pId] != null) {
if (this.idPull["polygon_"+pId].tbd.childNodes.length == 0) {
p2.push(pId);
this._updateItemComplexState(pId, false, false);
}
}
}
// delete nested polygons and parent's if any
for (var q=0; q= this.menuX1) && (x+w<=this.menuX2) && (y >= this.menuY1) && (y+h <= this.menuY2));
}*/
//#}
/**
* @desc: returns item's position in the current polygon
* @param: id - the item
* @type: public
*/
dhtmlXMenuObject.prototype.getItemPosition = function(id) {
id = this.idPrefix+id;
var pos = -1;
if (this.itemPull[id] == null) return pos;
var parent = this.itemPull[id]["parent"];
// var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.base);
var obj = (this.idPull["polygon_"+parent]!=null?this.idPull["polygon_"+parent].tbd:this.cont);
for (var q=0; q 0 && !this.itemPull[id]["complex"]) {
var t3t = document.createElement("DIV");
t3t.className = "sub_item_hk";
t3t.innerHTML = this.itemPull[id]["hotkey"];
t3.appendChild(t3t);
} else {
t3.innerHTML = " ";
}
}
tr.appendChild(this._rtl?t3:t1);
tr.appendChild(t2);
tr.appendChild(this._rtl?t1:t3);
//
tr.id = this.itemPull[id]["id"];
tr.parent = this.itemPull[id]["parent"];
// tooltip, added in 0.4
if (this.itemPull[id]["tip"].length > 0) tr.title = this.itemPull[id]["tip"];
//
tr.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; }
tr.onmouseover = function() {
if (main_self.menuMode == "web") window.clearTimeout(main_self.menuTimeoutHandler);
main_self._redistribSubLevelSelection(this.id, this.parent);
}
if (main_self.menuMode == "web") {
tr.onmouseout = function() {
window.clearTimeout(main_self.menuTimeoutHandler);
main_self.menuTimeoutHandler = window.setTimeout(function(){main_self._clearAndHide();}, main_self.menuTimeoutMsec, "JavaScript");
}
}
tr.onclick = function(e) {
// added in 0.4, preven complex closing if user event not defined
if (!main_self.checkEvent("onClick") && main_self.itemPull[this.id]["complex"]) return;
//
e = e || event; e.cancelBubble = true;
e.returnValue = false;
tc = (main_self.itemPull[this.id]["complex"]?"c":"-");
td = (main_self.itemPull[this.id]["state"]=="enabled"?"-":"d");
var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey};
switch (main_self.itemPull[this.id]["type"]) {
case "checkbox":
main_self._checkboxOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
break;
case "radio":
main_self._radioOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
break;
case "item":
main_self._doOnClick(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
break;
}
return false;
}
// add
var polygon = this.idPull["polygon_"+this.itemPull[id]["parent"]];
if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > polygon.tbd.childNodes.length - 1) pos = null; }
if (pos != null && polygon.tbd.childNodes[pos] != null) polygon.tbd.insertBefore(tr, polygon.tbd.childNodes[pos]); else polygon.tbd.appendChild(tr);
this.idPull[tr.id] = tr;
}
/****************************************************************************************************************************************************/
/* SEPARATOR */
dhtmlXMenuObject.prototype._renderSeparator = function(id, pos) {
var level = (this.context?"SubLevelArea":(this.itemPull[id]["parent"]==this.idPrefix+this.topId?"TopLevel":"SubLevelArea"));
if (level == "TopLevel" && this.context) return;
var main_self = this;
if (level != "TopLevel") {
var tr = document.createElement("TR");
tr.className = "sub_sep";
var td = document.createElement("TD");
td.colSpan = "3";
tr.appendChild(td);
}
var k = document.createElement("DIV");
k.id = "separator_"+id;
k.className = (level=="TopLevel"?"top_sep":"sub_sep");
k.onselectstart = function(e) { e = e || event; e.returnValue = false; }
k.onclick = function(e) {
e = e || event; e.cancelBubble = true;
var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey};
main_self._doOnClick(this.id.replace("separator_" + main_self.idPrefix, ""), "--s", cas);
}
if (level == "TopLevel") {
if (pos != null) {
pos++; if (pos < 0) { pos = 0; }
// if (this.base.childNodes[pos] != null) { this.base.insertBefore(k, this.base.childNodes[pos]); } else { this.base.appendChild(k); }
if (this.cont.childNodes[pos] != null) { this.cont.insertBefore(k, this.cont.childNodes[pos]); } else { this.cont.appendChild(k); }
} else {
// add as a last item
// var last = this.base.childNodes[this.base.childNodes.length-1];
var last = this.cont.childNodes[this.cont.childNodes.length-1];
// if (String(last).search("TopLevel_Text") == -1) { this.base.appendChild(k); } else { this.base.insertBefore(k, last); }
if (String(last).search("TopLevel_Text") == -1) { this.cont.appendChild(k); } else { this.cont.insertBefore(k, last); }
}
this.idPull[k.id] = k;
} else {
var polygon = this.idPull["polygon_"+this.itemPull[id]["parent"]];
if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > polygon.tbd.childNodes.length - 1) pos = null; }
if (pos != null && polygon.tbd.childNodes[pos] != null) polygon.tbd.insertBefore(tr, polygon.tbd.childNodes[pos]); else polygon.tbd.appendChild(tr);
td.appendChild(k);
this.idPull[k.id] = tr;
}
}
/**
* @desc: add a new separator
* @param: nextToId - id of the element after which a new separator will be inserted
* @param: itemId - id of a new separator
* @type: public
*/
dhtmlXMenuObject.prototype.addNewSeparator = function(nextToId, itemId) { //, disabled) {
itemId = this.idPrefix+(itemId!=null?itemId:this._genStr(24));
var parentId = this.idPrefix+this.getParentId(nextToId);
// if ((parentId == this.idPrefix+this.topId) && (!this.context)) { return; }
// this._addItemIntoGlobalStrorage(itemId, parentId, "", "item", disabled, "", "");
// this._addItemIntoGlobalStrorage(itemId, parentId, "", "item", false, "", "");
this._addItemIntoGlobalStrorage(itemId, parentId, "", "separator", false, "", "");
this._renderSeparator(itemId, this.getItemPosition(nextToId));
}
/****************************************************************************************************************************************************/
// hide any opened polygons
/**
* @desc: hides any open menu polygons
* @type: public
*/
dhtmlXMenuObject.prototype.hide = function() {
this._clearAndHide();
}
/**
* @desc: clear all loaded items
* @type: public
*/
dhtmlXMenuObject.prototype.clearAll = function() {
/*
for (var a in this.itemPull) {
if (this.itemPull[a]["parent"] == this.idPrefix+this.topId) {
this.removeItem(String(a).replace(this.idPrefix,""));
}
}
*/
this.removeItem(this.idPrefix+this.topId, true);
this._isInited = false;
this.idPrefix = this._genStr(12);
}
/****************************************************************************************************************************************************/
/**
* @desc: unloads menu from page (destructor)
* @type: public
*/
dhtmlXMenuObject.prototype.unload = function() {
if (_isIE) {
document.body.detachEvent("onclick", this._bodyClick);
document.body.detachEvent("oncontextmenu", this._bodyContext);
} else {
window.removeEventListener("click", this._bodyClick, false);
window.removeEventListener("contextmenu", this._bodyContext, false);
}
this._bodyClick = null;
this._bodyContext = null;
// will recursively remove all items
this.removeItem(this.idPrefix+this.topId, true);
this.itemPull = null;
this.idPull = null;
// clear context zones
if (this.context) for (var a in this.contextZones) this.removeContextZone(a);
if (this.cont != null) {
this.cont.className = "";
this.cont.parentNode.removeChild(this.cont);
this.cont = null;
}
if (this.base != null) {
this.base.className = "";
if (!this.context) this.base.oncontextmenu = (this.base._oldContextMenuHandler||null);
this.base.onselectstart = null;
this.base = null;
}
this.setSkin = null;
this.detachAllEvents();
if (this._xmlLoader) {
this._xmlLoader.destructor();
this._xmlLoader = null;
}
this._align = null;
this._arrowFFFix = null;
this._isIE6 = null;
this._isInited = null;
this._rtl = null;
this._scrollDownTMStep = null;
this._scrollDownTMTime = null;
this._scrollUpTMStep = null;
this._scrollUpTMTime = null;
this._topLevelBottomMargin = null;
this._topLevelOffsetLeft = null;
this._topLevelBottomMargin = null;
this._topLevelRightMargin = null;
this.addBaseIdAsContextZone = null;
this.context = null;
this.contextAutoHide = null;
this.contextAutoShow = null;
this.contextHideAllMode = null;
this.contextMenuZoneId = null;
this.dLoad = null;
this.dLoadSign = null;
this.dLoadUrl = null;
this.loaderIcon = null;
this.fixedPosition = null;
this.dirSubLevel = null;
this.dirTopLevel = null;
this.limit = null;
this.menuSelected = null;
this.menuLastClicked = null;
this.idPrefix = null;
this.imagePath = null;
this.menuMode = null;
this.menuModeTopLevelTimeout = null;
this.menuModeTopLevelTimeoutTime = null;
this.menuTimeoutHandler = null;
this.menuTimeoutMsec = null;
this.menuTouched = null;
this.isDhtmlxMenuObject = null;
this.itemHotKeyTagName = null;
this.itemHrefTagName = null;
this.itemTagName = null;
this.itemTextTagName = null;
this.itemTipTagName = null;
this.userDataTagName = null;
this.skin = null;
this.topId = null;
this.dacCycles = null;
this.dacCyclesIE = null;
this.dacSpeed = null;
this.dacSpeedIE = null;
this.zInd = null;
this.zIndInit = null;
this.zIndStep = null;
//
// unload basic methods
this._enableDacSupport = null;
this._selectedSubItems = null;
this._openedPolygons = null;
this._addSubItemToSelected = null;
this._removeSubItemFromSelected = null;
this._getSubItemToDeselectByPolygon = null;
this._hidePolygon = null;
this._showPolygon = null;
this._redistribSubLevelSelection = null;
this._doOnClick = null;
this._doOnTouchMenu = null;
this._searchMenuNode = null;
this._getMenuNodes = null;
this._genStr = null;
this._clearAndHide = null;
this._doOnLoad = null;
this.getItemType = null;
this.forEachItem = null;
this.init = null;
this.loadXML = null;
this.loadXMLString = null;
this._buildMenu = null;
this._xmlParser = null;
this._showSubLevelItem = null;
this._hideSubLevelItem = null;
this._countVisiblePolygonItems = null;
this._redefineComplexState = null;
this._updateItemComplexState = null;
this._getItemLevelType = null;
this._redistribTopLevelSelection = null;
this._initTopLevelMenu = null;
this._renderToplevelItem = null;
this.setImagePath = null;
this.setIconsPath = null;
this.setIconPath = null;
this._updateItemImage = null;
this.removeItem = null;
this._getAllParents = null;
this.renderAsContextMenu = null;
this.addContextZone = null;
this.removeContextZone = null;
this.isContextZone = null;
this._isContextMenuVisible = null;
this._showContextMenu = null;
this._doOnContextBeforeCall = null;
this._autoDetectVisibleArea = null;
this._addItemIntoGlobalStrorage = null;
this._addSubMenuPolygon = null;
this._renderSublevelPolygon = null;
this._renderSublevelItem = null;
this._renderSeparator = null;
this._hideContextMenu = null;
this.clearAll = null;
this.getItemPosition = null;
this.setItemPosition = null;
this.getParentId = null;
this.addNewSibling = null;
this.addNewChild = null;
this.addNewSeparator = null;
this.attachEvent = null;
this.callEvent = null;
this.checkEvent = null;
this.eventCatcher = null;
this.detachEvent = null;
this.dhx_Event = null;
this.unload = null;
this.items = null;
this.radio = null;
this.detachAllEvents = null;
this.hide = null;
this.showContextMenu = null;
this.hideContextMenu = null;
// unload extended methods
this._changeItemState = null;
this._changeItemVisible = null;
this._updateLoaderIcon = null;
this._clearAllSelectedSubItemsInPolygon = null;
this._checkArrowsState = null;
this._addUpArrow = null;
this._addDownArrow = null;
this._removeUpArrow = null;
this._removeDownArrow = null;
this._isArrowExists = null;
this._doScrollUp = null;
this._doScrollDown = null;
this._countPolygonItems = null;
this._getRadioImgObj = null;
this._setRadioState = null;
this._radioOnClickHandler = null;
this._getCheckboxState = null;
this._setCheckboxState = null;
this._readLevel = null;
this._updateCheckboxImage = null;
this._checkboxOnClickHandler = null;
this._removeArrow = null;
this.setItemEnabled = null;
this.setItemDisabled = null;
this.isItemEnabled = null;
this.getItemText = null;
this.setItemText = null;
this.loadFromHTML = null;
this.hideItem = null;
this.showItem = null;
this.isItemHidden = null;
this.setUserData = null;
this.getUserData = null;
this.setOpenMode = null;
this.setWebModeTimeout = null;
this.enableDynamicLoading = null;
this.getItemImage = null;
this.setItemImage = null;
this.clearItemImage = null;
this.setAutoShowMode = null;
this.setAutoHideMode = null;
this.setContextMenuHideAllMode = null;
this.getContextMenuHideAllMode = null;
this.setVisibleArea = null;
this.setTooltip = null;
this.getTooltip = null;
this.setHotKey = null;
this.getHotKey = null;
this.setItemSelected = null;
this.setTopText = null;
this.setRTL = null;
this.setAlign = null;
this.setHref = null;
this.clearHref = null;
this.getCircuit = null;
this.contextZones = null;
this.setOverflowHeight = null;
this.userData = null;
this.getRadioChecked = null;
this.setRadioChecked = null;
this.addRadioButton = null;
this.setCheckboxState = null;
this.getCheckboxState = null;
this.addCheckbox = null;
this.serialize = null;
this.extendedModule = null;
// remove menu from global store
dhtmlxMenuObjectLiveInstances[this._UID] = null;
try { delete dhtmlxMenuObjectLiveInstances[this._UID]; } catch(e) {}
this._UID = null;
}
// dhtmlxmenu global store
var dhtmlxMenuObjectLiveInstances = {};
dhtmlXMenuObject.prototype.i18n = {
dhxmenuextalert: "dhtmlxmenu_ext.js required"
};
//menu
(function(){
dhtmlx.extend_api("dhtmlXMenuObject",{
_init:function(obj){
return [obj.parent, obj.skin];
},
align:"setAlign",
top_text:"setTopText",
context:"renderAsContextMenu",
icon_path:"setIconsPath",
open_mode:"setOpenMode",
rtl:"setRTL",
skin:"setSkin",
dynamic:"enableDynamicLoading",
xml:"loadXML",
items:"items",
overflow:"setOverflowHeight"
},{
items:function(arr,parent){
var pos = 100000;
var lastItemId = null;
for (var i=0; i < arr.length; i++) {
var item=arr[i];
if (item.type == "separator") {
this.addNewSeparator(lastItemId, pos, item.id);
lastItemId = item.id;
} else {
this.addNewChild(parent, pos, item.id, item.text, item.disabled, item.img, item.img_disabled);
lastItemId = item.id;
if (item.items) this.items(item.items,item.id);
}
}
}
});
})();