@glitchr/transparent 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/js/transparent.js +4 -109
package/package.json
CHANGED
package/src/js/transparent.js
CHANGED
|
@@ -161,7 +161,6 @@
|
|
|
161
161
|
"disable": false,
|
|
162
162
|
"global_code": true,
|
|
163
163
|
"debug": true,
|
|
164
|
-
"lazyload": true,
|
|
165
164
|
"response_text": {},
|
|
166
165
|
"response_limit": 25,
|
|
167
166
|
"throttle": 1000,
|
|
@@ -211,12 +210,6 @@
|
|
|
211
210
|
dispatchEvent(new Event('transparent:'+Transparent.state.ACTIVE));
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
window.addEventListener("DOMContentLoaded", function()
|
|
215
|
-
{
|
|
216
|
-
Transparent.loader = $($(document).find(Settings.loader)[0] ?? Transparent.html);
|
|
217
|
-
Transparent.lazyLoad();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
213
|
Transparent.isRescueMode = function() { return rescueMode; }
|
|
221
214
|
Transparent.getData = function(uuid)
|
|
222
215
|
{
|
|
@@ -419,16 +412,14 @@
|
|
|
419
412
|
Transparent.configure({'x-ajax-request': true});
|
|
420
413
|
Transparent.configure(options);
|
|
421
414
|
|
|
415
|
+
if(isReady) return this;
|
|
422
416
|
isReady = true;
|
|
423
417
|
|
|
424
418
|
dispatchEvent(new Event('transparent:'+Transparent.state.READY));
|
|
425
419
|
Transparent.html.addClass(Transparent.state.READY);
|
|
426
420
|
|
|
427
421
|
Transparent.addLayout();
|
|
428
|
-
Transparent.lazyLoad();
|
|
429
|
-
|
|
430
422
|
Transparent.scrollToHash(location.hash, {}, function() {
|
|
431
|
-
|
|
432
423
|
Transparent.activeOut(() => Transparent.html.removeClass(Transparent.state.FIRST));
|
|
433
424
|
});
|
|
434
425
|
|
|
@@ -1035,105 +1026,6 @@
|
|
|
1035
1026
|
}, new Set());
|
|
1036
1027
|
}
|
|
1037
1028
|
|
|
1038
|
-
Transparent.lazyLoad = function (lazyloadImages = undefined)
|
|
1039
|
-
{
|
|
1040
|
-
lazyloadImages = lazyloadImages || document.querySelectorAll("img[data-src]:not(.loaded)");
|
|
1041
|
-
if ("IntersectionObserver" in window) {
|
|
1042
|
-
|
|
1043
|
-
let options = { root:null, rootMargin: "100%" };
|
|
1044
|
-
var imageObserver = new IntersectionObserver(function (entries, observer) {
|
|
1045
|
-
entries.forEach(function (entry) {
|
|
1046
|
-
if (entry.isIntersecting) {
|
|
1047
|
-
var image = entry.target;
|
|
1048
|
-
var lazybox = image.closest(".lazybox");
|
|
1049
|
-
|
|
1050
|
-
image.onload = function() {
|
|
1051
|
-
this.classList.add("loaded");
|
|
1052
|
-
this.classList.remove("loading");
|
|
1053
|
-
if(lazybox) lazybox.classList.add("loaded");
|
|
1054
|
-
if(lazybox) lazybox.classList.remove("loading");
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
|
-
if(lazybox) lazybox.classList.add("loading");
|
|
1058
|
-
image.classList.add("loading");
|
|
1059
|
-
image.src = image.dataset.src;
|
|
1060
|
-
|
|
1061
|
-
imageObserver.unobserve(image);
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
}, options);
|
|
1065
|
-
|
|
1066
|
-
lazyloadImages.forEach(function (image) {
|
|
1067
|
-
imageObserver.observe(image);
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
} else {
|
|
1071
|
-
|
|
1072
|
-
var lazyloadThrottleTimeout;
|
|
1073
|
-
|
|
1074
|
-
function lazyload() {
|
|
1075
|
-
if (lazyloadThrottleTimeout) {
|
|
1076
|
-
clearTimeout(lazyloadThrottleTimeout);
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
lazyloadThrottleTimeout = setTimeout(function () {
|
|
1080
|
-
var scrollTop = window.pageYOffset;
|
|
1081
|
-
lazyloadImages.forEach(function (img) {
|
|
1082
|
-
if (img.offsetTop < (window.innerHeight + scrollTop)) {
|
|
1083
|
-
img.src = img.dataset.src;
|
|
1084
|
-
img.classList.add('loaded');
|
|
1085
|
-
}
|
|
1086
|
-
});
|
|
1087
|
-
if (lazyloadImages.length == 0) {
|
|
1088
|
-
document.removeEventListener("scroll", lazyload);
|
|
1089
|
-
window.removeEventListener("resize", lazyload);
|
|
1090
|
-
window.removeEventListener("orientationChange", lazyload);
|
|
1091
|
-
}
|
|
1092
|
-
}, 20);
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
document.addEventListener("scroll", lazyload);
|
|
1096
|
-
window.addEventListener("resize", lazyload);
|
|
1097
|
-
window.addEventListener("orientationChange", lazyload);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
Transparent.loadImages = function()
|
|
1102
|
-
{
|
|
1103
|
-
function loadImg (src, timeout = 500) {
|
|
1104
|
-
var imgPromise = new Promise((resolve, reject) => {
|
|
1105
|
-
|
|
1106
|
-
let img = new Image()
|
|
1107
|
-
img.onload = () => {
|
|
1108
|
-
resolve({
|
|
1109
|
-
src: src,
|
|
1110
|
-
width: img.naturalWidth,
|
|
1111
|
-
height: img.naturalHeight
|
|
1112
|
-
})
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
img.onerror = reject
|
|
1116
|
-
img.src = src
|
|
1117
|
-
})
|
|
1118
|
-
|
|
1119
|
-
var timer = new Promise((resolve, reject) => { setTimeout(reject, timeout) })
|
|
1120
|
-
return Promise.race([imgPromise, timer])
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
function loadImgAll (imgList, timeout = 500) {
|
|
1124
|
-
return new Promise((resolve, reject) => {
|
|
1125
|
-
Promise.all(imgList
|
|
1126
|
-
.map(src => loadImg(src, timeout))
|
|
1127
|
-
.map(p => p.catch(e => false))
|
|
1128
|
-
).then(results => resolve(results.filter(r => r)))
|
|
1129
|
-
})
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
return new Promise((resolve, reject) => {
|
|
1133
|
-
loadImgAll(Array.from(Transparent.findImages(document.documentElement))).then(resolve, reject)
|
|
1134
|
-
})
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
1029
|
Transparent.transferAttributes = function(dom) {
|
|
1138
1030
|
|
|
1139
1031
|
var html = $(dom).find("html");
|
|
@@ -1635,6 +1527,9 @@
|
|
|
1635
1527
|
if (href != location.origin + location.pathname + location.hash)
|
|
1636
1528
|
history.replaceState({uuid: uuidv4(), status: history.state ? history.state.status : 200, data:{}, method: history.state ? history.state.method : "GET", href: location.origin + location.pathname + location.hash}, '', location.origin + location.pathname + location.hash);
|
|
1637
1529
|
|
|
1530
|
+
window.addEventListener("DOMContentLoaded", function() { Transparent.loader = $($(document).find(Settings.loader)[0] ?? Transparent.html); }, true);
|
|
1531
|
+
window.addEventListener("load",function() { Transparent.ready(); });
|
|
1532
|
+
|
|
1638
1533
|
// Overload onpopstate
|
|
1639
1534
|
if(Settings.disable) {
|
|
1640
1535
|
|