Additional icon changes

- Add high-res webpage icon
- Show webpage icon in grayscale when no translator (except on hover, for fun)
- Remove pre-Australis icons
- Switch to CustomizableUI API for toolbar icon
- Move icon generation code to separate file
- Add Zotero.hiRes flag for Retina/etc. displays (available only after a window
  has loaded)

Known issues:

- While the gray is mostly to be less distracting, the gray/color distinction
  will probably be lost on most people. A separate guidance panel for the gray
  icon might help.
- On pages with frames, the webpage icon appears first and then is replaced
  with a translator icon.
This commit is contained in:
Dan Stillman 2015-02-18 17:03:11 -05:00
parent 0eefd24d92
commit 424ee72f58
8 changed files with 162 additions and 160 deletions

View file

@ -429,15 +429,24 @@ var Zotero_Browser = new function() {
function updateStatus() {
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
var captureIcon = tab.getCaptureIcon();
if(captureIcon) {
Zotero_Browser.statusImage.src = captureIcon;
var state = tab.getCaptureState();
if (state != tab.CAPTURE_STATE_DISABLED) {
Zotero_Browser.statusImage.src = tab.getCaptureIcon();
Zotero_Browser.statusImage.tooltipText = tab.getCaptureTooltip();
if (state == tab.CAPTURE_STATE_TRANSLATABLE) {
Zotero_Browser.statusImage.classList.add('translate');
}
else {
Zotero_Browser.statusImage.classList.remove('translate');
}
Zotero_Browser.statusImage.hidden = false;
Zotero_Browser.statusImage.addEventListener("load", function() {
document.getElementById("zotero-status-image-guidance").show();
}, false);
if (state == tab.CAPTURE_STATE_TRANSLATABLE) {
Zotero_Browser.statusImage.addEventListener("load", function() {
document.getElementById("zotero-status-image-guidance").show();
}, false);
}
// TODO: Different guidance for web pages?
} else {
Zotero_Browser.statusImage.hidden = true;
}
@ -723,6 +732,10 @@ Zotero_Browser.Tab = function(browser) {
this.page = new Object();
}
Zotero_Browser.Tab.prototype.CAPTURE_STATE_DISABLED = 0;
Zotero_Browser.Tab.prototype.CAPTURE_STATE_GENERIC = 1;
Zotero_Browser.Tab.prototype.CAPTURE_STATE_TRANSLATABLE = 2;
/*
* clears page-specific information
*/
@ -735,8 +748,6 @@ Zotero_Browser.Tab.prototype.clear = function() {
* detects translators for this browser object
*/
Zotero_Browser.Tab.prototype.detectTranslators = function(rootDoc, doc) {
this.page.saveEnabled = true;
if (doc instanceof HTMLDocument) {
if (doc.documentURI.startsWith("about:")) {
this.page.saveEnabled = false;
@ -808,55 +819,69 @@ Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) {
}
}
Zotero_Browser.Tab.prototype.getCaptureState = function () {
if (!this.page.saveEnabled) {
return this.CAPTURE_STATE_DISABLED;
}
if (this.page.translators && this.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() {
if (!this.page.saveEnabled) {
return false;
}
var suffix = Zotero.hiRes ? "@2x" : "";
if(this.page.translators && this.page.translators.length) {
switch (this.getCaptureState()) {
case this.CAPTURE_STATE_DISABLED:
return false;
case this.CAPTURE_STATE_TRANSLATABLE:
var itemType = this.page.translators[0].itemType;
return (itemType === "multiple"
? "chrome://zotero/skin/treesource-collection.png"
: Zotero.ItemTypes.getImageSrc(itemType));
}
// TODO: Show icons for images, PDFs, etc.?
return "chrome://zotero/skin/treeitem-webpage.png";
default:
return "chrome://zotero/skin/treeitem-webpage" + suffix + ".png";
}
}
Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
if (!this.page.saveEnabled) {
switch (this.getCaptureState()) {
case this.CAPTURE_STATE_DISABLED:
return '';
}
if (this.page.translators && this.page.translators.length) {
case this.CAPTURE_STATE_TRANSLATABLE:
var arr = [Zotero.getString('ingester.saveToZotero')];
if (this.page.translators[0].itemType == 'multiple') {
arr.push('...');
}
arr.push (' ' , '(' + this.page.translators[0].label + ')');
return Zotero.localeJoin(arr, '');
}
// TODO: Different captions for images, PDFs, etc.?
return Zotero.getString('ingester.saveToZotero')
+ " (" + Zotero.getString('itemTypes.webpage') + ")";
default:
return Zotero.getString('ingester.saveToZotero')
+ " (" + Zotero.getString('itemTypes.webpage') + ")";
}
}
Zotero_Browser.Tab.prototype.getCaptureCommand = function () {
if (!this.page.saveEnabled) {
switch (this.getCaptureState()) {
case this.CAPTURE_STATE_DISABLED:
return '';
}
if (this.page.translators && this.page.translators.length) {
case this.CAPTURE_STATE_TRANSLATABLE:
return '';
default:
return 'cmd_zotero_newItemFromCurrentPage';
}
return 'cmd_zotero_newItemFromCurrentPage';
}
@ -882,6 +907,8 @@ Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList, callback) {
* called when translators are available
*/
Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, translators) {
this.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
@ -906,6 +933,7 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
return; //keep what we had
} else {
this.clear(); //clear URL bar icon
this.page.saveEnabled = true;
}
Zotero.debug("Translate: found translators for page\n"
@ -914,7 +942,6 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
this.page.translate = translate;
this.page.translators = translators;
this.page.document = translate.document;
this.page.saveEnabled = true;
this.page.translate.clearHandlers("select");
this.page.translate.setHandler("select", this._selectItems);

View file

@ -0,0 +1,90 @@
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2015 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 <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
"use strict";
Components.utils.import("resource:///modules/CustomizableUI.jsm");
var buttonID = 'zotero-toolbar-button';
CustomizableUI.createWidget({
id: buttonID,
label: "Zotero",
tooltiptext: "Zotero",
defaultArea: CustomizableUI.AREA_NAVBAR,
onCommand: function () {
ZoteroOverlay.toggleDisplay();
},
onCreated: function (node) {
if (Zotero && Zotero.initialized) {
// TODO: move to strings
let str = 'Zotero';
let key = Zotero.Keys.getKeyForCommand('openZotero');
if (key) {
str += ' ('
+ (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift'))
+ key
+ ')';
}
node.setAttribute('tooltiptext', str);
var placement = CustomizableUI.getPlacementOfWidget(buttonID);
// If icon is in toolbar, show guidance panel if necessary
if (placement && placement.area == 'nav-bar') {
window.setTimeout(function() {
var isUpgrade = false;
try {
isUpgrade = Zotero.Prefs.get("firstRunGuidanceShown.saveIcon");
} catch(e) {}
var property = "firstRunGuidance.toolbarButton."+(isUpgrade ? "upgrade" : "new");
var shortcut = Zotero.getString(Zotero.isMac ? "general.keys.cmdShift" : "general.keys.ctrlShift")+
Zotero.Prefs.get("keys.openZotero");
document.getElementById("zotero-toolbar-button-guidance").show(null, Zotero.getString(property, shortcut));
});
}
}
else {
if (Zotero) {
var errMsg = Zotero.startupError;
}
// Use defaults if necessary
if (!errMsg) {
// Get the stringbundle manually
var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
getService(Components.interfaces.nsILocaleService);
var appLocale = localeService.getApplicationLocale();
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var stringBundle = stringBundleService.createBundle(src, appLocale);
var errMsg = stringBundle.GetStringFromName('startupError');
}
node.setAttribute('tooltiptext', errMsg);
node.setAttribute('error', 'true');
}
}
});

View file

@ -70,89 +70,21 @@ var ZoteroOverlay = new function()
observerService.addObserver(zoteroObserver, "browser-delayed-startup-finished", false);
// Make Zotero icon visible, if requested
// Set a flag for hi-res displays
Zotero.hiRes = window.devicePixelRatio > 1;
// Clear old Zotero icon pref
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch('extensions.zotero.');
prefBranch.clearUserPref('statusBarIcon');
var navBar = document.getElementById('nav-bar');
var iconPref = prefBranch.getIntPref('statusBarIcon');
// Add icon to toolbar if not in the window already and not hidden by the pref
if (!document.getElementById("zotero-toolbar-button") && iconPref != 0) {
navBar.insertItem("zotero-toolbar-button");
navBar.setAttribute("currentset", navBar.currentSet);
document.persist(navBar.id, "currentset");
navBar.setAttribute("collapsed", false);
document.persist(navBar.id, "collapsed");
}
var icon = document.getElementById('zotero-toolbar-button');
// Add a listener for toolbar change events
window.addEventListener("customizationchange", onToolbarChange, false);
// Add toolbar icon
Services.scriptloader.loadSubScript("chrome://zotero/content/icon.js", {}, "UTF-8");
if (Zotero && Zotero.initialized){
// TODO: Add only when progress window is open
document.getElementById('appcontent').addEventListener('mousemove', Zotero.ProgressWindowSet.updateTimers, false);
if (icon) {
// TODO: move to strings
let str = 'Zotero';
let key = Zotero.Keys.getKeyForCommand('openZotero');
if (key) {
str += ' ('
+ (Zotero.isMac ? '⇧⌘' : Zotero.getString('general.keys.ctrlShift'))
+ key
+ ')';
}
icon.setAttribute('tooltiptext', str);
// If hidden in prefs, remove from add-on bar
if (iconPref == 0) {
var toolbar = icon.parentNode;
if (toolbar.id == 'nav-bar') {
var palette = document.getElementById("navigator-toolbox").palette;
palette.appendChild(icon);
toolbar.setAttribute("currentset", toolbar.currentSet);
document.persist(toolbar.id, "currentset");
}
}
if (icon.getAttribute("cui-areatype") == "toolbar") {
window.setTimeout(function() {
var isUpgrade = false;
try {
isUpgrade = Zotero.Prefs.get("firstRunGuidanceShown.saveIcon");
} catch(e) {}
var property = "firstRunGuidance.toolbarButton."+(isUpgrade ? "upgrade" : "new");
var shortcut = Zotero.getString(Zotero.isMac ? "general.keys.cmdShift" : "general.keys.ctrlShift")+
Zotero.Prefs.get("keys.openZotero");
document.getElementById("zotero-toolbar-button-guidance").show(null, Zotero.getString(property, shortcut));
}, 0);
}
}
}
else {
if (Zotero) {
var errMsg = Zotero.startupError;
}
// Use defaults if necessary
if (!errMsg) {
// Get the stringbundle manually
var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
getService(Components.interfaces.nsILocaleService);
var appLocale = localeService.getApplicationLocale();
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var stringBundle = stringBundleService.createBundle(src, appLocale);
var errMsg = stringBundle.GetStringFromName('startupError');
}
icon.setAttribute('tooltiptext', errMsg);
icon.setAttribute('error', 'true');
}
// Used for loading pages from upgrade wizard
@ -191,28 +123,7 @@ var ZoteroOverlay = new function()
}
function onToolbarChange(e) {
// e.target seems to be navigator-toolbox in all cases,
// so check the nav-bar directly
var navBar = document.getElementById("nav-bar");
var icon = document.getElementById("zotero-toolbar-button");
if (icon) {
// If dragged to nav bar
if (navBar.getElementsByAttribute("id", "zotero-toolbar-button").length) {
var statusBarPref = Zotero.Prefs.get("statusBarIcon");
// If pref set to hide, force to full
if (statusBarPref == 0) {
Zotero.Prefs.set("statusBarIcon", 1)
}
return;
}
}
Zotero.Prefs.set("statusBarIcon", 0);
}
this.onUnload = function() {
window.removeEventListener("customizationchange", onToolbarChange, false);
ZoteroPane.destroy();
}

View file

@ -43,12 +43,6 @@
<popup id="contentAreaContextMenu"/>
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="zotero-toolbar-button" class="toolbarbutton-1"
label="Zotero"
oncommand="ZoteroOverlay.toggleDisplay();"/>
</toolbarpalette>
<toolbar id="zotero-toolbar" nowindowdrag="true"/>
<vbox id="appcontent">

View file

@ -1,7 +1,11 @@
#zotero-status-image
{
#zotero-status-image {
width: 16px;
height: 16px;
margin-right: 3px;
}
#zotero-status-image:not(.translate):not(:hover) {
filter: grayscale(100%);
}
#zotero-pane

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -22,40 +22,17 @@
}
/*
Add-on bar and toolbar icon
Toolbar icons
*/
/* Old styling */
#zotero-toolbar-button {
list-style-image: url(chrome://zotero/skin/zotero-z-24px.png);
list-style-image: url("chrome://zotero/skin/zotero-z-16px-australis.svg");
}
#zotero-toolbar-button:active {
list-style-image: url(chrome://zotero/skin/zotero-z-24px-active.png);
}
toolbar[iconsize="small"] #zotero-toolbar-button {
list-style-image: url(chrome://zotero/skin/zotero-z-16px.png);
}
toolbar[iconsize="small"] #zotero-toolbar-button:active {
list-style-image: url(chrome://zotero/skin/zotero-z-16px-active.png);
}
/* Australis styling */
#zotero-toolbar-button[cui-areatype="menu-panel"],
toolbarpaletteitem[place="palette"] > #zotero-toolbar-button,
#zotero-toolbar-button:active[cui-areatype="menu-panel"],
toolbarpaletteitem[place="palette"] > #zotero-toolbar-button:active {
list-style-image: url("chrome://zotero/skin/zotero-z-32px-australis.svg");
toolbarpaletteitem[place="palette"] > #zotero-toolbar-button {
list-style-image: url("chrome://zotero/skin/zotero-z-32px-australis.svg");
}
#zotero-toolbar-button[cui-areatype="toolbar"],
#zotero-toolbar-button:active[cui-areatype="toolbar"] {
list-style-image: url("chrome://zotero/skin/zotero-z-16px-australis.svg") !important;
}
/* Bindings */
textbox[multiline="true"][type="timed"]
{

View file

@ -26,7 +26,6 @@ pref("extensions.zotero.triggerProxyAuthentication", true);
pref("extensions.zotero.proxyAuthenticationURLs", 'http://www.acm.org,http://www.ebscohost.com,http://www.elsevier.com,http://www.ieee.org,http://www.jstor.org,http://www.ovid.com,http://www.springer.com,http://www.tandfonline.com');
pref("extensions.zotero.cacheTranslatorData",true);
pref("extensions.zotero.showIn", 1);
pref("extensions.zotero.statusBarIcon", 1);
pref("extensions.zotero.browserContentContextMenu", true);
pref("extensions.zotero.openURL.resolver","http://worldcatlibraries.org/registry/gateway");
pref("extensions.zotero.openURL.version","1.0");