fix(frontend): fix non saving theme

This commit is contained in:
Romain J 2020-05-16 13:43:12 +02:00
parent fd0b936f67
commit e240980d48
3 changed files with 23 additions and 19 deletions

View file

@ -13,24 +13,31 @@ Don't judge me
window.theme = document.querySelector('input[name=theme]');
theme.checked = document.documentElement.getAttribute('data-theme') === 'dark';
theme.addEventListener('change', function () {
document.documentElement.setAttribute('data-theme', this.checked ? 'dark' : 'light')
window.applyTheme = function(theme) {
document.documentElement.setAttribute('data-theme', theme);
let cards = document.querySelectorAll(".uk-card.uk-card-default,.uk-card.uk-card-secondary");
cards.forEach(card => {
if (document.documentElement.getAttribute('data-theme') === 'dark') {
card.classList.replace("uk-card-default", `uk-card-secondary`);
if (theme === 'dark') {
card.classList.replace("uk-card-default", `uk-card-secondary`)
} else {
card.classList.replace("uk-card-secondary", `uk-card-default`);
card.classList.replace("uk-card-secondary", `uk-card-default`)
}
})
document.cookie = `theme=${theme}`
}
theme.addEventListener('change', function () {
applyTheme(theme.checked ? 'dark' : 'light')
})
</script>
<script>
let cookies = document.cookie.split('; ');
let banner_cookie = document.cookie.split('; ').filter(e => e.startsWith('cookie-banner='))[0]
let banner_cookie = document.cookie.split('; ').filter(e => e.startsWith('cookie-banner='))[0];
if (banner_cookie == undefined || banner_cookie.split('cookie-banner=')[1] != 'hidden') {
if (banner_cookie === undefined || banner_cookie.split('cookie-banner=')[1] !== 'hidden') {
cookie_notification = UIkit.notification(
'<span data-uk-icon="quote-right"></span> {% trans "Bla bla bla... bannière alakon pour dire qu&amp;on utilise des cookies (pour la langue et cette bannière)" %}',
{pos: 'bottom-center'}
@ -44,12 +51,9 @@ Don't judge me
</script>
<script>
let cards = document.querySelectorAll(".uk-card.uk-card-default,.uk-card.uk-card-secondary");
cards.forEach(card => {
if (document.documentElement.getAttribute('data-theme') === 'dark') {
card.classList.replace("uk-card-default", `uk-card-secondary`);
} else {
card.classList.replace("uk-card-secondary", `uk-card-default`);
}
})
let theme_cookie = document.cookie.split('; ').filter(e => e.startsWith('theme='))[0];
if (theme_cookie !== undefined) {
applyTheme(theme_cookie.split('theme=')[1]);
window.theme.checked = theme_cookie.split('theme=')[1] === 'dark'
}
</script>

View file

@ -173,7 +173,7 @@ msgid "Discutons plus en détails de votre proposition ! Nous sommes ouvert à t
msgstr "Let's discuss your proposal in more detail! We are open to any partnership."
#: apps/gnous_eu/templates/layouts/foot.html:26
#: apps/gnous_eu/templates/layouts/foot.html:42
msgid "Bla bla bla... bannière alakon pour dire qu&amp;on utilise des cookies (pour la langue et cette bannière)"
msgstr "GnousEU uses cookies in order to save the language of the site you are using and the closing of this banner."
msgstr "GnousEU uses cookies in order to save the language of the site you are using, its theme and the closing of this banner."

View file

@ -165,6 +165,6 @@ msgstr ""
msgid "Discutons plus en détails de votre proposition ! Nous sommes ouvert à tout partenariat."
msgstr ""
#: apps/gnous_eu/templates/layouts/foot.html:26
#: apps/gnous_eu/templates/layouts/foot.html:42
msgid "Bla bla bla... bannière alakon pour dire qu&amp;on utilise des cookies (pour la langue et cette bannière)"
msgstr "GnousEU utilise des cookies afin de sauvegarder la langue du site que vous utilisez ainsi que pour la fermeture de cette bannière."
msgstr "GnousEU utilise des cookies afin de sauvegarder la langue du site que vous utilisez, son theme ainsi que pour la fermeture de cette bannière."