mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
@@ -238,7 +238,10 @@ function formatImg($src, $enableImageResizer, $image_max_width, $image_max_heigh
|
|||||||
if (empty($src)) {
|
if (empty($src)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return addTempCode("<img style=\"max-width: 100%\" id=\"$imgId\" alt=\"image\" src=\"$src\"" .($enableImageResizer ? " onload=\"Scale(this,$image_max_width,$image_max_height);\" onclick=\"Preview(this);\"" : "") . " />");
|
return addTempCode("<img style=\"max-width: 100%\" id=\"$imgId\" alt=\"image\" src=\"$src\"" .
|
||||||
|
($enableImageResizer ?
|
||||||
|
" onload=\"Scale(this, $image_max_width, $image_max_height);\" onclick=\"Preview(this);\" " : "") .
|
||||||
|
" onerror=\"handleImageError(this, '$src');\" />");
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFlash($src, $width, $height) {
|
function formatFlash($src, $width, $height) {
|
||||||
|
|||||||
Vendored
+19
@@ -84,3 +84,22 @@ function Return() {
|
|||||||
$('curtain').style.display = "none";
|
$('curtain').style.display = "none";
|
||||||
$('lightbox').innerHTML = "";
|
$('lightbox').innerHTML = "";
|
||||||
}
|
}
|
||||||
|
// 处理图片加载失败的函数
|
||||||
|
function handleImageError(img, currentSrc) {
|
||||||
|
if (!currentSrc.includes('doubanio.com')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const domainList = ['img1.doubanio.com', 'img2.doubanio.com', 'img3.doubanio.com', 'img9.doubanio.com']; // 备用域名列表
|
||||||
|
let index = 0;
|
||||||
|
function tryNextDomain() {
|
||||||
|
if (index >= domainList.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
img.src = currentSrc.replace(/https:\/\/[a-zA-Z0-9.-]+\.doubanio\.com/, `https://${domainList[index]}`);
|
||||||
|
img.onload = () => {
|
||||||
|
img.onload = img.onerror = null;
|
||||||
|
};
|
||||||
|
img.onerror = tryNextDomain;
|
||||||
|
}
|
||||||
|
tryNextDomain();
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+39
-15
@@ -46,6 +46,9 @@ jQuery(document).ready(function () {
|
|||||||
|
|
||||||
// preview
|
// preview
|
||||||
function getPosition(e, position) {
|
function getPosition(e, position) {
|
||||||
|
if (!position) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
left: e.pageX + position.offsetX,
|
left: e.pageX + position.offsetX,
|
||||||
top: e.pageY + position.offsetY,
|
top: e.pageY + position.offsetY,
|
||||||
@@ -75,23 +78,44 @@ jQuery(document).ready(function () {
|
|||||||
|
|
||||||
// lazy load
|
// lazy load
|
||||||
if ("IntersectionObserver" in window) {
|
if ("IntersectionObserver" in window) {
|
||||||
const imgList = [...document.querySelectorAll('.nexus-lazy-load')]
|
const fallbackImage = 'pic/misc/spinner.svg';
|
||||||
var io = new IntersectionObserver((entries) =>{
|
const domainList = ['img1.doubanio.com', 'img2.doubanio.com', 'img3.doubanio.com', 'img9.doubanio.com'];
|
||||||
entries.forEach(entry => {
|
const imgList = [...document.querySelectorAll('.nexus-lazy-load')];
|
||||||
const el = entry.target
|
const loadedImages = {};
|
||||||
const intersectionRatio = entry.intersectionRatio
|
const io = new IntersectionObserver((entries) => {
|
||||||
// console.log(`el, ${el.getAttribute('data-src')}, intersectionRatio: ${intersectionRatio}`)
|
entries.forEach(entry => {
|
||||||
|
const el = entry.target;
|
||||||
|
const intersectionRatio = entry.intersectionRatio;
|
||||||
if (intersectionRatio > 0 && intersectionRatio <= 1 && !el.classList.contains('preview')) {
|
if (intersectionRatio > 0 && intersectionRatio <= 1 && !el.classList.contains('preview')) {
|
||||||
// console.log(`el, ${el.getAttribute('data-src')}, loadImg`)
|
let src = el.dataset.src;
|
||||||
const source = el.dataset.src
|
if (src && src.includes('doubanio.com') && src.includes('l_ratio_poster')) {
|
||||||
el.src = source
|
src = src.replace('l_ratio_poster', 's_ratio_poster');
|
||||||
el.classList.add('preview')
|
el.dataset.src = src;
|
||||||
|
}
|
||||||
|
el.src = src;
|
||||||
|
el.classList.add('preview');
|
||||||
|
loadedImages[src] = true;
|
||||||
|
el.onload = el.onerror = () => io.unobserve(el);
|
||||||
|
el.onerror = () => handleImageError(el, src);
|
||||||
}
|
}
|
||||||
el.onload = el.onerror = () => io.unobserve(el)
|
});
|
||||||
})
|
});
|
||||||
})
|
imgList.forEach(img => io.observe(img));
|
||||||
|
function handleImageError(img, currentSrc) {
|
||||||
imgList.forEach(img => io.observe(img))
|
if (!currentSrc.includes('doubanio.com')) {
|
||||||
|
img.src = fallbackImage;
|
||||||
|
} else {
|
||||||
|
tryNextDomain(img, currentSrc, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function tryNextDomain(img, currentSrc, index = 0) {
|
||||||
|
if (index >= domainList.length) {
|
||||||
|
img.src = fallbackImage;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
img.src = currentSrc.replace(/https:\/\/[a-zA-Z0-9.-]+\.doubanio\.com/, `https://${domainList[index]}`);
|
||||||
|
img.onerror = () => tryNextDomain(img, currentSrc, index + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//claim
|
//claim
|
||||||
|
|||||||
Reference in New Issue
Block a user