mirror of
https://github.com/django/django.git
synced 2025-06-03 10:39:12 +00:00
Fixed #34670 -- Improved loading of theme in admin.
Thanks Sarah Abderemane for the review.
This commit is contained in:
parent
e16d0c176e
commit
561e16d6a7
@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
{
|
||||
window.addEventListener('load', function(e) {
|
||||
|
||||
function setTheme(mode) {
|
||||
if (mode !== "light" && mode !== "dark" && mode !== "auto") {
|
||||
console.error(`Got invalid theme mode: ${mode}. Resetting to auto.`);
|
||||
@ -42,15 +40,12 @@
|
||||
currentTheme ? setTheme(currentTheme) : setTheme("auto");
|
||||
}
|
||||
|
||||
function setupTheme() {
|
||||
// Attach event handlers for toggling themes
|
||||
window.addEventListener('load', function(_) {
|
||||
const buttons = document.getElementsByClassName("theme-toggle");
|
||||
Array.from(buttons).forEach((btn) => {
|
||||
btn.addEventListener("click", cycleTheme);
|
||||
});
|
||||
});
|
||||
|
||||
initTheme();
|
||||
}
|
||||
|
||||
setupTheme();
|
||||
});
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
|
||||
{% block dark-mode-vars %}
|
||||
<link rel="stylesheet" href="{% static "admin/css/dark_mode.css" %}">
|
||||
<script src="{% static "admin/js/theme.js" %}" defer></script>
|
||||
<script src="{% static "admin/js/theme.js" %}"></script>
|
||||
{% endblock %}
|
||||
{% if not is_popup and is_nav_sidebar_enabled %}
|
||||
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
|
||||
|
Loading…
x
Reference in New Issue
Block a user