|
|
|
@ -8,6 +8,17 @@ import { IS_LINK, IS_IMAGE, IS_SRCSET } from './constants';
|
|
|
|
|
// attribute that a is a placeholer. We need to be able to properly fill in
|
|
|
|
|
// the src attribute so the images are no longer lazy loaded.
|
|
|
|
|
export default function convertLazyLoadedImages($) {
|
|
|
|
|
const extractSrcFromJSON = str => {
|
|
|
|
|
try {
|
|
|
|
|
const { src } = JSON.parse(str);
|
|
|
|
|
if (typeof src === 'string') return src;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$('img').each((_, img) => {
|
|
|
|
|
const attrs = getAttrs(img);
|
|
|
|
|
|
|
|
|
@ -22,7 +33,13 @@ export default function convertLazyLoadedImages($) {
|
|
|
|
|
IS_LINK.test(value) &&
|
|
|
|
|
IS_IMAGE.test(value)
|
|
|
|
|
) {
|
|
|
|
|
$(img).attr('src', value);
|
|
|
|
|
// Is the value a JSON object? If so, we should attempt to extract the image src from the data.
|
|
|
|
|
const existingSrc = extractSrcFromJSON(value);
|
|
|
|
|
if (existingSrc) {
|
|
|
|
|
$(img).attr('src', existingSrc);
|
|
|
|
|
} else {
|
|
|
|
|
$(img).attr('src', value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|