Context menu

context menu
context menu:
logs
with logs:
</> Source
<!DOCTYPE html>
<html>
<head>
	<title>Context menu</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<style>
		div.sample_info_here {
			position: relative;
			width: auto;
			margin: 20px;
			font-family: Roboto, Arial, Helvetica;
			font-size: 14px;
			color: #404040;
		}
		div.sample_info_here div.sample_info_title {
			line-height: 18px;
			font-size: 15px;
			color: #3b5e7c;
		}
		div#tree_here {
			position: relative;
			border: 1px solid #dfdfdf;
			box-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.09);
			width: 350px;
			height: 400px;
			margin-left: 20px;
			margin-bottom: 20px;
		}
		div.controls {
			position: relative;
			width: auto;
			margin: 0px 20px 20px 20px;
			font-family: Roboto, Arial, Helvetica;
			font-size: 14px;
			color: #404040;
		}
		div.controls input {
			font-family: Roboto, Arial, Helvetica;
			font-size: 14px;
			color: #404040;
		}
		div#logs_here {
			position: relative;
			height: 170px;
			width: auto;
			margin: 20px;
			border: 1px solid #e0e0e0;
			padding: 4px;
			font-size: 12px;
			font-family: Roboto, Arial, Helvetica;
			font-size: 14px;
			color: #404040;
			overflow: auto;
		}
	</style>
	<script>
		var myTreeView, myContextMenu, logIndex = 0;
		function doOnLoad() {
			myTreeView = new dhtmlXTreeView({
				parent: "tree_here",
				json: "../common/treeview.json"
			});
			myTreeView.attachEvent("onContextMenu", function(id, x, y, ev){
				if (myContextMenu == null) {
					myContextMenu = new dhtmlXMenuObject({
						icons_path: "../../../dhtmlxMenu/samples/common/imgs/",
						context: true,
						items: [
							{id: "itemText"},
							{type: "separator"},
							{id: "cut", text: "Cut", img: "cut.gif"},
							{id: "copy", text: "Copy", img: "copy.gif"},
							{id: "paste", text: "Paste", img: "paste.gif"}
						]
					});
				}
				myContextMenu.setItemText("itemText", myTreeView.getItemText(id));
				myContextMenu.showContextMenu(x, y);
				myTreeView.selectItem(id);
				writeLog("onContextMenu event, id: "+id+" ("+myTreeView.getItemText(id)+")");
				return false; // prevent default context menu
			});
			enable();
		}
		function enable() {
			myTreeView.enableContextMenu(true);
			writeLog("context menu enabled");
		}
		function disable() {
			myTreeView.enableContextMenu(false);
			writeLog("context menu disabled");
		}
		function writeLog(text) {
			document.getElementById("logs_here").innerHTML += "<br>"+"["+(++logIndex)+"] "+text;
			document.getElementById("logs_here").scrollTop = document.getElementById("logs_here").scrollHeight;
		}
		function clearLog() {
			document.getElementById("logs_here").innerHTML = "<u>logs</u>";
		}
	</script>
</head>
<body onload="doOnLoad()">
	<div class="sample_info_here">
		<div class="sample_info_title">context menu</div>
	</div>
	<div id="tree_here"></div>
	<div class="controls">
		context menu: <input type="button" value="enable" onclick="enable();"> <input type="button" value="disable" onclick="disable();">
	</div>
	<div id="logs_here"><u>logs</u></div>
	<div class="controls">
		with logs: <input type="button" value="clear" onclick="clearLog();">
	</div>
</body>
</html>

Documentation

Check documentation to learn how to use the components and easily implement them in your applications.