Code Duplication    Length = 146-150 lines in 2 locations

api/js/dhtmlxMenu/sources/dhtmlxmenu.js 1 location

@@ 972-1121 (lines=150) @@
969
	}
970
}
971
/* add top menu item, complex define that submenues are in presence */
972
dhtmlXMenuObject.prototype._renderToplevelItem = function(id, pos) {
973
	var main_self = this;
974
	var m = document.createElement("DIV");
975
	m.id = id;
976
	// custom css
977
	if (this.itemPull[id]["state"] == "enabled" && this.itemPull[id]["cssNormal"] != null) {
978
		m.className = this.itemPull[id]["cssNormal"];
979
	} else {
980
		m.className = "dhtmlxMenu_"+this.skin+"_TopLevel_Item_"+(this.itemPull[id]["state"]=="enabled"?"Normal":"Disabled");
981
	}
982
	
983
	// text
984
	if (this.itemPull[id]["title"] != "") {
985
		var t1 = document.createElement("DIV");
986
		t1.className = "top_level_text";
987
		t1.innerHTML = this.itemPull[id]["title"];
988
		m.appendChild(t1);
989
	}
990
	// tooltip
991
	if (this.itemPull[id]["tip"].length > 0) m.title = this.itemPull[id]["tip"];
992
	//
993
	// image in top level
994
	if ((this.itemPull[id]["imgen"]!="")||(this.itemPull[id]["imgdis"]!="")) {
995
		var imgTop=this.itemPull[id][(this.itemPull[id]["state"]=="enabled")?"imgen":"imgdis"];
996
		if (imgTop) {
997
			var img = document.createElement("IMG");
998
			img.border = "0";
999
			img.id = "image_"+id;
1000
			img.src= this.imagePath+imgTop;
1001
			img.className = "dhtmlxMenu_TopLevel_Item_Icon";
1002
			if (m.childNodes.length > 0 && !this._rtl) m.insertBefore(img, m.childNodes[0]); else m.appendChild(img);
1003
		}
1004
	}
1005
	m.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; }
1006
	m.oncontextmenu = function(e) { e = e || event; e.returnValue = false; return false; }
1007
	// add container for top-level items if not exists yet
1008
	if (!this.cont) {
1009
		this.cont = document.createElement("DIV");
1010
		this.cont.dir = "ltr";
1011
		this.cont.className = (this._align=="right"?"align_right":"align_left");
1012
		this.base.appendChild(this.cont);
1013
	}
1014
	// insert
1015
	/*
1016
	if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.base.childNodes.length - 1) pos = null; }
1017
	if (pos != null) this.base.insertBefore(m, this.base.childNodes[pos]); else this.base.appendChild(m);
1018
	*/
1019
	if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > this.cont.childNodes.length - 1) pos = null; }
1020
	if (pos != null) this.cont.insertBefore(m, this.cont.childNodes[pos]); else this.cont.appendChild(m);
1021
	
1022
	
1023
	//
1024
	this.idPull[m.id] = m;
1025
	// create submenues
1026
	if (this.itemPull[id]["complex"] && (!this.dLoad)) this._addSubMenuPolygon(this.itemPull[id]["id"], this.itemPull[id]["id"]);
1027
	// events
