diff --git a/themes/develop/include/head/js.twig b/themes/develop/include/head/js.twig index 60c14c1..133c799 100755 --- a/themes/develop/include/head/js.twig +++ b/themes/develop/include/head/js.twig @@ -7,6 +7,30 @@ {% set js = module('V2_Js') %} +{% else %} + {# htmx でスワップされたコンテンツの組み込みJS(src/js/main.js の window.dispatch)を再初期化する。 + acms.js を読み込む場合はコア側が行う。htmx 4 の htmx:after:swap は target がテキストノードになる + ことがあるため、挿入されたノード一覧を持つ htmx:after:settle を使う。htmx 2(CMS 3.2)向けに + afterSwap も残し、htmx 4 で htmx-2-compat 拡張が発火させる afterSwap は無視する。 #} + {# prettier-ignore #} + {% endif %} diff --git a/themes/develop/src/js/main.js b/themes/develop/src/js/main.js index 9b6b0d5..b6adc6e 100755 --- a/themes/develop/src/js/main.js +++ b/themes/develop/src/js/main.js @@ -77,14 +77,6 @@ async function main() { window.dispatch = createBuildInJsDispatcher(); if (window.ACMS === undefined) { window.dispatch(document); - // htmx (htmx_load_strategy: static) でスワップされたコンテンツに対しても組み込みJSを - // 再初期化する。ACMS読み込み時は window.dispatch === ACMS.Dispatch であり、コア側の - // afterSwap リスナー(main.php)がそちらを呼ぶため、ここでは未読込時のみ実行して二重初期化を避ける。 - window.addEventListener('htmx:afterSwap', (event) => { - if (event.target instanceof HTMLElement) { - window.dispatch(event.target); - } - }); } /**