mirror of
https://github.com/django/django.git
synced 2025-06-05 19:49:13 +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';
|
'use strict';
|
||||||
{
|
{
|
||||||
window.addEventListener('load', function(e) {
|
|
||||||
|
|
||||||
function setTheme(mode) {
|
function setTheme(mode) {
|
||||||
if (mode !== "light" && mode !== "dark" && mode !== "auto") {
|
if (mode !== "light" && mode !== "dark" && mode !== "auto") {
|
||||||
console.error(`Got invalid theme mode: ${mode}. Resetting to auto.`);
|
console.error(`Got invalid theme mode: ${mode}. Resetting to auto.`);
|
||||||
@ -42,15 +40,12 @@
|
|||||||
currentTheme ? setTheme(currentTheme) : setTheme("auto");
|
currentTheme ? setTheme(currentTheme) : setTheme("auto");
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupTheme() {
|
window.addEventListener('load', function(_) {
|
||||||
// Attach event handlers for toggling themes
|
|
||||||
const buttons = document.getElementsByClassName("theme-toggle");
|
const buttons = document.getElementsByClassName("theme-toggle");
|
||||||
Array.from(buttons).forEach((btn) => {
|
Array.from(buttons).forEach((btn) => {
|
||||||
btn.addEventListener("click", cycleTheme);
|
btn.addEventListener("click", cycleTheme);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
initTheme();
|
initTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTheme();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
|
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
|
||||||
{% block dark-mode-vars %}
|
{% block dark-mode-vars %}
|
||||||
<link rel="stylesheet" href="{% static "admin/css/dark_mode.css" %}">
|
<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 %}
|
{% endblock %}
|
||||||
{% if not is_popup and is_nav_sidebar_enabled %}
|
{% if not is_popup and is_nav_sidebar_enabled %}
|
||||||
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
|
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user