Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions public/scripts/themes/theme-switcher.js
Original file line number Diff line number Diff line change
@@ -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"),
});
});
12 changes: 12 additions & 0 deletions public/styles/themes/litera/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/lumen/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/lux/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/materia/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/minty/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/morph/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/pulse/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/sandstone/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/simplex/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/sketchy/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/solar/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/spacelab/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/united/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/vapor/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/yeti/bootstrap.min.css

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/styles/themes/zephyr/bootstrap.min.css

Large diffs are not rendered by default.

101 changes: 89 additions & 12 deletions views/default3.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@
<a href=# onclick="return account_showDeleteAccount()">Delete account</a><br />
</span>
<span id="accountCreateLoginTokenSpan" style="display:none"><a href=# onclick="return account_createLoginToken()">Create login token</a><br /></span>
<a href=# onclick="return account_showThemesSwitcher()">Switch theme</a><br />
</p>
<br style=clear:both />
</div>
Expand Down Expand Up @@ -1065,7 +1066,7 @@
<li class="ass"><a class="dropdown-item" onclick="cmtermaction(9,0,event)">User PowerShell</a></li>
<li class="lin"><a class="dropdown-item" onclick="cmtermaction(1,0,event)"><b>Root Shell</b></a></li>
<li class="lin"><a class="dropdown-item" onclick="cmtermaction(8,0,event)">User Shell</a></li>
<li class="lin"><a class="dropdown-item" onclick="cmtermaction(100,0,event)">Login Shell</a></li>
<li class="lin"><a class="dropdown-item" onclick="cmtermaction(100,0,event)">Login Shell</a></li>
</ul>
</div>
<div class="btn-group dropdown-center me-1" id=connectbutton2sspan>
Expand Down Expand Up @@ -1111,7 +1112,7 @@
<td class="areaFoot d-flex flex-wrap">
<div class="d-flex align-items-center">
<input type=button onkeypress="return false" onkeydown="return false"
class="btn btn-primary btn-sm me-1" id="ctrlcbutton"
class="btn btn-primary btn-sm me-1" id="ctrlcbutton"
value="Ctl-C" onclick="termSendKey(3,'ctrlcbutton')" />
<input type=button onkeypress="return false" onkeydown="return false"
class="btn btn-primary btn-sm me-1" id="ctrlxbutton"
Expand Down Expand Up @@ -1148,7 +1149,7 @@
</span>
<select id="specialkeylist" class="form-select-sm me-1" onkeypress="return false"></select>
<input id="specialkeylistinput" type="button" onkeypress="return false"
class="btn btn-primary btn-sm me-1" value="Send"
class="btn btn-primary btn-sm me-1" value="Send"
title="Send the selected special key" onclick="sendSpecialKey()" />
</div>
</td>
Expand Down Expand Up @@ -1775,16 +1776,9 @@
<div class="footer2" style="display:none;">
<div class="row">
<div class="col-md-6 d-flex gap-2">
<span>Themes: </span>
<select id="theme-switcher" class="form-select form-select-xs">
{{!-- <option value="default">Default</option> --}}
<option value="cerulean">Cerulean</option>
<option value="cosmo">Cosmo</option>
<option value="cyborg">Cyborg</option>
</select>
</div>
<div class="col-md-6">
<a id="verifyEmailId2" style="display:none" href=# onclick="account_showVerifyEmail()">Verify Email</a>
<a id="verifyEmailId2" href=# onclick="account_showVerifyEmail()">Verify Email</a>
&nbsp;<a id="termsLinkFooter" href=terms>Terms &amp; Privacy</a>
</div>
</div>
Expand Down Expand Up @@ -14183,6 +14177,89 @@
}
}

function account_showThemesSwitcher() {
if (xxdialogMode) return false;
var themes = [
{ value: "default", label: "Default" },
{ value: "cerulean", label: "Cerulean" },
{ value: "cosmo", label: "Cosmo" },
{ value: "cyborg", label: "Cyborg" },
{ value: "darkly", label: "Darkly" },
{ value: "flatly", label: "Flatly" },
{ value: "journal", label: "Journal" },
{ value: "litera", label: "Litera" },
{ value: "lumen", label: "Lumen" },
{ value: "lux", label: "Lux" },
{ value: "materia", label: "Materia" },
{ value: "minty", label: "Minty" },
{ value: "morph", label: "Morph" },
{ value: "pulse", label: "Pulse" },
{ value: "sandstone", label: "Sandstone" },
{ value: "simplex", label: "Simplex" },
{ value: "sketchy", label: "Sketchy" },
{ value: "solar", label: "Solar" },
{ value: "spacelab", label: "Spacelab" },
{ value: "united", label: "United" },
{ value: "vapor", label: "Vapor" },
{ value: "yeti", label: "Yeti" },
{ value: "zephyr", label: "Zephyr" }
];

var currentTheme = getstore('theme') || 'default';
var lastThemes = JSON.parse(getstore('lastThemes') || '[]');

// Create a set of themes already in "Recent Themes" to avoid duplicates
var recentThemesSet = new Set(lastThemes);
var x = '<div class="form-group"><label for="theme-switcher">Select a theme:</label>';
x += '<select id="theme-switcher" class="form-select" onchange="account_switchThemeEx()">';
// Add "Recent Themes" optgroup
if (lastThemes.length > 0) {
x += '<optgroup label="Recent Themes">';
lastThemes.forEach(function (theme) {
var selected = theme === currentTheme ? ' selected' : '';
x += `<option value="${theme}"${selected}>${theme.charAt(0).toUpperCase() + theme.slice(1)}</option>`;
});
x += '</optgroup>';
}
// Add "All Themes" optgroup, excluding duplicates
x += '<optgroup label="All Themes">';
themes.forEach(function (theme) {
if (!recentThemesSet.has(theme.value)) {
var selected = theme.value === currentTheme ? ' selected' : '';
x += `<option value="${theme.value}"${selected}>${theme.label}</option>`;
}
});
x += '</optgroup>';
x += '</select></div>';

setModalContent('xxAddAgent', 'Switch Theme', x);
showModal('xxAddAgentModal', 'idx_dlgOkButton');
return false;
}

function account_switchThemeEx() {
var themeSwitcher = document.getElementById("theme-switcher");
const selectedTheme = themeSwitcher.value;
const safeTheme = encodeURIComponent(selectedTheme);
var themeStylesheet = document.getElementById("theme-stylesheet");
var newThemeStylesheet = `styles/themes/${safeTheme}/bootstrap.min.css`;
themeStylesheet.href = newThemeStylesheet;
// Save selected theme
putstore('theme', selectedTheme);
// Update last 4 themes selected
var lastThemes = JSON.parse(getstore('lastThemes') || '[]');
if (!lastThemes.includes(selectedTheme)) {
if (lastThemes.length >= 4) {
lastThemes.pop();
}
lastThemes.unshift(selectedTheme);
} else {
lastThemes = lastThemes.filter(theme => theme !== selectedTheme);
lastThemes.unshift(selectedTheme);
}
putstore('lastThemes', JSON.stringify(lastThemes));
}

function account_createMesh() {
// Check if we are disallowed from creating a device group
if ((userinfo.siteadmin != 0xFFFFFFFF) && ((userinfo.siteadmin & 64) != 0)) {
Expand Down Expand Up @@ -20600,4 +20677,4 @@
</script>
</body>

</html>
</html>
Loading