1028
	m.onmouseover = function() {
1029
		if (main_self.menuMode == "web") { window.clearTimeout(main_self.menuTimeoutHandler); }
1030
		// kick polygons and decelect before selected menues
1031
		var i = main_self._getSubItemToDeselectByPolygon("parent");
1032
		main_self._removeSubItemFromSelected(-1, -1);
1033
		for (var q=0; q<i.length; q++) {
1034
			if (i[q] != this.id) { main_self._hidePolygon(i[q]); }
1035
			if ((main_self.idPull[i[q]] != null) && (i[q] != this.id)) {
1036
				// custom css
1037
				if (main_self.itemPull[i[q]]["cssNormal"] != null) {
1038
					main_self.idPull[i[q]].className = main_self.itemPull[i[q]]["cssNormal"];
1039
				} else {
1040
					if (main_self.idPull[i[q]].className == "sub_item_selected") main_self.idPull[i[q]].className = "sub_item";
1041
					main_self.idPull[i[q]].className = main_self.idPull[i[q]].className.replace(/Selected/g, "Normal");
1042
				}
1043
			}
1044
		}
1045
		// check if enabled
1046
		if (main_self.itemPull[this.id]["state"] == "enabled") {
1047
			this.className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Selected";
1048
			//
1049
			main_self._addSubItemToSelected(this.id, "parent");
1050
			main_self.menuSelected = (main_self.menuMode=="win"?(main_self.menuSelected!=-1?this.id:main_self.menuSelected):this.id);
1051
			if (main_self.dLoad && (main_self.itemPull[this.id]["loaded"]=="no")) {
1052
				if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) {
1053
					this._mouseOver = true;
1054
					this._dynLoadTM = new Date().getTime();
1055
				}
1056
				var xmlLoader = new dtmlXMLLoaderObject(main_self._xmlParser, window);
1057
				main_self.itemPull[this.id]["loaded"] = "get";
1058
				main_self.callEvent("onXLS", []);
1059
				xmlLoader.loadXML(main_self.dLoadUrl+main_self.dLoadSign+"action=loadMenu&parentId="+this.id.replace(main_self.idPrefix,"")+"&etc="+new Date().getTime());
1060
			}
1061
			if ((!main_self.dLoad) || (main_self.dLoad && (!main_self.itemPull[this.id]["loaded"] || main_self.itemPull[this.id]["loaded"]=="yes"))) {
1062
				if ((main_self.itemPull[this.id]["complex"]) && (main_self.menuSelected != -1)) {
1063
					if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) {
1064
						this._mouseOver = true;
1065
						var showItemId = this.id;
1066
						this._menuOpenTM = window.setTimeout(function(){main_self._showPolygon(showItemId, main_self.dirTopLevel);}, main_self.menuModeTopLevelTimeoutTime);
1067
					} else {
1068
						main_self._showPolygon(this.id, main_self.dirTopLevel);
1069
					}
1070
				}
1071
			}
1072
		}
1073
		main_self._doOnTouchMenu(this.id.replace(main_self.idPrefix, ""));
1074
	}
1075
	m.onmouseout = function() {
1076
		if (!((main_self.itemPull[this.id]["complex"]) && (main_self.menuSelected != -1)) && (main_self.itemPull[this.id]["state"]=="enabled")) {
1077
			// custom css
1078
			// console.log(main_self.itemPull[this.id])
1079
			if (main_self.itemPull[this.id]["cssNormal"] != null) {
1080
				// alert(1)
1081
				m.className = main_self.itemPull[this.id]["cssNormal"];
1082
			} else {
1083
				// default css
1084
				m.className = "dhtmlxMenu_"+main_self.skin+"_TopLevel_Item_Normal";
1085
			}
1086
		}
1087
		if (main_self.menuMode == "web") {
1088
			window.clearTimeout(main_self.menuTimeoutHandler);
1089
			main_self.menuTimeoutHandler = window.setTimeout(function(){main_self._clearAndHide();}, main_self.menuTimeoutMsec, "JavaScript");
1090
		}
1091
		if (main_self.menuModeTopLevelTimeout && main_self.menuMode == "web" && !main_self.context) {
1092
			this._mouseOver = false;
1093
			window.clearTimeout(this._menuOpenTM);
1094
		}
1095
	}
1096
	m.onclick = function(e) {
1097
		if (main_self.menuMode == "web") { window.clearTimeout(main_self.menuTimeoutHandler); }
1098
		// fix, added in 0.4
1099
		if (main_self.menuMode != "web" && main_self.itemPull[this.id]["state"] == "disabled") { return; }
1100
		//
1101
		e = e || event;
1102
		e.cancelBubble = true;
1103
		e.returnValue = false;
1104
		
1105
		if (main_self.menuMode == "win") {
1106
			if (main_self.itemPull[this.id]["complex"]) {
1107
				if (main_self.menuSelected == this.id) { main_self.menuSelected = -1; var s = false; } else { main_self.menuSelected = this.id; var s = true; }
1108
				if (s) { main_self._showPolygon(this.id, main_self.dirTopLevel); } else { main_self._hidePolygon(this.id); }
1109
			}
1110
		}
1111
		var tc = (main_self.itemPull[this.id]["complex"]?"c":"-");
1112
		var td = (main_self.itemPull[this.id]["state"]!="enabled"?"d":"-");
1113
		var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey};
1114
		main_self._doOnClick(this.id.replace(main_self.idPrefix, ""), tc+td+"t", cas);
1115
		return false;
1116
	}
1117
	
1118
	if (this.skin == "dhx_terrace") {
1119
		this._improveTerraceSkin();
1120
	}
1121
}
1122
/****************************************************************************************************************************************************/
1123
/**
1124
*   @desc: empty function, now more used from 90226

api/js/egw_action/test/js/dhtmlxmenu.js 1 location

@@ 943-1088 (lines=146) @@
940
	}
941
}
942
/* add top menu item, complex define that submenues are in presence */
943
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