1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

[NEW] Add Theme Switcher with Bootstrap/Bootswatch Themes (#6622)

This commit is contained in:
Sammy Ndabo 2024-12-24 12:15:45 +02:00 committed by GitHub
parent 5cf468159d
commit 8e70cd7187
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 292 additions and 31 deletions

View file

@ -1,29 +1,21 @@
document.addEventListener('DOMContentLoaded', function () {
const themeSwitcher = document.getElementById('theme-switcher');
const themeStylesheet = document.getElementById('theme-stylesheet');
document.addEventListener("DOMContentLoaded", function () {
const themeStylesheet = document.getElementById("theme-stylesheet");
// Load saved theme from local storage
const savedTheme = localStorage.getItem('theme');
const savedTheme = localStorage.getItem("theme");
if (savedTheme) {
const safeTheme = encodeURIComponent(savedTheme);
themeStylesheet.href = `styles/themes/${safeTheme}/bootstrap.min.css`;
themeSwitcher.value = savedTheme;
}
// Change theme on selection
themeSwitcher.addEventListener('change', function () {
const selectedTheme = themeSwitcher.value;
const safeTheme = encodeURIComponent(selectedTheme);
themeStylesheet.href = `styles/themes/${safeTheme}/bootstrap.min.css`;
// Save selected theme to local storage
localStorage.setItem('theme', selectedTheme);
});
// Initialize Select2 on all select elements with the 'select2' class
$('.select2').select2({
theme: 'bootstrap-5',
width: $( this ).data( 'width' ) ? $( this ).data( 'width' ) : $( this ).hasClass( 'w-100' ) ? '100%' : 'style',
placeholder: $( this ).data( 'placeholder' ),
$(".select2").select2({
theme: "bootstrap-5",
width: $(this).data("width")
? $(this).data("width")
: $(this).hasClass("w-100")
? "100%"
: "style",
placeholder: $(this).data("placeholder"),
});
});