fix(submit): render slide cover preview as a real swiper

Replace the static first-image preview with the reference theme's
.new-swiper contract (loop + autoplay + prev/next + pagination) in both
the server-rendered box and the JS re-render, and run auto_fun for
slide covers so new_swiper initializes them.
This commit is contained in:
2026-09-06 10:39:39 +08:00
parent d0c6c3e431
commit b7f5523874
3 changed files with 54 additions and 5 deletions
@@ -38,6 +38,33 @@ test('image picker folds multi-select into a slide cover like the reference them
assert.doesNotMatch(js, /act === 'slide'/);
});
test('slide cover preview renders a real swiper like the reference theme', () => {
const featured = read('templates/parts/submit/featured.php');
const js = read('assets/js/front-submit.js');
const swiperContract =
/new-swiper scale-height" data-loop="true" data-autoplay="true" data-interval="2000" style="--scale-height:50%;"/;
assert.match(featured, swiperContract);
assert.match(js, swiperContract);
// Server-rendered slides iterate the saved attachment list.
assert.match(featured, /foreach \(\$data as \$slide\) : \?>/);
assert.match(featured, /<div class="swiper-slide"><img src="<\?php echo esc_url\(\(string\) \$slide\['url'\]\); \?>"/);
// Client-rendered slides come from the multi-select payload; the runtime
// initializer (auto_fun -> new_swiper) must run for slide covers too.
assert.match(js, /'<div class="swiper-slide"><img src="' \+ escapeHtml\(item\.url\) \+ '" alt=""><\/div>'/);
assert.match(js, /t === 'video' \|\| t === 'slide'/);
for (const control of ['swiper-wrapper', 'swiper-button-prev', 'swiper-button-next', 'swiper-pagination']) {
assert.match(featured, new RegExp(`class="${control}"`));
assert.match(js, new RegExp(`class="${control}"`));
}
// The static first-image slide preview is gone.
assert.doesNotMatch(js, /escapeHtml\(d\[0\]\.url\)/);
});
test('submit.css mirrors the reference visibility matrix for the buttons row', () => {
const css = read('assets/css/frontend/pages/submit.css');