Files
pages/static/js/theme-picker.js
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

38 lines
1.8 KiB
JavaScript

(() => {
const picker = document.querySelector('[data-theme-picker]');
if (!picker) return;
const select = picker.querySelector('[data-theme-select]');
const status = picker.querySelector('[data-theme-status]');
const themeLink = [...document.querySelectorAll('link[rel="stylesheet"]')]
.find(link => link.getAttribute('href') === picker.dataset.currentCss);
if (!themeLink) { picker.hidden = true; return; }
let current = picker.dataset.currentId;
select.addEventListener('change', () => {
const option = select.selectedOptions[0];
const candidate = document.createElement('link');
candidate.rel = 'stylesheet';
candidate.href = option.dataset.css;
select.disabled = true;
status.textContent = '';
// Load before replacing, so failure cannot leave an unstyled page. Keeping
// the link's position preserves editor/component overrides and avoids reload.
candidate.media = 'not all';
candidate.onload = () => {
themeLink.href = candidate.href;
candidate.remove();
current = option.value;
const secure = location.protocol === 'https:' ? '; Secure' : '';
document.cookie = 'pageswiki_theme=' + encodeURIComponent(current) + '; Path=/; SameSite=Lax; Max-Age=' + (current ? 31536000 : 0) + secure;
select.disabled = false;
document.dispatchEvent(new Event('pageswiki:theme'));
};
candidate.onerror = () => {
candidate.remove(); select.value = current; select.disabled = false;
status.textContent = picker.dataset.failed;
};
document.head.append(candidate);
});
document.addEventListener('pointerdown', event => { if (!picker.contains(event.target)) picker.open = false; });
picker.addEventListener('keydown', event => { if (event.key === 'Escape') { picker.open = false; picker.querySelector('summary').focus(); } });
})();