mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
Custom styles manager
This commit is contained in:
@ -66,7 +66,8 @@ async function downloadStylesJson() {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const jsonData = await response.json();
|
||||
let jsonData = await response.json();
|
||||
jsonData = jsonData.filter((style) => style.dependent === 0);
|
||||
|
||||
await fs.writeFile(
|
||||
STYLES_JSON_FOLDER + "styles.json",
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
<script src="scripts/thirdparty/url-polyfill.min.js"></script>
|
||||
<script src="scripts/citeproc/citeproc_commonjs.js"></script>
|
||||
|
||||
<script src="scripts/csl/citation-item-data.js"></script>
|
||||
<script src="scripts/csl/citation/citation-item-data.js"></script>
|
||||
<script src="scripts/csl/citation/citation-tem.js"></script>
|
||||
<script src="scripts/csl/citation/citation.js"></script>
|
||||
<script src="scripts/csl/citation/storage.js"></script>
|
||||
|
||||
@ -4,8 +4,11 @@
|
||||
<translator>
|
||||
<name>dowens76</name>
|
||||
</translator>
|
||||
<translator>
|
||||
<name>Tran Quang Cuong</name>
|
||||
</translator>
|
||||
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
|
||||
<updated>2012-07-04T23:31:02+00:00</updated>
|
||||
<updated>2025-09-17T23:31:02+00:00</updated>
|
||||
</info>
|
||||
<style-options punctuation-in-quote="false"/>
|
||||
<date form="text">
|
||||
@ -49,8 +52,8 @@
|
||||
<term name="accessed">truy cập</term>
|
||||
<term name="and">và</term>
|
||||
<term name="and others">and others</term>
|
||||
<term name="anonymous">vô danh</term>
|
||||
<term name="anonymous" form="short">v.d</term>
|
||||
<term name="anonymous">khuyết danh</term>
|
||||
<term name="anonymous" form="short">k.d</term>
|
||||
<term name="at">tại</term>
|
||||
<term name="available at">available at</term>
|
||||
<term name="by">bởi</term>
|
||||
@ -265,8 +268,8 @@
|
||||
<multiple>chương</multiple>
|
||||
</term>
|
||||
<term name="column">
|
||||
<single>column</single>
|
||||
<multiple>columns</multiple>
|
||||
<single>cột</single>
|
||||
<multiple>cột</multiple>
|
||||
</term>
|
||||
<term name="figure">
|
||||
<single>figure</single>
|
||||
@ -323,16 +326,16 @@
|
||||
<multiple>trang</multiple>
|
||||
</term>
|
||||
<term name="paragraph">
|
||||
<single>đoạn văn</single>
|
||||
<multiple>đoạn văn</multiple>
|
||||
<single>đoạn</single>
|
||||
<multiple>đoạn</multiple>
|
||||
</term>
|
||||
<term name="part">
|
||||
<single>phần</single>
|
||||
<multiple>phần</multiple>
|
||||
</term>
|
||||
<term name="section">
|
||||
<single>section</single>
|
||||
<multiple>sections</multiple>
|
||||
<single>mục</single>
|
||||
<multiple>mục</multiple>
|
||||
</term>
|
||||
<term name="supplement">
|
||||
<single>supplement</single>
|
||||
@ -390,10 +393,10 @@
|
||||
</term>
|
||||
<term name="book" form="short">sách</term>
|
||||
<term name="chapter" form="short">ch</term>
|
||||
<term name="column" form="short">col</term>
|
||||
<term name="column" form="short">c.</term>
|
||||
<term name="figure" form="short">fig</term>
|
||||
<term name="folio" form="short">f</term>
|
||||
<term name="issue" form="short">số p.h</term>
|
||||
<term name="issue" form="short">số</term>
|
||||
<term name="line" form="short">d.</term>
|
||||
<term name="note" form="short">gc.</term>
|
||||
<term name="opus" form="short">op</term>
|
||||
@ -413,15 +416,13 @@
|
||||
<single>print.</single>
|
||||
<multiple>prints.</multiple>
|
||||
</term>
|
||||
|
||||
|
||||
<term name="number-of-pages" form="short">
|
||||
<single>tr</single>
|
||||
<multiple>tr</multiple>
|
||||
</term>
|
||||
<term name="paragraph" form="short">para</term>
|
||||
<term name="part" form="short">ph</term>
|
||||
<term name="section" form="short">sec</term>
|
||||
<term name="paragraph" form="short">đ.</term>
|
||||
<term name="part" form="short">ph.</term>
|
||||
<term name="section" form="short">sec.</term>
|
||||
<term name="supplement" form="short">
|
||||
<single>supp.</single>
|
||||
<multiple>supps.</multiple>
|
||||
@ -435,8 +436,8 @@
|
||||
<multiple>vv</multiple>
|
||||
</term>
|
||||
<term name="volume" form="short">
|
||||
<single>vol</single>
|
||||
<multiple>vols</multiple>
|
||||
<single>tập</single>
|
||||
<multiple>tập</multiple>
|
||||
</term>
|
||||
|
||||
<!-- SYMBOL LOCATOR FORMS -->
|
||||
@ -519,16 +520,16 @@
|
||||
<multiple>series creators</multiple>
|
||||
</term>
|
||||
<term name="director">
|
||||
<single>director</single>
|
||||
<multiple>directors</multiple>
|
||||
<single>chủ biênr</single>
|
||||
<multiple>chủ biên</multiple>
|
||||
</term>
|
||||
<term name="editor">
|
||||
<single>biên tập viên</single>
|
||||
<multiple>biên tập viên</multiple>
|
||||
</term>
|
||||
<term name="editorial-director">
|
||||
<single>biên tập viên</single>
|
||||
<multiple>biên tập viên</multiple>
|
||||
<single>chịu trách nhiệm xuất bản</single>
|
||||
<multiple>chịu trách nhiệm xuất bản</multiple>
|
||||
</term>
|
||||
<term name="illustrator">
|
||||
<single>họa sĩ</single>
|
||||
@ -589,28 +590,28 @@
|
||||
<multiple>cres.</multiple>
|
||||
</term>
|
||||
<term name="director" form="short">
|
||||
<single>dir.</single>
|
||||
<multiple>dirs.</multiple>
|
||||
<single>cb</single>
|
||||
<multiple>cb</multiple>
|
||||
</term>
|
||||
<term name="editor" form="short">
|
||||
<single>b.t.v</single>
|
||||
<multiple>b.t.v</multiple>
|
||||
<single>btv</single>
|
||||
<multiple>btv</multiple>
|
||||
</term>
|
||||
<term name="editorial-director" form="short">
|
||||
<single>b.t.v</single>
|
||||
<multiple>b.t.v</multiple>
|
||||
<single>ctnxb</single>
|
||||
<multiple>ctnxb</multiple>
|
||||
</term>
|
||||
<term name="illustrator" form="short">
|
||||
<single>h.s</single>
|
||||
<multiple>h.s</multiple>
|
||||
<single>hs</single>
|
||||
<multiple>hs</multiple>
|
||||
</term>
|
||||
<term name="translator" form="short">
|
||||
<single>b.d.v</single>
|
||||
<multiple>b.d.v</multiple>
|
||||
<single>bdv</single>
|
||||
<multiple>bdv</multiple>
|
||||
</term>
|
||||
<term name="editortranslator" form="short">
|
||||
<single>b.t.v & b.d.v</single>
|
||||
<multiple>b.t.v & b.d.v</multiple>
|
||||
<single>btv & bdv</single>
|
||||
<multiple>btv & bdv</multiple>
|
||||
</term>
|
||||
<term name="editor-translator" form="short">
|
||||
<single>b.t.v & b.d.v</single>
|
||||
@ -667,18 +668,18 @@
|
||||
<term name="editor-translator" form="verb-short">b.t & b.d bởi</term>
|
||||
|
||||
<!-- LONG MONTH FORMS -->
|
||||
<term name="month-01">Tháng Giêng</term>
|
||||
<term name="month-02">Tháng Hai</term>
|
||||
<term name="month-03">Tháng Ba</term>
|
||||
<term name="month-04">Tháng Tư</term>
|
||||
<term name="month-05">Tháng Năm</term>
|
||||
<term name="month-06">Tháng Sáu</term>
|
||||
<term name="month-07">Tháng Bảy</term>
|
||||
<term name="month-08">Tháng Tám</term>
|
||||
<term name="month-09">Tháng Chín</term>
|
||||
<term name="month-10">Tháng Mười</term>
|
||||
<term name="month-11">Tháng Mười-Một</term>
|
||||
<term name="month-12">Tháng Chạp</term>
|
||||
<term name="month-01">tháng một</term>
|
||||
<term name="month-02">tháng hai</term>
|
||||
<term name="month-03">tháng ba</term>
|
||||
<term name="month-04">tháng tư</term>
|
||||
<term name="month-05">tháng năm</term>
|
||||
<term name="month-06">tháng sáu</term>
|
||||
<term name="month-07">tháng bảy</term>
|
||||
<term name="month-08">tháng tám</term>
|
||||
<term name="month-09">tháng chín</term>
|
||||
<term name="month-10">tháng mười</term>
|
||||
<term name="month-11">tháng mười một</term>
|
||||
<term name="month-12">tháng mười hai</term>
|
||||
|
||||
<!-- SHORT MONTH FORMS -->
|
||||
<term name="month-01" form="short">tháng 1</term>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -60,19 +60,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
var defaultStyles =
|
||||
{
|
||||
"American Medical Association 11th edition" : 'american-medical-association',
|
||||
"American Political Science Association" : 'american-political-science-association',
|
||||
"American Psychological Association 7th edition" : 'apa',
|
||||
"American Sociological Association 6th/7th edition" : 'american-sociological-association',
|
||||
"Chicago Manual of Style 17th edition (author-date)" : 'chicago-author-date-17th-edition',
|
||||
"Cite Them Right 10th edition - Harvard" : 'harvard-cite-them-right-10th-edition',
|
||||
"IEEE" : 'ieee',
|
||||
"Modern Language Association 8th edition" : 'modern-language-association-8th-edition',
|
||||
"Nature" : 'nature'
|
||||
};
|
||||
|
||||
var locales = {};
|
||||
var styles = {};
|
||||
var selectedLocale;
|
||||
@ -199,7 +186,7 @@
|
||||
function loadStyles() {
|
||||
cslStylesManager.getStyles()
|
||||
.then(function (json) {
|
||||
var lastStyle = cslStylesManager._getLastUsedStyle();
|
||||
var lastStyle = cslStylesManager.getLastUsedStyle();
|
||||
var found = false;
|
||||
|
||||
var onStyleSelect = function (f) {
|
||||
@ -239,17 +226,11 @@
|
||||
};
|
||||
|
||||
for (var i = 0; i < json.length; i++) {
|
||||
if (json[i].dependent != 0) continue;
|
||||
|
||||
var el = document.createElement("span");
|
||||
el.setAttribute("data-value", json[i].name);
|
||||
el.textContent = json[i].title;
|
||||
if (cslStylesManager.defaultStyles[json[i].title] || json[i].name == lastStyle) {
|
||||
if (json[i].name == lastStyle)
|
||||
elements.styleSelectList.insertBefore(el, elements.styleSelectList.firstElementChild);
|
||||
else
|
||||
elements.styleSelectList.appendChild(el);
|
||||
|
||||
if (cslStylesManager.isStyleDefault(json[i].name) || json[i].name == lastStyle) {
|
||||
elements.styleSelectList.appendChild(el);
|
||||
el.onclick = onStyleSelect(onClickListElement(elements.styleSelectList, elements.styleSelect));
|
||||
} else {
|
||||
elements.styleSelectListOther.appendChild(el);
|
||||
@ -262,10 +243,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
var other = document.createElement("span");
|
||||
other.textContent = "More Styles...";
|
||||
elements.styleSelectList.appendChild(other);
|
||||
other.onclick = openOtherStyleList(elements.styleSelectListOther);
|
||||
if (elements.styleSelectListOther.children.length > 0) {
|
||||
var other = document.createElement("span");
|
||||
other.textContent = "More Styles...";
|
||||
elements.styleSelectListOther.appendChild(other);
|
||||
other.onclick = openOtherStyleList(elements.styleSelectList);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
var first = elements.styleSelectList.children[0];
|
||||
@ -273,7 +256,9 @@
|
||||
selectInput(elements.styleSelect, first, elements.styleSelectList, false);
|
||||
}
|
||||
})
|
||||
.catch(function (err) { });
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
function addEventListeners() {
|
||||
|
||||
@ -11,23 +11,17 @@ function CslStylesManager(isOnlineAvailable, isDesktopAvailable) {
|
||||
|
||||
this._lastStyleKey = "zoteroStyleId";
|
||||
|
||||
this.defaultStyles = {
|
||||
"American Medical Association 11th edition":
|
||||
"american-medical-association",
|
||||
"American Political Science Association":
|
||||
"american-political-science-association",
|
||||
"American Psychological Association 7th edition": "apa",
|
||||
"American Sociological Association 6th/7th edition":
|
||||
"american-sociological-association",
|
||||
"Chicago Manual of Style 17th edition (author-date)":
|
||||
"chicago-author-date-17th-edition",
|
||||
"Cite Them Right 10th edition - Harvard":
|
||||
"harvard-cite-them-right-10th-edition",
|
||||
IEEE: "ieee",
|
||||
"Modern Language Association 8th edition":
|
||||
"modern-language-association-8th-edition",
|
||||
Nature: "nature",
|
||||
};
|
||||
this._defaultStyles = [
|
||||
"american-medical-association",
|
||||
"american-political-science-association",
|
||||
"apa",
|
||||
"american-sociological-association",
|
||||
"chicago-author-date-17th-edition",
|
||||
"harvard-cite-them-right-10th-edition",
|
||||
"ieee",
|
||||
"modern-language-association-8th-edition",
|
||||
"nature",
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,31 +36,40 @@ CslStylesManager.prototype.addCustomStyle = function (style) {
|
||||
* @returns {Array<{name: string, title: string, dependent: number}>}
|
||||
*/
|
||||
CslStylesManager.prototype.getStyles = function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let jsonStyles = this._getStylesJson();
|
||||
let customStyles = this._customStylesStorage.getStyles();
|
||||
const self = this;
|
||||
const self = this;
|
||||
let jsonStyles = this._getStylesJson();
|
||||
let customStyles = this._customStylesStorage.getStyles();
|
||||
return Promise.all([jsonStyles, customStyles]).then(function (styles) {
|
||||
var lastStyle = self.getLastUsedStyle();
|
||||
var resultStyles = [];
|
||||
var resultStyleNames = self._customStylesStorage.getStyleNames();
|
||||
|
||||
Promise.all([jsonStyles, customStyles])
|
||||
.then(function (styles) {
|
||||
var resultStyles = styles[1];
|
||||
if (self._isDesktopAvailable && !self._isOnlineAvailable) {
|
||||
styles[0] = styles[0].filter(function (style, i) {
|
||||
return !!self.defaultStyles[style[i].title];
|
||||
});
|
||||
}
|
||||
styles[0].forEach(function (style) {
|
||||
resultStyles.push(style);
|
||||
});
|
||||
resolve(
|
||||
resultStyles.filter(function (style) {
|
||||
return style.dependent === 0;
|
||||
})
|
||||
if (self._isDesktopAvailable && !self._isOnlineAvailable) {
|
||||
styles[0] = styles[0].filter(function (style) {
|
||||
return (
|
||||
self._defaultStyles.indexOf(style.name) >= 0 ||
|
||||
style.name == lastStyle
|
||||
);
|
||||
})
|
||||
.catch(function (err) {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
|
||||
styles[1].forEach(function (style) {
|
||||
if (lastStyle === style.name) {
|
||||
resultStyles.unshift(style);
|
||||
} else {
|
||||
resultStyles.push(style);
|
||||
}
|
||||
});
|
||||
|
||||
styles[0].forEach(function (style) {
|
||||
if (lastStyle === style.name) {
|
||||
resultStyles.unshift(style);
|
||||
} else if (resultStyleNames.indexOf(style.name) === -1) {
|
||||
resultStyles.push(style);
|
||||
}
|
||||
});
|
||||
|
||||
return resultStyles;
|
||||
});
|
||||
};
|
||||
|
||||
@ -98,9 +101,14 @@ CslStylesManager.prototype.getStyle = function (styleName) {
|
||||
});
|
||||
};
|
||||
|
||||
CslStylesManager.prototype.getLastUsedStyle = function () {
|
||||
return localStorage.getItem(this._lastStyleKey);
|
||||
};
|
||||
|
||||
CslStylesManager.prototype.isStyleDefault = function (styleName) {
|
||||
return this._defaultStyles.indexOf(styleName) >= 0;
|
||||
};
|
||||
|
||||
CslStylesManager.prototype.saveLastUsedStyle = function (id) {
|
||||
localStorage.setItem(this._lastStyleKey, id);
|
||||
};
|
||||
CslStylesManager.prototype._getLastUsedStyle = function () {
|
||||
return localStorage.getItem(this._lastStyleKey);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user