-
Notifications
You must be signed in to change notification settings - Fork 0
/
verlok_vanilla-lazyload.min.js
2 lines (2 loc) · 4.99 KB
/
verlok_vanilla-lazyload.min.js
1
2
var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.LazyLoad=e()}(this,function(){"use strict";function t(t){return t.filter(function(t){return!i(t)})}function e(t,e,n){!n&&i(t)||(L(e.callback_enter,t),C.indexOf(t.tagName)>-1&&(N(t,e),E(t,e.class_loading)),w(t,e),a(t),L(e.callback_set,t))}var n={elements_selector:"img",container:document,threshold:300,data_src:"src",data_srcset:"srcset",data_sizes:"sizes",class_loading:"loading",class_loaded:"loaded",class_error:"error",load_delay:0,callback_load:null,callback_error:null,callback_set:null,callback_enter:null,to_webp:!1},r=function(t){return _extends({},n,t)},o=function(t,e){return t.getAttribute("data-"+e)},s=function(t,e,n){var r="data-"+e;null!==n?t.setAttribute(r,n):t.removeAttribute(r)},a=function(t){return s(t,"was-processed","true")},i=function(t){return"true"===o(t,"was-processed")},c=function(t,e){return s(t,"ll-timeout",e)},l=function(t){return o(t,"ll-timeout")},u=function(t,e){var n,r=new t(e);try{n=new CustomEvent("LazyLoad::Initialized",{detail:{instance:r}})}catch(t){(n=document.createEvent("CustomEvent")).initCustomEvent("LazyLoad::Initialized",!1,!1,{instance:r})}window.dispatchEvent(n)},d=function(t,e){return e?t.replace(/\.(jpe?g|png)/gi,".webp"):t},f="undefined"!=typeof window,_=f&&!("onscroll"in window)||/(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent),v=f&&"IntersectionObserver"in window,m=f&&"classList"in document.createElement("p"),h=f&&function(){var t=document.createElement("canvas");return!(!t.getContext||!t.getContext("2d"))&&0===t.toDataURL("image/webp").indexOf("data:image/webp")}(),b=function(t,e,n,r){for(var s,a=0;s=t.children[a];a+=1)if("SOURCE"===s.tagName){var i=o(s,n);p(s,e,i,r)}},p=function(t,e,n,r){n&&t.setAttribute(e,d(n,r))},g=function(t,e){var n=h&&e.to_webp,r=o(t,e.data_src);if(r){var s=d(r,n);t.style.backgroundImage='url("'+s+'")'}},y={IMG:function(t,e){var n=h&&e.to_webp,r=e.data_srcset,s=t.parentNode;s&&"PICTURE"===s.tagName&&b(s,"srcset",r,n);var a=o(t,e.data_sizes);p(t,"sizes",a);var i=o(t,r);p(t,"srcset",i,n);var c=o(t,e.data_src);p(t,"src",c,n)},IFRAME:function(t,e){var n=o(t,e.data_src);p(t,"src",n)},VIDEO:function(t,e){var n=e.data_src,r=o(t,n);b(t,"src",n),p(t,"src",r),t.load()}},w=function(t,e){var n=t.tagName,r=y[n];r?r(t,e):g(t,e)},E=function(t,e){m?t.classList.add(e):t.className+=(t.className?" ":"")+e},I=function(t,e){m?t.classList.remove(e):t.className=t.className.replace(new RegExp("(^|\\s+)"+e+"(\\s+|$)")," ").replace(/^\s+/,"").replace(/\s+$/,"")},L=function(t,e){t&&t(e)},O=function(t,e,n){t.addEventListener(e,n)},x=function(t,e,n){t.removeEventListener(e,n)},A=function(t,e,n){O(t,"load",e),O(t,"loadeddata",e),O(t,"error",n)},z=function(t,e,n){x(t,"load",e),x(t,"loadeddata",e),x(t,"error",n)},k=function(t,e,n){var r=e?n.class_loaded:n.class_error,o=e?n.callback_load:n.callback_error,s=t.target;I(s,n.class_loading),E(s,r),L(o,s)},N=function(t,e){var n=function n(o){k(o,!0,e),z(t,n,r)},r=function r(o){k(o,!1,e),z(t,n,r)};A(t,n,r)},C=["IMG","IFRAME","VIDEO"],R=function(t,n,r){e(t,r),n.unobserve(t)},S=function(t){var e=l(t);e&&(clearTimeout(e),c(t,null))},M=function(t,e,n){var r=n.load_delay,o=l(t);o||(o=setTimeout(function(){R(t,e,n),S(t)},r),c(t,o))},j=function(t){return t.isIntersecting||t.intersectionRatio>0},D=function(t){return{root:t.container===document?null:t.container,rootMargin:t.threshold+"px",threshold:0}},T=function(t,e){this._settings=r(t),this._setObserver(),this.update(e)};return T.prototype={_manageIntersection:function(t){var e=this._observer,n=this._settings,r=this._settings.load_delay,o=t.target;j(t)&&(r?M(o,e,n):R(o,e,n)),j(t)||S(o)},_onIntersection:function(e){e.forEach(this._manageIntersection.bind(this)),this._elements=t(this._elements)},_setObserver:function(){v&&(this._observer=new IntersectionObserver(this._onIntersection.bind(this),D(this._settings)))},loadAll:function(){var e=this;this._elements.forEach(function(t){e.load(t)}),this._elements=t(this._elements)},update:function(e){var n=this,r=this._settings,o=e||r.container.querySelectorAll(r.elements_selector);this._elements=t(Array.prototype.slice.call(o)),!_&&this._observer?this._elements.forEach(function(t){n._observer.observe(t)}):this.loadAll()},destroy:function(){var e=this;this._observer&&(t(this._elements).forEach(function(t){e._observer.unobserve(t)}),this._observer=null),this._elements=null,this._settings=null},load:function(t,n){e(t,this._settings,n)}},f&&function(t,e){if(e)if(e.length)for(var n,r=0;n=e[r];r+=1)u(t,n);else u(t,e)}(T,window.lazyLoadOptions),T});
//# sourceMappingURL=lazyload.min.js.map