Skip to content

Commit

Permalink
fix of theme selector
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Sep 25, 2024
1 parent c7ba1a8 commit 537bac6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions assets/src/js/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ window.progress = {
};

import {bindAsync} from '../lib/async';
// const av = (await import('../lib/asyncView')).initAsyncView;
const av = (await import('../lib/asyncView')).initAsyncView;
import themeSelector from "../lib/themeSelector";

function onLoad() {
themeSelector(document.querySelector('[data-toggle-theme]'));
// av(document.querySelector('nav'), 'index', async function() {
// themeSelector(document.querySelector('[data-toggle-theme]'));
// });
av(document.querySelector('nav'), 'index', async function() {
themeSelector(document.querySelector('[data-toggle-theme]'));
});
document.body.style.display = 'flex';
hideProgress();
bindAsync({
Expand Down
5 changes: 4 additions & 1 deletion assets/src/js/lib/asyncView.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export function initAsyncView(target, name, init, destroy) {
}
window.dispatchEvent(event);
}
const key = `__async${name}_loaded`;
let keySuffix = '';
if (init) keySuffix += init.toString();
if (destroy) keySuffix += destroy.toString();
let key = `__async${name}_loaded_${MD5(keySuffix)}`;
if (!window[key]) {
window.addEventListener(`async:${name}`, onLoad);
window.addEventListener(`async:${name}_destroy`, onDestroy);
Expand Down

0 comments on commit 537bac6

Please sign in to comment.