UNPKG

@fancyapps/ui

Version:

Robust JavaScript UI Component Library

1 lines 2.04 kB
!/*! License details at fancyapps.com/license */function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).window=e.window||{})}(this,function(e){"use strict";let t=e=>"object"==typeof e&&null!==e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e),a={showLoading:!0,preload:1},o="is-lazyloading",l="is-lazyloaded";e.Lazyload=()=>{let e;function s(){let o=e?.getOptions().Lazyload;return t(o)?{...a,...o}:a}function d(t){let a=t.el;if(!a)return;let d="[data-lazy-src],[data-lazy-srcset],[data-lazy-bg]",n=Array.from(a.querySelectorAll(d));for(let i of(a.matches(d)&&n.push(a),n)){let a=i.dataset.lazySrc,d=i.dataset.lazySrcset,n=i.dataset.lazySizes,r=i.dataset.lazyBg,c=(i instanceof HTMLImageElement||i instanceof HTMLSourceElement)&&(a||d),f=i instanceof HTMLElement&&r;if(!(c||f))continue;let y=a||d||r;y&&(c&&y?(s().showLoading&&e?.showLoading(t),i.addEventListener("load",()=>{e?.hideLoading(t),i instanceof HTMLImageElement?i.decode().then(()=>{i.classList.remove(o),i.classList.add(l)}):(i.classList.remove(o),i.classList.add(l)),e?.emit("lazyLoad:loaded",t,i,y)}),i.addEventListener("error",()=>{e?.hideLoading(t),i.classList.remove(o),i.classList.add("has-lazyerror"),e?.emit("lazyLoad:error",t,i,y)}),i.classList.add("f-lazyload"),i.classList.add(o),e?.emit("lazyLoad:load",t,i,y),a&&(i.src=a),d&&(i.srcset=d),n&&(i.sizes=n)):f&&(document.body.contains(i)||(document.createElement("img").src=r),i.style.backgroundImage=`url('${r}')`),delete i.dataset.lazySrc,delete i.dataset.lazySrcset,delete i.dataset.lazySizes)}}function n(){if(!e)return;let t=s().preload,a=e.getPages(),o=a.length,l=e.getPageIndex();for(let e=l-t;e<=l+t;e++){let t=(e%o+o)%o;for(let e of a[t]?.slides||[])d(e)}}function i(e,t){d(t)}return{init:function(t){(e=t).on(["ready","change"],n),e.on("attachSlideEl",i)},destroy:function(){e?.off(["ready","change"],n),e?.off("attachSlideEl",i),e=void 0}}}});