Files
com.xaymar.www/assets/site.js
T

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-12-24 20:05:17 +01:00
(function() {
2021-12-24 20:14:03 +01:00
'use strict';
2021-12-24 20:05:17 +01:00
// Support for Mobile Devices
document.querySelector("#navigation-toggle").addEventListener("click", (ev) => {
document.querySelector("#header #navigation").classList.toggle("open");
});
2022-01-12 05:53:50 +01:00
{ // Lazily load Media
let info = {}
new Promise((resolve, reject) => {
// Figure out what to load.
info.elements = document.querySelectorAll(".block-media > [data-lazyload]");
info.stack = Array.from(info.elements);
console.debug("Lazily loading " + info.stack.length + " elements...");
// Begin processing at 1ms intervals.
info.cbid = 0;
info.cbid = window.setInterval(() => {
let el = info.stack.pop();
2022-01-12 06:16:37 +01:00
if (el === undefined) {
reject();
return;
}
2022-01-12 05:53:50 +01:00
let lazycontent = el.querySelector("noscript");
2022-01-12 06:16:37 +01:00
if (lazycontent === undefined) {
reject();
return;
}
2022-01-12 05:53:50 +01:00
el.innerHTML = lazycontent.innerHTML;
if (info.stack.length == 0) {
window.clearInterval(info.cbid);
resolve();
2022-01-12 06:16:37 +01:00
return;
2022-01-12 05:53:50 +01:00
}
}, 1);
2022-01-12 06:16:37 +01:00
}).then(() => {
window.clearInterval(info.cbid);
}).catch(() => {
2022-01-12 05:53:50 +01:00
}).finally(() => {
console.debug("Lazy loading complete.");
});
}
2021-12-24 20:05:17 +01:00
})();