2007-10-23 07:11:59 +00:00
|
|
|
/*
|
|
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
Copyright © 2009 Center for History and New Media
|
|
|
|
George Mason University, Fairfax, Virginia, USA
|
|
|
|
http://zotero.org
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
This file is part of Zotero.
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
Zotero is free software: you can redistribute it and/or modify
|
2011-05-18 18:34:22 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2009-12-28 09:47:49 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2009-12-28 09:47:49 +00:00
|
|
|
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
|
2011-05-18 18:34:22 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2009-12-28 09:47:49 +00:00
|
|
|
|
2011-05-18 18:34:22 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2009-12-28 09:47:49 +00:00
|
|
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
Based on code from Greasemonkey and PiggyBank
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
***** 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.scrapeThisPage = scrapeThisPage;
|
|
|
|
this.annotatePage = annotatePage;
|
|
|
|
this.toggleMode = toggleMode;
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
this.toggleCollapsed = toggleCollapsed;
|
2007-10-23 07:11:59 +00:00
|
|
|
this.chromeLoad = chromeLoad;
|
|
|
|
this.chromeUnload = chromeUnload;
|
|
|
|
this.contentLoad = contentLoad;
|
|
|
|
this.contentHide = contentHide;
|
|
|
|
this.tabClose = tabClose;
|
|
|
|
this.resize = resize;
|
|
|
|
this.updateStatus = updateStatus;
|
|
|
|
this.finishScraping = finishScraping;
|
|
|
|
this.itemDone = itemDone;
|
|
|
|
|
|
|
|
this.tabbrowser = null;
|
|
|
|
this.appcontent = null;
|
|
|
|
this.statusImage = null;
|
2009-04-30 00:10:03 +00:00
|
|
|
this.isScraping = false;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
var _scrapePopupShowing = false;
|
|
|
|
var _browserData = new Object();
|
|
|
|
|
|
|
|
var _blacklist = [
|
|
|
|
"googlesyndication.com",
|
|
|
|
"doubleclick.net",
|
|
|
|
"questionmarket.com",
|
|
|
|
"atdmt.com",
|
2009-04-22 00:36:29 +00:00
|
|
|
"aggregateknowledge.com",
|
|
|
|
"ad.yieldmanager.com"
|
2007-10-23 07:11:59 +00:00
|
|
|
];
|
|
|
|
|
2009-08-11 02:26:47 +00:00
|
|
|
var _locationBlacklist = [
|
|
|
|
"zotero://debug/"
|
|
|
|
];
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
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
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2010-11-30 20:34:08 +00:00
|
|
|
/**
|
|
|
|
* Initialize some variables and prepare event listeners for when chrome is done loading
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
|
|
|
function init() {
|
2011-03-02 02:08:05 +00:00
|
|
|
if (!Zotero || !Zotero.initialized || !window.hasOwnProperty("gBrowser")) {
|
2011-01-24 10:29:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
window.addEventListener("load",
|
|
|
|
function(e) { Zotero_Browser.chromeLoad(e) }, false);
|
|
|
|
window.addEventListener("unload",
|
|
|
|
function(e) { Zotero_Browser.chromeUnload(e) }, false);
|
2011-06-14 00:36:21 +00:00
|
|
|
|
|
|
|
ZoteroPane_Local.addReloadListener(reload);
|
|
|
|
reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when Zotero is reloaded
|
|
|
|
*/
|
|
|
|
function reload() {
|
|
|
|
// Handles the display of a div showing progress in scraping
|
|
|
|
Zotero_Browser.progress = new Zotero.ProgressWindow();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
/**
|
2011-01-30 09:44:01 +00:00
|
|
|
* Scrapes a page (called when the capture icon is clicked
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
* @return void
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
2011-01-30 09:44:01 +00:00
|
|
|
function scrapeThisPage(/*libraryID, collectionID*/) {
|
2009-08-08 07:38:34 +00:00
|
|
|
if (Zotero.locked) {
|
|
|
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
2009-12-30 07:22:53 +00:00
|
|
|
var desc = Zotero.localeJoin([
|
|
|
|
Zotero.getString('general.operationInProgress'),
|
|
|
|
Zotero.getString('general.operationInProgress.waitUntilFinishedAndTryAgain')
|
|
|
|
]);
|
2009-08-08 07:38:34 +00:00
|
|
|
Zotero_Browser.progress.addDescription(desc);
|
|
|
|
Zotero_Browser.progress.show();
|
|
|
|
Zotero_Browser.progress.startCloseTimer(8000);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
if (!Zotero.stateCheck()) {
|
|
|
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
2009-12-30 07:22:53 +00:00
|
|
|
var desc = Zotero.getString("ingester.scrapeErrorDescription.previousError")
|
2007-10-23 07:11:59 +00:00
|
|
|
+ ' ' + Zotero.getString("general.restartFirefoxAndTryAgain");
|
|
|
|
Zotero_Browser.progress.addDescription(desc);
|
|
|
|
Zotero_Browser.progress.show();
|
|
|
|
Zotero_Browser.progress.startCloseTimer(8000);
|
|
|
|
return;
|
|
|
|
}
|
2011-01-30 09:44:01 +00:00
|
|
|
|
|
|
|
// get libraryID and collectionID
|
|
|
|
var libraryID, collectionID;
|
2011-06-14 00:36:21 +00:00
|
|
|
if(ZoteroPane && !Zotero.isConnector) {
|
2011-02-03 05:00:08 +00:00
|
|
|
libraryID = ZoteroPane.getSelectedLibraryID();
|
|
|
|
collectionID = ZoteroPane.getSelectedCollection(true);
|
2011-01-30 09:44:01 +00:00
|
|
|
} else {
|
|
|
|
libraryID = collectionID = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// translate into specified library and collection
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
_getTabObject(this.tabbrowser.selectedBrowser).translate(libraryID, collectionID);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
if(tab.page && tab.page.annotations && tab.page.annotations.clearAction) tab.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
|
|
|
|
*/
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
function toggleCollapsed() {
|
2007-10-23 07:11:59 +00:00
|
|
|
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
tab.page.annotations.toggleCollapsed();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called to hide the collection selection popup
|
|
|
|
*/
|
|
|
|
function hidePopup(collectionID) {
|
|
|
|
_scrapePopupShowing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called to show the collection selection popup
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
*
|
|
|
|
* not currently used
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
|
|
|
function showPopup(collectionID, parentElement) {
|
|
|
|
if(_scrapePopupShowing && parentElement.hasChildNodes()) {
|
|
|
|
return false; // Don't dynamically reload popups that are already showing
|
|
|
|
}
|
|
|
|
_scrapePopupShowing = true;
|
|
|
|
parentElement.removeAllItems();
|
|
|
|
|
|
|
|
if(collectionID == null) { // show library
|
|
|
|
var newItem = document.createElement("menuitem");
|
|
|
|
newItem.setAttribute("label", Zotero.getString("pane.collections.library"));
|
|
|
|
newItem.setAttribute("class", "menuitem-iconic zotero-scrape-popup-library");
|
|
|
|
newItem.setAttribute("oncommand", 'Zotero_Browser.scrapeThisPage()');
|
|
|
|
parentElement.appendChild(newItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
var childrenList = Zotero.getCollections(collectionID);
|
|
|
|
for(var i = 0; i < childrenList.length; i++) {
|
|
|
|
if(childrenList[i].hasChildCollections()) {
|
|
|
|
var newItem = document.createElement("menu");
|
|
|
|
var subMenu = document.createElement("menupopup");
|
|
|
|
subMenu.setAttribute("onpopupshowing", 'Zotero_Browser.showPopup("'+childrenList[i].getID()+'", this)');
|
|
|
|
newItem.setAttribute("class", "menu-iconic zotero-scrape-popup-collection");
|
|
|
|
newItem.appendChild(subMenu);
|
|
|
|
} else {
|
|
|
|
var newItem = document.createElement("menuitem");
|
|
|
|
newItem.setAttribute("class", "menuitem-iconic zotero-scrape-popup-collection");
|
|
|
|
}
|
|
|
|
newItem.setAttribute("label", childrenList[i].getName());
|
|
|
|
newItem.setAttribute("oncommand", 'Zotero_Browser.scrapeThisPage("'+childrenList[i].getID()+'")');
|
|
|
|
|
|
|
|
parentElement.appendChild(newItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When chrome loads, register our event handlers with the appropriate interfaces
|
|
|
|
*/
|
|
|
|
function chromeLoad() {
|
2010-11-04 01:30:59 +00:00
|
|
|
this.tabbrowser = gBrowser;
|
2007-10-23 07:11:59 +00:00
|
|
|
this.appcontent = document.getElementById("appcontent");
|
|
|
|
this.statusImage = document.getElementById("zotero-status-image");
|
|
|
|
|
|
|
|
// this gives us onLocationChange, for updating when tabs are switched/created
|
2010-11-04 01:30:59 +00:00
|
|
|
gBrowser.tabContainer.addEventListener("TabClose",
|
2007-10-23 07:11:59 +00:00
|
|
|
function(e) {
|
|
|
|
//Zotero.debug("TabClose");
|
|
|
|
Zotero_Browser.tabClose(e);
|
|
|
|
}, false);
|
2010-11-04 01:30:59 +00:00
|
|
|
gBrowser.tabContainer.addEventListener("TabSelect",
|
2007-10-23 07:11:59 +00:00
|
|
|
function(e) {
|
2010-11-04 01:31:30 +00:00
|
|
|
//Zotero.debug("TabSelect");
|
2007-10-23 07:11:59 +00:00
|
|
|
Zotero_Browser.updateStatus();
|
|
|
|
}, false);
|
|
|
|
// this is for pageshow, for updating the status of the book icon
|
|
|
|
this.appcontent.addEventListener("pageshow",
|
|
|
|
function(e) {
|
|
|
|
//Zotero.debug("pageshow");
|
|
|
|
Zotero_Browser.contentLoad(e);
|
|
|
|
}, 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
|
Initial Zotero 1.5 Megacommit
Apologies for the massive (and, due to data_access.js splitting, difficult-to-follow) commit. Please note that external code that accesses the data layer may need to be tweaked for compatibility. Here's a comprehensive-as-possible changelog:
- Added server sync functionality (incomplete)
- Overhaul of data layer
- Split data_access.js into separate files (item.js, items.js, creator.js, etc.)
- Made creators and collections first-class objects, similar to items
- Constructors now take id as first parameter, e.g. new Zotero.Item(1234, 'book'), to allow explicit id setting and id changing
- Made various data layer operations (including attachment fields) require a save() rather than making direct DB changes
- Better handling of unsaved objects
- Item.setCreator() now takes creator objects instead of creator ids, and Item.save() will auto-save unsaved creators
- clone() now works on unsaved objects
- Newly created object instances are now disabled after save() to force refetch of globally accessible instance using Zotero.(Items|Creators|etc.).get()
- Added secondary lookup key to data objects
- Deprecated getID() and getItemType() methods in favor of .id and .itemTypeID properties
- toArray() deprecated in favor of serialize(), which has a somewhat modified format
- Added support for multiple creators with identical data -- currently unimplemented in interface and most of data layer
- Added Item.diff() for comparing item metadata
- Database changes
- Added SQLite triggers to enforce foreign key constraints
- Added Zotero.DB.transactionVacuum flag to run a VACUUM after a transaction
- Added Zotero.DB.transactionDate, .transactionDateTime, and transactionTimestamp to retrieve consistent timestamps for entire transaction
- Properly store 64-bit integers
- Set PRAGMA locking_mode=EXCLUSIVE on database
- Set SQLite page size to 4096 on new databases
- Set SQLite page cache to 8MB
- Do some database cleanup and integrity checking on migration from 1.0 branch
- Removed IF NOT EXISTS from userdata.sql CREATE statements -- userdata.sql is now processed only on DB initialization
- Removed itemNoteTitles table and moved titles into itemNotes
- Abstracted metadata edit box and note box into flexible XBL bindings with various modes, including read-only states
- Massive speed-up of item tree view
- Several fixes from 1.0 branch for Fx3 compatibility
- Added Notifier observer to log delete events for syncing
- Zotero.Utilities changes
- New methods getSQLDataType() and md5()
- Removed onError from Zotero.Utilities.HTTP.doGet()
- Don't display more than 1024 characters in doPost() debug output
- Don't display passwords in doPost() debug output
- Added Zotero.Notifier.untrigger() -- currently unused
- Added Zotero.reloadDataObjects() to reset all in-memory objects
- Added |chars| parameter to Zotero.randomString(len, chars)
- Added Zotero.Date.getUnixTimestamp() and Date.toUnixTimestamp(JSDate)
- Adjusted zotero-service.js to simplify file inclusion
Various things (such as tags) are temporarily broken.
2008-05-04 08:32:48 +00:00
|
|
|
|
|
|
|
// Fx2
|
|
|
|
var reduce = document.getElementById('cmd_textZoomReduce');
|
|
|
|
if (reduce) {
|
|
|
|
var enlarge = document.getElementById('cmd_textZoomEnlarge');
|
|
|
|
var reset = document.getElementById('cmd_textZoomReset');
|
|
|
|
}
|
|
|
|
// Fx3
|
|
|
|
else {
|
|
|
|
var reduce = document.getElementById('cmd_fullZoomReduce');
|
|
|
|
var enlarge = document.getElementById('cmd_fullZoomEnlarge');
|
|
|
|
var reset = document.getElementById('cmd_fullZoomReset');
|
|
|
|
}
|
|
|
|
|
2010-03-28 07:21:17 +00:00
|
|
|
if(reduce) reduce.addEventListener("command",
|
2007-10-23 07:11:59 +00:00
|
|
|
function(e) { Zotero_Browser.resize(e) }, false);
|
2010-03-28 07:21:17 +00:00
|
|
|
if(enlarge) enlarge.addEventListener("command",
|
2007-10-23 07:11:59 +00:00
|
|
|
function(e) { Zotero_Browser.resize(e) }, false);
|
2010-03-28 07:21:17 +00:00
|
|
|
if(reset) reset.addEventListener("command",
|
2007-10-23 07:11:59 +00:00
|
|
|
function(e) { Zotero_Browser.resize(e) }, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-02 02:08:05 +00:00
|
|
|
* Called when chrome is unloaded
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
|
|
|
function chromeUnload() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An event handler called when a new document is loaded. Creates a new document
|
|
|
|
* object, and updates the status of the capture icon
|
|
|
|
*/
|
|
|
|
function contentLoad(event) {
|
|
|
|
var isHTML = event.originalTarget instanceof HTMLDocument;
|
|
|
|
var doc = event.originalTarget;
|
|
|
|
var rootDoc = doc;
|
|
|
|
|
|
|
|
if(isHTML) {
|
|
|
|
// get the appropriate root document to check which browser we're on
|
|
|
|
while(rootDoc.defaultView.frameElement) {
|
|
|
|
rootDoc = rootDoc.defaultView.frameElement.ownerDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore blacklisted domains
|
|
|
|
try {
|
|
|
|
if(doc.domain) {
|
|
|
|
for each(var blacklistedURL in _blacklist) {
|
|
|
|
if(doc.domain.substr(doc.domain.length-blacklistedURL.length) == blacklistedURL) {
|
|
|
|
Zotero.debug("Ignoring blacklisted URL "+doc.location);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
}
|
|
|
|
|
2009-08-11 02:26:47 +00:00
|
|
|
try {
|
|
|
|
if (_locationBlacklist.indexOf(doc.location.href) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
2010-10-09 18:03:03 +00:00
|
|
|
|
|
|
|
// Ignore TinyMCE popups
|
2011-02-04 03:51:33 +00:00
|
|
|
if (!doc.location.host && doc.location.href.indexOf("tinymce/") != -1) {
|
2010-10-09 18:03:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-11 02:26:47 +00:00
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
|
2007-10-23 07:11:59 +00:00
|
|
|
// Figure out what browser this contentDocument is associated with
|
|
|
|
var browser;
|
|
|
|
for(var i=0; i<this.tabbrowser.browsers.length; i++) {
|
|
|
|
if(rootDoc == this.tabbrowser.browsers[i].contentDocument) {
|
|
|
|
browser = this.tabbrowser.browsers[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!browser) return;
|
|
|
|
|
|
|
|
// get data object
|
|
|
|
var tab = _getTabObject(browser);
|
|
|
|
|
2011-06-14 00:36:21 +00:00
|
|
|
if(isHTML && !Zotero.isConnector) {
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
var annotationID = Zotero.Annotate.getAnnotationIDFromURL(browser.currentURI.spec);
|
|
|
|
if(annotationID) {
|
|
|
|
if(Zotero.Annotate.isAnnotated(annotationID)) {
|
2007-10-23 07:11:59 +00:00
|
|
|
window.alert(Zotero.getString("annotations.oneWindowWarning"));
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
} else if(!tab.page.annotations) {
|
2007-10-23 07:11:59 +00:00
|
|
|
// enable annotation
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
tab.page.annotations = new Zotero.Annotations(this, browser, annotationID);
|
|
|
|
var saveAnnotations = function() {
|
|
|
|
tab.page.annotations.save();
|
|
|
|
tab.page.annotations = undefined;
|
|
|
|
};
|
|
|
|
browser.contentWindow.addEventListener('beforeunload', saveAnnotations, false);
|
|
|
|
browser.contentWindow.addEventListener('close', saveAnnotations, false);
|
|
|
|
tab.page.annotations.load();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// detect translators
|
|
|
|
tab.detectTranslators(rootDoc, doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called to unregister Zotero icon, etc.
|
|
|
|
*/
|
|
|
|
function contentHide(event) {
|
2009-01-11 10:08:53 +00:00
|
|
|
if(event.originalTarget instanceof HTMLDocument) {
|
|
|
|
// Get root document if this is a frameset
|
2007-10-23 07:11:59 +00:00
|
|
|
var doc = event.originalTarget;
|
2009-01-11 10:08:53 +00:00
|
|
|
var rootDoc = doc;
|
|
|
|
while(rootDoc.defaultView.frameElement) {
|
|
|
|
rootDoc = rootDoc.defaultView.frameElement.ownerDocument;
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
// Figure out what browser this contentDocument is associated with
|
|
|
|
var browser;
|
|
|
|
for(var i=0; i<this.tabbrowser.browsers.length; i++) {
|
2009-01-11 10:08:53 +00:00
|
|
|
if(rootDoc == this.tabbrowser.browsers[i].contentDocument) {
|
2007-10-23 07:11:59 +00:00
|
|
|
browser = this.tabbrowser.browsers[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var tab = _getTabObject(browser);
|
|
|
|
if(!tab) return;
|
2009-01-11 10:08:53 +00:00
|
|
|
if(doc == tab.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();
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
|
|
|
|
// update status
|
|
|
|
if(this.tabbrowser.selectedBrowser == browser) {
|
|
|
|
updateStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
if(tab.page && tab.page.annotations) tab.page.annotations.save();
|
|
|
|
tab.clear();
|
|
|
|
|
|
|
|
// To execute if document object does not exist
|
|
|
|
_deleteTabObject(event.target.linkedBrowser);
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
toggleMode();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when the window is resized
|
|
|
|
*/
|
|
|
|
function resize(event) {
|
|
|
|
var tab = _getTabObject(this.tabbrowser.selectedBrowser);
|
|
|
|
if(!tab.page.annotations) return;
|
|
|
|
|
|
|
|
tab.page.annotations.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Updates the status of the capture icon to reflect the scrapability or lack
|
|
|
|
* thereof of the current page
|
|
|
|
*/
|
|
|
|
function updateStatus() {
|
|
|
|
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
|
|
|
|
|
|
|
|
var captureIcon = tab.getCaptureIcon();
|
|
|
|
if(captureIcon) {
|
|
|
|
Zotero_Browser.statusImage.src = captureIcon;
|
|
|
|
Zotero_Browser.statusImage.tooltipText = tab.getCaptureTooltip();
|
|
|
|
Zotero_Browser.statusImage.hidden = false;
|
|
|
|
} else {
|
|
|
|
Zotero_Browser.statusImage.hidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set annotation bar status
|
|
|
|
if(tab.page.annotations) {
|
|
|
|
document.getElementById('zotero-annotate-tb').hidden = false;
|
|
|
|
toggleMode();
|
|
|
|
} else {
|
|
|
|
document.getElementById('zotero-annotate-tb').hidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback to be executed when scraping is complete
|
|
|
|
*/
|
|
|
|
function finishScraping(obj, returnValue) {
|
|
|
|
if(!returnValue) {
|
2009-04-30 00:10:03 +00:00
|
|
|
Zotero_Browser.progress.show();
|
2007-10-23 07:11:59 +00:00
|
|
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scrapeError"));
|
|
|
|
// Include link to Known Translator Issues page
|
|
|
|
var url = "http://www.zotero.org/documentation/known_translator_issues";
|
|
|
|
var linkText = '<a href="' + url + '" tooltiptext="' + url + '">'
|
|
|
|
+ Zotero.getString('ingester.scrapeErrorDescription.linkText') + '</a>';
|
|
|
|
Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText));
|
2009-04-30 00:10:03 +00:00
|
|
|
Zotero_Browser.progress.startCloseTimer(8000);
|
|
|
|
} else {
|
|
|
|
Zotero_Browser.progress.startCloseTimer();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
2009-04-30 00:10:03 +00:00
|
|
|
Zotero_Browser.isScraping = false;
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback to be executed when an item has been finished
|
|
|
|
*/
|
2011-06-21 19:55:00 +00:00
|
|
|
function itemDone(obj, dbItem, item, collection) {
|
2011-06-14 00:36:21 +00:00
|
|
|
var title = item.title;
|
|
|
|
var icon = Zotero.ItemTypes.getImageSrc(item.itemType);
|
2009-04-30 00:10:03 +00:00
|
|
|
Zotero_Browser.progress.show();
|
2007-10-23 07:11:59 +00:00
|
|
|
Zotero_Browser.progress.changeHeadline(Zotero.getString("ingester.scraping"));
|
|
|
|
Zotero_Browser.progress.addLines([title], [icon]);
|
|
|
|
|
|
|
|
// add item to collection, if one was specified
|
|
|
|
if(collection) {
|
2011-06-21 19:55:00 +00:00
|
|
|
collection.addItem(dbItem.id);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
2009-04-30 00:10:03 +00:00
|
|
|
|
|
|
|
if(Zotero_Browser.isScraping) {
|
|
|
|
// initialize close timer between item saves in case translator doesn't call done
|
|
|
|
Zotero_Browser.progress.startCloseTimer(10000); // is this long enough?
|
|
|
|
} else {
|
|
|
|
// if we aren't supposed to be scraping now, the translator is broken; assume we're
|
|
|
|
// done
|
|
|
|
Zotero_Browser.progress.startCloseTimer();
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Private Zotero_Browser methods
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets a data object given a browser window object
|
|
|
|
*
|
|
|
|
* NOTE: Browser objects are associated with document objects via keys generated
|
|
|
|
* from the time the browser object is opened. I'm not sure if this is the
|
|
|
|
* appropriate mechanism for handling this, but it's what PiggyBank used and it
|
|
|
|
* appears to work.
|
|
|
|
*
|
|
|
|
* Currently, the data object contains only one property: "translators," which
|
|
|
|
* is an array of translators that should work with the given page as returned
|
|
|
|
* from Zotero.Translate.getTranslator()
|
|
|
|
*/
|
|
|
|
function _getTabObject(browser) {
|
|
|
|
if(!browser) return false;
|
|
|
|
try {
|
|
|
|
var key = browser.getAttribute("zotero-key");
|
|
|
|
if(_browserData[key]) {
|
|
|
|
return _browserData[key];
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if(!key) {
|
|
|
|
var key = (new Date()).getTime();
|
|
|
|
browser.setAttribute("zotero-key", key);
|
|
|
|
return (_browserData[key] = new Zotero_Browser.Tab(browser));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deletes the document object associated with a given browser window object
|
|
|
|
*/
|
|
|
|
function _deleteTabObject(browser) {
|
|
|
|
if(!browser) return false;
|
|
|
|
try {
|
|
|
|
var key = browser.getAttribute("zotero-key");
|
|
|
|
if(_browserData[key]) {
|
|
|
|
delete _browserData[key];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} finally {}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.page.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") {
|
Merged revisions 3080-3081,3084,3087-3088,3090,3092,3099-3103,3113-3114,3132,3134-3143,3145,3148-3151,3154-3159,3165,3174,3194,3234-3235,3239-3240,3244,3246-3254,3258-3262,3268,3270,3274,3279,3286-3288,3294-3295 from 1.0 branch via svnmerge
2008-09-01 01:54:00 +00:00
|
|
|
tab.page.annotations.highlight(selection.getRangeAt(0));
|
2007-10-23 07:11:59 +00:00
|
|
|
} else if(type == "unhighlight") {
|
|
|
|
tab.page.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.page = new Object();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clears page-specific information
|
|
|
|
*/
|
|
|
|
Zotero_Browser.Tab.prototype.clear = function() {
|
|
|
|
delete this.page;
|
|
|
|
this.page = new Object();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* detects translators for this browser object
|
|
|
|
*/
|
|
|
|
Zotero_Browser.Tab.prototype.detectTranslators = function(rootDoc, doc) {
|
|
|
|
// if there's already a scrapable page in the browser window, and it's
|
|
|
|
// still there, ensure it is actually part of the page, then return
|
|
|
|
if(this.page.translators && this.page.translators.length && this.page.document.location) {
|
2009-01-11 10:08:53 +00:00
|
|
|
if(this._searchFrames(rootDoc, this.page.document)) return;
|
|
|
|
this.clear();
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
2008-09-11 19:40:38 +00:00
|
|
|
if(doc instanceof HTMLDocument && doc.documentURI.substr(0, 6) != "about:") {
|
2007-10-23 07:11:59 +00:00
|
|
|
// get translators
|
|
|
|
var me = this;
|
|
|
|
|
2011-03-02 02:50:31 +00:00
|
|
|
var translate = new Zotero.Translate.Web();
|
2007-10-23 07:11:59 +00:00
|
|
|
translate.setDocument(doc);
|
|
|
|
translate.setHandler("translators", function(obj, item) { me._translatorsAvailable(obj, item) });
|
|
|
|
translate.getTranslators();
|
2008-09-11 19:40:38 +00:00
|
|
|
} else if(doc.documentURI.substr(0, 7) == "file://") {
|
2007-10-23 07:11:59 +00:00
|
|
|
this._attemptLocalFileImport(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* searches for a document in all of the frames of a given document
|
|
|
|
*/
|
|
|
|
Zotero_Browser.Tab.prototype._searchFrames = function(rootDoc, searchDoc) {
|
2009-01-12 07:31:36 +00:00
|
|
|
if(rootDoc == searchDoc) return true;
|
2007-10-23 07:11:59 +00:00
|
|
|
var frames = rootDoc.getElementsByTagName("frame");
|
|
|
|
for each(var frame in frames) {
|
|
|
|
if(frame.contentDocument &&
|
2009-05-05 00:02:18 +00:00
|
|
|
(frame.contentDocument == searchDoc ||
|
|
|
|
this._searchFrames(frame.contentDocument, searchDoc))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var frames = rootDoc.getElementsByTagName("iframe");
|
|
|
|
for each(var frame in frames) {
|
|
|
|
if(frame.contentDocument &&
|
|
|
|
(frame.contentDocument == searchDoc ||
|
|
|
|
this._searchFrames(frame.contentDocument, searchDoc))) {
|
2007-10-23 07:11:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempts import of a file; to be run on local files only
|
|
|
|
*/
|
|
|
|
Zotero_Browser.Tab.prototype._attemptLocalFileImport = function(doc) {
|
2011-03-23 21:29:19 +00:00
|
|
|
if(doc.documentURI.match(/\.csl(\.xml|\.txt)?$/i)) {
|
2007-12-02 05:45:07 +00:00
|
|
|
// 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
|
2008-09-11 21:29:05 +00:00
|
|
|
Zotero.Styles.install(csl, doc.documentURI);
|
2007-12-02 05:45:07 +00:00
|
|
|
}
|
|
|
|
} 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;
|
2011-03-02 02:50:31 +00:00
|
|
|
var translate = new Zotero.Translate.Import();
|
2007-12-02 05:45:07 +00:00
|
|
|
translate.setLocation(file);
|
|
|
|
translate.setHandler("translators", function(obj, item) { me._translatorsAvailable(obj, item) });
|
|
|
|
translate.getTranslators();
|
|
|
|
}
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
* translate a page
|
|
|
|
*
|
|
|
|
* @param {Integer} libraryID
|
|
|
|
* @param {Integer} collectionID
|
2007-10-23 07:11:59 +00:00
|
|
|
*/
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
Zotero_Browser.Tab.prototype.translate = function(libraryID, collectionID) {
|
2007-10-23 07:11:59 +00:00
|
|
|
if(this.page.translators && this.page.translators.length) {
|
|
|
|
Zotero_Browser.progress.show();
|
2009-04-30 00:10:03 +00:00
|
|
|
Zotero_Browser.isScraping = true;
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
if(collectionID) {
|
2009-05-15 07:01:42 +00:00
|
|
|
var collection = Zotero.Collections.get(collectionID);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var collection = false;
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
if(!this.page.hasBeenTranslated) {
|
|
|
|
// use first translator available
|
|
|
|
this.page.translate.setTranslator(this.page.translators[0]);
|
|
|
|
this.page.translate.setHandler("select", me._selectItems);
|
|
|
|
this.page.translate.setHandler("done", function(obj, item) { Zotero_Browser.finishScraping(obj, item) });
|
|
|
|
this.page.hasBeenTranslated = true;
|
|
|
|
}
|
|
|
|
this.page.translate.clearHandlers("itemDone");
|
2011-06-21 19:55:00 +00:00
|
|
|
this.page.translate.setHandler("itemDone", function(obj, dbItem, item) { Zotero_Browser.itemDone(obj, dbItem, item, collection) });
|
2007-10-23 07:11:59 +00:00
|
|
|
|
2.0b3 megacommit
- Support for group libraries
- General support for multiple libraries of different types
- Streamlined sync support
- Using solely libraryID and key rather than itemID, and removed all itemID-changing code
- Combined two requests for increased performance and decreased server load
- Added warning on user account change
- Provide explicit error message on SSL failure
- Removed snapshot and link toolbar buttons and changed browser context menu options and drags to create parent items + snapshots
- Closes #786, Add numPages field
- Fixes #1063, Duplicate item with tags broken in Sync Preview
- Added better purging of deleted tags
- Added local user key before first sync
- Add clientDateModified to all objects for more flexibility in syncing
- Added new triples-based Relation object type, currently used to store links between items copied between local and group libraries
- Updated zotero.org translator for groups
- Additional trigger-based consistency checks
- Fixed broken URL drag in Firefox 3.5
- Disabled zeroconf menu option (no longer functional)
Developer-specific changes:
- Overhauled data layer
- Data object constructors no longer take arguments (return to 1.0-like API)
- Existing objects can be retrieved by setting id or library/key properties
- id/library/key must be set for new objects before other fields
- New methods:
- ZoteroPane.getSelectedLibraryID()
- ZoteroPane.getSelectedGroup(asID)
- ZoteroPane.addItemFromDocument(doc, itemType, saveSnapshot)
- ZoteroPane.addItemFromURL(url, itemType)
- ZoteroPane.canEdit()
- Zotero.CollectionTreeView.selectLibrary(libraryID)
- New Zotero.URI methods
- Changed methods
- Many data object methods now take a libraryID
- ZoteroPane.addAttachmentFromPage(link, itemID)
- Removed saveItem and saveAttachments parameters from Zotero.Translate constructor
- translate() now takes a libraryID, null for local library, or false to not save items (previously on constructor)
- saveAttachments is now a translate() parameter
- Zotero.flattenArguments() better handles passed objects
- Zotero.File.getFileHash() (not currently used)
2009-05-14 18:23:40 +00:00
|
|
|
this.page.translate.translate(libraryID);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.translators && this.page.translators.length) {
|
|
|
|
var itemType = this.page.translators[0].itemType;
|
2011-06-14 00:36:21 +00:00
|
|
|
return (itemType === "multiple"
|
|
|
|
? "chrome://zotero/skin/treesource-collection.png"
|
|
|
|
: Zotero.ItemTypes.getImageSrc(itemType));
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Zotero_Browser.Tab.prototype.getCaptureTooltip = function() {
|
|
|
|
if (this.page.translators && this.page.translators.length) {
|
|
|
|
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, '');
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********CALLBACKS**********/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when a user is supposed to select items
|
|
|
|
*/
|
2011-06-14 00:36:21 +00:00
|
|
|
Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList, callback) {
|
2007-10-23 07:11:59 +00:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2011-06-14 00:36:21 +00:00
|
|
|
callback(io.dataOut);
|
2007-10-23 07:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when translators are available
|
|
|
|
*/
|
|
|
|
Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, translators) {
|
|
|
|
if(translators && translators.length) {
|
|
|
|
this.page.translate = translate;
|
|
|
|
this.page.translators = translators;
|
|
|
|
this.page.document = translate.document;
|
|
|
|
} else if(translate.type != "import" && translate.document.documentURI.length > 7
|
|
|
|
&& translate.document.documentURI.substr(0, 7) == "file://") {
|
|
|
|
this._attemptLocalFileImport(translate.document);
|
|
|
|
}
|
|
|
|
Zotero_Browser.updateStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
Zotero_Browser.init();
|