Update web/templates/base.html
This commit is contained in:
+15
-16
@@ -9,32 +9,31 @@
|
|||||||
|
|
||||||
{# === THEME SYSTEM (BEGIN) === #}
|
{# === THEME SYSTEM (BEGIN) === #}
|
||||||
<link rel="stylesheet" href="{% static 'css/theme-base.css' %}">
|
<link rel="stylesheet" href="{% static 'css/theme-base.css' %}">
|
||||||
<link id="theme-css" rel="stylesheet"
|
<!-- default to classic; JS below will swap based on storage/session -->
|
||||||
href="{% static 'themes/' %}{{ request.session.theme|default:'classic' }}.css">
|
<link id="theme-css" rel="stylesheet" href="{% static 'themes/classic.css' %}?v={{ APP_VERSION }}">
|
||||||
<script>
|
<script>
|
||||||
// Resolve theme ASAP: localStorage first, else server session fallback.
|
// Pre-resolve every theme to its exact static URL (works with hashed filenames).
|
||||||
// Then: set data-theme, point the theme CSS, and remember it.
|
window.THEME_URLS = {
|
||||||
|
{% for t in available_themes %}
|
||||||
|
"{{ t }}": "{% static 'themes/'|add:t|add:'.css' %}?v={{ APP_VERSION }}"{% if not forloop.last %},{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pick theme (localStorage > session fallback), set data-theme, and point the CSS href.
|
||||||
(function () {
|
(function () {
|
||||||
try {
|
try {
|
||||||
var server = "{{ request.session.theme|default:'classic' }}";
|
var server = "{{ request.session.theme|default:'classic' }}";
|
||||||
var stored = localStorage.getItem('theme');
|
var stored = localStorage.getItem('theme');
|
||||||
var theme = stored || server;
|
var theme = (stored && window.THEME_URLS[stored]) ? stored : server;
|
||||||
|
|
||||||
// Mark the document with the final theme
|
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
|
|
||||||
// Point the theme stylesheet (only if localStorage had something)
|
var href = window.THEME_URLS[theme] || window.THEME_URLS['classic'];
|
||||||
if (stored) {
|
|
||||||
var href = "{% static 'themes/' %}" + stored + ".css";
|
|
||||||
var link = document.getElementById('theme-css');
|
var link = document.getElementById('theme-css');
|
||||||
if (link && link.href.indexOf(href) === -1) link.href = href;
|
if (link && href) link.href = href;
|
||||||
}
|
|
||||||
|
|
||||||
// Persist the final theme so next load is consistent
|
try { localStorage.setItem('theme', theme); } catch(e) {}
|
||||||
localStorage.setItem('theme', theme);
|
window.__resolvedTheme = theme; // used later to toggle gradient body class
|
||||||
|
|
||||||
// Defer body class toggle to right after <body> opens (below).
|
|
||||||
window.__resolvedTheme = theme;
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user