diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul
index f6b665f942..1eb1e97464 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, ZoteroPane.getSelectedCollection(true))"/>
+ oncommand="Zotero.Attachments.importFromURL(window.gContextMenu.onImage ? window.gContextMenu.imageURL : window.gContextMenu.bgImageURL, false, false, ZoteroPane.getSelectedCollection(true))"/>
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
index 83303921f3..f86beccc3c 100644
--- a/chrome/content/zotero/xpcom/attachments.js
+++ b/chrome/content/zotero/xpcom/attachments.js
@@ -168,7 +168,7 @@ Zotero.Attachments = new function(){
}
- function importFromURL(url, sourceItemID, forceTitle){
+ function importFromURL(url, sourceItemID, forceTitle, parentCollectionIDs){
Zotero.debug('Importing attachment from URL');
Zotero.Utilities.HTTP.doHead(url, function(obj){
@@ -191,9 +191,13 @@ Zotero.Attachments = new function(){
if (Zotero.MIME.hasNativeHandler(mimeType, ext)){
var browser = Zotero.Browser.createHiddenBrowser();
browser.addEventListener("pageshow", function(){
- Zotero.Attachments.importFromDocument(browser.contentDocument, sourceItemID, forceTitle);
- browser.removeEventListener("pageshow", arguments.callee, true);
- Zotero.Browser.deleteHiddenBrowser(browser);
+ var callback = function () {
+ browser.removeEventListener("pageshow", arguments.callee, true);
+ Zotero.Browser.deleteHiddenBrowser(browser);
+ };
+
+ Zotero.Attachments.importFromDocument(browser.contentDocument,
+ sourceItemID, forceTitle, parentCollectionIDs, callback);
}, true);
browser.loadURI(url);
}
@@ -221,6 +225,15 @@ Zotero.Attachments = new function(){
attachmentItem.save();
var itemID = attachmentItem.getID();
+ // Add to collections
+ if (parentCollectionIDs){
+ var ids = Zotero.flattenArguments(parentCollectionIDs);
+ for each(var id in ids){
+ var col = Zotero.Collections.get(id);
+ col.addItem(itemID);
+ }
+ }
+
// Create a new folder for this item in the storage directory
var destDir = Zotero.getStorageDirectory();
destDir.append(itemID);
@@ -351,7 +364,7 @@ Zotero.Attachments = new function(){
}
- function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs){
+ function importFromDocument(document, sourceItemID, forceTitle, parentCollectionIDs, callback){
Zotero.debug('Importing attachment from document');
var url = document.location.href;
@@ -444,6 +457,10 @@ Zotero.Attachments = new function(){
}
Zotero.Fulltext.indexDocument(document, itemID);
+
+ if (callback) {
+ callback();
+ }
});
// The attachment is still incomplete here, but we can't risk
@@ -635,6 +652,8 @@ Zotero.Attachments = new function(){
// Chain fulltext indexer inside the charset callback,
// since it's asynchronous and a prerequisite
Zotero.Fulltext.indexDocument(browser.contentDocument, itemID);
+
+ Zotero.Browser.deleteHiddenBrowser(browser);
}
}, itemID);
diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js
index 72111772c3..5f3970c354 100644
--- a/chrome/content/zotero/xpcom/file.js
+++ b/chrome/content/zotero/xpcom/file.js
@@ -155,8 +155,6 @@ Zotero.File = new function(){
prefService.setCharPref('intl.charset.detector', oldPref);
callback(charset, args);
-
- Zotero.Browser.deleteHiddenBrowser(browser);
}, false);
}
}
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
index 9566b41452..c50b4cb869 100644
--- a/chrome/content/zotero/xpcom/zotero.js
+++ b/chrome/content/zotero/xpcom/zotero.js
@@ -1271,7 +1271,7 @@ Zotero.Browser = new function() {
return newHiddenBrowser;
}
- function deleteHiddenBrowser(myBrowser) {
+ function deleteHiddenBrowser(myBrowser) {
// Delete a hidden browser
myBrowser.parentNode.removeChild(myBrowser);
delete myBrowser;