From 787b97a30f788957eb471f2ed3f08b66a405b092 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 8 Apr 2023 22:26:43 -0400 Subject: static/js: Babel fish --- static/js/contextmenu.ts | 4 +-- static/js/fixedsearch.ts | 27 +++++++----------- static/js/pager.ts | 6 ++-- static/js/timeago.ts | 74 ++++++++++++++++++++++++------------------------ 4 files changed, 53 insertions(+), 58 deletions(-) (limited to 'static') diff --git a/static/js/contextmenu.ts b/static/js/contextmenu.ts index dea9bec..b19cf9e 100644 --- a/static/js/contextmenu.ts +++ b/static/js/contextmenu.ts @@ -1,11 +1,11 @@ (function () { - const hide = (triggers) => { + const hide = function (triggers) { for (let i = 0; i < triggers.length; i++) { triggers[i].checked = false; } }; - const hideIfClickedOutside = (menus, triggers, event) => { + const hideIfClickedOutside = function (menus, triggers, event) { for (let i = 0; i < menus.length; i++) { const active = triggers[i].checked === true; const outside = !menus[i].contains(event.target); diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts index 938e1f5..b42a620 100644 --- a/static/js/fixedsearch.ts +++ b/static/js/fixedsearch.ts @@ -170,7 +170,7 @@ function initialize() { if (firstRun) { loadScript(window.location.origin + "/js/fuzzysort.js") - .then(() => { + .then(function () { firstRun = false; fetchJson("/index.json", {}); @@ -185,7 +185,7 @@ }); search(query.value, data.items, options); - }).catch((error) => { + }).catch(function (error) { console.log("Error failed to load fuzzy sort: " + error); }); } @@ -204,18 +204,15 @@ if (results.length === 0 && term.length >= 0) { let separator = "—"; if (term.length === 0) separator = ""; - items = ` -
  • - ${ - escape(term) - } ${separator} No Results Found -
  • - `; + items = '
  • '.concat( + escape(term), + " ", + ).concat(separator, " No Results Found
  • "); dropdown.removeAttribute("hidden"); container.setAttribute("data-focus", ""); } else { dropdown.removeAttribute("hidden"); - for (const string in results.slice(0, 10)) { + for (var string in results.slice(0, 10)) { const title = results[string].obj.title; let highlight = fuzzysort.highlight( fuzzysort.single(escape(term), escape(title)), @@ -228,14 +225,12 @@ } items = items + - ` -
  • - ${highlight} -
  • - `; + '\n
  • \n', + ).concat(highlight, "\n
  • \n"); } } - dropdown.innerHTML = items; } }); diff --git a/static/js/pager.ts b/static/js/pager.ts index 01d40d7..8b89897 100644 --- a/static/js/pager.ts +++ b/static/js/pager.ts @@ -11,7 +11,7 @@ const url = self.location.href.split("#")[0].split("?")[0]; - const scrollRestore = (url) => { + const scrollRestore = function (url) { if (history.scrollRestoration) history.scrollRestoration = "manual"; if (localStorage["settings"]) { settings = JSON.parse(localStorage["settings"]); @@ -35,13 +35,13 @@ localStorage["settings"] = JSON.stringify(settings); }; - const scrollTrack = (url) => { + const scrollTrack = function (url) { const currentPosition = self.pageYOffset; settings["pager"][url] = currentPosition; localStorage["settings"] = JSON.stringify(settings); }; - const backTrack = (back, up, event) => { + const backTrack = function (back, up, event) { if (document.body.contains(up) && up.contains(event.target)) { event.preventDefault(); window.scrollTo(0, 0); diff --git a/static/js/timeago.ts b/static/js/timeago.ts index af974fc..f7567ed 100644 --- a/static/js/timeago.ts +++ b/static/js/timeago.ts @@ -8,47 +8,47 @@ style: "long", }); - const date = () => { - [...document.querySelectorAll("time")] - .forEach( - (element) => { - try { - const time: millisecond = new Date(element.dateTime) || new Date(); - const interval: second = ((new Date().getTime() - time.getTime()) / 1000); - - const seconds: number = Math.floor(interval); - const minutes: number = Math.floor(seconds / 60); - const hours: number = Math.floor(minutes / 60); - const days: number = Math.floor(hours / 24); - - if (Math.sign(seconds) === 1) { - if (seconds <= 60) { return element.textContent = relative.format(-1 * seconds, "second",); } - if (minutes <= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } - if (hours <= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } - if (days <= 60) { return element.textContent = relative.format(-1 * days, "day",); } - } - - if (Math.sign(seconds) === -1) { - if (-1 * days >= 60) { return element.textContent = relative.format(-1 * days, "day",); } - if (-1 * hours >= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } - if (-1 * minutes >= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } - if (-1 * seconds >= 0) { return element.textContent = relative.format(-1 * seconds, "second",); } - } - - } catch (error) { - console.error( - "Error: Unable to resolve relative time format!", - error, - ); + const date = function () { + const elements = document.querySelectorAll("time"); + for (let i = 0; i < elements.length; ++i) { + (function (element) { + try { + const time: millisecond = new Date(element.dateTime) || new Date(); + const interval: second = ((new Date().getTime() - time.getTime()) / 1000); + + const seconds: number = Math.floor(interval); + const minutes: number = Math.floor(seconds / 60); + const hours: number = Math.floor(minutes / 60); + const days: number = Math.floor(hours / 24); + + if (Math.sign(seconds) === 1) { + if (seconds <= 60) { return element.textContent = relative.format(-1 * seconds, "second",); } + if (minutes <= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } + if (hours <= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } + if (days <= 60) { return element.textContent = relative.format(-1 * days, "day",); } } - }, - ); - } + + if (Math.sign(seconds) === -1) { + if (-1 * days >= 60) { return element.textContent = relative.format(-1 * days, "day",); } + if (-1 * hours >= 48) { return element.textContent = relative.format(-1 * hours, "hour",); } + if (-1 * minutes >= 120) { return element.textContent = relative.format(-1 * minutes, "minute",); } + if (-1 * seconds >= 0) { return element.textContent = relative.format(-1 * seconds, "second",); } + } + + } catch (error) { + console.error( + "Error: Unable to resolve relative time format!", + error, + ); + } + })(elements[i]); + } + }; const substitution = setInterval(date, 4); - self.addEventListener("load", () => { - setTimeout(() => { + self.addEventListener("load", function () { + setTimeout(function () { clearInterval(substitution); setInterval(date, 1000); }, 1000); -- cgit v1.2.3