diff --git a/chrome.manifest b/chrome.manifest index ded1a374b9b..7c64f1edba6 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -58,17 +58,7 @@ skin zotero default chrome/skin/default/zotero/ overlay chrome://browser/content/browser.xul chrome://zotero/content/overlay.xul -overlay chrome://zotero/content/preferences/preferences.xul chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -overlay chrome://zotero/content/preferences/preferences.xul#cite chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -overlay chrome://zotero/content/preferences/preferences_general.xul chrome://zotero/content/preferences/preferences_general_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -overlay chrome://zotero/content/preferences/preferences_export.xul chrome://zotero/content/preferences/preferences_export_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -overlay chrome://zotero/content/preferences/preferences_keys.xul chrome://zotero/content/preferences/preferences_keys_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} -overlay chrome://zotero/content/preferences/preferences_advanced.xul chrome://zotero/content/preferences/preferences_advanced_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} - -overlay chrome://mozapps/content/downloads/unknownContentType.xul chrome://zotero/content/downloadOverlay.xul - style chrome://browser/content/browser.xul chrome://zotero/skin/zotero.css -style chrome://global/content/customizeToolbar.xul chrome://zotero/skin/zotero.css component {e4c61080-ec2d-11da-8ad9-0800200c9a66} components/zotero-service.js component {531828f8-a16c-46be-b9aa-14845c3b010f} components/zotero-service.js diff --git a/chrome/content/zotero-platform/mac/overlay.css b/chrome/content/zotero-platform/mac/overlay.css index 40b88901622..e2bb79e24fd 100644 --- a/chrome/content/zotero-platform/mac/overlay.css +++ b/chrome/content/zotero-platform/mac/overlay.css @@ -1,94 +1,3 @@ -/* - As of Fx36, the built-in Mac styles don't properly handle a menu-button within a combined - button, so we need this ungodly mess. -*/ -#zotero-toolbar-buttons[cui-areatype="toolbar"] > separator, -#zotero-toolbar-save-button[cui-areatype="toolbar"]:not(:hover) > .toolbarbutton-menubutton-dropmarker::before, -#zotero-toolbar-buttons[cui-areatype="toolbar"]:hover > #zotero-toolbar-save-button { - box-shadow: none; -} - -#zotero-toolbar-save-button[cui-areatype="toolbar"] { - border: 0; -} - -#zotero-toolbar-main-button[cui-areatype="toolbar"] { - margin-right: 0; - border-top-right-radius: 0; - border-bottom-right-radius: 0; - padding-right: 2px; - padding-left: 2px; -} - -#zotero-toolbar-save-button[cui-areatype="toolbar"] { - margin-left: -1px; - border-top-left-radius: 0; - border-bottom-left-radius: 0; - border-left: 0 solid transparent; -} - -#zotero-toolbar-save-button[cui-areatype="toolbar"] > .toolbarbutton-menubutton-button { - min-width: 27px; - padding-left: 1px; - padding-right: 1px; -} - -/* - * Recreate standard hover effect (except in overflow list) - */ -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-button, -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker { - border-width: 1px; - border-style: solid; - border-color: var(--toolbarbutton-hover-bordercolor) !important; - box-shadow: var(--toolbarbutton-hover-boxshadow) !important; - border-top-left-radius: 0; - border-bottom-left-radius: 0; -} - -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker::before { - background: none; -} - -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-button { - border-right: 1px solid transparent; -} - -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker { - border-left: 1px solid transparent; -} - -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > .toolbarbutton-menubutton-dropmarker { - background: inherit; -} - -#zotero-toolbar-save-button[cui-areatype="toolbar"]:not([overflowedItem=true]) > .toolbarbutton-menubutton-dropmarker:hover { - background: var(--toolbarbutton-hover-background); -} - -#zotero-toolbar-main-button[cui-areatype="toolbar"] { - border-right: 1px solid transparent; -} -#zotero-toolbar-save-button[cui-areatype="toolbar"]:not([overflowedItem=true]):hover { - border-left: 0 solid transparent; -} -#zotero-toolbar-buttons[cui-areatype="toolbar"]:not([overflowedItem=true]):hover > #zotero-toolbar-save-button > .toolbarbutton-menubutton-button { - border-left: 1px solid transparent; -} - -/* - * Alterations for overflow menu - */ -#zotero-toolbar-buttons[overflowedItem=true] { - margin: 6px 4px 0; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-main-button { - max-width: 16px; -} - -/* End toolbar icons */ - #zotero-splitter { border-top: none; @@ -474,11 +383,6 @@ treechildren::-moz-tree-image { list-style-image: url('chrome://zotero/skin/mac/toolbar-note-add.png'); } -#zotero-tb-actions-menu -{ - list-style-image: url('chrome://zotero/skin/mac/cog.png'); -} - #zotero-collectionmenu > .menuitem-iconic, #zotero-itemmenu > .menuitem-iconic, #zotero-collectionmenu > .menu-iconic, #zotero-itemmenu > .menu-iconic { padding-top: 0px !important; padding-bottom: 2px !important; diff --git a/chrome/content/zotero-platform/unix/overlay.css b/chrome/content/zotero-platform/unix/overlay.css index f4bff14f362..5fb28ea65ab 100644 --- a/chrome/content/zotero-platform/unix/overlay.css +++ b/chrome/content/zotero-platform/unix/overlay.css @@ -1,159 +1,3 @@ -/* - As of Fx36, the built-in styles don't properly handle a menu-button within combined buttons. - - On Windows and Linux, the padding and hover effect (border and shading) are applied directly to - the .toolbarbutton-icon (image) instead of the toolbarbutton, so proper sizing of the SVG depends - on the total width including border and padding. -*/ - -/* - * Nav bar - */ -toolbar[id="nav-bar"] #zotero-toolbar-main-button .toolbarbutton-icon { - width: 28px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button .toolbarbutton-icon { - width: 30px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons #zotero-toolbar-main-button { - margin-right: -1px; - padding: 0; /* avoid shift on :active */ -} - -toolbar[id="nav-bar"] #zotero-toolbar-main-button .toolbarbutton-icon { - margin-left: 2px; - padding-left: 5px !important; - padding-right: 5px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button > .toolbarbutton-menubutton-button { - padding-left: 0; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button > .toolbarbutton-menubutton-button .toolbarbutton-icon { - padding-left: 6px !important; - padding-right: 6px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker { - width: 18px !important; - margin-top: 6px; - margin-bottom: 6px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - padding-left: 14px !important; - padding-right: 3px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-dropmarker > .dropmarker-icon { - margin-top: 3px; - margin-bottom: 3px; - padding-left: 8px !important; - padding-right: 8px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover > .toolbarbutton-menubutton-dropmarker > .dropmarker-icon, -toolbar[id="nav-bar"] #zotero-toolbar-save-button[open] > .toolbarbutton-menubutton-dropmarker > .dropmarker-icon { - margin-top: 0; - margin-bottom: 0; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-dropmarker > .dropmarker-icon { - margin-top: 3px; - margin-bottom: 3px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > separator { - /* Copied from .toolbarbutton-menubutton-dropmarker::before */ - display: -moz-box; - width: 1px; - height: 18px; - -moz-margin-end: -1px; - background-clip: padding-box; - background-position: center; - background-repeat: no-repeat; - background-size: 1px 18px; - box-shadow: var(--toolbarbutton-combined-boxshadow); -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-main-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button .dropmarker-icon { - border-color: var(--toolbarbutton-hover-bordercolor) !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button:hover:not(:active) > .toolbarbutton-menubutton-button > .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button:hover > .toolbarbutton-menubutton-dropmarker > .dropmarker-icon { - background: inherit; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button > .toolbarbutton-menubutton-button:hover:not(:active) > .toolbarbutton-icon, -/* This selector doesn't work, so the dropmarker doesn't get a hover effect. :hover doesn't seem - to have an effect on either part of the dropmarker */ -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker:hover > .dropmarker-icon { - background: var(--toolbarbutton-hover-background) !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button:hover:active:not([open]):not([disabled]) .toolbarbutton-menubutton-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button:hover[open]:not([disabled]) .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - background: var(--toolbarbutton-active-background); - border-color: var(--toolbarbutton-active-bordercolor); - box-shadow: var(--toolbarbutton-active-boxshadow); - transition-duration: 10ms; -} - - -/* - * Alterations for non-nav-bar toolbars - */ -toolbar:not([id="nav-bar"]) #zotero-toolbar-main-button > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-main-button-single > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button > .toolbarbutton-menubutton-button > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-button > .toolbarbutton-icon { - height: 16px; - width: 16px; - padding: 0; -} - -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-dropmarker { - margin-left: -1px; -} - -toolbar:not([id="nav-bar"]) #zotero-toolbar-buttons separator { - display: none; -} - - -/* Alterations for overflow panel */ -#zotero-toolbar-main-button-single[overflowedItem=true] .toolbarbutton-icon, -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-main-button .toolbarbutton-icon, -#zotero-toolbar-save-button-single[overflowedItem=true] .toolbarbutton-icon, -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-save-button .toolbarbutton-icon { - width: 16px; -} - -#zotero-toolbar-buttons[overflowedItem=true] { - margin-left: 0 !important; - margin-bottom: 0 !important; - margin-right: 0 !important; - padding: 0 !important; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-main-button { - max-width: 28px !important; - margin: 0 4px 0 0 !important; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-save-button .toolbarbutton-menubutton-button { - margin-left: 8px; -} -/* End toolbar buttons */ - - /* Override selected, unfocused tree row highlight color, which is too similar to the alternating row color by default diff --git a/chrome/content/zotero-platform/win/overlay.css b/chrome/content/zotero-platform/win/overlay.css index 0aa17feb820..05b28fb4678 100644 --- a/chrome/content/zotero-platform/win/overlay.css +++ b/chrome/content/zotero-platform/win/overlay.css @@ -13,183 +13,6 @@ border-bottom-color: var(--theme-border-color); } -/* - As of Fx36, the built-in styles don't properly handle a menu-button within combined buttons. - - On Windows and Linux, the padding and hover effect (border and shading) are applied directly to - the .toolbarbutton-icon (image) instead of the toolbarbutton, so proper sizing of the SVG depends - on the total width including border and padding. -*/ - -/* - * Nav bar - */ -toolbar[id="nav-bar"] #zotero-toolbar-main-button .toolbarbutton-icon { - width: 30px; /* 16 + 1 + 1 + 6 + 6 */ - padding-left: 6px !important; - padding-right: 6px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button .toolbarbutton-icon { - width: 29px; /* 16 + 6 + 6 + 1 */ - padding-left: 6px !important; - padding-right: 6px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-main-button-single .toolbarbutton-icon { - width: 32px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button-single .toolbarbutton-icon { - width: 31px; /* Compensate for border on only one side */ -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - padding-left: 4px; - padding-right: 4px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > separator { - margin-top: 11px; - margin-bottom: 11px; - -moz-margin-start: -1px !important; - -moz-margin-end: -3px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > separator, -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker::before { - width: 1px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons > #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker::before { - -moz-margin-end: -1px; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > separator, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button:not([disabled]) > .toolbarbutton-menubutton-dropmarker::before { - background-image: none; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-main-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button:not([disabled]) .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button:not([disabled]) .dropmarker-icon { - border-color: var(--toolbarbutton-hover-bordercolor) !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-main-button:not(:active) .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover:not([disabled]) > #zotero-toolbar-save-button:not(:active) .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover:not([disabled]) > #zotero-toolbar-save-button:not(:active) .dropmarker-icon { - background: var(--toolbarbutton-hover-background); -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button .dropmarker-icon { - box-shadow: none; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-main-button .toolbarbutton-icon { - border-top-right-radius: 0px !important; - border-bottom-right-radius: 0px !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-buttons:hover > #zotero-toolbar-save-button .toolbarbutton-icon { - border-top-left-radius: 0px !important; - border-bottom-left-radius: 0px !important; -} - -/* - There are two hover effects: when the toolbaritem is hovered over, and when the button is hovered over. - This applies the latter (and may not be right on different versions of Windows). -*/ -toolbar[id="nav-bar"] #zotero-toolbar-main-button:hover:not(:active):not([disabled]) > .toolbarbutton-icon, -/* - The dropmarker doesn't honor :hover, so instead of showing the hover effect for each segment individually, do the - menu-button parts together, which at least looks like a choice. -*/ -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover .toolbarbutton-menubutton-button .toolbarbutton-icon, -toolbar[id="nav-bar"] > #zotero-toolbar-save-button:hover:not(:active):not([disabled]) .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - background-color: hsla(210,48%,96%,.75) !important; -} -toolbar[id="nav-bar"] #zotero-toolbar-main-button:hover > .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover:not([disabled]) .toolbarbutton-menubutton-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover:not([disabled]) .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - border-color: hsla(210,54%,20%,.3) hsla(210,54%,20%,.35) hsla(210,54%,20%,.4) !important; - box-shadow: 0 0 1px hsla(210,54%,20%,.03), - 0 0 2px hsla(210,54%,20%,.1) !important; -} - -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover:active:not([open]):not([disabled]) .toolbarbutton-menubutton-button .toolbarbutton-icon, -toolbar[id="nav-bar"] #zotero-toolbar-save-button:hover[open]:not([disabled]) .toolbarbutton-menubutton-dropmarker .dropmarker-icon { - background: var(--toolbarbutton-active-background) !important; - border-color: var(--toolbarbutton-active-bordercolor) !important; - box-shadow: var(--toolbarbutton-active-boxshadow) !important; - transition-duration: 10ms; -} - -#zotero-toolbar-save-button[cui-areatype="toolbar"] > menupopup, -#zotero-toolbar-save-button-single[cui-areatype="toolbar"] > menupopup { - margin-top: -7px; -} - - -/* - * Alterations for non-nav-bar toolbars - */ -toolbar:not([id="nav-bar"]) #zotero-toolbar-main-button > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-main-button-single > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button > .toolbarbutton-menubutton-button > .toolbarbutton-icon, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-button > .toolbarbutton-icon { - height: 16px; - width: 16px; - padding: 0; -} - -toolbar:not([id="nav-bar"]) #zotero-toolbar-main-button-single, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-button, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button > .toolbarbutton-menubutton-button { - width: 24px; -} - -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button > .toolbarbutton-menubutton-dropmarker, -toolbar:not([id="nav-bar"]) #zotero-toolbar-save-button-single > .toolbarbutton-menubutton-dropmarker { - padding-left: 2px; - padding-right: 3px; -} - -toolbar:not([id="nav-bar"]) #zotero-toolbar-buttons separator { - display: none; -} - - -/* - * Alterations for overflow panel - */ -#zotero-toolbar-main-button-single[overflowedItem=true] .toolbarbutton-icon, -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-main-button .toolbarbutton-icon, -#zotero-toolbar-save-button-single[overflowedItem=true] .toolbarbutton-icon, -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-save-button .toolbarbutton-icon { - height: 16px; -} - -#zotero-toolbar-buttons[overflowedItem=true] { - margin: 6px 0 0 0 !important; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-main-button { - max-width: 18px; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-save-button toolbarbutton { - margin-left: 0 !important; -} - -#zotero-toolbar-buttons[overflowedItem=true] #zotero-toolbar-save-button .toolbarbutton-icon { - margin-left: 8px; - padding-right: 0 !important; -} - -/* End toolbar buttons */ - @media (min-resolution: 1.25dppx) { #zotero-toolbar .toolbarbutton-icon { diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js deleted file mode 100644 index a2ac94f8a6b..00000000000 --- a/chrome/content/zotero/browser.js +++ /dev/null @@ -1,1036 +0,0 @@ -/* - ***** BEGIN LICENSE BLOCK ***** - - Copyright © 2009 Center for History and New Media - George Mason University, Fairfax, Virginia, USA - http://zotero.org - - This file is part of Zotero. - - Zotero is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Zotero is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with Zotero. If not, see . - - - Based on code from Greasemonkey and PiggyBank - - ***** END LICENSE BLOCK ***** -*/ - -// -// Zotero Ingester Browser Functions -// - -////////////////////////////////////////////////////////////////////////////// -// -// Zotero_Browser -// -////////////////////////////////////////////////////////////////////////////// - -// Class to interface with the browser when ingesting data - -var Zotero_Browser = new function() { - this.init = init; - this.annotatePage = annotatePage; - this.toggleMode = toggleMode; - this.toggleCollapsed = toggleCollapsed; - this.chromeLoad = chromeLoad; - this.itemUpdated = itemUpdated; - this.tabClose = tabClose; - this.resize = resize; - - this.tabbrowser = null; - this.appcontent = null; - this.isScraping = false; - - var _browserData = new WeakMap(); - var _attachmentsMap = new WeakMap(); - var _detectCallbacks = []; - - var _blacklist = [ - "googlesyndication.com", - "doubleclick.net", - "questionmarket.com", - "atdmt.com", - "aggregateknowledge.com", - "ad.yieldmanager.com" - ]; - - var _locationBlacklist = [ - "zotero://debug/" - ]; - - var tools = { - 'zotero-annotate-tb-add':{ - cursor:"pointer", - event:"click", - callback:function(e) { _add("annotation", e) } - }, - 'zotero-annotate-tb-highlight':{ - cursor:"text", - event:"mouseup", - callback:function(e) { _add("highlight", e) } - }, - 'zotero-annotate-tb-unhighlight':{ - cursor:"text", - event:"mouseup", - callback:function(e) { _add("unhighlight", e) } - } - }; - - ////////////////////////////////////////////////////////////////////////////// - // - // Public Zotero_Browser methods - // - ////////////////////////////////////////////////////////////////////////////// - - - /** - * Initialize some variables and prepare event listeners for when chrome is done loading - */ - function init() { - // No gBrowser - running in standalone - if (!window.hasOwnProperty("gBrowser")) { - return; - } - - var zoteroInitDone; - if (!Zotero || Zotero.skipLoading) { - // Zotero either failed to load or is reloading in Connector mode - // In case of the latter, listen for the 'zotero-loaded' event (once) and retry - var zoteroInitDone_deferred = Zotero.Promise.defer(); - var obs = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); - var observer = { - "observe":function() { - obs.removeObserver(observer, 'zotero-loaded') - zoteroInitDone_deferred.resolve(); - } - }; - obs.addObserver(observer, 'zotero-loaded', false); - - zoteroInitDone = zoteroInitDone_deferred.promise; - } else { - zoteroInitDone = Zotero.Promise.resolve(); - } - - var chromeLoaded = Zotero.Promise.defer(); - window.addEventListener("load", function(e) { chromeLoaded.resolve() }, false); - - // Wait for Zotero to init and chrome to load before proceeding - Zotero.Promise.all([ - zoteroInitDone.then(function() { - ZoteroPane_Local.addReloadListener(reload); - reload(); - }), - chromeLoaded.promise - ]) - .then(function() { - Zotero_Browser.chromeLoad() - }); - } - - /** - * Called when Zotero is reloaded - */ - function reload() { - // Handles the display of a div showing progress in scraping - Zotero_Browser.progress = new Zotero.ProgressWindow(); - } - - /** - * Saves from current page using translator (called when the capture icon is clicked) - * - * @param {String} [translator] - * @param {Event} [event] - * @return {Promise} - */ - this.scrapeThisPage = Zotero.Promise.coroutine(function* (translator, event) { - // Perform translation - var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - var page = tab.getPageObject(); - if(page.translators && page.translators.length) { - page.translate.setTranslator(translator || page.translators[0]); - yield Zotero_Browser.performTranslation(page.translate); - } - else { - yield this.saveAsWebPage( - (event && event.shiftKey) ? !Zotero.Prefs.get('automaticSnapshots') : null - ); - } - }); - - /** - * Keep in sync with cmd_zotero_newItemFromCurrentPage - * - * @return {Promise} - */ - this.saveAsWebPage = function (includeSnapshots) { - // DEBUG: Possible to just trigger command directly with event? Assigning it to the - // command property of the icon doesn't seem to work, and neither does goDoCommand() - // from chrome://global/content/globalOverlay.js. Getting the command by id and - // running doCommand() works but doesn't pass the event. - return ZoteroPane.addItemFromPage('temporaryPDFHack', includeSnapshots); - } - - /* - * flags a page for annotation - */ - function annotatePage(id, browser) { - if (browser) { - var tab = _getTabObject(browser); - } - else { - var tab = _getTabObject(this.tabbrowser.selectedBrowser); - } - } - - /* - * toggles a tool on/off - */ - function toggleMode(toggleTool, ignoreOtherTools) { - // make sure other tools are turned off - if(!ignoreOtherTools) { - for(var tool in tools) { - if(tool != toggleTool && document.getElementById(tool).getAttribute("tool-active")) { - toggleMode(tool, true); - } - } - } - - // make sure annotation action is toggled - var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - var page = tab.getPageObject(); - if(page && page.annotations && page.annotations.clearAction) page.annotations.clearAction(); - - if(!toggleTool) return; - - var body = Zotero_Browser.tabbrowser.selectedBrowser.contentDocument.getElementsByTagName("body")[0]; - var addElement = document.getElementById(toggleTool); - - if(addElement.getAttribute("tool-active")) { - // turn off - body.style.cursor = "auto"; - addElement.removeAttribute("tool-active"); - Zotero_Browser.tabbrowser.selectedBrowser.removeEventListener(tools[toggleTool].event, tools[toggleTool].callback, true); - } else { - body.style.cursor = tools[toggleTool].cursor; - addElement.setAttribute("tool-active", "true"); - Zotero_Browser.tabbrowser.selectedBrowser.addEventListener(tools[toggleTool].event, tools[toggleTool].callback, true); - } - } - - /* - * expands all annotations - */ - function toggleCollapsed() { - var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - tab.getPageObject().annotations.toggleCollapsed(); - } - - /* - * When chrome loads, register our event handlers with the appropriate interfaces - */ - function chromeLoad() { - this.tabbrowser = gBrowser; - this.appcontent = document.getElementById("appcontent"); - - // this gives us onLocationChange, for updating when tabs are switched/created - gBrowser.tabContainer.addEventListener("TabClose", - function(e) { - //Zotero.debug("TabClose"); - Zotero_Browser.tabClose(e); - }, false); - gBrowser.tabContainer.addEventListener("TabSelect", - function(e) { - //Zotero.debug("TabSelect"); - // Note: async - Zotero_Browser.updateStatus(); - }, false); - // this is for pageshow, for updating the status of the book icon - this.appcontent.addEventListener("pageshow", contentLoad, true); - // this is for turning off the book icon when a user navigates away from a page - this.appcontent.addEventListener("pagehide", - function(e) { - //Zotero.debug("pagehide"); - Zotero_Browser.contentHide(e); - }, true); - - this.tabbrowser.addEventListener("resize", - function(e) { Zotero_Browser.resize(e) }, false); - // Resize on text zoom changes - - var reduce = document.getElementById('cmd_fullZoomReduce'); - var enlarge = document.getElementById('cmd_fullZoomEnlarge'); - var reset = document.getElementById('cmd_fullZoomReset'); - - if(reduce) reduce.addEventListener("command", - function(e) { Zotero_Browser.resize(e) }, false); - if(enlarge) enlarge.addEventListener("command", - function(e) { Zotero_Browser.resize(e) }, false); - if(reset) reset.addEventListener("command", - function(e) { Zotero_Browser.resize(e) }, false); - } - - - /* - * An event handler called when a new document is loaded. Creates a new document - * object, and updates the status of the capture icon - */ - var contentLoad = function (event) { - var doc = event.originalTarget; - var isHTML = doc instanceof HTMLDocument; - var rootDoc = (doc instanceof HTMLDocument ? doc.defaultView.top.document : doc); - var browser = Zotero_Browser.tabbrowser.getBrowserForDocument(rootDoc); - if(!browser) return; - - if(isHTML) { - // ignore blacklisted domains - try { - if(doc.domain) { - for (let i = 0; i < _blacklist.length; i++) { - let blacklistedURL = _blacklist[i]; - if(doc.domain.substr(doc.domain.length-blacklistedURL.length) == blacklistedURL) { - Zotero.debug("Ignoring blacklisted URL "+doc.location); - return; - } - } - } - } - catch (e) {} - } - - try { - if (_locationBlacklist.indexOf(doc.location.href) != -1) { - return; - } - - // Ignore TinyMCE popups - if (!doc.location.host && doc.location.href.indexOf("tinymce/") != -1) { - return; - } - } - catch (e) {} - - // get data object - var tab = _getTabObject(browser); - - if(isHTML && !Zotero.isConnector) { - var annotationID = Zotero.Annotate.getAnnotationIDFromURL(browser.currentURI.spec); - if(annotationID) { - if(Zotero.Annotate.isAnnotated(annotationID)) { - //window.alert(Zotero.getString("annotations.oneWindowWarning")); - } else { - var page = tab.getPageObject(); - if(!page.annotations) { - // enable annotation - page.annotations = new Zotero.Annotations(Zotero_Browser, browser, annotationID); - var saveAnnotations = function() { - page.annotations.save(); - page.annotations = undefined; - }; - browser.contentWindow.addEventListener('beforeunload', saveAnnotations, false); - browser.contentWindow.addEventListener('close', saveAnnotations, false); - page.annotations.load(); - } - } - } - } - - // detect translators - tab.detectTranslators(rootDoc, doc); - - // register metadata updated event - if(isHTML) { - var contentWin = doc.defaultView; - if(!contentWin.haveZoteroEventListener) { - contentWin.addEventListener("ZoteroItemUpdated", function(event) { itemUpdated(event.originalTarget) }, false); - contentWin.haveZoteroEventListener = true; - } - } - }; - - /* - * called to unregister Zotero icon, etc. - */ - this.contentHide = function (event) { - var doc = event.originalTarget; - if(!(doc instanceof HTMLDocument)) return; - - var rootDoc = (doc instanceof HTMLDocument ? doc.defaultView.top.document : doc); - var browser = Zotero_Browser.tabbrowser.getBrowserForDocument(rootDoc); - if(!browser) return; - - var tab = _getTabObject(browser); - if(!tab) return; - - var page = tab.getPageObject(); - if(!page) return; - - if(doc == page.document || doc == rootDoc) { - // clear translator only if the page on which the pagehide event was called is - // either the page to which the translator corresponded, or the root document - // (the second check is probably paranoid, but won't hurt) - tab.clear(); - } - - // update status - if(Zotero_Browser.tabbrowser.selectedBrowser == browser) { - // Note: async - this.updateStatus(); - } - } - - /** - * Called when item should be updated due to a DOM event - */ - function itemUpdated(doc) { - try { - var rootDoc = (doc instanceof HTMLDocument ? doc.defaultView.top.document : doc); - var browser = Zotero_Browser.tabbrowser.getBrowserForDocument(rootDoc); - var tab = _getTabObject(browser); - if(doc == tab.getPageObject().document || doc == rootDoc) tab.clear(); - tab.detectTranslators(rootDoc, doc); - } catch(e) { - Zotero.debug(e); - } - } - - /* - * called when a tab is closed - */ - function tabClose(event) { - // Save annotations when closing a tab, since the browser is already - // gone from tabbrowser by the time contentHide() gets called - var tab = _getTabObject(event.target); - var page = tab.getPageObject(); - if(page && page.annotations) page.annotations.save(); - tab.clear(); - - // To execute if document object does not exist - toggleMode(); - } - - - /* - * called when the window is resized - */ - function resize(event) { - var tab = _getTabObject(this.tabbrowser.selectedBrowser); - var page = tab.getPageObject(); - if(!page.annotations) return; - - page.annotations.refresh(); - } - - /* - * Updates the status of the capture icon to reflect the scrapability or lack - * thereof of the current page - */ - this.updateStatus = Zotero.Promise.coroutine(function* () { - // Wait for translator initialization. This allows detection to still run on a page at startup - // once translators have finished loading. - if (Zotero.Schema && Zotero.Schema.schemaUpdatePromise.isPending()) { - yield Zotero.Schema.schemaUpdatePromise; - } - - if (!Zotero_Browser.tabbrowser) return; - var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - - Components.utils.import("resource:///modules/CustomizableUI.jsm"); - var buttons = getSaveButtons(); - if (buttons.length) { - let state = tab.getCaptureState(); - let tooltiptext = tab.getCaptureTooltip(); - for (let { button, placement } of buttons) { - let inToolbar = placement.area == CustomizableUI.AREA_NAVBAR; - button.image = tab.getCaptureIcon(Zotero.hiDPI || !inToolbar); - button.tooltipText = tooltiptext; - if (state == tab.CAPTURE_STATE_TRANSLATABLE) { - button.classList.add('translate'); - } - else { - button.classList.remove('translate'); - } - button.removeAttribute('disabled'); - } - } - - // set annotation bar status - var page = tab.getPageObject(); - if(page.annotations && page.annotations.annotations.length) { - document.getElementById('zotero-annotate-tb').hidden = false; - toggleMode(); - } else { - document.getElementById('zotero-annotate-tb').hidden = true; - } - }); - - this.addDetectCallback = function (func) { - _detectCallbacks.push(func); - }; - - this.resolveDetectCallbacks = Zotero.Promise.coroutine(function* () { - while (_detectCallbacks.length) { - let cb = _detectCallbacks.shift(); - var res = cb(); - if (res && res.then) { - yield res.then; - } - } - }); - - function getSaveButtons() { - Components.utils.import("resource:///modules/CustomizableUI.jsm"); - var buttons = []; - - var placement = CustomizableUI.getPlacementOfWidget("zotero-toolbar-buttons"); - if (placement) { - let button = document.getElementById("zotero-toolbar-save-button"); - if (button) { - buttons.push({ - button: button, - placement: placement - }); - } - } - - placement = CustomizableUI.getPlacementOfWidget("zotero-toolbar-save-button-single"); - if (placement) { - let button = document.getElementById("zotero-toolbar-save-button-single"); - if (button) { - buttons.push({ - button: button, - placement: placement - }); - } - } - - return buttons; - } - - /** - * Called when status bar icon is right-clicked - */ - this.onStatusPopupShowing = function(e) { - var popup = e.target; - while(popup.hasChildNodes()) popup.removeChild(popup.lastChild); - - var tab = _getTabObject(this.tabbrowser.selectedBrowser); - var captureState = tab.getCaptureState(); - if (captureState == tab.CAPTURE_STATE_TRANSLATABLE) { - let translators = tab.getPageObject().translators; - for (var i=0, n = translators.length; i < n; i++) { - let translator = translators[i]; - - let menuitem = document.createElement("menuitem"); - menuitem.setAttribute("label", - Zotero.getString("ingester.saveToZoteroUsing", translator.label)); - menuitem.setAttribute("image", (translator.itemType === "multiple" - ? "chrome://zotero/skin/treesource-collection.png" - : Zotero.ItemTypes.getImageSrc(translator.itemType))); - menuitem.setAttribute("class", "menuitem-iconic"); - menuitem.addEventListener("command", function(e) { - Zotero_Browser.scrapeThisPage(translator, e); - e.stopPropagation(); - }, false); - popup.appendChild(menuitem); - } - } - - let webPageIcon = tab.getWebPageCaptureIcon(Zotero.hiDPI); - let menuitem = document.createElement("menuitem"); - menuitem.setAttribute("label", Zotero.getString('ingester.saveToZoteroAsWebPageWithSnapshot')); - menuitem.setAttribute("image", webPageIcon); - menuitem.setAttribute("class", "menuitem-iconic"); - menuitem.addEventListener("command", function (event) { - Zotero_Browser.saveAsWebPage(true); - event.stopPropagation(); - }); - popup.appendChild(menuitem); - - menuitem = document.createElement("menuitem"); - menuitem.setAttribute("label", Zotero.getString('ingester.saveToZoteroAsWebPageWithoutSnapshot')); - menuitem.setAttribute("image", webPageIcon); - menuitem.setAttribute("class", "menuitem-iconic"); - menuitem.addEventListener("command", function (event) { - Zotero_Browser.saveAsWebPage(false); - event.stopPropagation(); - }); - popup.appendChild(menuitem); - - if (captureState == tab.CAPTURE_STATE_TRANSLATABLE) { - popup.appendChild(document.createElement("menuseparator")); - - let menuitem = document.createElement("menuitem"); - menuitem.setAttribute("label", Zotero.getString("locate.libraryLookup.label")); - menuitem.setAttribute("tooltiptext", Zotero.getString("locate.libraryLookup.tooltip")); - menuitem.setAttribute("image", "chrome://zotero/skin/locate-library-lookup.png"); - menuitem.setAttribute("class", "menuitem-iconic"); - menuitem.addEventListener("command", _constructLookupFunction(tab, function(event, obj) { - var urls = []; - for (let i = 0; i < obj.newItems.length; i++) { - var url = Zotero.OpenURL.resolve(obj.newItems[i]); - if(url) urls.push(url); - } - ZoteroPane.loadURI(urls, event); - }), false); - popup.appendChild(menuitem); - - var locateEngines = Zotero.LocateManager.getVisibleEngines(); - Zotero_LocateMenu.addLocateEngines(popup, locateEngines, - _constructLookupFunction(tab, function(e, obj) { - Zotero_LocateMenu.locateItem(e, obj.newItems); - }), true); - } - } - - /** - * Translates using the specified translation instance. setTranslator() must already - * have been called - * @param {Zotero.Translate} translate - */ - this.performTranslation = Zotero.Promise.coroutine(function* (translate, libraryID, collection) { - if (Zotero.locked) { - Zotero_Browser.progress.Translation.operationInProgress(); - return; - } - - if (!Zotero.isConnector && Zotero.DB.inTransaction()) { - yield Zotero.DB.waitForTransaction(); - } - - Zotero_Browser.progress.show(); - Zotero_Browser.isScraping = true; - - // Get libraryID and collectionID - if(libraryID === undefined && ZoteroPane && !Zotero.isConnector) { - // Save to My Library by default if pane hasn't been opened - if (!ZoteroPane.collectionsView || !ZoteroPane.collectionsView.selectedTreeRow) { - libraryID = Zotero.Libraries.userLibraryID; - } - else if (!ZoteroPane.collectionsView.editable) { - Zotero_Browser.progress.Translation.cannotEditCollection(); - return; - } - else { - libraryID = ZoteroPane.getSelectedLibraryID(); - } - - collection = ZoteroPane.getSelectedCollection(); - } - - if (!Zotero.isConnector) { - if (ZoteroPane.collectionsView - && ZoteroPane.collectionsView - && ZoteroPane.collectionsView.selectedTreeRow - && ZoteroPane.collectionsView.selectedTreeRow.isPublications()) { - Zotero_Browser.progress.Translation.cannotAddToPublications(); - return; - } - - if (Zotero.Feeds.get(libraryID)) { - Zotero_Browser.progress.Translation.cannotAddToFeed(); - return; - } - } - - Zotero_Browser.progress.Translation.scrapingTo(libraryID, collection); - - translate.clearHandlers("done"); - translate.clearHandlers("itemDone"); - translate.clearHandlers("attachmentProgress"); - - var deferred = Zotero.Promise.defer(); - - translate.setHandler("done", function() { - Zotero_Browser.progress.Translation.doneHandler.apply(Zotero_Browser.progress.Translation, arguments); - Zotero_Browser.isScraping = false; - deferred.resolve(); - }); - - translate.setHandler("itemDone", function() { - let handler = Zotero_Browser.progress.Translation.itemDoneHandler(_attachmentsMap); - handler.apply(Zotero_Browser.progress.Translation, arguments); - }); - - translate.setHandler("attachmentProgress", function() { - let handler = Zotero_Browser.progress.Translation.attachmentProgressHandler(_attachmentsMap); - handler.apply(Zotero_Browser.progress.Translation, arguments); - }); - - translate.translate({ - libraryID, - collections: collection ? [collection.id] : false - }); - - return deferred.promise; - }); - - - ////////////////////////////////////////////////////////////////////////////// - // - // Private Zotero_Browser methods - // - ////////////////////////////////////////////////////////////////////////////// - - function _constructLookupFunction(tab, success) { - return function(e) { - var page = tab.getPageObject(); - page.translate.setTranslator(page.translators[0]); - page.translate.clearHandlers("done"); - page.translate.clearHandlers("itemDone"); - page.translate.setHandler("done", function(obj, status) { - if(status) { - success(e, obj); - Zotero_Browser.progress.close(); - } else { - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.lookup.error")); - Zotero_Browser.progress.startCloseTimer(8000); - } - }); - - Zotero_Browser.progress.show(); - Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.lookup.performing")); - page.translate.translate(false); - e.stopPropagation(); - } - } - - /* - * Gets a data object given a browser window object - */ - function _getTabObject(browser) { - if(!browser) return false; - var obj = _browserData.get(browser); - if(!obj) { - obj = new Zotero_Browser.Tab(browser); - _browserData.set(browser, obj); - } - return obj; - } - - /** - * Adds an annotation - */ - function _add(type, e) { - var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser); - - if(type == "annotation") { - // ignore click if it's on an existing annotation - if(e.target.getAttribute("zotero-annotation")) return; - - var annotation = tab.getPageObject().annotations.createAnnotation(); - annotation.initWithEvent(e); - - // disable add mode, now that we've used it - toggleMode(); - } else { - try { - var selection = Zotero_Browser.tabbrowser.selectedBrowser.contentWindow.getSelection(); - } catch(err) { - return; - } - if(selection.isCollapsed) return; - - if(type == "highlight") { - tab.getPageObject().annotations.highlight(selection.getRangeAt(0)); - } else if(type == "unhighlight") { - tab.getPageObject().annotations.unhighlight(selection.getRangeAt(0)); - } - - selection.removeAllRanges(); - } - - // stop propagation - e.stopPropagation(); - e.preventDefault(); - } -} - - -////////////////////////////////////////////////////////////////////////////// -// -// Zotero_Browser.Tab -// -////////////////////////////////////////////////////////////////////////////// - -Zotero_Browser.Tab = function(browser) { - this.browser = browser; - this.wm = new WeakMap(); -} - -Zotero_Browser.Tab.prototype.CAPTURE_STATE_DISABLED = 0; -Zotero_Browser.Tab.prototype.CAPTURE_STATE_GENERIC = 1; -Zotero_Browser.Tab.prototype.CAPTURE_STATE_TRANSLATABLE = 2; - -/** - * Gets page-specific information (stored in WeakMap to prevent holding - * a reference to translate) - */ -Zotero_Browser.Tab.prototype.getPageObject = function() { - var doc = this.browser.contentWindow; - if(!doc) return null; - var obj = this.wm.get(doc); - if(!obj) { - obj = {}; - this.wm.set(doc, obj); - } - return obj; -} - -/* - * Removes page-specific information from WeakMap - */ -Zotero_Browser.Tab.prototype.clear = function() { - this.wm.delete(this.browser.contentWindow); -} - -/* - * detects translators for this browser object - */ -Zotero_Browser.Tab.prototype.detectTranslators = Zotero.Promise.coroutine(function* (rootDoc, doc) { - if (Zotero.Schema && Zotero.Schema.schemaUpdatePromise.isPending()) { - yield Zotero.Schema.schemaUpdatePromise; - } - - // If document no longer exists after waiting for schema updates (probably because another page has - // been loaded), bail - if (Components.utils.isDeadWrapper(doc)) { - return; - } - - if (doc instanceof HTMLDocument) { - if (doc.documentURI.startsWith("about:")) { - return; - } - - // get translators - var me = this; - - var translate = new Zotero.Translate.Web(); - translate.setDocument(doc); - translate.setHandler("translators", function(obj, item) { me._translatorsAvailable(obj, item) }); - translate.setHandler("pageModified", function(translate, doc) { Zotero_Browser.itemUpdated(doc) }); - translate.getTranslators(true); - } else if(doc.documentURI.substr(0, 7) == "file://") { - this._attemptLocalFileImport(doc); - } -}); - - -/* - * searches for a document in all of the frames of a given document - */ -Zotero_Browser.Tab.prototype._searchFrames = function(rootDoc, searchDoc) { - if(rootDoc == searchDoc) return true; - var frames = rootDoc.getElementsByTagName("frame"); - for (let i = 0; i < frames.length; i++) { - let frame = frames[i]; - if(frame.contentDocument && - (frame.contentDocument == searchDoc || - this._searchFrames(frame.contentDocument, searchDoc))) { - return true; - } - } - - var frames = rootDoc.getElementsByTagName("iframe"); - for (let i = 0; i < frames.length; i++) { - let frame = frames[i]; - if(frame.contentDocument && - (frame.contentDocument == searchDoc || - this._searchFrames(frame.contentDocument, searchDoc))) { - return true; - } - } - - return false; -} - -/* - * Attempts import of a file; to be run on local files only - */ -Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) { - if(doc.documentURI.match(/\.csl(\.xml|\.txt)?$/i)) { - // read CSL string - var csl = Zotero.File.getContentsFromURL(doc.documentURI); - if(csl.indexOf("http://purl.org/net/xbiblio/csl") != -1) { - // looks like a CSL; try to import - Zotero.Styles.install(csl, doc.documentURI); - } - } else { - // see if we can import this file - var file = Components.classes["@mozilla.org/network/protocol;1?name=file"] - .getService(Components.interfaces.nsIFileProtocolHandler) - .getFileFromURLSpec(doc.documentURI); - - var me = this; - var translate = new Zotero.Translate.Import(); - translate.setLocation(file); - translate.setHandler("translators", function(obj, item) { me._translatorsAvailable(obj, item) }); - translate.getTranslators(); - } -} - - -Zotero_Browser.Tab.prototype.getCaptureState = function () { - var page = this.getPageObject(); - if (!page.saveEnabled) { - return this.CAPTURE_STATE_DISABLED; - } - if (page.translators && page.translators.length) { - return this.CAPTURE_STATE_TRANSLATABLE; - } - return this.CAPTURE_STATE_GENERIC; -} - -/* - * returns the URL of the image representing the translator to be called on the - * current page, or false if the page cannot be scraped - */ -Zotero_Browser.Tab.prototype.getCaptureIcon = function (hiDPI) { - switch (this.getCaptureState()) { - case this.CAPTURE_STATE_TRANSLATABLE: - var itemType = this.getPageObject().translators[0].itemType; - return (itemType === "multiple" - ? "chrome://zotero/skin/treesource-collection" + Zotero.hiDPISuffix + ".png" - : Zotero.ItemTypes.getImageSrc(itemType)); - - default: - return this.getWebPageCaptureIcon(hiDPI); - } -} - -// TODO: Show icons for images, PDFs, etc.? -Zotero_Browser.Tab.prototype.getWebPageCaptureIcon = function (hiDPI) { - return "chrome://zotero/skin/treeitem-webpage" + Zotero.hiDPISuffix + ".png"; -} - -Zotero_Browser.Tab.prototype.getCaptureTooltip = function() { - switch (this.getCaptureState()) { - case this.CAPTURE_STATE_DISABLED: - var text = Zotero.getString('ingester.saveToZotero'); - break; - - case this.CAPTURE_STATE_TRANSLATABLE: - var text = Zotero.getString('ingester.saveToZotero'); - var translator = this.getPageObject().translators[0]; - if (translator.itemType == 'multiple') { - text += '…'; - } - text += ' (' + translator.label + ')'; - break; - - // TODO: Different captions for images, PDFs, etc.? - default: - var text = Zotero.getString('ingester.saveToZotero') - + " (" + Zotero.getString('itemTypes.webpage') + ")"; - } - - var key = Zotero.Keys.getKeyForCommand('saveToZotero'); - if (key) { - // Add RLE mark in RTL mode to make shortcut render the right way - text += (Zotero.rtl ? ' \u202B' : ' ') + '(' - + (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift')) - + key - + ')'; - } - - return text; -} - -Zotero_Browser.Tab.prototype.getCaptureCommand = function () { - switch (this.getCaptureState()) { - case this.CAPTURE_STATE_DISABLED: - return ''; - case this.CAPTURE_STATE_TRANSLATABLE: - return ''; - default: - return 'cmd_zotero_newItemFromCurrentPage'; - } -} - - -/**********CALLBACKS**********/ - -/* - * called when a user is supposed to select items - */ -Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList, callback) { - // this is kinda ugly, mozillazine made me do it! honest! - var io = { dataIn:itemList, dataOut:null } - var newDialog = window.openDialog("chrome://zotero/content/ingester/selectitems.xul", - "_blank","chrome,modal,centerscreen,resizable=yes", io); - - if(!io.dataOut) { // user selected no items, so close the progress indicatior - Zotero_Browser.progress.close(); - } - - callback(io.dataOut); -} - -/* - * called when translators are available - */ -Zotero_Browser.Tab.prototype._translatorsAvailable = Zotero.Promise.coroutine(function* (translate, translators) { - var page = this.getPageObject(); - if (!page) return; - page.saveEnabled = true; - - if(translators && translators.length) { - //see if we should keep the previous set of translators - if(//we already have a translator for part of this page - page.translators && page.translators.length && page.document.location - //and the page is still there - && page.document.defaultView && !page.document.defaultView.closed - //this set of translators is not targeting the same URL as a previous set of translators, - // because otherwise we want to use the newer set, - // but only if it's not in a subframe of the previous set - && (page.document.location.href != translate.document.location.href || - Zotero.Utilities.Internal.isIframeOf(translate.document.defaultView, page.document.defaultView)) - //the best translator we had was of higher priority than the new set - && (page.translators[0].priority < translators[0].priority - //or the priority was the same, but... - || (page.translators[0].priority == translators[0].priority - //the previous set of translators targets the top frame or the current one does not either - && (page.document.defaultView == page.document.defaultView.top - || translate.document.defaultView !== page.document.defaultView.top) - )) - ) { - Zotero.debug("Translate: a better translator was already found for this page"); - return; //keep what we had - } else { - this.clear(); //clear URL bar icon - page = this.getPageObject(); - page.saveEnabled = true; - } - - Zotero.debug("Translate: found translators for page\n" - + "Best translator: " + translators[0].label + " with priority " + translators[0].priority); - page.translate = translate; - page.translators = translators; - page.document = translate.document; - - translate.clearHandlers("select"); - translate.setHandler("select", this._selectItems); - } else if(translate.type != "import" && translate.document.documentURI.length > 7 - && translate.document.documentURI.substr(0, 7) == "file://") { - this._attemptLocalFileImport(translate.document); - } - - if(!translators || !translators.length) Zotero.debug("Translate: No translators found"); - - yield Zotero_Browser.updateStatus(); - yield Zotero_Browser.resolveDetectCallbacks(); -}); - -Zotero_Browser.init(); \ No newline at end of file diff --git a/chrome/content/zotero/downloadOverlay.js b/chrome/content/zotero/downloadOverlay.js deleted file mode 100644 index 3ae485a0575..00000000000 --- a/chrome/content/zotero/downloadOverlay.js +++ /dev/null @@ -1,211 +0,0 @@ -/* - ***** BEGIN LICENSE BLOCK ***** - - Copyright © 2011 Center for History and New Media - George Mason University, Fairfax, Virginia, USA - http://zotero.org - - This file is part of Zotero. - - Zotero is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Zotero is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with Zotero. If not, see . - - ***** END LICENSE BLOCK ***** -*/ -var Zotero_DownloadOverlay = new function() { - const PDF_MIME_TYPE = "application/pdf"; - const ALLOW_LIST = [ - "application/pdf", - "application/postscript", - "application/xhtml+xml", - "text/html", - "text/plain", - /^audio\//, - /^image\//, - /^video\//, - /^application\/vnd\.oasis\.opendocument\./, - /^application\/vnd\.ms-/, - /^application\/vnd\.openxmlformats-officedocument/, - /^application\/vnd\.lotus-/, - /^application\/vnd\.wolfram\./, - "application/vnd.wordperfect", - "application/wordperfect5.1", - "application/msword", - "application/x-latex" - ]; - - /** - * Saves this item, if we are supposed to save it. - * - * @return {Boolean} True if an item was saved, false if we were not supposed to save - */ - this.handleSave = Zotero.Promise.coroutine(function* () { - if(!document.getElementById('zotero-radio').selected) return false; - - var retrieveMetadata = document.getElementById('zotero-recognizePDF').selected; - - var url = dialog.mLauncher.source.spec; - Zotero.debug("Zotero_DownloadOverlay: Downloading from "+url); - - // set up progress window - var win = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator) - .getMostRecentWindow("navigator:browser"); - var libraryID, collection; - try { - let itemGroup = win.ZoteroPane.getCollectionTreeRow(); - if (itemGroup.filesEditable && !itemGroup.isPublications()) { - libraryID = win.ZoteroPane.getSelectedLibraryID(); - collection = win.ZoteroPane.getSelectedCollection(); - } - // TODO: Just show an error instead? - else { - Zotero.debug("Cannot save files to library " + itemGroup.ref.libraryID - + " -- saving to My Library instead", 2); - libraryID = Zotero.Libraries.userLibraryID; - } - } catch(e) { - Zotero.debug(e, 1); - }; - - var recognizePDF = document.getElementById('zotero-recognizePDF').checked - && !document.getElementById('zotero-recognizePDF').hidden - && !document.getElementById('zotero-recognizePDF').disabled; - var contentType = dialog.mLauncher.MIMEInfo.MIMEType; - - // mimic dialog cancellation - dialog.onCancel(); - - // show progress dialog - var progressWin = new Zotero.ProgressWindow(); - progressWin.changeHeadline(Zotero.getString("save.link")); - progressWin.show(); - - // perform import - try { - var item = yield Zotero.Attachments.importFromURL({ - libraryID, - url, - collections: collection ? [collection.id] : [], - contentType - }); - } - catch (e) { - if (!win) return; - progressWin.addDescription(Zotero.getString("save.link.error")); - progressWin.startCloseTimer(8000); - Zotero.logError(e); - return false; - } - - if(!win) return; - - progressWin.addLines([item.getDisplayTitle()], [item.getImageSrc()]); - progressWin.startCloseTimer(); - if (collection) { - yield collection.addItem(item.id); - } - - yield win.ZoteroPane.selectItem(item.id); - - if(recognizePDF) { - var timer = Components.classes["@mozilla.org/timer;1"] - .createInstance(Components.interfaces.nsITimer); - timer.init(function() { - try { - if (item && item.getFile()) { - timer.cancel(); - Zotero.RecognizePDF.recognizeItems([item]); - } - } catch(e) { dump(e.toSource()) }; - }, 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); - } - - return true; - }); - - /** - * Called when mode in dialog has been changed - */ - this.modeChanged = function() { - var zoteroSelected = document.getElementById('zotero-radio').selected; - - // don't allow user to remember Zotero option for file type; i'm not sure anyone wants this - // to happen automatically - if(zoteroSelected) document.getElementById('rememberChoice').selected = false; - document.getElementById('rememberChoice').disabled = zoteroSelected; - document.getElementById('zotero-recognizePDF').disabled = !zoteroSelected; - - Zotero_DownloadOverlay.updateLibraryNote(); - }; - - /** - * Determines whether the note stating that the item will be saved to "My Library" is shown - */ - this.updateLibraryNote = function() { - var zoteroSelected = document.getElementById('zotero-radio').selected; - var zp = Zotero.getActiveZoteroPane(), canSave = true; - try { - canSave = zp.getCollectionTreeRow().filesEditable; - } catch(e) { - Zotero.logError(e); - }; - document.getElementById('zotero-saveToLibrary-description').hidden = !zoteroSelected || canSave; - window.sizeToContent(); - } - - /** - * Called when the save dialog is opened - */ - this.init = function() { - if(Zotero.isConnector) return; - - // Disable for filetypes people probably don't want to save - var show = false; - var mimeType = dialog.mLauncher.MIMEInfo.MIMEType.toLowerCase(); - for (let elem of ALLOW_LIST) { - if(typeof elem === "string") { - if(elem === mimeType) { - document.getElementById('zotero-container').hidden = false; - document.getElementById('zotero-radio').disabled = false; - break; - } - } else if(elem.test(mimeType)) { - document.getElementById('zotero-container').hidden = false; - document.getElementById('zotero-radio').disabled = false; - break; - } - } - - // Hook in event listener to ondialogaccept - document.documentElement.setAttribute('ondialogaccept', - 'Zotero_DownloadOverlay.handleSave().then(function (saved) { if (!saved) {' - + document.documentElement.getAttribute('ondialogaccept') - +'}})'); - - // Hook in event listener for mode change - var radios = document.getElementById('mode'). - addEventListener("command", Zotero_DownloadOverlay.modeChanged, false); - - // Set label on retrieve PDF option - if(mimeType === PDF_MIME_TYPE) { - var recognizePDF = document.getElementById('zotero-recognizePDF'); - recognizePDF.label = Zotero.getString("pane.items.menu.recognizePDF"); - recognizePDF.hidden = false; - recognizePDF.disabled = true; - } - }; -} - -window.addEventListener("load", Zotero_DownloadOverlay.init, false); -window.addEventListener("activate", Zotero_DownloadOverlay.updateLibraryNote, false); \ No newline at end of file diff --git a/chrome/content/zotero/downloadOverlay.xul b/chrome/content/zotero/downloadOverlay.xul deleted file mode 100644 index 0fe6a958749..00000000000 --- a/chrome/content/zotero/downloadOverlay.xul +++ /dev/null @@ -1,50 +0,0 @@ - - - - %zoteroDTD; -]> - - - -