From 2875c0d4cef22672968caa709be741483aa4bbbc Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 19 Mar 2007 04:38:27 +0000 Subject: [PATCH] Fixes #257, snapshots not getting the CSS from some web pages Switched importFromURL() from native Mozilla saveDocument() to WebPageDump code (originally from Scrapbook), which fixes CSS saving problems and other issues -- viewing a WPD snapshot of the New York Times front page causes a crash in the Flash plugin in all Mac browsers, however, unless the Flash security settings are changed to whitelist the Zotero storage directory for accessing the network (but this should be done anyway, since the warning is annoying) Also: - Fix broken items list in Related and Advanced Search windows from r1231 - Fix several _getItemAtRow() errors from r1231 - Adjusted Zotero.Progress API: fade()->startCloseTimer(), kill()->close() - Added forceTitle parameter to importFromURL(), currently unimplemented -- note that order of the last parameter changed - Added progress windows for "Create New Item from Current Page", snapshot, and link actions - Added "Miscellaneous" caption in General pane of preferences - Clarify Mac rich-text warnings - Switched small Export prefpane to generic icon --- chrome/content/zotero/browser.js | 9 +- chrome/content/zotero/overlay.js | 57 +- chrome/content/zotero/overlay.xul | 4 +- chrome/content/zotero/preferences.xul | 2 + chrome/content/zotero/webpagedump/common.js | 790 +++++++++++++ chrome/content/zotero/webpagedump/domsaver.js | 1029 +++++++++++++++++ chrome/content/zotero/xpcom/attachments.js | 122 +- .../zotero/xpcom/collectionTreeView.js | 5 +- chrome/content/zotero/xpcom/data_access.js | 1 - chrome/content/zotero/xpcom/ingester.js | 2 +- chrome/content/zotero/xpcom/itemTreeView.js | 18 +- chrome/content/zotero/xpcom/progressWindow.js | 33 +- chrome/locale/en-US/zotero/preferences.dtd | 3 +- chrome/locale/en-US/zotero/zotero.dtd | 2 +- chrome/locale/en-US/zotero/zotero.properties | 3 + chrome/skin/default/zotero/preferences.css | 5 +- 16 files changed, 2037 insertions(+), 48 deletions(-) create mode 100644 chrome/content/zotero/webpagedump/common.js create mode 100644 chrome/content/zotero/webpagedump/domsaver.js diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index c42b14af7..e14243162 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -394,9 +394,8 @@ var Zotero_Browser = new function() { var linkText = '' + Zotero.getString('ingester.scrapeErrorDescription.linkText') + ''; Zotero_Browser.progress.addDescription(Zotero.getString("ingester.scrapeErrorDescription", linkText)); + Zotero_Browser.progress.startCloseTimer(); } - - Zotero_Browser.progress.fade(); } @@ -413,6 +412,8 @@ var Zotero_Browser = new function() { if(collection) { collection.addItem(item.getID()); } + + Zotero_Browser.progress.startCloseTimer(); } ////////////////////////////////////////////////////////////////////////////// @@ -622,8 +623,8 @@ Zotero_Browser.Tab.prototype._selectItems = function(obj, itemList) { 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 kill the progress indicatior - Zotero_Browser.progress.kill(); + if(!io.dataOut) { // user selected no items, so close the progress indicatior + Zotero_Browser.progress.close(); } return io.dataOut; diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index d7b6c7441..8a76eabca 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -1504,6 +1504,13 @@ var ZoteroPane = new function() function addItemFromPage() { + var progressWin = new Zotero.ProgressWindow(); + progressWin.changeHeadline(Zotero.getString('ingester.scraping')); + var icon = 'chrome://zotero/skin/treeitem-webpage.png'; + progressWin.addLines(window.content.document.title, icon) + progressWin.show(); + progressWin.startCloseTimer(); + var data = { title: window.content.document.title, url: window.content.document.location.href, @@ -1515,27 +1522,55 @@ var ZoteroPane = new function() // Automatically save snapshot if pref set if (item.getID() && Zotero.Prefs.get('automaticSnapshots')) { - this.addAttachmentFromPage(false, item.getID(), true); + var f = function() { + // We set |noParent|, since child items don't belong to collections + ZoteroPane.addAttachmentFromPage(false, item.getID(), true); + } + // Give progress window time to appear + setTimeout(f, 300); } return item.getID(); } - function addAttachmentFromPage(link, id, noParent) + /* + * Create an attachment from the current page + * + * |link| -- create web link instead of snapshot + * |itemID| -- itemID of parent item + * |noParent| -- don't add to current collection + */ + function addAttachmentFromPage(link, itemID, noParent) { - if (this.itemsView && this.itemsView._itemGroup.isCollection() && !noParent) { - var parentCollectionID = this.itemsView._itemGroup.ref.getID(); + if (!noParent) { + var progressWin = new Zotero.ProgressWindow(); + progressWin.changeHeadline(Zotero.getString('save.' + (link ? 'link' : 'attachment'))); + var type = link ? 'web-link' : 'snapshot'; + var icon = 'chrome://zotero/skin/treeitem-attachment-' + type + '.png'; + progressWin.addLines(window.content.document.title, icon) + progressWin.show(); + progressWin.startCloseTimer(); + + Zotero.debug('here'); + if (this.itemsView && this.itemsView._itemGroup.isCollection()) { + Zotero.debug('here2'); + var parentCollectionID = this.itemsView._itemGroup.ref.getID(); + Zotero.debug(parentCollectionID); + } } - if(link) - { - Zotero.Attachments.linkFromDocument(window.content.document, id, parentCollectionID); - } - else - { - Zotero.Attachments.importFromDocument(window.content.document, id, false, parentCollectionID); + var f = function() { + Zotero.debug(parentCollectionID); + if (link) { + Zotero.Attachments.linkFromDocument(window.content.document, itemID, false, parentCollectionID); + } + else { + Zotero.Attachments.importFromDocument(window.content.document, itemID, false, false, parentCollectionID); + } } + // Give progress window time to appear + setTimeout(f, 100); } diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul index 5f4a88fa9..bae40857a 100644 --- a/chrome/content/zotero/overlay.xul +++ b/chrome/content/zotero/overlay.xul @@ -55,10 +55,10 @@ oncommand="var itemID = ZoteroPane.addItemFromPage(); ZoteroPane.newNote(false, itemID, window.content.getSelection().toString())"/> + oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.linkURL, false, false, false, ZoteroPane.getSelectedCollection(true))"/> + oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, false, ZoteroPane.getSelectedCollection(true))"/> diff --git a/chrome/content/zotero/preferences.xul b/chrome/content/zotero/preferences.xul index 554cb4b31..0b205abcd 100644 --- a/chrome/content/zotero/preferences.xul +++ b/chrome/content/zotero/preferences.xul @@ -108,6 +108,8 @@ To add a new preference: + +