feat(frontend): replace lazy loading with zibll lazysizes
This commit is contained in:
@@ -67,14 +67,24 @@ final class GeneralRenderer {
|
||||
return RendererHelpers::empty_state(__('请配置视频地址', 'aksrt'));
|
||||
}
|
||||
$ratio = (string) $i['ratio'];
|
||||
return '<div class="aksrt-widget-video aksrt-widget-video--' . esc_attr(str_replace(':', '-', $ratio)) . '" data-video-url="' . $url . '" data-video-poster="' . esc_url((string) $i['poster']) . '" data-autoplay="' . (!empty($i['autoplay']) ? '1' : '0') . '" data-muted="' . (!empty($i['muted']) ? '1' : '0') . '"><video controls playsinline preload="metadata"' . (!empty($i['autoplay']) ? ' autoplay' : '') . (!empty($i['muted']) ? ' muted' : '') . (!empty($i['poster']) ? ' poster="' . esc_url((string) $i['poster']) . '"' : '') . '><source src="' . $url . '"></video><p class="aksrt-widget-media-error" role="alert" aria-live="assertive" hidden>' . esc_html__('视频加载失败,请稍后重试。', 'aksrt') . '</p></div>';
|
||||
if (aksrt_is_lazy('lazy_other')) {
|
||||
$video_attr = ' class="lazyload" src="" data-src="' . $url . '"';
|
||||
$poster_attr = !empty($i['poster']) ? ' data-poster="' . esc_url((string) $i['poster']) . '"' : '';
|
||||
} else {
|
||||
$video_attr = ' src="' . $url . '"';
|
||||
$poster_attr = !empty($i['poster']) ? ' poster="' . esc_url((string) $i['poster']) . '"' : '';
|
||||
}
|
||||
return '<div class="aksrt-widget-video aksrt-widget-video--' . esc_attr(str_replace(':', '-', $ratio)) . '" data-video-url="' . $url . '" data-video-poster="' . esc_url((string) $i['poster']) . '" data-autoplay="' . (!empty($i['autoplay']) ? '1' : '0') . '" data-muted="' . (!empty($i['muted']) ? '1' : '0') . '"><video controls playsinline preload="metadata"' . $video_attr . $poster_attr . (!empty($i['autoplay']) ? ' autoplay' : '') . (!empty($i['muted']) ? ' muted' : '') . '></video><p class="aksrt-widget-media-error" role="alert" aria-live="assertive" hidden>' . esc_html__('视频加载失败,请稍后重试。', 'aksrt') . '</p></div>';
|
||||
}
|
||||
|
||||
private static function render_embed(array $i): string {
|
||||
if (empty($i['url'])) {
|
||||
return RendererHelpers::empty_state(__('请配置嵌入地址', 'aksrt'));
|
||||
}
|
||||
return '<div class="aksrt-widget-embed" style="--aksrt-embed-ratio:' . esc_attr((string) (float) $i['ratio']) . '%"><iframe src="' . esc_url((string) $i['url']) . '" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"' . (!empty($i['allow_fullscreen']) ? ' allowfullscreen' : '') . ' title="' . esc_attr__('嵌入内容', 'aksrt') . '"></iframe></div>';
|
||||
$src_attr = aksrt_is_lazy('lazy_other')
|
||||
? ' class="lazyload" src="" data-src="' . esc_url((string) $i['url']) . '"'
|
||||
: ' src="' . esc_url((string) $i['url']) . '"';
|
||||
return '<div class="aksrt-widget-embed" style="--aksrt-embed-ratio:' . esc_attr((string) (float) $i['ratio']) . '%"><iframe' . $src_attr . ' referrerpolicy="strict-origin-when-cross-origin"' . (!empty($i['allow_fullscreen']) ? ' allowfullscreen' : '') . ' title="' . esc_attr__('嵌入内容', 'aksrt') . '"></iframe></div>';
|
||||
}
|
||||
|
||||
private static function render_media_cards(array $i): string {
|
||||
|
||||
@@ -16,13 +16,19 @@ final class SliderRenderer {
|
||||
continue;
|
||||
}
|
||||
$link = RendererHelpers::link((array) ($slide['link'] ?? []));
|
||||
$media = !empty($slide['background_video'])
|
||||
? '<video src="' . esc_url((string) $slide['background_video']) . '" muted loop playsinline preload="metadata"></video>'
|
||||
: RendererHelpers::image((string) $slide['background'], (string) ($slide['title'] ?? ''), 'swiper-lazy');
|
||||
if (!empty($slide['background_video'])) {
|
||||
$video = esc_url((string) $slide['background_video']);
|
||||
$video_attr = aksrt_is_lazy('lazy_sider')
|
||||
? ' class="lazyload" src="" data-src="' . $video . '"'
|
||||
: ' src="' . $video . '"';
|
||||
$media = '<video' . $video_attr . ' muted loop playsinline preload="metadata"></video>';
|
||||
} else {
|
||||
$media = RendererHelpers::image((string) $slide['background'], (string) ($slide['title'] ?? ''), '', 'lazy_sider', aksrt_get_lazy_thumb('lg'));
|
||||
}
|
||||
$layers = '';
|
||||
foreach ((array) ($slide['layers'] ?? []) as $layer) {
|
||||
if (!empty($layer['image'])) {
|
||||
$layers .= '<img class="aksrt-slide-layer" src="' . esc_url((string) $layer['image']) . '" alt="" data-swiper-parallax="' . (int) ($layer['parallax'] ?? 0) . '" data-swiper-parallax-scale="' . esc_attr((string) ((float) ($layer['scale'] ?? 100) / 100)) . '">';
|
||||
$layers .= '<img' . aksrt_get_lazy_attr('lazy_sider', (string) $layer['image'], 'aksrt-slide-layer', aksrt_get_lazy_thumb('lg')) . ' alt="" data-swiper-parallax="' . (int) ($layer['parallax'] ?? 0) . '" data-swiper-parallax-scale="' . esc_attr((string) ((float) ($layer['scale'] ?? 100) / 100)) . '">';
|
||||
}
|
||||
}
|
||||
$copy = '<div class="aksrt-slide-copy is-' . esc_attr((string) ($slide['text_align'] ?? 'left-bottom')) . '"><h3>' . esc_html((string) ($slide['title'] ?? '')) . '</h3><p>' . esc_html((string) ($slide['description'] ?? '')) . '</p></div>';
|
||||
|
||||
Reference in New Issue
Block a user