diff --git a/sdkjs-plugins/content/zotero/index.html b/sdkjs-plugins/content/zotero/index.html
index 9d5638a4..cac79464 100644
--- a/sdkjs-plugins/content/zotero/index.html
+++ b/sdkjs-plugins/content/zotero/index.html
@@ -154,12 +154,6 @@
-
diff --git a/sdkjs-plugins/content/zotero/scripts/code.js b/sdkjs-plugins/content/zotero/scripts/code.js
index 51162dfa..c93287b9 100644
--- a/sdkjs-plugins/content/zotero/scripts/code.js
+++ b/sdkjs-plugins/content/zotero/scripts/code.js
@@ -608,19 +608,13 @@
citationService
.updateCslItems(true, false, false)
.then(function () {
- const prefix = getPrefix();
- const suffix = getSuffix();
- const locatorInfo = getLocator();
let checked = false;
if (elements.checkOmitAuthor instanceof HTMLInputElement) {
checked = elements.checkOmitAuthor.checked;
}
return citationService.insertSelectedCitations(
- selectCitation.getItems(),
- prefix,
- suffix,
- locatorInfo,
+ selectCitation.getSelectedItems(),
checked
);
})
@@ -1164,59 +1158,6 @@
});
}
- /**
- * @returns {string}
- */
- function getPrefix() {
- const prefixInput = document.getElementById("prefixField");
- if (
- prefixInput &&
- prefixInput instanceof HTMLInputElement &&
- prefixInput.value
- ) {
- return prefixInput.value;
- }
- return "";
- }
-
- /**
- * @returns {string}
- */
- function getSuffix() {
- const suffixInput = document.getElementById("suffixField");
- if (
- suffixInput &&
- suffixInput instanceof HTMLInputElement &&
- suffixInput.value
- ) {
- return suffixInput.value;
- }
- return "";
- }
-
- /**
- * @returns {{locator: string, label: string} | null}
- */
- function getLocator() {
- const locatorInput = document.getElementById("locator");
- if (
- !locatorInput ||
- !(locatorInput instanceof HTMLInputElement) ||
- !locatorInput.value
- ) {
- return null;
- }
- const label = document.getElementById("locatorLabel");
- if (!label || !(label instanceof HTMLInputElement) || !label.value) {
- return null;
- }
-
- return {
- locator: locatorInput.value,
- label: label.getAttribute("data-value") || "",
- };
- }
-
/**
* @param {boolean} append
* @param {SearchResult | null} res
diff --git a/sdkjs-plugins/content/zotero/scripts/services/citation-service.js b/sdkjs-plugins/content/zotero/scripts/services/citation-service.js
index a5ae065f..aa170354 100644
--- a/sdkjs-plugins/content/zotero/scripts/services/citation-service.js
+++ b/sdkjs-plugins/content/zotero/scripts/services/citation-service.js
@@ -189,20 +189,11 @@ CitationService.prototype = {
},
/**
- * @param {Array} items
- * @param {string} prefix
- * @param {string} suffix
- * @param {{locator: string, label: string} | null} locatorInfo
+ * @param {Array} items
* @param {boolean} bOmitAuthor
* @returns {Promise>}
*/
- insertSelectedCitations: function (
- items,
- prefix,
- suffix,
- locatorInfo,
- bOmitAuthor
- ) {
+ insertSelectedCitations: function (items, bOmitAuthor) {
const self = this;
var cslCitation = new CSLCitation(CSLCitationStorage.size, "");
@@ -210,16 +201,6 @@ CitationService.prototype = {
const item = items[citationID];
item["suppress-author"] = bOmitAuthor;
- if (prefix !== "") {
- item.prefix = prefix;
- }
- if (suffix !== "") {
- item.suffix = suffix;
- }
- if (locatorInfo) {
- item.locator = locatorInfo.locator;
- item.label = locatorInfo.label;
- }
cslCitation.fillFromObject(item);
}
diff --git a/sdkjs-plugins/content/zotero/scripts/shared/components/select-citation.js b/sdkjs-plugins/content/zotero/scripts/shared/components/select-citation.js
index 520daa91..27cebda1 100644
--- a/sdkjs-plugins/content/zotero/scripts/shared/components/select-citation.js
+++ b/sdkjs-plugins/content/zotero/scripts/shared/components/select-citation.js
@@ -27,7 +27,7 @@ function SelectCitationsComponent(
/** @type {Object} */
this._checks = {};
- this._locatorValues = [
+ this._LOCATOR_VALUES = [
["appendix", "Appendix"],
["article", "Article"],
["book", "Book"],
@@ -159,7 +159,7 @@ SelectCitationsComponent.prototype.displaySearchItems = function (
};
/** @returns {Object} */
-SelectCitationsComponent.prototype.getItems = function () {
+SelectCitationsComponent.prototype.getSelectedItems = function () {
return this._items;
};
@@ -290,7 +290,7 @@ SelectCitationsComponent.prototype._buildDocElement = function (item) {
function toggleItem() {
root.classList.toggle("doc-open");
if (!params) {
- params = self._buildCitationParams();
+ params = self._buildCitationParams(item);
root.appendChild(params);
}
}
@@ -305,9 +305,13 @@ SelectCitationsComponent.prototype._buildDocElement = function (item) {
};
/**
+ * @param {SearchResultItem} item
* @returns {DocumentFragment}
*/
-SelectCitationsComponent.prototype._buildCitationParams = function () {
+SelectCitationsComponent.prototype._buildCitationParams = function (item) {
+ const locatorLabel = localStorage.getItem("selectedLocator") || "page";
+ item.label = locatorLabel;
+
const params = document.createDocumentFragment();
const prefixSuffixContainer = document.createElement("div");
const prefix = document.createElement("input");
@@ -340,19 +344,35 @@ SelectCitationsComponent.prototype._buildCitationParams = function () {
placeholder: "",
});
- const id = localStorage.getItem("selectedLocator") || "page";
- this._locatorValues.forEach(function (info) {
- const selected = info[0] === id;
+ prefixInput.subscribe(function (event) {
+ if (event.type !== "input:change") {
+ return;
+ }
+ item.prefix = event.detail.value;
+ });
+ suffixInput.subscribe(function (event) {
+ if (event.type !== "input:change") {
+ return;
+ }
+ item.suffix = event.detail.value;
+ });
+ locatorInput.subscribe(function (event) {
+ if (event.type !== "input:change") {
+ return;
+ }
+ item.locator = event.detail.value;
+ });
+
+ this._LOCATOR_VALUES.forEach(function (info) {
+ const selected = info[0] === locatorLabel;
locatorSelectbox.addItem(info[0], info[1], selected);
});
locatorSelectbox.subscribe(function (event) {
if (event.type !== "selectbox:change") {
return;
}
- localStorage.setItem(
- "selectedLocator",
- event.detail.values[0].toString()
- );
+ item.label = event.detail.values[0].toString();
+ localStorage.setItem("selectedLocator", item.label);
});
return params;
diff --git a/sdkjs-plugins/content/zotero/scripts/types-global.js b/sdkjs-plugins/content/zotero/scripts/types-global.js
index ee7aa93d..80a5a159 100644
--- a/sdkjs-plugins/content/zotero/scripts/types-global.js
+++ b/sdkjs-plugins/content/zotero/scripts/types-global.js
@@ -113,6 +113,11 @@
* @property {string} [URL]
* @property {number|string} [userID]
* @property {string} [volume]
+ * @property {string} [prefix]
+ * @property {string} [suffix]
+ * @property {string} [label]
+ * @property {string} [locator]
+ * @property {boolean} [suppress-author]
*/
/** ------------------------------------------------ */