feat: 移除 lazyload 插件,改用浏览器原生懒加载
This commit is contained in:
@@ -989,7 +989,7 @@ function argon_get_comment_text($comment_ID = 0, $args = array()) {
|
||||
if (!isset($emotion['src']) || mb_strlen($emotion['src']) == 0){
|
||||
continue;
|
||||
}
|
||||
$comment_text = str_replace(':' . $emotion['code'] . ':', "<img class='comment-sticker lazyload' src='data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iZW1vdGlvbi1sb2FkaW5nIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9Ii04IC04IDQwIDQwIiBzdHJva2U9IiM4ODgiIG9wYWNpdHk9Ii41IiB3aWR0aD0iNjAiIGhlaWdodD0iNjAiPgogIDxwYXRoIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxLjUiIGQ9Ik0xNC44MjggMTQuODI4YTQgNCAwIDAxLTUuNjU2IDBNOSAxMGguMDFNMTUgMTBoLjAxTTIxIDEyYTkgOSAwIDExLTE4IDAgOSA5IDAgMDExOCAweiIvPgo8L3N2Zz4=' data-original='" . $emotion['src'] . "'/><noscript><img class='comment-sticker' src='" . $emotion['src'] . "'/></noscript>", $comment_text);
|
||||
$comment_text = str_replace(':' . $emotion['code'] . ':', "<img class='comment-sticker' src='" . $emotion['src'] . "' loading='lazy'/>", $comment_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2262,35 +2262,23 @@ function get_banner_background_url(){
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
//Lazyload 对 <img> 标签预处理以加载 Lazyload
|
||||
//原生懒加载:对 <img> 标签添加 loading="lazy" 属性
|
||||
function argon_lazyload($content){
|
||||
$lazyload_loading_style = get_option('argon_lazyload_loading_style');
|
||||
if ($lazyload_loading_style == ''){
|
||||
$lazyload_loading_style = 'none';
|
||||
}
|
||||
$lazyload_loading_style = "lazyload-style-" . $lazyload_loading_style;
|
||||
|
||||
if(!is_feed() && !is_robots() && !is_home()){
|
||||
$content = preg_replace('/<img(.*?)src=[\'"](.*?)[\'"](.*?)((\/>)|(<\/img>))/i',"<img class=\"lazyload " . $lazyload_loading_style . "\" src=\"data:image/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\" \$1data-original=\"\$2\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC\"\$3$4" , $content);
|
||||
$content = preg_replace('/<img(.*?)data-full-url=[\'"]([^\'"]+)[\'"](.*)>/i',"<img$1data-full-url=\"$2\" data-original=\"$2\"$3>" , $content);
|
||||
$content = preg_replace('/<img(.*?)srcset=[\'"](.*?)[\'"](.*?)>/i',"<img$1$3>" , $content);
|
||||
// 为没有 loading 属性的图片添加 loading="lazy"
|
||||
$content = preg_replace('/<img((?!loading=)[^>]*)>/i', '<img$1 loading="lazy">', $content);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
function argon_fancybox($content){
|
||||
if(!is_feed() && !is_robots() && !is_home()){
|
||||
if (get_option('argon_enable_lazyload') != 'false'){
|
||||
$content = preg_replace('/<img(.*?)data-original=[\'"](.*?)[\'"](.*?)((\/>)|>|(<\/img>))/i',"<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='$2'>$0</div>" , $content);
|
||||
}else{
|
||||
$content = preg_replace('/<img(.*?)src=[\'"](.*?)[\'"](.*?)((\/>)|>|(<\/img>))/i',"<div class='fancybox-wrapper' data-fancybox='post-images' href='$2'>$0</div>" , $content);
|
||||
}
|
||||
$content = preg_replace('/<img(.*?)src=[\'"](.*?)[\'"](.*?)((\/>)|>|(<\/img>))/i',"<div class='fancybox-wrapper' data-fancybox='post-images' href='$2'>$0</div>" , $content);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
function the_content_filter($content){
|
||||
if (get_option('argon_enable_lazyload') != 'false'){
|
||||
$content = argon_lazyload($content);
|
||||
}
|
||||
// 始终使用原生懒加载
|
||||
$content = argon_lazyload($content);
|
||||
if (get_option('argon_enable_fancybox') != 'false' && get_option('argon_enable_zoomify') == 'false'){
|
||||
$content = argon_fancybox($content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user