-
Notifications
You must be signed in to change notification settings - Fork 5
/
imagesloader.js
70 lines (70 loc) · 3.5 KB
/
imagesloader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* do not edit this file! */
// @ts-check
/**
* lazy image loader
* @package GZip Plugin
* @copyright Copyright (C) 2005 - 2018 Thierry Bela.
*
* dual licensed
*
* @license LGPL v3
* @license MIT License
*/
LIB.ready((function(e) {
function t() {
LIB.images.lazy(".image-placeholder").on({
/**
*
* @param {HTMLImageElement} img
* @param {HTMLImageElement} oldImage
*/
preload(e, t) {
const r = !("currentSrc" in e);
r ? t.insertAdjacentHTML("beforebegin", '<span class=image-placeholder-wrapper><span class=image-placeholder-svg><svg width=100% height=100% version=1.1 xmlns=http://www.w3.org/2000/svg ><image xlink:href="' + (e.currentSrc || e.src) + '" width=100% height=100% filter=url(#blur-lqip) x=0 y=0 />') : t.insertAdjacentHTML("beforebegin", "<span class=image-placeholder-wrapper><span class=image-placeholder-opacity><span class=image-placeholder-element style=background-image:url(" + (e.currentSrc || e.src) + ")>");
const n = t.previousElementSibling;
if (r) {
if ("function" != typeof window.CustomEvent) {
window.Event.prototype;
}
const t = n.querySelector("svg");
// const svgImage = container.querySelector('svg image');
function s() {
const e = this.height, r = this.width;
t.setAttribute("height", e), t.setAttribute("width", r);
}
e.addEventListener("sourcechange", s), e.addEventListener("load", s);
}
t.classList.remove("image-placeholder", "image-placeholder-lqip", "image-placeholder-svg"),
n.insertBefore(t, n.firstElementChild);
},
load: r,
error(e, t, n) {
r(t, n);
}
});
}
function r(e, t) {
t.dataset.src && (t.src = t.dataset.src), t.dataset.srcset && (t.srcset = t.dataset.srcset),
setTimeout((function() {
let e = t;
for (t.removeAttribute("data-srcset"), t.removeAttribute("data-src"), t.classList.add("image-placeholder-complete"); e instanceof HTMLElement && !e.classList.contains("image-placeholder-wrapper"); ) e = e.parentElement;
e && e.parentElement.insertBefore(t, e), setTimeout((function() {
t.classList.remove("image-placeholder-complete"), e && e.parentElement.removeChild(e);
}), 5);
}), 5);
}
if (
// intersection-observer.min.js
"srcset" in new Image ||
// try {
document.body.insertAdjacentHTML("beforeend", "<svg xmlns=http://www.w3.org/2000/svg width=1 height=1><defs><filter id=blur-lqip width=100% height=100% ><feGaussianBlur stdDeviation=20 /></filter></defs></svg>"),
"IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in IntersectionObserverEntry.prototype) "isIntersecting" in IntersectionObserverEntry.prototype || Object.defineProperty(IntersectionObserverEntry.prototype, "isIntersecting", {
get: function() {
return this.intersectionRatio > 0;
}
}), t(); else {
const e = document.createElement("script");
/*script.onreadystatechange =*/ e.onload = t, e.defer = !0, e.async = !0,
e.src = "{script-src}", document.body.appendChild(e);
}
}));