﻿
var Menu = function(refData, Parent) { var refThis = this; this.Init = function() { var divMenu = _newElement("div", "Menu"); refThis.eMenu = divMenu; divMenu.refData = refData; divMenu.style.display = "none"; divMenu.setAttribute("tabindex", "-1"); var mTable = _newElement("table"); mTable.cellSpacing = 1; mTable.cellPadding = 0; divMenu.appendChild(mTable); Parent.appendChild(divMenu); divMenu.insertItem = function(item, row) { var cellIcon = row.insertCell(0); if(item.icon) { var imgIcon = _newElement("img", "icon"); imgIcon.setAttribute("src", item.icon); cellIcon.appendChild(imgIcon); } var cellText = row.insertCell(1); if(item.text) { cellText.className = "item"; cellText.appendChild(_newText(item.text)); cellText.description = item.description; cellText.onmouseover = function() { this.className = "over"; window.status = this.description; }; cellText.onmouseout = function() { this.className = "item"; window.status = ""; }; cellText.onmousedown = function() { this.className = "down"; }; cellText.onmouseup = function() { this.className = "over"; divMenu.execute(item); }; cellText.onclick = function(event) { _cancelBubble(true, event); }; } var cellSub = row.insertCell(2); if(item.subMenu) { } }; divMenu.execute = function(item) { divMenu.style.display = "none"; if(item.exec) eval(item.exec); if(item.call) item.call(item); }; divMenu.onblur = function(event) { var rect = getRect(divMenu); var mouse = getMouse(event); if(!PtInRect(mouse.x, mouse.y, rect)) { divMenu.style.display = "none"; } }; if(refData.items) { for(var i=0; i<refData.items.length; i++) { var row = mTable.insertRow(i); divMenu.insertItem(refData.items[i], row); } } }; this.Popup = function(x, y) { refThis.eMenu.style.display = ""; refThis.eMenu.style.left = x+"px"; refThis.eMenu.style.top = y+"px"; refThis.eMenu.focus(); }; this.Free = function() { _removeNode(refThis.eMenu); delete refThis; }; this.Init(); }; 
