1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * Contributor(s): Michael J Gruber http://locallink.mozdev.org/
16 * Alternatively, the contents of this file may be used under the terms of
17 * either the GNU General Public License Version 2 or later (the "GPL"), or
18 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
19 * in which case the provisions of the GPL or the LGPL are applicable instead
20 * of those above. If you wish to allow use of your version of this file only
21 * under the terms of either the GPL or the LGPL, and not to allow others to
22 * use your version of this file under the terms of the MPL, indicate your
23 * decision by deleting the provisions above and replace them with the notice
24 * and other provisions required by the GPL or the LGPL. If you do not delete
25 * the provisions above, a recipient may use your version of this file under
26 * the terms of any one of the MPL, the GPL or the LGPL.
28 * ***** END LICENSE BLOCK ***** */
32 // _URIFixup : Components.classes["@mozilla.org/docshell/urifixup;1"].getService(Components.interfaces.nsIURIFixup),
33 // _pref : Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null),
35 // This is the node user right clicks on, null if it is not an address node.
36 // It is initiliased and reassigned in _isOverLink() only.
39 // Modified from optimoz mosgestoverlay.js
40 // Given a node, try to get the address node of itself or its parent(s).
41 // Returns null if cannot find any.
42 _findNodeLink : function(domPosition) {
43 if (domPosition == document)
46 if(domPosition.nodeName == "A")
47 return {node : domPosition, uri : domPosition.href};
49 return this._findNodeLink(domPosition.parentNode);
56 // Returns true if the popup node is an address node.
57 _isOverLink : function() {
58 this._overLink = this._findNodeLink(document.popupNode);
59 return (this._overLink != null);
62 // Taken from LinkVisitor.
63 // This function is invoked in window (?) context,
64 // so use 'LocalLink' instead of 'this'.
65 // event.originalTarget is the loaded document.
66 onBrowserWindowLoad : function(event) {
67 var parentPopup = document.getElementById('contentAreaContextMenu');
68 parentPopup.addEventListener("popupshown", LocalLink._onParentPopupShown, true);
71 // onMailWindowLoad : function(event) {
72 // var parentPopup = document.getElementById('messagePaneContext');
73 // parentPopup.addEventListener("popupshown", LocalLink._onParentPopupShown, true);
76 // This function is invoked in window (?) context,
77 // so use 'LocalLink' instead of 'this'
78 _onParentPopupShown : function() {
79 if (LocalLink._isOverLink()) {
80 document.getElementById('llOpenLocalLink').setAttribute('hidden', false);
82 // var fixupURI = LocalLink._getFixupURI(LocalLink._overLink.uri);
83 // maybe check file: protocol
86 document.getElementById('llOpenLocalLink').setAttribute('hidden', true);
89 openLinkInThisTab : function(event) {
90 if (this._overLink == null)
93 window.loadURI(this._overLink.uri, null, null);
96 openLinkInNewTab : function(event) {
97 if (this._overLink == null)
100 openNewTabWith(this._overLink.uri, null, null, event);
103 openLinkInNewWindow : function(event) {
104 if (this._overLink == null)
107 openNewWindowWith(this._overLink.uri, null, null);
111 // openLinkInMail : function(event) {
112 // if (this._overLink == null)
115 // var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(Components.interfaces.nsIMessenger);
116 // messenger.SetWindow(window,null);
117 // messenger.OpenURL(this._overLink.uri);
120 // openLinkFromMail : function() {
121 // if (this._overLink == null)
124 // var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
125 // messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
126 // try { messenger.launchExternalURL(this._overLink.uri); }
128 // var proto = this._overLink.uri.split(/:/)[0];
129 // var bundle = document.getElementById("bundle_locallink");
130 // alert(bundle.getString("protocolNotFound").replace(/%S/, proto));
135 // _getFixupURI : function(uri) {
137 // var fixedURI = this._URIFixup.createFixupURI(uri, 0);
147 // register listener so that we can update the popup
148 // This is done from the corresponding xul
149 // gBrowser.addEventListener("load", LocalLink.onWindowLoad, true);