Rename 'area' annotations to 'image' annotations
This commit is contained in:
parent
05318b3021
commit
427a227370
6 changed files with 30 additions and 30 deletions
|
@ -29,7 +29,7 @@ Zotero.Annotations = new function () {
|
||||||
// Keep in sync with items.js::loadAnnotations()
|
// Keep in sync with items.js::loadAnnotations()
|
||||||
Zotero.defineProperty(this, 'ANNOTATION_TYPE_HIGHLIGHT', { value: 1 });
|
Zotero.defineProperty(this, 'ANNOTATION_TYPE_HIGHLIGHT', { value: 1 });
|
||||||
Zotero.defineProperty(this, 'ANNOTATION_TYPE_NOTE', { value: 2 });
|
Zotero.defineProperty(this, 'ANNOTATION_TYPE_NOTE', { value: 2 });
|
||||||
Zotero.defineProperty(this, 'ANNOTATION_TYPE_AREA', { value: 3 });
|
Zotero.defineProperty(this, 'ANNOTATION_TYPE_IMAGE', { value: 3 });
|
||||||
|
|
||||||
|
|
||||||
this.toJSON = function (item) {
|
this.toJSON = function (item) {
|
||||||
|
@ -43,7 +43,7 @@ Zotero.Annotations = new function () {
|
||||||
if (o.type == 'highlight') {
|
if (o.type == 'highlight') {
|
||||||
o.text = item.annotationText;
|
o.text = item.annotationText;
|
||||||
}
|
}
|
||||||
else if (o.type == 'area') {
|
else if (o.type == 'image') {
|
||||||
o.imageURL = item.annotationImageURL;
|
o.imageURL = item.annotationImageURL;
|
||||||
}
|
}
|
||||||
o.comment = item.annotationComment;
|
o.comment = item.annotationComment;
|
||||||
|
|
|
@ -354,7 +354,7 @@ Zotero.Attachments = new function(){
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves an image for a parent note or area annotation
|
* Saves an image for a parent note or image annotation
|
||||||
*
|
*
|
||||||
* @param {Object} params
|
* @param {Object} params
|
||||||
* @param {Blob} params.blob - Image to save
|
* @param {Blob} params.blob - Image to save
|
||||||
|
|
|
@ -3519,7 +3519,7 @@ for (let name of ['type', 'text', 'comment', 'color', 'pageLabel', 'sortIndex'])
|
||||||
if (currentType && currentType != value) {
|
if (currentType && currentType != value) {
|
||||||
throw new Error("Cannot change annotation type");
|
throw new Error("Cannot change annotation type");
|
||||||
}
|
}
|
||||||
if (!['highlight', 'note', 'area'].includes(value)) {
|
if (!['highlight', 'note', 'image'].includes(value)) {
|
||||||
throw new Error(`Invalid annotation type '${value}'`);
|
throw new Error(`Invalid annotation type '${value}'`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3569,12 +3569,12 @@ for (let name of ['position']) {
|
||||||
*/
|
*/
|
||||||
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', {
|
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', {
|
||||||
get: function () {
|
get: function () {
|
||||||
if (!this.isAreaAnnotation()) {
|
if (!this.isImageAnnotation()) {
|
||||||
throw new Error("'annotationImageAttachment' is only valid for area annotations");
|
throw new Error("'annotationImageAttachment' is only valid for image annotations");
|
||||||
}
|
}
|
||||||
var attachments = this.getAttachments();
|
var attachments = this.getAttachments();
|
||||||
if (!attachments.length) {
|
if (!attachments.length) {
|
||||||
throw new Error("No attachments found for area annotation");
|
throw new Error("No attachments found for image annotation");
|
||||||
}
|
}
|
||||||
return Zotero.Items.get(attachments[0]);
|
return Zotero.Items.get(attachments[0]);
|
||||||
}
|
}
|
||||||
|
@ -3586,12 +3586,12 @@ Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageAttachment', {
|
||||||
*/
|
*/
|
||||||
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageURL', {
|
Zotero.defineProperty(Zotero.Item.prototype, 'annotationImageURL', {
|
||||||
get: function () {
|
get: function () {
|
||||||
if (!this.isAreaAnnotation()) {
|
if (!this.isImageAnnotation()) {
|
||||||
throw new Error("'annotationImageURL' is only valid for area annotations");
|
throw new Error("'annotationImageURL' is only valid for image annotations");
|
||||||
}
|
}
|
||||||
var attachments = this.getAttachments();
|
var attachments = this.getAttachments();
|
||||||
if (!attachments.length) {
|
if (!attachments.length) {
|
||||||
throw new Error("No attachments found for area annotation");
|
throw new Error("No attachments found for image annotation");
|
||||||
}
|
}
|
||||||
|
|
||||||
var { libraryID, key } = Zotero.Items.getLibraryAndKeyFromID(attachments[0]);
|
var { libraryID, key } = Zotero.Items.getLibraryAndKeyFromID(attachments[0]);
|
||||||
|
@ -3624,8 +3624,8 @@ Zotero.Item.prototype.isAnnotation = function() {
|
||||||
*
|
*
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
**/
|
**/
|
||||||
Zotero.Item.prototype.isAreaAnnotation = function() {
|
Zotero.Item.prototype.isImageAnnotation = function() {
|
||||||
return this.isAnnotation() && this._getLatestField('annotationType') == 'area';
|
return this.isAnnotation() && this._getLatestField('annotationType') == 'image';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -527,8 +527,8 @@ Zotero.Items = function() {
|
||||||
type = 'note';
|
type = 'note';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Zotero.Annotations.ANNOTATION_TYPE_AREA:
|
case Zotero.Annotations.ANNOTATION_TYPE_IMAGE:
|
||||||
type = 'area';
|
type = 'image';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -47,9 +47,9 @@ describe("Zotero.Annotations", function() {
|
||||||
"dateModified": "2019-05-14 06:50:54"
|
"dateModified": "2019-05-14 06:50:54"
|
||||||
};
|
};
|
||||||
|
|
||||||
var exampleArea = {
|
var exampleImage = {
|
||||||
"key": "QD32MQJF",
|
"key": "QD32MQJF",
|
||||||
"type": "area",
|
"type": "image",
|
||||||
"isAuthor": true,
|
"isAuthor": true,
|
||||||
"imageURL": "zotero://attachment/library/items/LB417FR4",
|
"imageURL": "zotero://attachment/library/items/LB417FR4",
|
||||||
"comment": "This is a comment",
|
"comment": "This is a comment",
|
||||||
|
@ -162,16 +162,16 @@ describe("Zotero.Annotations", function() {
|
||||||
await annotation.eraseTx();
|
await annotation.eraseTx();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should generate an object for an area", async function () {
|
it("should generate an object for an image", async function () {
|
||||||
var annotation = new Zotero.Item('annotation');
|
var annotation = new Zotero.Item('annotation');
|
||||||
annotation.libraryID = attachment.libraryID;
|
annotation.libraryID = attachment.libraryID;
|
||||||
annotation.key = exampleArea.key;
|
annotation.key = exampleImage.key;
|
||||||
await annotation.loadPrimaryData();
|
await annotation.loadPrimaryData();
|
||||||
annotation.parentID = attachment.id;
|
annotation.parentID = attachment.id;
|
||||||
annotation.annotationType = 'area';
|
annotation.annotationType = 'image';
|
||||||
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
|
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
|
||||||
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
|
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
|
||||||
annotation[itemProp] = exampleArea[prop];
|
annotation[itemProp] = exampleImage[prop];
|
||||||
}
|
}
|
||||||
await annotation.saveTx();
|
await annotation.saveTx();
|
||||||
|
|
||||||
|
@ -189,13 +189,13 @@ describe("Zotero.Annotations", function() {
|
||||||
|
|
||||||
var json = Zotero.Annotations.toJSON(annotation);
|
var json = Zotero.Annotations.toJSON(annotation);
|
||||||
|
|
||||||
assert.sameMembers(Object.keys(json), Object.keys(exampleArea));
|
assert.sameMembers(Object.keys(json), Object.keys(exampleImage));
|
||||||
for (let prop of Object.keys(exampleArea)) {
|
for (let prop of Object.keys(exampleImage)) {
|
||||||
if (prop == 'imageURL'
|
if (prop == 'imageURL'
|
||||||
|| prop == 'dateModified') {
|
|| prop == 'dateModified') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
assert.deepEqual(json[prop], exampleArea[prop], `'${prop}' doesn't match`);
|
assert.deepEqual(json[prop], exampleImage[prop], `'${prop}' doesn't match`);
|
||||||
}
|
}
|
||||||
assert.equal(json.imageURL, `zotero://attachment/library/items/${imageAttachment.key}`);
|
assert.equal(json.imageURL, `zotero://attachment/library/items/${imageAttachment.key}`);
|
||||||
|
|
||||||
|
@ -251,15 +251,15 @@ describe("Zotero.Annotations", function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create an item from an area", async function () {
|
it("should create an item from an image", async function () {
|
||||||
var annotation = await Zotero.Annotations.saveFromJSON(attachment, exampleArea);
|
var annotation = await Zotero.Annotations.saveFromJSON(attachment, exampleImage);
|
||||||
|
|
||||||
// Note: Image is created separately using Zotero.Attachments.importEmbeddedImage()
|
// Note: Image is created separately using Zotero.Attachments.importEmbeddedImage()
|
||||||
|
|
||||||
assert.equal(annotation.key, exampleArea.key);
|
assert.equal(annotation.key, exampleImage.key);
|
||||||
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
|
for (let prop of ['comment', 'color', 'pageLabel', 'sortIndex', 'position']) {
|
||||||
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
|
let itemProp = 'annotation' + prop[0].toUpperCase() + prop.substr(1);
|
||||||
assert.deepEqual(annotation[itemProp], exampleArea[prop], `'${prop}' doesn't match`);
|
assert.deepEqual(annotation[itemProp], exampleImage[prop], `'${prop}' doesn't match`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1212,7 +1212,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.throws(() => a.annotationText = "This is highlighted text.");
|
assert.throws(() => a.annotationText = "This is highlighted text.");
|
||||||
|
|
||||||
a = new Zotero.Item('annotation');
|
a = new Zotero.Item('annotation');
|
||||||
a.annotationType = 'area';
|
a.annotationType = 'image';
|
||||||
assert.throws(() => a.annotationText = "This is highlighted text.");
|
assert.throws(() => a.annotationText = "This is highlighted text.");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1248,7 +1248,7 @@ describe("Zotero.Item", function () {
|
||||||
await annotation.saveTx();
|
await annotation.saveTx();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should save an area annotation", async function () {
|
it("should save an image annotation", async function () {
|
||||||
// Create a Blob from a PNG
|
// Create a Blob from a PNG
|
||||||
var path = OS.Path.join(getTestDataDirectory().path, 'test.png');
|
var path = OS.Path.join(getTestDataDirectory().path, 'test.png');
|
||||||
var imageData = await Zotero.File.getBinaryContentsAsync(path);
|
var imageData = await Zotero.File.getBinaryContentsAsync(path);
|
||||||
|
@ -1259,7 +1259,7 @@ describe("Zotero.Item", function () {
|
||||||
|
|
||||||
var annotation = new Zotero.Item('annotation');
|
var annotation = new Zotero.Item('annotation');
|
||||||
annotation.parentID = attachment.id;
|
annotation.parentID = attachment.id;
|
||||||
annotation.annotationType = 'area';
|
annotation.annotationType = 'image';
|
||||||
annotation.annotationSortIndex = '000015|0002431|000000.000';
|
annotation.annotationSortIndex = '000015|0002431|000000.000';
|
||||||
annotation.annotationPosition = {
|
annotation.annotationPosition = {
|
||||||
pageIndex: 123,
|
pageIndex: 123,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue