Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
5d4d2ef4df
@ -7,17 +7,14 @@
|
||||
const cache = new Map();
|
||||
const loaded = new Set([...document.scripts].map(script => script.src));
|
||||
// 局部替换导航只会换掉工作区节点,页面在 body_end 追加的行内脚本不会执行,
|
||||
// 导入/编辑弹窗这类按钮就会“点了没反应”。这里按源码内容去重后补执行一次。
|
||||
const executedInline = new Set(
|
||||
[...document.querySelectorAll('body script:not([src])')].map(script => script.textContent.trim())
|
||||
);
|
||||
const collectInlineScripts = doc => [...doc.querySelectorAll('body script:not([src])')]
|
||||
// 导入/编辑弹窗这类按钮就会“点了没反应”。带 data-caiwu-replay 的脚本每次替换后
|
||||
// 重新执行一次;各页面用的是同一段脚本,必须重跑才能绑定到新换进来的弹窗元素。
|
||||
// 脚本自身用目标元素的 data-ready 做去重,重复插入同一节点不会重复绑定。
|
||||
const collectReplayScripts = doc => [...doc.querySelectorAll('body script[data-caiwu-replay]')]
|
||||
.map(script => script.textContent.trim())
|
||||
.filter(code => code !== '' && !executedInline.has(code));
|
||||
const runInlineScripts = codes => {
|
||||
.filter(code => code !== '');
|
||||
const runReplayScripts = codes => {
|
||||
for (const code of codes || []) {
|
||||
if (executedInline.has(code)) continue;
|
||||
executedInline.add(code);
|
||||
const script = document.createElement('script');
|
||||
script.textContent = code;
|
||||
document.body.appendChild(script);
|
||||
@ -55,7 +52,7 @@
|
||||
node: document.importNode(node, true),
|
||||
title: doc.title,
|
||||
heading: doc.querySelector('#main-body h1')?.innerHTML || '',
|
||||
inline: collectInlineScripts(doc),
|
||||
replay: collectReplayScripts(doc),
|
||||
};
|
||||
}
|
||||
remember();
|
||||
@ -70,7 +67,7 @@
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
}
|
||||
runInlineScripts(next.inline);
|
||||
runReplayScripts(next.replay);
|
||||
cache.set(href, next);
|
||||
current = href;
|
||||
document.title = next.title;
|
||||
|
||||
@ -55,7 +55,8 @@
|
||||
@endonce
|
||||
|
||||
@push('body_end')
|
||||
<script>
|
||||
{{-- data-caiwu-replay:局部替换导航后需要重跑,才能绑定到新换进来的弹窗 --}}
|
||||
<script data-caiwu-replay>
|
||||
(() => {
|
||||
const modal = document.querySelector('[data-supplier-maintenance-modal]');
|
||||
if (!modal || modal.dataset.ready) return;
|
||||
|
||||
@ -44,7 +44,8 @@
|
||||
@endonce
|
||||
|
||||
@push('body_end')
|
||||
<script>
|
||||
{{-- data-caiwu-replay:局部替换导航后需要重跑,才能绑定到新换进来的弹窗 --}}
|
||||
<script data-caiwu-replay>
|
||||
(() => {
|
||||
const modal = document.querySelector('[data-supplier-import-modal]');
|
||||
if (!modal || modal.dataset.ready) return;
|
||||
|
||||
@ -43,6 +43,8 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase
|
||||
->assertSee('data-supplier-import-choose', false)
|
||||
->assertSee('modal.dataset.ready', false)
|
||||
->assertSee('data-supplier-maintenance-modal', false)
|
||||
// 页签是局部替换导航,弹窗脚本要带 replay 标记,替换后才会重新执行并绑定。
|
||||
->assertSee('data-caiwu-replay', false)
|
||||
->assertDontSee('workspace/supplier-payables/actions/board-deductions/import', false);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user