This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
test-unlit.html
252 lines (227 loc) · 10.1 KB
/
test-unlit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png">
<link rel="shortcut icon" href="img/favicon.ico">
<!-- The page supports both dark and light color schemes, and the page author prefers dark. -->
<meta name="color-scheme" content="dark light">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="./dist/bootstrap-unlit.css">
<!-- Prism.js for syntax highlighting -->
<script>
if (window.matchMedia("(prefers-color-scheme: light)").media === "not all") {
document.head.insertAdjacentHTML(
"beforeend",
"<link id=\"prism\" rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism-tomorrow.min.css\">"
);
}
</script>
<link id="prism-light" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism.min.css" media="(prefers-color-scheme: light)">
<link id="prism-dark" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism-tomorrow.min.css" media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)">
<title>bootstrap-unlit</title>
<style>
.d-clipboard {
position: relative;
float: right;
}
.btn-clipboard {
position: absolute;
top: .25rem;
right: .25rem;
opacity: .25;
}
.btn-clipboard:hover,
.btn-clipboard:active {
opacity: 1;
}
.token.comment {
font-style: italic;
}
</style>
</head>
<body>
<header>
<nav class="navbar navbar-dark navbar-expand-lg navbar-light bg-primary">
<div class="container">
<a class="navbar-brand">bootstrap-unlit</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto" id="nav-links"></ul>
</div>
</div>
</nav>
</header>
<main class="mt-5 mb-5">
<div class="container">
<div class="row">
<div class="col">
<h1>Dark Mode in a single CSS theme file <small>(dark first version)</small></h1>
</div>
</div>
<div class="row mt-5">
<div class="col-sm">
<h2>Basic Setup</h2>
<ul>
<li>A single, fully themed, 2 color mode, Bootstrap CSS</li>
<li>Filtered internally by stylesheet media filters</li>
<li>Does not require and additional JavaScript, or jQuery</li>
</ul>
<p>Replace the bootstrap stylesheet with the following code:</p>
<div class="code"><pre><code class="language-html language-js"><!-- Inform the browser that this page supports both dark
and light color schemes, and the page author prefers light. -->
<meta name="color-scheme" content="dark light">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="bootstrap-unlit.css">
</code></pre></div>
<p>This is all you need to enable dark mode with Bootstrap.</p>
<p>If you need to notify other components that the color-scheme has changed you can use this <a class="link collapsed" data-toggle="collapse" data-target=".more-code" href="#more" aria-expanded="false"
aria-controls="more" >example additional code</a>.</p>
</div>
</div><div class="row mt-5 collapse more-code" id="more">
<div class="col-sm">
<h2>Advanced Features</h2>
<p>You may also want to be notified when the browser changes the color scheme. For example you may want to toggle a `<code>light</code>` class in the `<html>` with this code:</p>
<div class="code"><pre><code class="language-html language-js"><script>
$(document).ready(function(){
// dark mode update and listner
function updateDarkColorScheme() {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
$("html").removeClass("dark").addClass('light');
} else {
$("html").addClass("dark").removeClass('light');
}
}
// Update on first load.
updateDarkColorScheme();
// and every time it changes
if (window.matchMedia) window.matchMedia("(prefers-color-scheme: light)").addListener( updateDarkColorScheme );
});
</script>
</code></pre></div>
<p>You <b class="text-danger">really don't need</b> the additional code.
This is only usefull if you have other dependancies that have not been coded to support dark mode.</p>
</div>
</div><div class="row">
<div class="col-sm">
<p>Read the <a href="readme.html">README.md</a> for more on this proof of concept.</p>
<p><i>(You are viewing this page in
<span class="d-no-preference-none d-dark-none d-light-none">{browser not supported}</span>
<span class="d-none d-no-preference-inline">no-preference</span>
<span class="d-none d-light-inline">light</span>
<span class="d-none d-dark-inline">dark</span>
mode.
Read about the helper classes in the <a href="readme.html#helper-classes">README.md</a>.)</i></p>
</div>
</div>
</div>
</main>
<footer id="copyright" class="text-center">
<small class="text-muted">© 2020</small>
</footer>
<!-- Optional JavaScript --> <!-- ** needed for toggle -->
<!-- jQuery first, then Popper.js + Bootstrap JS bundle -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<!-- Prism.js for syntax highlighting -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/plugins/autoloader/prism-autoloader.min.js"></script>
<!-- Clipboard.js for copy code -->
<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<!-- js.cookie for ... cookies -->
<script src="https://cdn.jsdelivr.net/npm/js-cookie/dist/js.cookie.min.js"></script>
<script>
$(document).ready(function(){
// only when jQuery is ready
// init the tooltip
// ----------------------------------------
$('[data-toggle="tooltip"]').tooltip()
.on('mouseleave', function () {
$(this).tooltip('hide')
});;
// Insert copy to clipboard button before .highlight
// borrowed from Bootstrap docs, uses Clipboard.js
// ----------------------------------------
$('div.code').each(function () {
var btnHtml = '<div class="d-clipboard"><button type="button" class="btn btn-outline-info btn-sm btn-clipboard" title="Copy to clipboard">Copy</button></div>'
$(this).before(btnHtml)
$('.btn-clipboard')
.tooltip()
.on('mouseleave', function () {
$(this).tooltip('hide')
});
});
var clipboard = new ClipboardJS('.btn-clipboard', {
target: function (trigger) {
return trigger.parentNode.nextElementSibling
}
});
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', 'Copied!')
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip('_fixTitle')
e.clearSelection()
});
clipboard.on('error', function (e) {
var modifierKey = /mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
$(e.trigger)
.attr('title', fallbackMsg)
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip('_fixTitle')
});
// dark mode update and listner
// ----------------------------------------
function updateDarkColorScheme() {
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) {
$("html").removeClass("dark").addClass('light');
} else {
$("html").addClass("dark").removeClass('light');
}
}
// Update on first load.
updateDarkColorScheme();
// and every time it changes
if (window.matchMedia) window.matchMedia("(prefers-color-scheme: light)").addListener( updateDarkColorScheme );
// dark mode cookie to send to server
// ----------------------------------------
var $prefers_color_scheme = Cookies.get("prefers_color_scheme");
function get_prefers_color_scheme() {
return (window.matchMedia && window.matchMedia("(prefers-color-scheme: light)").matches) ? "light" : "dark";
}
function update_prefers_color_scheme() {
Cookies.set("prefers_color_scheme", get_prefers_color_scheme());
}
// read & compare cookie `color-scheme`
if ((typeof $prefers_color_scheme === "undefined") || (get_prefers_color_scheme() != $prefers_color_scheme))
update_prefers_color_scheme();
// detect changes and change the cookie
if (window.matchMedia)
window.matchMedia("(prefers-color-scheme: light)").addListener( update_prefers_color_scheme );
// ----- Nav & Copyright ------------------
$.ajax( {
url: './navbar.htm', type: 'get',
success: function(content) {
$("#nav-links").html( content );
$("#nav-tests,#nav-unlit").addClass("active");
}
} );
$.ajax( {
url: './copyright.htm', type: 'get',
success: function(content) {
$("#copyright").html( content );
}
} );
});
</script>
</body>
</html>