-
Notifications
You must be signed in to change notification settings - Fork 5
/
bgstyles.js
48 lines (48 loc) · 1.77 KB
/
bgstyles.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
/* 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
*/
// load responsive css background images
LIB.ready((function(e) {
// dynamic inline background images
// or Array.from()
const t = [].slice.apply(document.querySelectorAll("[data-bg-style]"));
// responsive css background-image in [style] attribute
if (t.length > 0) {
// or use resizeObserver
const o = t.map((function(e) {
return JSON.parse(e.dataset.bgStyle);
}));
let c = [];
function n() {
let n, i, a, r, u, l = c.length;
for (l = t.length; l--; ) {
for (i = t[l], a = Object.keys(o[l]).map(e => +e).sort((e, t) => t - e), u = e,
r = 0; r < a.length && (u = window.matchMedia("(min-width: " + a[r] + "px)"), !u.matches); r++) ;
if (u == e || !u.matches || r == a.length) continue;
if (n = "url(" + o[l][a[r]] + ")", i.style.backgroundImage == n) continue;
let c = new Image, s = function(e) {
return function() {
i.style.backgroundImage = e;
};
}(n);
c.src = o[l][a[r]], c.width > 0 && c.height > 0 ? s() : "decode" in c ? c.decode().then(s) : c.onload = s;
}
}
Object.values(o).forEach((function(e) {
Object.keys(e).forEach((function(e) {
e = +e, -1 == c.indexOf(e) && c.push(e);
}));
})), c.sort((function(e, t) {
return t - e;
})), window.addEventListener("resize", n, !1), setTimeout(n, 25);
}
}));