63 lines
1.7 KiB
JavaScript

$("#themeToggle").on("click", function() {
const currentTheme = $("body").attr("data-bs-theme");
const newTheme = currentTheme === "light" ? "dark" : "light";
updateTheme(newTheme);
});
function updateTheme(theme) {
$("body").attr("data-bs-theme", theme);
localStorage.setItem("theme", theme);
}
function getCurrentDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = String(now.getMonth() + 1).padStart(2, '0');
var day = String(now.getDate()).padStart(2, '0');
var hours = String(now.getHours()).padStart(2, '0');
var minutes = String(now.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
// Sanitise a given string to remove HTML, making it DOM safe.
function sanitise(string) {
if (typeof string !== "string") {
return string;
}
const map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
"/": '&#x2F;',
};
const reg = /[&<>"'/]/ig;
return string.replace(reg, (match) => map[match]);
}
$(document).ready(function() {
// Activate all tooltips
$('[data-bs-toggle="tooltip"]').tooltip();
// Activate select2s
$(".select-2").each(function() {
var dropdownParent = $(this).attr("data-dropdownparent");
$(this).select2({
theme: "bootstrap",
minimumResultsForSearch: 10,
dropdownParent: dropdownParent
});
});
// Activate datepickers
// $(".input-group.date").datepicker({format: "yyyy-mm-dd"});
// Load theme
var theme = localStorage.getItem("theme");
if (theme === null)
theme = "light";
updateTheme(theme);
});