...
|
...
|
@@ -4,6 +4,8 @@ const $ = require('yoho-jquery'); |
|
|
|
|
|
require('jquery-lazyload');
|
|
|
|
|
|
const defaultQuality = 60;
|
|
|
|
|
|
/**
|
|
|
* 图片链接处理
|
|
|
*/
|
...
|
...
|
@@ -20,14 +22,33 @@ const imgSrcHandle = (imgUrl, params) => { |
|
|
if (window.supportWebp) {
|
|
|
url += `?imageView2/0/interlace/1/format/webp/q/${params.q}`;
|
|
|
} else {
|
|
|
let extQuery = params.q === 75 ? '?imageslim' : `?imageView2/0/interlace/1/q/${params.q}`;
|
|
|
let extQuery = params.q === defaultQuality ? '?imageslim' : `?imageView2/0/interlace/1/q/${params.q}`;
|
|
|
|
|
|
url += extQuery;
|
|
|
}
|
|
|
return url;
|
|
|
} else {
|
|
|
return imgUrl;
|
|
|
imgUrl = url;
|
|
|
} else if (/imageView2/.test(query)) {
|
|
|
if (!/\/q\/\d+/.test(imgUrl)) {
|
|
|
imgUrl += `/q/${params.q}`;
|
|
|
} else {
|
|
|
imgUrl = imgUrl.replace(/\/q\/\d+/g, '/q/' + params.q);
|
|
|
}
|
|
|
|
|
|
if (window.supportWebp && !/format\//.test(imgUrl)) {
|
|
|
imgUrl += '/format/webp';
|
|
|
}
|
|
|
} else if (/imageMogr2/.test(query)) {
|
|
|
if (!/\/quality\/\d+/.test(imgUrl)) {
|
|
|
imgUrl += `/quality/${params.q}`;
|
|
|
} else {
|
|
|
imgUrl = imgUrl.replace(/\/quality\/\d+/g, '/quality/' + params.q);
|
|
|
}
|
|
|
|
|
|
if (window.supportWebp && !/format\//.test(imgUrl)) {
|
|
|
imgUrl += '/format/webp';
|
|
|
}
|
|
|
}
|
|
|
return imgUrl;
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -39,7 +60,7 @@ const rawLazyload = (selector, options) => { |
|
|
threshold: 700
|
|
|
};
|
|
|
let imgParams = {
|
|
|
q: options && options.q || 75
|
|
|
q: options && options.q || defaultQuality
|
|
|
};
|
|
|
|
|
|
if (selector instanceof $) {
|
...
|
...
|
|