syriastreet.com/assets/js/lib/jquery.lazyloadxt.js

1 line
2.3 KiB
JavaScript
Raw Permalink Normal View History

2023-10-06 21:29:45 +00:00
!function(h,v,e,o){var m="lazyLoadXT",p="lazied",y="load error",t="lazy-hidden",C=e.documentElement||e.body,w={autoInit:!0,selector:"img[data-src]",blankImage:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",throttle:99,forceLoad:v.onscroll===o||!!v.operamini||!C.getBoundingClientRect,loadEvent:"pageshow",updateEvent:"load orientationchange resize scroll touchmove focus",forceEvent:"lazyloadall",oninit:{removeClass:"lazy"},onshow:{addClass:t},onload:{removeClass:t,addClass:"lazy-loaded"},onerror:{removeClass:t},checkDuplicates:!0},n={srcAttr:"data-src",edgeX:0,edgeY:0,visibleOnly:!0},a=h(v),z=h.isFunction,c=h.extend,E=h.data||function(e,t){return h(e).data(t)},b=[],I=0,i=0;function d(e,t){return(e[t]===o?w:e)[t]}function T(){var e=v.pageYOffset;return e===o?C.scrollTop:e}function B(e,t){var o=w["on"+e];o&&(z(o)?o.call(t[0]):(o.addClass&&t.addClass(o.addClass),o.removeClass&&t.removeClass(o.removeClass))),t.trigger("lazy"+e,[t]),u()}function L(e){B(e.type,h(this).off(y,L))}function l(e){if(b.length){e=e||w.forceLoad,I=1/0;for(var t=T(),o=v.innerHeight||C.clientHeight,n=v.innerWidth||C.clientWidth,a=0,i=b.length;a<i;a++){var l,r,s,c,d=b[a],u=d[0],f=d[m],A=!1,g=e||E(u,p)<0;h.contains(C,u)?(e||!f.visibleOnly||u.offsetWidth||u.offsetHeight)&&(g||(c=u.getBoundingClientRect(),l=f.edgeX,s=f.edgeY,g=(r=c.top+t-s-o)<=t&&c.bottom>-s&&c.left<=n+l&&c.right>-l),g?(d.on(y,L),B("show",d),s=f.srcAttr,(c=z(s)?s(d):u.getAttribute(s))&&(u.src=c),A=!0):r<I&&(I=r)):A=!0,A&&(E(u,p,0),b.splice(a--,1),i--)}i||B("complete",h(C))}}function r(){1<i?(i=1,l(),setTimeout(r,w.throttle)):i=0}function u(e){!b.length||e&&"scroll"===e.type&&e.currentTarget===v&&I>=T()||(i||setTimeout(r,0),i=2)}function s(){a.lazyLoadXT()}function f(){l(!0)}h[m]=c(w,n,h[m]),h.fn[m]=function(a){var e,i=d(a=a||{},"blankImage"),l=d(a,"checkDuplicates"),t=d(a,"scrollContainer"),r=d(a,"show"),s={};for(e in h(t).on("scroll",u),n)s[e]=d(a,e);return this.each(function(e,t){var o,n;t===v?h(w.selector).lazyLoadXT(a):(o=l&&E(t,p),n=h(t).data(p,r?-1:1),o||(i&&"IMG"===t.tagName&&!t.src&&(t.src=i),n[m]=c({},s),B("init",n),b.push(n)),u())})},h(e).ready(function(){B("start",a),a.on(w.updateEvent,u).on(w.forceEvent,f),h(e).on(w.updateEvent,u),w.autoInit&&(a.on(w.loadEvent,s),s())})}(window.jQuery||window.Zepto||window.$,window,document);