⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.moz.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* * Bindows 1.01 * http://www.bindows.net/ * Copyright (c) 2003-2004 MB Technologies * * Bindows(tm) belongs to MB Technologies (Georgia, USA). All rights reserved. * You are not allowed to copy or modify this code. Commercial use requires * license. */var xulNs = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";var menuCache = {    _count: 0, _idPrefix: "-menu-cache-", getId: function(){    return this._idPrefix + this._count++;} , remove: function(o){    delete this[o.id];}};function BiMenu(){    BiEventTarget.call(this);    this._children = [];    this._xulElement = document.createElementNS(xulNs, "menupopup");    this.id = menuCache.getId();    menuCache[this.id] = this;    this._xulElement.setAttribute("id", this.id);    this._xulElement.setAttribute("onpopupshowing", "menuCache[this.id]._onbeforeshow()");    this._xulElement.setAttribute("onpopupshown", "menuCache[this.id]._onshow()");    this._xulElement.setAttribute("onpopuphidden", "menuCache[this.id]._onhide()");}var _p = BiMenu.prototype = new BiEventTarget;_p._className = "BiMenu";_p._parent = null;_p._left = 0;_p._top = 0;_p._width = null;_p._height = null;_p._component = null;_p._showTimeStamp = new Date(0);_p._hideTimeStamp = new Date(0);_p._visible = false;BiMenu.prototype.getShowTimeStamp = function(){    return this._showTimeStamp;} ;BiMenu.prototype.getHideTimeStamp = function(){    return this._hideTimeStamp;} ;_p._onbeforeshow = function(){    this.dispatchEvent(new BiEvent("beforeshow"));} ;_p._onshow = function(){    this._showTimeStamp = new Date;    this._visible = true;    this._updateLocation();    this.dispatchEvent(new BiEvent("show"));};_p._onhide = function(){    this._hideTimeStamp = new Date;    this._visible = false;    this._updateLocation();    this.dispatchEvent(new BiEvent("hide"));};_p.add = function(oChild, oBefore){    if (oBefore)        this._xulElement.insertBefore(oChild._xulElement, oBefore._xulElement);    else        this._xulElement.appendChild(oChild._xulElement);    var p = oChild._parent;    if (oBefore == null)    {        if (p != null)            p.remove(oChild);        this._children.push(oChild);    }    else    {        if (oBefore._parent != this)            throw new Error("Can only add components before siblings");        if (p != null)            p.remove(oChild);        this._children.insertBefore(oChild, oBefore);    }    oChild._parent = this;};_p.remove = function(oChild){    this._xulElement.removeChild(oChild._xulElement);    if (oChild._parent != this)        throw new Error("Can only remove children");    this._children.remove(oChild);    oChild._parent = null;    return oChild;};_p.removeAll = function(){    var cs = this.getChildren();    var l = cs.length;    for (var i = 0; i < l; i++)    {        this.remove(cs[i]);        cs[i].dispose();    }};BiMenu.prototype.getParent = function(){    return this._parent;} ;_p.getParentMenu = function(){    if (this._parent)        return this._parent.getParent();    return null;};BiMenu.prototype.getChildren = function(){    return this._children;} ;_p.hasChildren = function(){    return this._children.length > 0;} ;_p.getTopLevelComponent = function(){    if (this._parent == null)        return null;    return this._parent.getTopLevelComponent();};_p.contains = function(oDescendant){    if (oDescendant == this)        return true;    var p = oDescendant.getParent();    if (p == null)        return false;    return this.contains(p);};_p.getFirstChild = function(){    return this._children[0];} ;_p.getLastChild = function(){    return this._children[this._children.length - 1];} ;_p.setVisible = function(b){    if (b)    {        this._insertContextMenu();        this._xulElement.showPopup();    }    else        this._xulElement.hidePopup();};_p.setLocation = function(nLeft, nTop){    this._left = nLeft;    this._top = nTop;    this._updateLocation();};_p._insertContextMenu = function(){    var mbLeft = 0, mbTop = 0;    if (!BiMenu._contextMenuBar)    {        var mb = BiMenu._contextMenuBar = document.createElementNS(xulNs, "menubar");        var m = document.createElementNS(xulNs, "menu");        m.setAttribute("label", "");        m.setAttribute("style", "-moz-opacity:0;");        mb.appendChild(m);        document.body.appendChild(mb);        this._updateLocation();    }    var mb = BiMenu._contextMenuBar;    var m = mb.firstChild;    BiMenu._contextMenuBar.removeChild(m);    while (m.hasChildNodes())        m.removeChild(m.lastChild);    m.appendChild(this._xulElement);    BiMenu._contextMenuBar.appendChild(m);};_p._updateLocation = function(){    if (BiMenu._contextMenuBar)    {        var mb = BiMenu._contextMenuBar;        var mbLeft = 0, mbTop = 0;        var docBo = document.getBoxObjectFor(document.documentElement);        if (this._left)            mbLeft = this._left - docBo.screenX;        if (this._top)            mbTop = this._top - docBo.screenY;        var mbHeight = mb.boxObject.height;        mb.setAttribute("style",                        "position:absolute;overflow:hidden;" + "width:0;height:0;" + "left:" + mbLeft + "px;top:"                            + (mbTop + -mbHeight) + "px;");    }};_p.setLeft = function(nLeft){    this.setLocation(nLeft, this.getTop());} ;_p.setTop = function(nTop){    this.setLocation(this.getLeft(), nTop);} ;_p.setSize = function(nWidth, nHeight){    this._width = nWidth;    this._height = nHeight;    if (this.getIsVisible())        this._xulElement.sizeTo(nWidth, nHeight);};_p.setWidth = function(nWidth){    this.setSize(nWidth, this.getHeight());} ;_p.setHeight = function(nWidth){    this.setSize(nWidth, this.getHeight());} ;_p.getIsVisible = function(){    return this._visible;} ;_p.getWidth = function(){    if (!this._xulElement.parentNode)        this._insertContextMenu();    return this._xulElement.boxObject.width;};_p.getHeight = function(){    if (!this._xulElement.parentNode)        this._insertContextMenu();    return this._xulElement.boxObject.height;};_p.getPreferredWidth = function(){    return this.getWidth();} ;_p.getPreferredHeight = function(){    return this.getHeight();} ;_p.getLeft = function(){    return this._xulElement.boxObject.x;} ;_p.getTop = function(){    return this._xulElement.boxObject.y;} ;_p.getInsetLeft = function(){    var w = this._xulElement.ownerDocument.defaultView;    return parseInt(w.getComputedStyle(this._xulElement, "").borderLeftWidth);};_p.getInsetRight = function(){    var w = this._xulElement.ownerDocument.defaultView;    return parseInt(w.getComputedStyle(this._xulElement, "").borderRightpWidth);};_p.getInsetTop = function(){    var w = this._xulElement.ownerDocument.defaultView;    return parseInt(w.getComputedStyle(this._xulElement, "").borderTopWidth);};_p.getInsetBottom = function(){    var w = this._xulElement.ownerDocument.defaultView;    return parseInt(w.getComputedStyle(this._xulElement, "").borderBottomWidth);};_p.dispose = function(){    if (this._disposed)        return;    BiEventTarget.prototype.dispose.call(this);    this._xulElement = null;    this._component = null;};BiMenu.prototype.getComponent = function(){    return this._component;} ;_p._invalidate = function(){} ;_p.addXmlNode = function(oNode, oXmlResourceParser){    if (oNode.nodeType == 1)    {        var c = oXmlResourceParser.fromNode(oNode);        if (c instanceof BiMenuItem)            this.add(c);    }};function BiMenuItem(sText, oSubMenu){    BiEventTarget.call(this);    this._subMenu = oSubMenu;    if (oSubMenu)    {        this._xulElement = document.createElementNS(xulNs, "menu");        this._xulElement.appendChild(oSubMenu._xulElement);    }    else        this._xulElement = document.createElementNS(xulNs, "menuitem");    this._xulElement.setAttribute("label", sText);    this.id = menuCache.getId();    menuCache[this.id] = this;    this._xulElement.setAttribute("id", this.id);    this._xulElement.setAttribute("oncommand", "menuCache[this.id]._onaction();event.stopPropagation()");};var _p = BiMenuItem.prototype = new BiEventTarget;_p._className = "BiMenuItem";BiMenuItem.prototype.getParent = function(){    return this._parent;} ;_p.getTopLevelComponent = function(){    if (this._parent == null)        return null;    return this._parent.getTopLevelComponent();};_p.contains = function(oDescendant){    if (oDescendant == this)        return true;    var p = oDescendant.getParent();    if (p == null)        return false;    return this.contains(p);};_p.getPreviousSibling = function(){    var p = this.getParent();    if (p == null)        return null;    var cs = p.getChildren();    return cs[cs.indexOf(this) - 1]};_p.getNextSibling = function(){    var p = this.getParent();    if (p == null)        return null;    var cs = p.getChildren();    return cs[cs.indexOf(this) + 1]};_p.getText = function(){    var s = this._xulElement.getAttribute("label");    return s != "undefined" ? s : "";};_p.setText = function(sText){    return this._xulElement.setAttribute("label", sText);} ;_p.getHtml = function(){    return BiLabel.textToHtml(this.getText());} ;_p.setHtml = function(sHtml){    this.setText(BiLabel.htmlToText(sHtml));} ;_p.setIcon = function(oIcon){    this._icon = oIcon;    if (oIcon == null)    {        this._xulElement.removeAttribute("style");        this._xulElement.removeAttribute("class");    }    else    {        this._xulElement.setAttribute("style", "list-style-image: url('" + oIcon.getUri() + "');");        this._xulElement.setAttribute("class", "menuitem-iconic menu-iconic");    }};_p.getIcon = function(){    return this._icon;} ;_p.setMnemonic = function(s){    this._xulElement.setAttribute("accesskey", s);} ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -