Skip to content

Commit 25c1be9

Browse files
committed
add dark mode toggle (fix #1937)
icons from bootstrap icons: https://icons.getbootstrap.com/?q=bulb
1 parent 4b033ee commit 25c1be9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

anitya/templates/master.html

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
>
2929
<header>
3030
<!-- Static navbar -->
31-
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
31+
<nav class="navbar navbar-expand-lg fixed-top">
3232
<div id="wrap" class="container-fluid ms-2">
3333
<a class="navbar-brand" href="{{url_for('anitya_ui.index')}}">
3434
release-monitoring.org
@@ -171,7 +171,7 @@
171171
{% block body %}{% endblock %}
172172
</main>
173173

174-
<footer class="footer mt-auto bg-light">
174+
<footer class="footer mt-auto">
175175
<div class="d-flex justify-content-center flex-nowrap">
176176
<p class="text-muted credit">
177177
Anitya ({{ version }}):
@@ -190,6 +190,8 @@
190190
Err ({{ cron_status.error_count }})
191191
Rate ({{ cron_status.ratelimit_count }})
192192
{% endif %}
193+
194+
<span id="theme-toggle"></span>
193195
</p>
194196
</div>
195197
</footer>
@@ -226,6 +228,37 @@
226228
delay: 600,
227229
});
228230
});
231+
232+
const html = document.documentElement;
233+
234+
const bulbOn = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lightbulb-fill" viewBox="0 0 16 16">
235+
<path d="M2 6a6 6 0 1 1 10.174 4.31c-.203.196-.359.4-.453.619l-.762 1.769A.5.5 0 0 1 10.5 13h-5a.5.5 0 0 1-.46-.302l-.761-1.77a2 2 0 0 0-.453-.618A5.98 5.98 0 0 1 2 6m3 8.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1l-.224.447a1 1 0 0 1-.894.553H6.618a1 1 0 0 1-.894-.553L5.5 15a.5.5 0 0 1-.5-.5"/>
236+
</svg>`;
237+
238+
const bulbOff = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-lightbulb-off" viewBox="0 0 16 16">
239+
<path fill-rule="evenodd" d="M2.23 4.35A6 6 0 0 0 2 6c0 1.691.7 3.22 1.826 4.31.203.196.359.4.453.619l.762 1.769A.5.5 0 0 0 5.5 13a.5.5 0 0 0 0 1 .5.5 0 0 0 0 1l.224.447a1 1 0 0 0 .894.553h2.764a1 1 0 0 0 .894-.553L10.5 15a.5.5 0 0 0 0-1 .5.5 0 0 0 0-1 .5.5 0 0 0 .288-.091L9.878 12H5.83l-.632-1.467a3 3 0 0 0-.676-.941 4.98 4.98 0 0 1-1.455-4.405zm1.588-2.653.708.707a5 5 0 0 1 7.07 7.07l.707.707a6 6 0 0 0-8.484-8.484zm-2.172-.051a.5.5 0 0 1 .708 0l12 12a.5.5 0 0 1-.708.708l-12-12a.5.5 0 0 1 0-.708"/>
240+
</svg>`;
241+
242+
const toggle = document.getElementById('theme-toggle');
243+
let currentTheme = localStorage.getItem('theme');
244+
if (!currentTheme) {
245+
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
246+
if (prefersDark) {
247+
currentTheme = 'dark';
248+
} else {
249+
currentTheme = 'light';
250+
}
251+
}
252+
253+
html.setAttribute('data-bs-theme', currentTheme);
254+
toggle.innerHTML = currentTheme === 'dark' ? bulbOff : bulbOn;
255+
toggle.onclick = function() {
256+
currentTheme = currentTheme === 'dark' ? 'light' : 'dark';
257+
html.setAttribute('data-bs-theme', currentTheme);
258+
localStorage.setItem('theme', currentTheme);
259+
toggle.innerHTML = currentTheme === 'dark' ? bulbOff : bulbOn;
260+
};
261+
229262
</script>
230263
{% block jscript %}{% endblock %}
231264
</body>

news/1937.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement dark mode via Bootstrap 5.3

0 commit comments

Comments
 (0)