Files
kupshop/web/common/static/js/iolazy.min.js
2025-08-02 16:30:27 +02:00

66 lines
2.9 KiB
JavaScript

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(typeof self !== 'undefined' ? self : this, function () {
var _createClass = function() {
function t(t, e) {
for (var r = 0; r < e.length; r++) {
var n = e[r];
n.enumerable = n.enumerable || !1, n.configurable = !0, 'value' in n &&
(n.writable = !0), Object.defineProperty(t, n.key, n);
}
}
return function(e, r, n) {return r && t(e.prototype, r), n && t(e, n), e;};
}();
function _classCallCheck(t, e) {if (!(t instanceof e)) throw new TypeError('Cannot call a class as a function');}
'IntersectionObserver' in window && 'IntersectionObserverEntry' in window && 'intersectionRatio' in
window.IntersectionObserverEntry.prototype && !('isIntersecting' in IntersectionObserverEntry.prototype) &&
Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting',
{get: function() {return this.intersectionRatio > 0;}}), window.NodeList && !NodeList.prototype.forEach &&
(NodeList.prototype.forEach = function(t, e) {
e = e || window;
for (var r = 0; r < this.length; r++) t.call(e, this[r], r, this);
});
var IOlazy = function() {
function t() {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, r = e.image,
n = void 0 === r ? '.lazyload' : r, i = e.threshold, o = void 0 === i ? .006 : i, s = e.rootMargin,
a = void 0 === s ? '0px' : s;
_classCallCheck(this, t), this.threshold = o, this.rootMargin = a, this.image = document.querySelectorAll(
n), this.observer = new IntersectionObserver(this.handleChange.bind(this),
{threshold: [this.threshold], rootMargin: this.rootMargin}), this.lazyLoad();
}
return _createClass(t, [
{
key: 'handleChange', value: function(t) {
var e = this;
t.forEach(function(t) {
t.isIntersecting && (t.target.classList.add('visible'), t.target.getAttribute('data-srcset') &&
(t.target.srcset = t.target.getAttribute('data-srcset')), t.target.getAttribute('data-src') &&
(t.target.src = t.target.getAttribute('data-src')), e.observer.unobserve(t.target));
});
},
}, {
key: 'lazyLoad', value: function() {
var t = this;
this.image.forEach(function(e) {t.observer.observe(e);});
},
}]), t;
}();
return IOlazy;
}));