mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
save last used style, select first from list if none saved
This commit is contained in:
31
src/code.js
31
src/code.js
@ -194,6 +194,16 @@
|
||||
fetch("https://www.zotero.org/styles-files/styles.json")
|
||||
.then(function (resp) { return resp.json(); })
|
||||
.then(function (json) {
|
||||
var lastStyle = getLastUsedStyle();
|
||||
var found = false;
|
||||
|
||||
var onStyleSelect = function (f) {
|
||||
return function (ev) {
|
||||
var sel = ev.target.getAttribute("data-value");
|
||||
saveLastUsedStyle(sel);
|
||||
f(ev);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < json.length; i++) {
|
||||
if (json[i].dependent != 0) continue;
|
||||
|
||||
@ -202,7 +212,18 @@
|
||||
el.textContent = json[i].title;
|
||||
switchClass(el, displayNoneClass, true);
|
||||
elements.styleSelectList.append(el);
|
||||
el.onclick = onClickListElement(elements.styleSelectList, elements.styleSelect);
|
||||
el.onclick = onStyleSelect(onClickListElement(elements.styleSelectList, elements.styleSelect));
|
||||
if (json[i].name == lastStyle) {
|
||||
el.setAttribute("selected", "");
|
||||
selectInput(elements.styleSelect, el, elements.styleSelectList);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
var first = elements.styleSelectList.children[0];
|
||||
first.setAttribute("selected", "");
|
||||
selectInput(elements.styleSelect, first, elements.styleSelectList);
|
||||
}
|
||||
})
|
||||
.catch(function (err) { });
|
||||
@ -397,6 +418,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
function saveLastUsedStyle(id) {
|
||||
localStorage.setItem("mendStyleId", id);
|
||||
}
|
||||
|
||||
function getLastUsedStyle() {
|
||||
return localStorage.getItem("mendStyleId");
|
||||
}
|
||||
|
||||
function saveSettings(id) {
|
||||
mendAppId = id;
|
||||
localStorage.setItem("mendAppId", id);
|
||||
|
||||
Reference in New Issue
Block a user