FreeSTAR-Status-Engine/js/main.js

62 lines
1.9 KiB
JavaScript
Raw Normal View History

function timeago() {
$("time.timeago").timeago();
$("time.timeago").each(function () {
var date = new Date($(this).attr("datetime"));
$(this).attr("title", date.toLocaleString());
});
2017-11-23 18:09:36 -05:00
}
(function () {
jQuery.timeago.settings.allowFuture = true;
timeago();
$("body").on("click", ".navbar-toggle", function () {
$($(this).data("target")).toggleClass("collapse");
});
var incidents = $(".timeline");
$("body").on("click", "#loadmore", function (e) {
e.preventDefault();
var url = $("#loadmore").attr("href") + "&ajax=true";
$("#loadmore").remove();
$.get(url, function (data) {
incidents.append(data);
timeago();
});
});
})();
2021-03-20 08:08:49 -04:00
var darkSwitch = document.getElementById("darkSwitch");
window.addEventListener("load", function () {
if (darkSwitch) {
initTheme();
darkSwitch.addEventListener("change", function () {
resetTheme();
});
}
});
function initTheme() {
var darkThemeSelected = localStorage.getItem("darkSwitch") !== null && localStorage.getItem("darkSwitch") === "dark";
darkSwitch.checked = darkThemeSelected;
darkThemeSelected ? document.body.setAttribute("data-theme", "dark") : document.body.removeAttribute("data-theme");
}
function resetTheme() {
if (darkSwitch.checked) {
document.body.setAttribute("data-theme", "dark");
localStorage.setItem("darkSwitch", "dark");
} else {
document.body.removeAttribute("data-theme");
localStorage.removeItem("darkSwitch");
}
}
2021-03-20 08:18:48 -04:00
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.body.setAttribute("data-theme", "dark");
}
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
const newColorScheme = e.matches ? document.body.setAttribute("data-theme", "dark") : document.body.removeAttribute("data-theme");
});