aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-04-08 22:26:43 -0400
committertdro <tdro@noreply.example.com>2023-04-08 22:26:43 -0400
commit787b97a30f788957eb471f2ed3f08b66a405b092 (patch)
tree95f10e86ca44f5bea78c119753a8d09ad675fc0d /assets
parentf0cbdec755e91fc3f02e96b03e1fc200b135815e (diff)
downloadcanory-787b97a30f788957eb471f2ed3f08b66a405b092.tar.gz
canory-787b97a30f788957eb471f2ed3f08b66a405b092.tar.bz2
canory-787b97a30f788957eb471f2ed3f08b66a405b092.zip
static/js: Babel fish
Diffstat (limited to 'assets')
-rw-r--r--assets/js/index.js113
1 files changed, 53 insertions, 60 deletions
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 = `
- <li>
- <a href="javascript: void(0)" tabindex="0">${escape(term)} ${separator} No Results Found</a>
- </li>
- `;
+ items = '<li><a href="javascript: void(0)" tabindex="0">'.concat(escape(term), " ").concat(separator, " No Results Found</a></li>");
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)), "<span>", "</span>");
if (highlight === null) {
highlight = title;
}
- items = items + `
- <li>
- <a href="${results[string].obj.url}" tabindex="0">${highlight}</a>
- </li>
- `;
+ items = items + '\n<li>\n<a href="'.concat(results[string].obj.url, '" tabindex="0">').concat(highlight, "</a>\n</li>\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);