mirror of
https://github.com/lovasoa/whitebophir
synced 2024-11-10 06:24:17 +00:00
Convert to old javascript for compatibility
This commit is contained in:
parent
4439457520
commit
b0a428ab29
3 changed files with 26 additions and 30 deletions
|
@ -75,6 +75,6 @@
|
|||
</footer>
|
||||
</body>
|
||||
|
||||
<script src="../js/index.js"></script>
|
||||
<script src="../js/index.js" async defer></script>
|
||||
|
||||
</html>
|
|
@ -94,29 +94,26 @@ Tools.boardName = (function () {
|
|||
Tools.socket.emit("getboard", Tools.boardName);
|
||||
|
||||
function saveBoardNametoLocalStorage() {
|
||||
const boardName = Tools.boardName;
|
||||
var boardName = Tools.boardName;
|
||||
if (boardName.toLowerCase() === 'anonymous') return;
|
||||
|
||||
var recentBoards, key = "recent-boards";
|
||||
try {
|
||||
const key = "recent-boards";
|
||||
let recentBoards = JSON.parse(localStorage.getItem(key)) || [];
|
||||
|
||||
const nameIndex = recentBoards.findIndex((name) => {
|
||||
return name.toLowerCase() === boardName.toLowerCase();
|
||||
});
|
||||
|
||||
if (nameIndex > -1) recentBoards.splice(nameIndex, 1);
|
||||
|
||||
if (recentBoards.length === 20) recentBoards.pop();
|
||||
|
||||
recentBoards = [boardName, ...recentBoards];
|
||||
localStorage.setItem(key, JSON.stringify(recentBoards));
|
||||
} catch (e) {
|
||||
console.error("Unable to update localStorage.", e);
|
||||
recentBoards = JSON.parse(localStorage.getItem(key));
|
||||
if (!Array.isArray(recentBoards)) throw new Error("Invalid type");
|
||||
} catch(e) {
|
||||
// On localstorage or json error, reset board list
|
||||
recentBoards = [];
|
||||
console.log("Board history loading error", e);
|
||||
}
|
||||
recentBoards = recentBoards.filter(function (name) {
|
||||
return name !== boardName;
|
||||
});
|
||||
recentBoards.unshift(boardName);
|
||||
recentBoards = recentBoards.slice(0, 20);
|
||||
localStorage.setItem(key, JSON.stringify(recentBoards));
|
||||
}
|
||||
|
||||
saveBoardNametoLocalStorage();
|
||||
// Refresh recent boards list on each page show
|
||||
window.addEventListener("pageshow", saveBoardNametoLocalStorage);
|
||||
|
||||
Tools.HTML = {
|
||||
template: new Minitpl("#tools > .tool"),
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
window.addEventListener("pageshow", () => showRecentBoards());
|
||||
|
||||
function showRecentBoards() {
|
||||
const parent = document.getElementById("recent-boards");
|
||||
const ul = document.querySelector("#recent-boards ul");
|
||||
var parent = document.getElementById("recent-boards");
|
||||
var ul = document.querySelector("#recent-boards ul");
|
||||
ul && parent.removeChild(ul);
|
||||
parent.classList.add("hidden");
|
||||
|
||||
const recentBoards = JSON.parse(localStorage.getItem("recent-boards")) || [];
|
||||
|
||||
var recentBoards = JSON.parse(localStorage.getItem("recent-boards")) || [];
|
||||
if (recentBoards.length === 0) return;
|
||||
|
||||
const list = document.createElement("ul");
|
||||
var list = document.createElement("ul");
|
||||
|
||||
recentBoards.forEach(function(name) {
|
||||
const listItem = document.createElement("li");
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", `/boards/${name}`);
|
||||
var listItem = document.createElement("li");
|
||||
var link = document.createElement("a");
|
||||
link.setAttribute("href", `/boards/${encodeURIComponent(name)}`);
|
||||
link.textContent = name;
|
||||
listItem.appendChild(link);
|
||||
list.appendChild(listItem);
|
||||
|
@ -24,3 +21,5 @@ function showRecentBoards() {
|
|||
parent.appendChild(list);
|
||||
parent.classList.remove("hidden");
|
||||
}
|
||||
|
||||
window.addEventListener("pageshow", showRecentBoards);
|
Loading…
Reference in a new issue