cs-midi-docs/internal/server/static/app.js

65 lines
2.1 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
var input = document.querySelector('.search-form input');
if (input) {
input.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
input.value = '';
input.blur();
}
});
}
// --- Platform selector ---
var platformSel = document.getElementById('platform-select');
if (platformSel) {
var storedPlatform = localStorage.getItem('cs-midi-platform');
if (storedPlatform) platformSel.value = storedPlatform;
function applyPlatform() {
var platform = platformSel.value;
localStorage.setItem('cs-midi-platform', platform);
var blocks = document.querySelectorAll('[data-platform]');
var anyVisible = false;
blocks.forEach(function(el) {
if (el.getAttribute('data-platform') === platform) {
el.style.display = '';
anyVisible = true;
} else {
el.style.display = 'none';
}
});
var notice = document.getElementById('platform-notice');
if (notice) {
notice.style.display = (blocks.length > 0 && !anyVisible) ? '' : 'none';
}
}
platformSel.addEventListener('change', applyPlatform);
applyPlatform();
}
// --- Theme selector ---
var themeSel = document.getElementById('theme-select');
if (themeSel) {
var storedTheme = localStorage.getItem('cs-midi-theme') || 'auto';
themeSel.value = storedTheme;
function applyTheme() {
var theme = themeSel.value;
localStorage.setItem('cs-midi-theme', theme);
if (theme === 'auto') {
document.documentElement.removeAttribute('data-theme');
} else {
document.documentElement.setAttribute('data-theme', theme);
}
}
themeSel.addEventListener('change', applyTheme);
applyTheme();
}
});