mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
remove prefix/suffix inputs and streamline citation insertion logic
This commit is contained in:
@ -154,12 +154,6 @@
|
||||
<input id="omitAuthor" type="checkbox" class="form-control i18n" title="Omit Author">
|
||||
</div>
|
||||
</div>
|
||||
<div id="prefixSuffixDiv">
|
||||
<input id="prefixField" autocomplete="off" class="form-control i18n" type="text"
|
||||
placeholder="Prefix" />
|
||||
<input id="suffixField" autocomplete="off" class="form-control i18n" type="text"
|
||||
placeholder="Suffix" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="configState" class="hidden">
|
||||
<p>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -189,20 +189,11 @@ CitationService.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array<any>} items
|
||||
* @param {string} prefix
|
||||
* @param {string} suffix
|
||||
* @param {{locator: string, label: string} | null} locatorInfo
|
||||
* @param {Array<SearchResultItem>} items
|
||||
* @param {boolean} bOmitAuthor
|
||||
* @returns {Promise<Array<string|number>>}
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ function SelectCitationsComponent(
|
||||
/** @type {Object<string|number, HTMLInputElement>} */
|
||||
this._checks = {};
|
||||
|
||||
this._locatorValues = [
|
||||
this._LOCATOR_VALUES = [
|
||||
["appendix", "Appendix"],
|
||||
["article", "Article"],
|
||||
["book", "Book"],
|
||||
@ -159,7 +159,7 @@ SelectCitationsComponent.prototype.displaySearchItems = function (
|
||||
};
|
||||
|
||||
/** @returns {Object<string|number, SearchResultItem>} */
|
||||
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;
|
||||
|
||||
@ -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]
|
||||
*/
|
||||
|
||||
/** ------------------------------------------------ */
|
||||
|
||||
Reference in New Issue
Block a user