85 lines
2.4 KiB
JavaScript
85 lines
2.4 KiB
JavaScript
// @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0
|
|
/****************************************************************************
|
|
* It's Eric Woodward's Site
|
|
*
|
|
* Copyright 2014-2023 Eric Woodward
|
|
* Source released under CC0 Public Domain License v1.0
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
****************************************************************************/
|
|
|
|
export const onLoad = () => {
|
|
if (window.dayjs) dayjs.extend(window.dayjs_plugin_relativeTime);
|
|
|
|
// Indicate JS is loaded
|
|
document.documentElement.className =
|
|
document.documentElement.className.replace("no-js", "js");
|
|
|
|
// Enable cached fonts ASAP
|
|
if (window.Cookies && !!Cookies.get("fonts_loaded")) {
|
|
document.documentElement.className += " js-hasFontsLoaded";
|
|
}
|
|
|
|
docReady(() => {
|
|
setTimeout(() => {
|
|
if (!window.Cookies || !window.FontFaceObserver) return;
|
|
|
|
// Handle Fonts
|
|
const fontRaleway = new FontFaceObserver("raleway"),
|
|
fontUnbounded = new FontFaceObserver("unbounded");
|
|
Promise.all([
|
|
fontRaleway.load(null, 5000),
|
|
fontUnbounded.load(null, 6000),
|
|
])
|
|
.then(() => {
|
|
if (
|
|
document.documentElement.className.indexOf(
|
|
"js-hasFontsLoaded"
|
|
) == -1
|
|
) {
|
|
document.documentElement.className +=
|
|
" js-hasFontsLoaded";
|
|
}
|
|
Cookies.set("fonts_loaded", true);
|
|
})
|
|
.catch((err) => {
|
|
console.log("Error!", err);
|
|
});
|
|
|
|
// Lazy-Load Media
|
|
if (typeof loadMedia === "function") {
|
|
loadMedia(".js-lazyLoader", null, true);
|
|
}
|
|
|
|
// Add relative dates via dayjs
|
|
if (window.dayjs) {
|
|
const times = document.getElementsByTagName("time");
|
|
|
|
[].forEach.call(times, function (the_time) {
|
|
let pub_time = the_time.getAttribute("datetime");
|
|
if (the_time.className.indexOf("js-noRelativeTime") === -1)
|
|
the_time.innerHTML +=
|
|
' <span class="js-momentTime">(' +
|
|
dayjs(pub_time).from(dayjs()) +
|
|
")</span>";
|
|
the_time.classList.add("isDone");
|
|
});
|
|
}
|
|
|
|
if (document.documentElement.className.indexOf("is404") > -1) {
|
|
document.getElementById("searchQuery").value =
|
|
window.location.pathname
|
|
.replace(/\\.html?$/, "")
|
|
.replace(/\//g, " ");
|
|
}
|
|
|
|
document
|
|
.getElementById("searchForm")
|
|
.addEventListener("submit", function (e) {
|
|
document.getElementById("searchQuery").value +=
|
|
" site:" + window.location.hostname;
|
|
});
|
|
}, 1);
|
|
});
|
|
};
|
|
// @license-end
|