Code Duplication    Length = 109-116 lines in 2 locations

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

@@ 1668-1783 (lines=116) @@
1665
	}
1666
	return s;
1667
}
1668
dhtmlXMenuObject.prototype._renderSublevelItem = function(id, pos) {
1669
	var main_self = this;
1670
	
1671
	var tr = document.createElement("TR");
1672
	tr.className = (this.itemPull[id]["state"]=="enabled"?"sub_item":"sub_item_dis");
1673
	
1674
	// icon
1675
	var t1 = document.createElement("TD");
1676
	t1.className = "sub_item_icon";
1677
	var icon = this.itemPull[id][(this.itemPull[id]["state"]=="enabled"?"imgen":"imgdis")];
1678
	if (icon != "") {
1679
		var tp = this.itemPull[id]["type"];
1680
		if (tp=="checkbox"||tp=="radio") {
1681
			var img = document.createElement("DIV");
1682
			img.id = "image_"+this.itemPull[id]["id"];
1683
			img.className = "sub_icon "+icon;
1684
			t1.appendChild(img);
1685
		}
1686
		if (!(tp=="checkbox"||tp=="radio")) {
1687
			var img = document.createElement("IMG");
1688
			img.id = "image_"+this.itemPull[id]["id"];
1689
			img.className = "sub_icon";
1690
			img.src = this.imagePath+icon;
1691
			t1.appendChild(img);
1692
		}
1693
	}
1694
	
1695
	// text
1696
	var t2 = document.createElement("TD");
1697
	t2.className = "sub_item_text";
1698
	if (this.itemPull[id]["title"] != "") {
1699
		var t2t = document.createElement("DIV");
1700
		t2t.className = "sub_item_text";
1701
		t2t.innerHTML = this.itemPull[id]["title"];
1702
		t2.appendChild(t2t);
1703
	} else {
1704
		t2.innerHTML = " ";
1705
	}
1706
	
1707
	// hotkey/sublevel arrow
1708
	var t3 = document.createElement("TD");
1709
	t3.className = "sub_item_hk";
1710
	if (this.itemPull[id]["complex"]) {
1711
		
1712
		var arw = document.createElement("DIV");
1713
		arw.className = "complex_arrow";
1714
		arw.id = "arrow_"+this.itemPull[id]["id"];
1715
		t3.appendChild(arw);
1716
		
1717
	} else {
1718
		if (this.itemPull[id]["hotkey"].length > 0 && !this.itemPull[id]["complex"]) {
1719
			var t3t = document.createElement("DIV");
1720
			t3t.className = "sub_item_hk";
1721
			t3t.innerHTML = this.itemPull[id]["hotkey"];
1722
			t3.appendChild(t3t);
1723
		} else {
1724
			t3.innerHTML = " ";
1725
		}
1726
	}
1727
	tr.appendChild(this._rtl?t3:t1);
1728
	tr.appendChild(t2);
1729
	tr.appendChild(this._rtl?t1:t3);
1730
	
1731
	
1732
	//
1733
	tr.id = this.itemPull[id]["id"];
1734
	tr.parent = this.itemPull[id]["parent"];
1735
	// tooltip, added in 0.4
1736
	if (this.itemPull[id]["tip"].length > 0) tr.title = this.itemPull[id]["tip"];
1737
	//
1738
	if (!this._hideTMData) this._hideTMData = {};
1739
	
1740
	tr.onselectstart = function(e) { e = e || event; e.returnValue = false; return false; }
1741
	tr.onmouseover = function(e) {
1742
		if (main_self._hideTMData[this.id]) window.clearTimeout(main_self._hideTMData[this.id]);
1743
		if (main_self.menuMode == "web") window.clearTimeout(main_self.menuTimeoutHandler);
1744
		if (!this._visible) main_self._redistribSubLevelSelection(this.id, this.parent); // if not visible
1745
		this._visible = true;
1746
	}
1747
	tr.onmouseout = function() {
1748
		if (main_self.menuMode == "web") {
1749
			if (main_self.menuTimeoutHandler) window.clearTimeout(main_self.menuTimeoutHandler);
1750
			main_self.menuTimeoutHandler = window.setTimeout(function(){if(main_self&&main_self._clearAndHide)main_self._clearAndHide();}, main_self.menuTimeoutMsec, "JavaScript");
1751
		}
1752
		var k = this;
1753
		if (main_self._hideTMData[this.id]) window.clearTimeout(main_self._hideTMData[this.id]);
1754
		main_self._hideTMData[this.id] = window.setTimeout(function(){k._visible=false;}, 50);
1755
	}
1756
	tr.onclick = function(e) {
1757
		// added in 0.4, preven complex closing if user event not defined
1758
		if (!main_self.checkEvent("onClick") && main_self.itemPull[this.id]["complex"]) return;
1759
		//
1760
		e = e || event; e.cancelBubble = true;
1761
		e.returnValue = false;
1762
		tc = (main_self.itemPull[this.id]["complex"]?"c":"-");
1763
		td = (main_self.itemPull[this.id]["state"]=="enabled"?"-":"d");
1764
		var cas = {"ctrl": e.ctrlKey, "alt": e.altKey, "shift": e.shiftKey};
1765
		switch (main_self.itemPull[this.id]["type"]) {
1766
			case "checkbox":
1767
				main_self._checkboxOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
1768
				break;
1769
			case "radio":
1770
				main_self._radioOnClickHandler(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
1771
				break;
1772
			case "item":
1773
				main_self._doOnClick(this.id.replace(main_self.idPrefix, ""), tc+td+"n", cas);
1774
				break;
1775
		}
1776
		return false;
1777
	}
1778
	// add
1779
	var polygon = this.idPull["polygon_"+this.itemPull[id]["parent"]];
1780
	if (pos != null) { pos++; if (pos < 0) pos = 0; if (pos > polygon.tbd.childNodes.length - 1) pos = null; }
1781
	if (pos != null && polygon.tbd.childNodes[pos] != null) polygon.tbd.insertBefore(tr, polygon.tbd.childNodes[pos]); else polygon.tbd.appendChild(tr);
1782
	this.idPull[tr.id] = tr;
1783
}
1784
/****************************************************************************************************************************************************/
1785
/*								 	SEPARATOR								    */
1786
dhtmlXMenuObject.prototype._renderSeparator = function(id, pos) {

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

@@ 1700-1808 (lines=109) @@
1697
	}
1698
	return s;
1699
}
1700
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 = "&nbsp;";
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 = "&nbsp;";
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
dhtmlXMenuObject.prototype._renderSeparator = function(id, pos) {