Skip to content

Commit

Permalink
fix(img): 修复图片加载失败时的替代方案报错的 BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG committed Jan 25, 2021
1 parent 7c4669d commit 5636f32
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion archives.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.archives_patternimg?? && settings.archives_patternimg!='')>
<img data-src="${settings.archives_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.archives_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?archives=archives&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion categories.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.category_patternimg?? && settings.category_patternimg!='')>
<img data-src="${settings.category_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.category_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?category=category&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion category.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && ((category.thumbnail?? && category.thumbnail!='') || (settings.category_patternimg?? && settings.category_patternimg!=''))>
<img data-src='${((category.thumbnail)?length>0)?string((category.thumbnail),"${settings.category_patternimg!}")}' src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src='${((category.thumbnail)?length>0)?string((category.thumbnail),"${settings.category_patternimg!}")}' src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?category=#{category.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
4 changes: 2 additions & 2 deletions journals.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.journals_patternimg?? && settings.journals_patternimg!='')>
<img data-src="${settings.journals_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.journals_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?journal=journal&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down Expand Up @@ -51,7 +51,7 @@
<#list journals.content as journal>
<li id="journal-${journal.id?c}" class="journal">
<span class="journal-author-img">
<img class="lazyload avatar" data-src="${user.avatar!}" alt="${user.nickname!}" width="48" height="48" src="${res_base_url!}/source/images/svg/loader/trans.ajax-spinner-preloader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload avatar" data-src="${user.avatar!}" alt="${user.nickname!}" width="48" height="48" src="${res_base_url!}/source/images/svg/loader/trans.ajax-spinner-preloader.svg" onerror="imgError(this)">
<span class="journal-label">${journal.content!}
<p class="journal-time">
<span> ${journal.createTime?string('yyyy-MM-dd HH:mm:ss')}</span>
Expand Down
2 changes: 1 addition & 1 deletion links.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.links_patternimg?? && settings.links_patternimg!='')>
<img data-src="${settings.links_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.links_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?link=link&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion photos.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.photos_patternimg?? && settings.photos_patternimg!='')>
<img data-src="${settings.photos_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.photos_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?photos=photos&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion post.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center single-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (post.thumbnail?? && post.thumbnail!='')>
<img class="lazyload" data-src="${post.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${post.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?postid=${post.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
15 changes: 3 additions & 12 deletions script/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,21 +836,12 @@ var LIlGGAttachContext = {
}
};

// 图片错误类型
var IMG_Type = {
DEFAULT: {
id: 0,
url:
"https://cdn.lixingyong.com/2020/07/18/98fca04416944b282a558b98b2131879.png",
},
};
/**
* 图片加载失败/错误后的替补方案
* @param {Document} ele 失败的图片dom
* @param {Number} type 加载的图片类型
* @param {Document} ele 失败的图片do
*/
var imgError = function (ele, type) {
ele.src = type.url;
var imgError = function (ele) {
ele.src = "https://cdn.lixingyong.com/2020/07/18/98fca04416944b282a558b98b2131879.png";
};

/**
Expand Down
2 changes: 1 addition & 1 deletion script/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion search.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.searh_patternimg?? && settings.searh_patternimg!='')>
<img data-src="${settings.searh_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.searh_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?serach=serach&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion sheet.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (sheet.thumbnail?? && sheet.thumbnail!='')>
<img class="lazyload" data-src="${sheet.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${sheet.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?sheetid=${sheet.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion sheet_links.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (sheet.thumbnail?? && sheet.thumbnail!='')>
<img class="lazyload" data-src="${sheet.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${sheet.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?sheetid=${sheet.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion tag.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && ((tag.thumbnail?? && tag.thumbnail!='') || (settings.tag_patternimg?? && settings.tag_patternimg!=''))>
<img class="lazyload" data-src='${((tag.thumbnail)?length>0)?string((tag.thumbnail),"${settings.tag_patternimg!}")}' src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src='${((tag.thumbnail)?length>0)?string((tag.thumbnail),"${settings.tag_patternimg!}")}' src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?tagid=${tag.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion tags.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="pattern-center">
<div class="pattern-attachment-img">
<#if (settings.patternimg!true) && (settings.tag_patternimg?? && settings.tag_patternimg!='')>
<img data-src="${settings.tag_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this, IMG_Type.DEFAULT)">
<img data-src="${settings.tag_patternimg!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" class="lazyload" onerror="imgError(this)">
<#else>
<img
src="${settings.rimage_url!}?tagid=tag&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand Down
2 changes: 1 addition & 1 deletion tpl/content-links.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<#list item.links?sort_by('priority')?reverse as link>
<li class="link-item">
<a class="link-item-inner effect-apollo" href="${link.url!}" title="${link.name!}" target="_blank">
<img class="lazyload" data-src="${link.logo!}" src="${res_base_url!}/source/images/svg/loader/trans.ajax-spinner-preloader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${link.logo!}" src="${res_base_url!}/source/images/svg/loader/trans.ajax-spinner-preloader.svg" onerror="imgError(this)">
<span class="sitename">${link.name!}</span>
<div class="linkdes">${link.description!}</div>
</a>
Expand Down
4 changes: 2 additions & 2 deletions tpl/content-thumb.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="post-thumb">
<a href="${post.fullPath!}">
<#if post.thumbnail?? && post.thumbnail!=''>
<img class="lazyload" data-src="${post.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${post.thumbnail!}" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
<#elseif settings.rimage_cover_open!true && settings.rimage_url?? && settings.rimage_url!=''>
<img
src="${settings.rimage_url!}?postid=${post.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>"
Expand All @@ -18,7 +18,7 @@
data-sizes="auto"
class="lazyload<#if settings.rimage_cover_lqip == 'lowquality'> blur-up</#if>" />
<#else>
<img class="lazyload" data-src="${res_base_url!}/source/images/temp.jpg" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this, IMG_Type.DEFAULT)">
<img class="lazyload" data-src="${res_base_url!}/source/images/temp.jpg" src="${res_base_url!}/source/images/svg/loader/orange.progress-bar-stripe-loader.svg" onerror="imgError(this)">
</#if>
</a>
</div><!-- thumbnail-->
Expand Down
4 changes: 2 additions & 2 deletions tpl/content.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<a href="${post.fullPath!}">
<div class="overlay"><i class="iconfont icon-text"></i></div>
<#if post.thumbnail?? && post.thumbnail!=''>
<img width="150" height="150" src="${post.thumbnail!}" class="attachment-post-thumbnail size-post-thumbnail" onerror="imgError(this, IMG_Type.DEFAULT)"/>
<img width="150" height="150" src="${post.thumbnail!}" class="attachment-post-thumbnail size-post-thumbnail" onerror="imgError(this)"/>
<#elseif settings.rimage_cover_open!true && settings.rimage_url?? && settings.rimage_url!=''>
<img width="150" height="150" src="${settings.rimage_url!}?postid=${post.id}&type=url&itype=${settings.rimage_cover_itype!}<#if settings.rimage_cover_itype != 'image'>&id=${(settings.rimage_cover_id)!''}</#if>&th=150" class="attachment-post-thumbnail size-post-thumbnail"/>
<#else>
<img src="${res_base_url!}/source/images/random/d-${randomMethod(1,10)}.jpg" onerror="imgError(this, IMG_Type.DEFAULT)"/>
<img src="${res_base_url!}/source/images/random/d-${randomMethod(1,10)}.jpg" onerror="imgError(this)"/>
</#if>
</a>
</div>
Expand Down

0 comments on commit 5636f32

Please sign in to comment.