You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
757 B
JavaScript
29 lines
757 B
JavaScript
import { getAttrs } from 'utils/dom';
|
|
|
|
import {
|
|
IS_LINK,
|
|
IS_IMAGE,
|
|
} from './constants';
|
|
|
|
// Convert all instances of images with potentially
|
|
// lazy loaded images into normal images.
|
|
// Many sites will have img tags with no source, or an image tag with a src
|
|
// 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($) {
|
|
$('img').each((_, img) => {
|
|
const attrs = getAttrs(img);
|
|
|
|
Reflect.ownKeys(attrs).forEach((attr) => {
|
|
const value = attrs[attr];
|
|
|
|
if (attr !== 'src' && IS_LINK.test(value) &&
|
|
IS_IMAGE.test(value)) {
|
|
$(img).attr('src', value);
|
|
}
|
|
});
|
|
});
|
|
|
|
return $;
|
|
}
|