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 --- assets/js/index.js | 113 +++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 60 deletions(-) (limited to 'assets') diff --git a/assets/js/index.js b/assets/js/index.js index 67331da..22c6cb7 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -9,7 +9,7 @@ pager: {} }; 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"]); @@ -32,12 +32,12 @@ settings["pager"][url] = self.pageYOffset; 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); @@ -335,12 +335,12 @@ }); })(); (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); @@ -492,7 +492,7 @@ let firstRun = true; function initialize() { if (firstRun) { - loadScript(window.location.origin + "/js/fuzzysort.js").then(()=>{ + loadScript(window.location.origin + "/js/fuzzysort.js").then(function() { firstRun = false; fetchJson("/index.json", {}); const options = { @@ -507,7 +507,7 @@ search(query.value, data.items, options); }); search(query.value, data.items, options); - }).catch((error)=>{ + }).catch(function(error) { console.log("Error failed to load fuzzy sort: " + error); }); } @@ -523,26 +523,18 @@ 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)), "", ""); if (highlight === null) { highlight = title; } - items = items + ` -
  • - ${highlight} -
  • - `; + items = items + '\n
  • \n').concat(highlight, "\n
  • \n"); } } dropdown.innerHTML = items; @@ -555,53 +547,54 @@ numeric: "always", style: "long" }); - const date = ()=>{ - [ - ...document.querySelectorAll("time") - ].forEach((element)=>{ - try { - const time = new Date(element.dateTime) || new Date(); - const interval = (new Date().getTime() - time.getTime()) / 1000; - const seconds = Math.floor(interval); - const minutes = Math.floor(seconds / 60); - const hours = Math.floor(minutes / 60); - const days = 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"); + const date = function() { + const elements = document.querySelectorAll("time"); + for(let i = 0; i < elements.length; ++i){ + (function(element) { + try { + const time = new Date(element.dateTime) || new Date(); + const interval = (new Date().getTime() - time.getTime()) / 1000; + const seconds = Math.floor(interval); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = 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 (-1 * seconds >= 0) { - return element.textContent = relative.format(-1 * seconds, "second"); + 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); } - } 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