Fix issue #290: ViewTransitions on Layout.astro disables the theme
This commit is contained in:
@ -17,6 +17,7 @@ import { UI } from '~/utils/config';
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initTheme = function () {
|
||||||
if ((defaultTheme && defaultTheme.endsWith(':only')) || (!localStorage.theme && defaultTheme !== 'system')) {
|
if ((defaultTheme && defaultTheme.endsWith(':only')) || (!localStorage.theme && defaultTheme !== 'system')) {
|
||||||
applyTheme(defaultTheme.replace(':only', ''));
|
applyTheme(defaultTheme.replace(':only', ''));
|
||||||
} else if (
|
} else if (
|
||||||
@ -27,6 +28,8 @@ import { UI } from '~/utils/config';
|
|||||||
} else {
|
} else {
|
||||||
applyTheme('light');
|
applyTheme('light');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
initTheme();
|
||||||
|
|
||||||
function attachEvent(selector, event, fn) {
|
function attachEvent(selector, event, fn) {
|
||||||
const matches = typeof selector === 'string' ? document.querySelectorAll(selector) : selector;
|
const matches = typeof selector === 'string' ? document.querySelectorAll(selector) : selector;
|
||||||
@ -134,12 +137,13 @@ import { UI } from '~/utils/config';
|
|||||||
document.getElementById('header')?.classList.remove('h-screen');
|
document.getElementById('header')?.classList.remove('h-screen');
|
||||||
document.getElementById('header')?.classList.remove('expanded');
|
document.getElementById('header')?.classList.remove('expanded');
|
||||||
document.querySelector('#header nav')?.classList.add('hidden');
|
document.querySelector('#header nav')?.classList.add('hidden');
|
||||||
}
|
};
|
||||||
|
|
||||||
window.onload = onLoad;
|
window.onload = onLoad;
|
||||||
window.onpageshow = onPageShow;
|
window.onpageshow = onPageShow;
|
||||||
|
|
||||||
document.addEventListener('astro:after-swap', () => {
|
document.addEventListener('astro:after-swap', () => {
|
||||||
|
initTheme();
|
||||||
onLoad();
|
onLoad();
|
||||||
onPageShow();
|
onPageShow();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user