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

📄 nscontextmenu.js

📁 现在很火的邮件客户端软件thunderbird的源码
💻 JS
📖 第 1 页 / 共 3 页
字号:
          reference = focusedWindow.getSelection();        else if (context == "mathml")          reference = this.target;        else          throw "not reached";        var docUrl = null; // unused (and play nice for fragments generated via XSLT too)        window.openDialog("chrome://navigator/content/viewPartialSource.xul",                          "_blank", "scrollbars,resizable,chrome,dialog=no",                          docUrl, docCharset, reference, context);    },    // Open new "view source" window with the frame's URL.    viewFrameSource : function () {        BrowserViewSourceOfDocument(this.target.ownerDocument);    },    viewInfo : function () {        BrowserPageInfo();    },    viewFrameInfo : function () {        BrowserPageInfo(this.target.ownerDocument);    },    toggleImageSize : function () {        _content.document.toggleImageSize();    },    // Change current window to the URL of the image.    viewImage : function () {        // we don't really want to open the url in a top level window because we don't have a         // browser window...for now do nothing    },    // Change current window to the URL of the background image.    viewBGImage : function () {        openTopWin( this.bgImageURL );    },    setWallpaper: function() {      var winhooks = Components.classes[ "@mozilla.org/winhooks;1" ].                       getService(Components.interfaces.nsIWindowsHooks);            winhooks.setImageAsWallpaper(this.target, false);    },        // Save URL of clicked-on frame.    saveFrame : function () {        saveDocument( this.target.ownerDocument );    },    // Save URL of clicked-on link.    saveLink : function () {        saveURL( this.linkURL(), this.linkText(), null, true );    },    // Save URL of clicked-on image.    saveImage : function () {        saveURL( this.imageURL, null, "SaveImageTitle", false );    },    // Generate email address and put it on clipboard.    copyEmail : function () {        // Copy the comma-separated list of email addresses only.        // There are other ways of embedding email addresses in a mailto:        // link, but such complex parsing is beyond us.                const kMailToLength = 7; // length of "mailto:"        var url = this.linkURL();        var qmark = url.indexOf( "?" );        var addresses;                if ( qmark > kMailToLength ) {            addresses = url.substring( kMailToLength, qmark );        } else {            addresses = url.substr( kMailToLength );        }        // Let's try to unescape it using a character set        try {          var ownerDocument = new XPCNativeWrapper(this.target, "ownerDocument").ownerDocument;          var characterSet = new XPCNativeWrapper(ownerDocument, "characterSet").characterSet;          const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]                                         .getService(Components.interfaces.nsITextToSubURI);          addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);        }        catch(ex) {          // Do nothing.        }        var clipboard = this.getService( "@mozilla.org/widget/clipboardhelper;1",                                         Components.interfaces.nsIClipboardHelper );        clipboard.copyString(addresses);    },        ///////////////    // Utilities //    ///////////////    // Create instance of component given contractId and iid (as string).    createInstance : function ( contractId, iidName ) {        var iid = Components.interfaces[ iidName ];        return Components.classes[ contractId ].createInstance( iid );    },    // Get service given contractId and iid (as string).    getService : function ( contractId, iidName ) {        var iid = Components.interfaces[ iidName ];        return Components.classes[ contractId ].getService( iid );    },    // Show/hide one item (specified via name or the item element itself).    showItem : function ( itemOrId, show ) {        var item = itemOrId.constructor == String ? document.getElementById(itemOrId) : itemOrId;        if (item)           item.hidden = !show;    },    // Set given attribute of specified context-menu item.  If the    // value is null, then it removes the attribute (which works    // nicely for the disabled attribute).    setItemAttr : function ( id, attr, val ) {        var elem = document.getElementById( id );        if ( elem ) {            if ( val == null ) {                // null indicates attr should be removed.                elem.removeAttribute( attr );            } else {                // Set attr=val.                elem.setAttribute( attr, val );            }        }    },    // Set context menu attribute according to like attribute of another node    // (such as a broadcaster).    setItemAttrFromNode : function ( item_id, attr, other_id ) {        var elem = document.getElementById( other_id );        if ( elem && elem.getAttribute( attr ) == "true" ) {            this.setItemAttr( item_id, attr, "true" );        } else {            this.setItemAttr( item_id, attr, null );        }    },    // Temporary workaround for DOM api not yet implemented by XUL nodes.    cloneNode : function ( item ) {        // Create another element like the one we're cloning.        var node = document.createElement( item.tagName );        // Copy attributes from argument item to the new one.        var attrs = item.attributes;        for ( var i = 0; i < attrs.length; i++ ) {            var attr = attrs.item( i );            node.setAttribute( attr.nodeName, attr.nodeValue );        }        // Voila!        return node;    },    // Generate fully-qualified URL for clicked-on link.    linkURL : function () {        if (this.link.href) {          return this.link.href;        }        var href = this.link.getAttributeNS("http://www.w3.org/1999/xlink","href");        if (!href || !href.match(/\S/)) {          throw "Empty href"; // Without this we try to save as the current doc, for example, HTML case also throws if empty        }        href = this.makeURLAbsolute(this.link.baseURI,href);        return href;    },    // Get text of link.    linkText : function () {        var text = gatherTextUnder( this.link );        if (!text || !text.match(/\S/)) {          text = this.link.getAttribute("title");          if (!text || !text.match(/\S/)) {            text = this.link.getAttribute("alt");            if (!text || !text.match(/\S/)) {              if (this.link.href) {                                text = this.link.href;              } else {                text = getAttributeNS("http://www.w3.org/1999/xlink", "href");                if (text && text.match(/\S/)) {                  text = this.makeURLAbsolute(this.link.baseURI, text);                }              }            }          }        }        return text;    },    //Get selected object and convert it to a string to get    //selected text.   Only use the first 15 chars.    isTextSelection : function() {        var result = false;        var selection = this.searchSelected();        var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");        var searchSelectText;        if (selection != "") {            searchSelectText = selection.toString();            if (searchSelectText.length > 15)                searchSelectText = searchSelectText.substr(0,15) + "...";            result = true;          // format "Search for <selection>" string to show in menu          searchSelectText = bundle.formatStringFromName("searchText",                                                         [searchSelectText], 1);          this.setItemAttr("context-searchselect", "label", searchSelectText);        }         return result;    },        searchSelected : function() {        var focusedWindow = document.commandDispatcher.focusedWindow;        var searchStr = focusedWindow.getSelection();;        searchStr = searchStr.toString();        searchStr = searchStr.replace( /^\s+/, "" );        searchStr = searchStr.replace(/(\n|\r|\t)+/g, " ");        searchStr = searchStr.replace(/\s+$/,"");        return searchStr;    },        // Convert relative URL to absolute, using document's <base>.    makeURLAbsolute : function ( base, url ) {        // Construct nsIURL.        var ioService = Components.classes["@mozilla.org/network/io-service;1"]                      .getService(Components.interfaces.nsIIOService);        var baseURI  = ioService.newURI(base, null, null);                return ioService.newURI(baseURI.resolve(url), null, null).spec;    },    toString : function () {        return "contextMenu.target     = " + this.target + "\n" +               "contextMenu.onImage    = " + this.onImage + "\n" +               "contextMenu.onLink     = " + this.onLink + "\n" +               "contextMenu.link       = " + this.link + "\n" +               "contextMenu.inFrame    = " + this.inFrame + "\n" +               "contextMenu.hasBGImage = " + this.hasBGImage + "\n";    },    isTargetATextBox : function ( node )    {      if (node instanceof HTMLInputElement)        return (node.type == "text" || node.type == "password")      return (node instanceof HTMLTextAreaElement);    },    // Determines whether or not the separator with the specified ID should be     // shown or not by determining if there are any non-hidden items between it    // and the previous separator.     shouldShowSeparator : function ( aSeparatorID )    {      var separator = document.getElementById(aSeparatorID);      if (separator) {        var sibling = separator.previousSibling;        while (sibling && sibling.localName != "menuseparator") {          if (sibling.getAttribute("hidden") != "true")            return true;          sibling = sibling.previousSibling;        }      }      return false;      }};

⌨️ 快捷键说明

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