feat(lightbox): 接入全站图片预览
This commit is contained in:
@@ -24,8 +24,6 @@ test('comment smilie assets and their runtime chain stay removed', () => {
|
||||
'assets/js/build/public.js',
|
||||
'assets/js/comment-tools.js',
|
||||
'assets/js/enhancements.js',
|
||||
'assets/js/runtime/imgbox.js',
|
||||
'assets/js/runtime/imgbox.min.js',
|
||||
'assets/js/runtime/main.js',
|
||||
'assets/js/runtime/main.min.js',
|
||||
'inc/helpers/aksrt-comments.php',
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
|
||||
const root = path.resolve(__dirname, '..', '..');
|
||||
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
|
||||
|
||||
test('runtime exposes the article media settings to the single lightbox owner', () => {
|
||||
const scripts = read('src/Core/ScriptsPart1c.php');
|
||||
const enhancements = read('assets/js/enhancements.js');
|
||||
|
||||
assert.match(scripts, /Settings::get_post_page_settings\(\)/);
|
||||
for (const key of ['lightbox', 'lightbox_thumbs', 'lightbox_zoom', 'lightbox_full', 'lightbox_play', 'lightbox_down']) {
|
||||
assert.match(scripts, new RegExp(`['"]${key}['"]`));
|
||||
}
|
||||
assert.doesNotMatch(scripts, /'imgbox'\s*=>\s*false/);
|
||||
assert.match(enhancements, /window\._win/);
|
||||
assert.doesNotMatch(enhancements, /aksrtData\.imgbox/);
|
||||
});
|
||||
|
||||
test('the modern lightbox owns content, galleries and explicit links without a hard size gate', () => {
|
||||
const enhancements = read('assets/js/enhancements.js');
|
||||
const gallery = read('templates/parts/content-gallery.php');
|
||||
|
||||
assert.match(enhancements, /data-aksrt-lightbox-trigger/);
|
||||
assert.match(enhancements, /data-caption/);
|
||||
assert.match(enhancements, /data-lazy-src/);
|
||||
assert.doesNotMatch(enhancements, /img\.width\s*<\s*100/);
|
||||
assert.doesNotMatch(enhancements, /img\.height\s*<\s*100/);
|
||||
assert.match(gallery, /data-aksrt-lightbox/);
|
||||
});
|
||||
|
||||
test('legacy overlay and imgbox entry points are no longer enqueued or built', () => {
|
||||
const scripts = read('src/Core/ScriptsPart1c.php');
|
||||
const build = read('tools/build-public-assets.mjs');
|
||||
const loader = read('assets/js/runtime/loader.js');
|
||||
const part2 = read('inc/core-hooks/part-2.php');
|
||||
const single = read('single.php');
|
||||
const page = read('page.php');
|
||||
|
||||
assert.doesNotMatch(scripts, /needs_page_template[^\n]*lightbox/);
|
||||
assert.doesNotMatch(read('assets/js/page-template.js'), /function initLightbox|lightbox-overlay/);
|
||||
assert.doesNotMatch(build, /assets\/js\/runtime\/imgbox/);
|
||||
assert.doesNotMatch(loader, /['"]imgbox['"]\s*:/);
|
||||
assert.doesNotMatch(part2, /aksrt_print_win_var/);
|
||||
assert.doesNotMatch(single, /id="lightbox-overlay"/);
|
||||
assert.doesNotMatch(page, /id="lightbox-overlay"/);
|
||||
});
|
||||
|
||||
test('non-navigational page media and carousel images opt into the shared contract', () => {
|
||||
const page = read('page.php');
|
||||
const carousel = read('inc/core-hooks/part-3.php');
|
||||
|
||||
assert.match(page, /entry-thumb[^>]*data-aksrt-lightbox/);
|
||||
assert.match(carousel, /data-aksrt-lightbox/);
|
||||
});
|
||||
Reference in New Issue
Block a user