From 537bac614fd82210b0519af9bb9b6e19b467f6a7 Mon Sep 17 00:00:00 2001 From: Pavel Tatarskiy Date: Wed, 25 Sep 2024 22:25:31 +0300 Subject: [PATCH] fix of theme selector --- assets/src/js/app/layout.js | 8 ++++---- assets/src/js/lib/asyncView.js | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/assets/src/js/app/layout.js b/assets/src/js/app/layout.js index 317b2ca..2a05cd7 100644 --- a/assets/src/js/app/layout.js +++ b/assets/src/js/app/layout.js @@ -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({ diff --git a/assets/src/js/lib/asyncView.js b/assets/src/js/lib/asyncView.js index 9ce846d..808ce82 100644 --- a/assets/src/js/lib/asyncView.js +++ b/assets/src/js/lib/asyncView.js @@ -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);