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

📄 nscontextmenu.js

📁 现在很火的邮件客户端软件thunderbird的源码
💻 JS
📖 第 1 页 / 共 3 页
字号:
# -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */# ***** BEGIN LICENSE BLOCK *****# Version: MPL 1.1/GPL 2.0/LGPL 2.1## The contents of this file are subject to the Mozilla Public License Version# 1.1 (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at# http://www.mozilla.org/MPL/## Software distributed under the License is distributed on an "AS IS" basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.## The Original Code is Mozilla Communicator client code, released# March 31, 1998.## The Initial Developer of the Original Code is# Netscape Communications Corporation.# Portions created by the Initial Developer are Copyright (C) 1998# the Initial Developer. All Rights Reserved.## Contributor(s):#   William A. ("PowerGUI") Law <law@netscape.com>#   Blake Ross <blakeross@telocity.com>#   Gervase Markham <gerv@gerv.net>## Alternatively, the contents of this file may be used under the terms of# either the GNU General Public License Version 2 or later (the "GPL"), or# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),# in which case the provisions of the GPL or the LGPL are applicable instead# of those above. If you wish to allow use of your version of this file only# under the terms of either the GPL or the LGPL, and not to allow others to# use your version of this file under the terms of the MPL, indicate your# decision by deleting the provisions above and replace them with the notice# and other provisions required by the GPL or the LGPL. If you do not delete# the provisions above, a recipient may use your version of this file under# the terms of any one of the MPL, the GPL or the LGPL.## ***** END LICENSE BLOCK *****/*------------------------------ nsContextMenu ---------------------------------|   This JavaScript "class" is used to implement the browser's content-area    ||   context menu.                                                              ||                                                                              ||   For usage, see references to this class in navigator.xul.                  ||                                                                              ||   Currently, this code is relatively useless for any other purpose.  In the  ||   longer term, this code will be restructured to make it more reusable.      |------------------------------------------------------------------------------*/function nsContextMenu( xulMenu ) {    this.target         = null;    this.menu           = null;    this.popupURL       = null;    this.onTextInput    = false;    this.onImage        = false;    this.onLoadedImage  = false;    this.onLink         = false;    this.onMailtoLink   = false;    this.onSaveableLink = false;    this.onMetaDataItem = false;    this.onMathML       = false;    this.link           = false;    this.inFrame        = false;    this.hasBGImage     = false;    this.isTextSelected = false;    this.inDirList      = false;    this.shouldDisplay  = true;    // Initialize new menu.    this.initMenu( xulMenu );}// Prototype for nsContextMenu "class."nsContextMenu.prototype = {    // onDestroy is a no-op at this point.    onDestroy : function () {    },    // Initialize context menu.    initMenu : function ( popup ) {        // Save menu.        this.menu = popup;        // Get contextual info.        this.setTarget( document.popupNode );                this.isTextSelected = this.isTextSelection();        this.initPopupURL();        // Initialize (disable/remove) menu items.        this.initItems();    },    initItems : function () {        this.initOpenItems();        this.initNavigationItems();        this.initViewItems();        this.initMiscItems();        this.initSaveItems();        this.initClipboardItems();        this.initMetadataItems();    },    initOpenItems : function () {        // this.showItem( "context-openlink", this.onSaveableLink || ( this.inDirList && this.onLink ) );        this.showItem( "context-openlinkintab", this.onSaveableLink || ( this.inDirList && this.onLink ) );        this.showItem( "context-sep-open", this.onSaveableLink || ( this.inDirList && this.onLink ) );    },    initNavigationItems : function () {        // Back determined by canGoBack broadcaster.        this.setItemAttrFromNode( "context-back", "disabled", "canGoBack" );        // Forward determined by canGoForward broadcaster.        this.setItemAttrFromNode( "context-forward", "disabled", "canGoForward" );                this.showItem( "context-back", !( this.isTextSelected || this.onLink || this.onImage || this.onTextInput ) );        this.showItem( "context-forward", !( this.isTextSelected || this.onLink || this.onImage || this.onTextInput ) );        this.showItem( "context-reload", !( this.isTextSelected || this.onLink || this.onImage || this.onTextInput ) );                this.showItem( "context-stop", !( this.isTextSelected || this.onLink || this.onImage || this.onTextInput ) );        this.showItem( "context-sep-stop", !( this.isTextSelected || this.onLink || this.onImage || this.onTextInput ) );        // XXX: Stop is determined in navigator.js; the canStop broadcaster is broken        //this.setItemAttrFromNode( "context-stop", "disabled", "canStop" );    },    initSaveItems : function () {        this.showItem( "context-savepage", !( this.inDirList || this.isTextSelected || this.onTextInput ) && !( this.onLink && this.onImage ) );        // Save link depends on whether we're in a link.        this.showItem( "context-savelink", this.onSaveableLink );        // Save image depends on whether there is one.        this.showItem( "context-saveimage", this.onLoadedImage );                this.showItem( "context-sendimage", this.onImage );    },    initViewItems : function () {        // View source is always OK, unless in directory listing.        this.showItem( "context-viewpartialsource-selection", this.isTextSelected && !this.onTextInput );        this.showItem( "context-viewpartialsource-mathml", this.onMathML && !this.isTextSelected );        this.showItem( "context-viewsource", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) );        this.showItem( "context-viewinfo", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) );        this.showItem( "context-sep-properties", !( this.inDirList || this.isTextSelected || this.onTextInput ) );        // Set As Wallpaper depends on whether an image was clicked on, and only works on Windows.        var isWin = navigator.appVersion.indexOf("Windows") != -1;        this.showItem( "context-setWallpaper", isWin && this.onLoadedImage );        this.showItem( "context-sep-image", this.onImage );        if( isWin && this.onLoadedImage )            // Disable the Set As Wallpaper menu item if we're still trying to load the image          this.setItemAttr( "context-setWallpaper", "disabled", (("complete" in this.target) && !this.target.complete) ? "true" : null );        this.showItem( "context-fitimage", this.onStandaloneImage && _content.document.imageResizingEnabled );        if ( this.onStandaloneImage && _content.document.imageResizingEnabled ) {          this.setItemAttr( "context-fitimage", "disabled", _content.document.imageIsOverflowing ? null : "true");          this.setItemAttr( "context-fitimage", "checked", _content.document.imageIsResized ? "true" : null);        }        // View Image depends on whether an image was clicked on.        this.showItem( "context-viewimage", this.onImage && !this.onStandaloneImage);        // View background image depends on whether there is one.        this.showItem( "context-viewbgimage", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) );        this.showItem( "context-sep-viewbgimage", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) );        this.setItemAttr( "context-viewbgimage", "disabled", this.hasBGImage ? null : "true");    },    initMiscItems : function () {        // Use "Bookmark This Link" if on a link.        this.showItem( "context-bookmarkpage", !( this.isTextSelected || this.onTextInput ) );        this.showItem( "context-bookmarklink", this.onLink && !this.onMailtoLink );        this.showItem( "context-searchselect", this.isTextSelected && !this.onTextInput );        this.showItem( "frame", this.inFrame );        this.showItem( "frame-sep", this.inFrame );        var blocking = true;        if (this.popupURL)          try {            const PM = Components.classes["@mozilla.org/PopupWindowManager;1"]                       .getService(Components.interfaces.nsIPopupWindowManager);            blocking = PM.testPermission(this.popupURL) ==                       Components.interfaces.nsIPopupWindowManager.DENY_POPUP;          } catch (e) {          }        this.showItem( "popupwindow-reject", this.popupURL && !blocking);        this.showItem( "popupwindow-allow", this.popupURL && blocking);        this.showItem( "context-sep-popup", this.popupURL);    },    initClipboardItems : function () {        // Copy depends on whether there is selected text.        // Enabling this context menu item is now done through the global        // command updating system        // this.setItemAttr( "context-copy", "disabled", !this.isTextSelected() );        goUpdateGlobalEditMenuItems();        this.showItem( "context-undo", this.onTextInput );        this.showItem( "context-redo", this.onTextInput );        this.showItem( "context-sep-undo", this.onTextInput );        this.showItem( "context-cut", this.onTextInput );        this.showItem( "context-copy", this.isTextSelected || this.onTextInput);        this.showItem( "context-paste", this.onTextInput );        this.showItem( "context-delete", this.onTextInput );        this.showItem( "context-sep-paste", this.onTextInput );        this.showItem( "context-selectall", true );        this.showItem( "context-sep-selectall", this.isTextSelected && !this.onTextInput );        // In a text area there will be nothing after select all, so we don't want a sep        // Otherwise, if there's text selected then there are extra menu items        // (search for selection and view selection source), so we do want a sep        // XXX dr        // ------        // nsDocumentViewer.cpp has code to determine whether we're        // on a link or an image. we really ought to be using that...        // Copy email link depends on whether we're on an email link.        this.showItem( "context-copyemail", this.onMailtoLink );        // Copy link location depends on whether we're on a link.        this.showItem( "context-copylink", this.onLink );        this.showItem( "context-sep-copylink", this.onLink );        // Copy image location depends on whether we're on an image.        this.showItem( "context-copyimage", this.onImage );        this.showItem( "context-sep-copyimage", this.onImage );    },    initMetadataItems : function () {        // Show if user clicked on something which has metadata.        this.showItem( "context-metadata", this.onMetaDataItem );    },    // Set various context menu attributes based on the state of the world.    setTarget : function ( node ) {        const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";        if ( node.namespaceURI == xulNS ) {          this.shouldDisplay = false;          return;        }        // Initialize contextual info.        this.onImage    = false;        this.onLoadedImage = false;        this.onStandaloneImage = false;        this.onMetaDataItem = false;        this.onTextInput = false;        this.imageURL   = "";        this.onLink     = false;        this.onMathML   = false;        this.inFrame    = false;        this.hasBGImage = false;        this.bgImageURL = "";        // Remember the node that was clicked.        this.target = node;

⌨️ 快捷键说明

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