home *** CD-ROM | disk | FTP | other *** search
- function ContextMenu(id, win)
- {
- ContextMenu.prototype.uniqueID++;
- this.win = (win) ? win : window;
- this.el = this.win.document.createElement("<div id='' hidefocus tabindex=-1 style='font-size:7pt;font-family:verdana;position:absolute;visibility:hidden;overflow:hidden;cursor:hand;z-index:20000; border: outset 2px #696969; background-color:#DCDCDC' nowrap></div>");
- this.el.id = id + "_contextMenu_" + this.uniqueID;
- this.captureSet = false;
- this.items = [];
- this.over = false;
- };
- ContextMenu.prototype.uniqueID = 0;
-
- ContextMenu.prototype.write = function(adjacentEl, whereStr)
- {
- try {
- this.doc = this.win.document;
- if (!whereStr) { whereStr = "beforeEnd"; };
- if (!adjacentEl) {
- if (this.doc.readyState == "complete") {
- this.doc.body.insertAdajcentHTML("beforeEnd", this.el.outerHTML);
- } else {
- this.doc.write(this.el.outerHTML);
- }
- } else {
- adjacentEl.appendChild(this.el);
- };
- this.el = this.win.document.getElementById(this.el.id);
- for (var idx = 0; idx < this.items.length; idx++)
- {
- this.el.childNodes[idx].onitemselect = this.items[idx];
- this.el.childNodes[idx].onmousedown = this._itemDown;
- this.el.childNodes[idx].onmouseenter = this._itemOver;
- this.el.childNodes[idx].onmouseleave = this._itemOut;
- };
- this.el = this.doc.getElementById(this.el.id);
- this.el.onmousedown = this._blurMenu;
- this.doc = null; delete this.doc;
- this.el.mgr = this;
- } catch (e) {
- };
-
- win = adjacentEl = whereStr = null;
- };
- ContextMenu.prototype.addMenuItem = function(theID, text, fOnClick)
- {
- this._img = this.win.document.createElement("IMG");
- this._itemDiv = this.win.document.createElement("DIV");
-
- this._img.src = System.getInstallFolder(true) + "fe/common/images/framework/arrow_right_333333.gif";
- this._img.border = 0;
- this._img.align = "absmiddle";
-
- this._itemDiv.innerHTML = " " + this._img.outerHTML + " <span>" +text + " </span>";
- this._itemDiv.id = theID;
- this._itemDiv.style.fontFamily = "verdana";
- this._itemDiv.style.color = "black";
- this._itemDiv.style.backgroundColor = "#DCDCDC";
- this._itemDiv.style.cursor = "hand";
-
- this.el.appendChild(this._itemDiv);
- this.items[this.items.length] = fOnClick;
-
- this._img = this._itemDiv = null;
- delete this._img; delete this._itemDiv;
- };
- ContextMenu.prototype.show = function(attachElement, nDeltaX, nDeltaY, bDontAddWindowPos)
- {
- nDeltaX = (nDeltaX) ? nDeltaX : 0;
- nDeltaY = (nDeltaY) ? nDeltaY : 0;
-
- this._el_frameEl = this.el.document.parentWindow.frameElement;
- this._el_xpos_indoc = this._getRealLeft(attachElement);
- this._el_ypos_indoc = this._getRealTop(attachElement);
-
- this._el_win_xpos =((this._el_frameEl) && (!bDontAddWindowPos)) ? this._getRealLeft(this._el_frameEl) : 0;
- this._el_win_ypos =((this._el_frameEl) && (!bDontAddWindowPos)) ? this._getRealTop(this._el_frameEl) : 0;
-
- this.el.style.pixelLeft = (this._el_xpos_indoc + this._el_win_xpos + nDeltaX);
- this.el.style.pixelTop = (this._el_ypos_indoc + this._el_win_ypos + nDeltaY + 12);
- this.el.style.visibility = "visible";
- this.captureSet = true;
- this.win.document.releaseCapture();
- this.el.setCapture(false);
-
- delete this._el_xpos_indoc; delete this._el_ypos_indoc; delete this._el_win_xpos; delete this._el_win_ypos; delete this._el_frameEl;
-
- var ti = this;
- setTimeout(function() { ti._closeAfterTime(); ti=null;}, 2000);
-
- System.GUI.playSFX(7);
- };
-
- ContextMenu.prototype._closeAfterTime = function()
- {
- if (this.isOn()) {
- if (!this.over) {
- this.hide();
- } else {
- var ti = this;
- setTimeout(function() { ti._closeAfterTime(); ti = null; }, 2000);
- };
- };
- };
- ContextMenu.prototype.getHeight = function() { return this.el.offsetHeight; };
- ContextMenu.prototype.getWidth = function() { return this.el.offsetWidth; };
- ContextMenu.prototype.hide = function()
- {
- this.el.style.visibility='hidden';
- this.el.releaseCapture();
- this.captureSet = false;
- this.over = false;
- };
- ContextMenu.prototype.isOn = function() { return (this.el.style.visibility == "visible"); };
- ContextMenu.prototype._itemOver = function()
- {
- this.getElementsByTagName("SPAN")[0].style.textDecoration = "underline";
- this.style.color = "black";
- this.style.backgroundColor = "#A9A9A9";
- this.style.cursor="hand";
- System.GUI.playSFX(9);
- this.parentElement.mgr.over = true;
- };
- ContextMenu.prototype._itemOut = function()
- {
- this.getElementsByTagName("SPAN")[0].style.textDecoration = "none";
- this.style.color="black";
- this.style.backgroundColor="#DCDCDC";
- this.style.cursor="hand";
- this.parentElement.mgr.over = false;
- };
- ContextMenu.prototype._itemDown = function()
- {
- if (this.onitemselect) {
- if (typeof(this.onitemselect) == "function") this.onitemselect();
- };
- this.parentElement.mgr.hide();
- };
- ContextMenu.prototype._blurMenu = function()
- {
- this.mgr.hide();
- };
- ContextMenu.prototype._getRealLeft = function(el)
- {
- if ( !("offsetLeft" in el) ) { return 0; };
- var realLeft = el.offsetLeft;
- this._tempEl = el.offsetParent;
-
- while (this._tempEl != null)
- {
- realLeft += this._tempEl.offsetLeft;
- if (this._tempEl.style) {
- realLeft += (isNaN(parseInt(this._tempEl.style.borderLeftWidth)) ) ? 0 : parseInt(this._tempEl.style.borderLeftWidth);
- };
- this._tempEl = this._tempEl.offsetParent;
- };
- this._tempEl = el = null;
- delete this._tempEl;
- return realLeft;
- };
- ContextMenu.prototype._getRealTop = function(el)
- {
- if ( !("offsetLeft" in el) ) { return 0; };
- var realTop = el.offsetTop;
- this._tempEl = el.offsetParent;
-
- while (this._tempEl != null)
- {
- realTop += this._tempEl.offsetTop;
- if (this._tempEl.style) {
- realTop += (isNaN(parseInt(this._tempEl.style.borderTopWidth)) ) ? 0 : parseInt(this._tempEl.style.borderTopWidth);
- };
- this._tempEl = this._tempEl.offsetParent;
- };
- this._tempEl = el = null;
- delete this._tempEl;
- return realTop;
- };
-