remove mail/Tbird related stuff for now
[LocalLink.git] / src / chrome / content / locallink / locallink.js
blob21a45ec2cef150586873635e6a55b67479136aa5
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
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/
8  *
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
12  * License.
13  *
14  * Contributor(s): Michael J Gruber  http://locallink.mozdev.org/
15  *
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.
27  *
28  * ***** END LICENSE BLOCK ***** */
31 var LocalLink = {
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.
37   _overLink : null,
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)
44       return null;
45     try {
46       if(domPosition.nodeName == "A")
47         return {node : domPosition, uri : domPosition.href};
48       else
49         return this._findNodeLink(domPosition.parentNode);
50     }
51     catch(e) {
52       return null;
53     }
54   },
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);
60   },
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);
69   },
71   // onMailWindowLoad : function(event) {
72   //  var parentPopup = document.getElementById('messagePaneContext');
73   //  parentPopup.addEventListener("popupshown", LocalLink._onParentPopupShown, true);
74   // },
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
84     }
85     else
86       document.getElementById('llOpenLocalLink').setAttribute('hidden', true);
87   },
89   openLinkInThisTab : function(event) {
90     if (this._overLink == null)
91       return;
93     window.loadURI(this._overLink.uri, null, null);
94   },
96   openLinkInNewTab : function(event) {
97     if (this._overLink == null)
98       return;
100     openNewTabWith(this._overLink.uri, null, null, event);
101   },
103   openLinkInNewWindow : function(event) {
104     if (this._overLink == null)
105       return;
107     openNewWindowWith(this._overLink.uri, null, null);
108   },
111   // openLinkInMail : function(event) {
112   //  if (this._overLink == null)
113   //    return;
115   //   var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance(Components.interfaces.nsIMessenger);
116   //   messenger.SetWindow(window,null);
117   //   messenger.OpenURL(this._overLink.uri);
118   // },
120   // openLinkFromMail : function() {
121   //   if (this._overLink == null)
122   //     return;
124   //   var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance();
125   //   messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
126   //   try { messenger.launchExternalURL(this._overLink.uri); }
127   //   catch(e) {
128   //     var proto = this._overLink.uri.split(/:/)[0];
129   //     var bundle = document.getElementById("bundle_locallink");
130   //     alert(bundle.getString("protocolNotFound").replace(/%S/, proto));
131   //   }
132   // },
135 //  _getFixupURI : function(uri) {
136 //   try {
137 //      var fixedURI = this._URIFixup.createFixupURI(uri, 0);
138 //      return fixedURI;
139 //    }
140 //    catch(e) {
141 //      return null;
142 //    }
143 //  },
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);