commit ad0d6765d75842b1bd0b19c627381aae96deb3b5
parent e137a05201d85fd4d00a3c120d9449727fa7b41b
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 11 Feb 2016 02:54:52 -0500
Fix Zotero.Attachments.linkFromDocument()
Diffstat:
2 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js
@@ -510,28 +510,23 @@ Zotero.Attachments = new function(){
var title = document.title; // TODO: don't use Mozilla-generated title for images, etc.
var contentType = document.contentType;
- var item = yield Zotero.DB.executeTransaction(function* () {
- return _addToDB({
- url: url,
- title: title,
- linkMode: this.LINK_MODE_LINKED_URL,
- contentType: contentType,
- charset: document.characterSet,
- parentItemID: parentItemID,
- collections: collections
- });
- }.bind(this));
+ var item = yield _addToDB({
+ url,
+ title,
+ linkMode: this.LINK_MODE_LINKED_URL,
+ contentType,
+ charset: document.characterSet,
+ parentItemID,
+ collections
+ });
- // Run the indexer asynchronously
- setTimeout(function () {
- if (Zotero.Fulltext.isCachedMIMEType(contentType)) {
- // No file, so no point running the PDF indexer
- //Zotero.Fulltext.indexItems([itemID]);
- }
- else if (Zotero.MIME.isTextType(document.contentType)) {
- Zotero.Fulltext.indexDocument(document, item.id);
- }
- }, 50);
+ if (Zotero.Fulltext.isCachedMIMEType(contentType)) {
+ // No file, so no point running the PDF indexer
+ //Zotero.Fulltext.indexItems([itemID]);
+ }
+ else if (Zotero.MIME.isTextType(document.contentType)) {
+ yield Zotero.Fulltext.indexDocument(document, item.id);
+ }
return item;
});
diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js
@@ -112,6 +112,32 @@ describe("Zotero.Attachments", function() {
})
})
+ describe("#linkFromDocument", function () {
+ it("should add a link attachment for the current webpage", function* () {
+ var item = yield createDataObject('item');
+
+ var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
+ var deferred = Zotero.Promise.defer();
+ win.addEventListener('pageshow', () => deferred.resolve());
+ win.loadURI(uri);
+ yield deferred.promise;
+
+ var file = getTestDataDirectory();
+ file.append('test.png');
+ var attachment = yield Zotero.Attachments.linkFromDocument({
+ document: win.content.document,
+ parentItemID: item.id
+ });
+
+ assert.equal(attachment.getField('url'), "file://" + uri);
+
+ // Check indexing
+ var matches = yield Zotero.Fulltext.findTextInItems([attachment.id], 'works');
+ assert.lengthOf(matches, 1);
+ assert.propertyVal(matches[0], 'id', attachment.id);
+ })
+ })
+
describe("#getTotalFileSize", function () {
it("should return the size for a single-file attachment", function* () {
var file = getTestDataDirectory();