Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/themes/beastie/assets/js/theme-chooser.js
18096 views
1
/*
2
BSD 2-Clause License
3
4
Copyright (c) 1994-2026, The FreeBSD Documentation Project
5
Copyright (c) 2026, Vladlen Popolitov
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
1. Redistributions of source code must retain the above copyright notice, this
12
list of conditions and the following disclaimer.
13
14
2. Redistributions in binary form must reproduce the above copyright notice,
15
this list of conditions and the following disclaimer in the documentation
16
and/or other materials provided with the distribution.
17
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30
// FreeBSD light/dark theme persists
31
;(function() {
32
const toggle = document.getElementById('theme-switch');
33
if (!toggle) return;
34
35
// restore saved state
36
const saved = localStorage.getItem('theme-preference');
37
if (saved === 'dark') {
38
toggle.checked = true;
39
} else if (saved === 'light') {
40
toggle.checked = false;
41
}
42
// if state was no saved - use current state (CSS uses prefers-color-scheme)
43
// save state, when theme switched to or from dark
44
toggle.addEventListener('change', function() {
45
localStorage.setItem('theme-preference', this.checked ? 'dark' : 'light');
46
});
47
})();
48
49