preferences.js (5280B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2006–2013 Center for History and New Media 5 George Mason University, Fairfax, Virginia, USA 6 http://zotero.org 7 8 This file is part of Zotero. 9 10 Zotero is free software: you can redistribute it and/or modify 11 it under the terms of the GNU Affero General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 Zotero is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Affero General Public License for more details. 19 20 You should have received a copy of the GNU Affero General Public License 21 along with Zotero. If not, see <http://www.gnu.org/licenses/>. 22 23 ***** END LICENSE BLOCK ***** 24 */ 25 26 "use strict"; 27 28 var Zotero_Preferences = { 29 init: function () { 30 if(Zotero.isConnector) { 31 Zotero.activateStandalone(); 32 window.close(); 33 return; 34 } 35 36 observerService.addObserver(function() { 37 if(Zotero.isConnector) window.close(); 38 }, "zotero-reloaded", false); 39 40 if(window.arguments) { 41 var io = window.arguments[0]; 42 io = io.wrappedJSObject || io; 43 44 if(io.pane) { 45 let tabID = io.tab; 46 let tabIndex = io.tabIndex; 47 var pane = document.getElementById(io.pane); 48 document.getElementById('zotero-prefs').showPane(pane); 49 // Select tab within pane by tab id 50 if (tabID !== undefined) { 51 if (pane.loaded) { 52 let tab = document.querySelector('tab#' + tabID); 53 if (tab) { 54 document.getElementsByTagName('tabbox')[0].selectedTab = tab; 55 } 56 } 57 else { 58 pane.addEventListener('paneload', function () { 59 let tab = document.querySelector('tab#' + tabID); 60 if (tab) { 61 document.getElementsByTagName('tabbox')[0].selectedTab = tab; 62 } 63 }) 64 } 65 } 66 // Select tab within pane by index 67 else if (tabIndex !== undefined) { 68 if (pane.loaded) { 69 document.getElementsByTagName('tabbox')[0].selectedIndex = tabIndex; 70 } 71 else { 72 pane.addEventListener('paneload', function () { 73 document.getElementsByTagName('tabbox')[0].selectedIndex = tabIndex; 74 }) 75 } 76 } 77 } 78 } else if(document.location.hash == "#cite") { 79 document.getElementById('zotero-prefs').showPane(document.getElementById("zotero-prefpane-cite")); 80 } 81 }, 82 83 onUnload: function () { 84 if (Zotero_Preferences.Debug_Output) { 85 Zotero_Preferences.Debug_Output.onUnload(); 86 } 87 }, 88 89 openURL: function (url, windowName) { 90 // Non-instantApply prefwindows are usually modal, so we can't open in the topmost window, 91 // since it's probably behind the window 92 var instantApply = Zotero.Prefs.get("browser.preferences.instantApply", true); 93 94 if (instantApply) { 95 window.opener.ZoteroPane_Local.loadURI(url, { shiftKey: true, metaKey: true }); 96 } 97 else { 98 if (Zotero.isStandalone) { 99 var io = Components.classes['@mozilla.org/network/io-service;1'] 100 .getService(Components.interfaces.nsIIOService); 101 var uri = io.newURI(url, null, null); 102 var handler = Components.classes['@mozilla.org/uriloader/external-protocol-service;1'] 103 .getService(Components.interfaces.nsIExternalProtocolService) 104 .getProtocolHandlerInfo('http'); 105 handler.preferredAction = Components.interfaces.nsIHandlerInfo.useSystemDefault; 106 handler.launchWithURI(uri, null); 107 } 108 else { 109 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] 110 .getService(Components.interfaces.nsIWindowWatcher); 111 var win = ww.openWindow( 112 window, 113 url, 114 windowName ? windowName : null, 115 "chrome=no,menubar=yes,location=yes,toolbar=yes,personalbar=yes,resizable=yes,scrollbars=yes,status=yes", 116 null 117 ); 118 } 119 } 120 }, 121 122 openHelpLink: function () { 123 var url = "http://www.zotero.org/support/preferences/"; 124 var helpTopic = document.getElementsByTagName("prefwindow")[0].currentPane.helpTopic; 125 url += helpTopic; 126 127 this.openURL(url, "helpWindow"); 128 }, 129 130 131 /** 132 * Opens a URI in the basic viewer in Standalone, or a new window in Firefox 133 */ 134 openInViewer: function (uri, newTab) { 135 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] 136 .getService(Components.interfaces.nsIWindowMediator); 137 const features = "menubar=yes,toolbar=no,location=no,scrollbars,centerscreen,resizable"; 138 139 if(Zotero.isStandalone) { 140 var win = wm.getMostRecentWindow("zotero:basicViewer"); 141 if(win) { 142 win.loadURI(uri); 143 } else { 144 window.openDialog("chrome://zotero/content/standalone/basicViewer.xul", 145 "basicViewer", "chrome,resizable,centerscreen,menubar,scrollbars", uri); 146 } 147 } else { 148 var win = wm.getMostRecentWindow("navigator:browser"); 149 if(win) { 150 if(newTab) { 151 win.gBrowser.selectedTab = win.gBrowser.addTab(uri); 152 } else { 153 win.open(uri, null, features); 154 } 155 } 156 else { 157 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] 158 .getService(Components.interfaces.nsIWindowWatcher); 159 var win = ww.openWindow(null, uri, null, features + ",width=775,height=575", null); 160 } 161 } 162 } 163 };