-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlazyload.min.js
12 lines (11 loc) · 3.14 KB
/
lazyload.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
Plugin for lazy loading images
@link https://github.com/nechehin/lazyload
*/
(function(a){"function"===typeof define&&define.amd?define(["jquery"],a):"object"===typeof module&&module.exports?module.exports=function(g,f){void 0===f&&(f="undefined"!==typeof window?require("jquery"):require("jquery")(g));a(f);return f}:a(jQuery)})(function(a){var g=a(window),f=g.width(),k=g.height();g.on("resize",function(){f=g.width();k=g.height()});a.fn.lazyload=function(d){function b(a){var c=a.tagName.toLowerCase(),b=a.getAttribute("data-src");"img"===c?(a.src=b,a.getAttribute("data-srcset")&&
(a.srcset=a.getAttribute("data-srcset"))):"iframe"===c?a.src=b:a.backgroundImage="url("+b+")"}function f(){c.pageYOffset=window.pageYOffset;c.pageXOffset=window.pageXOffset;var b=0;h.each(function(){var e=a(this);if(!(c.skip_invisible&&!e.is(":visible")||a.abovethetop(this,c)||a.leftofbegin(this,c)))if(!a.belowthefold(this,c)&&!a.rightoffold(this,c))e.trigger("appear"),b=0;else if(++b>c.failure_limit)return!1})}var h=this,c={threshold:0,failure_limit:0,event:"scroll",container:window,skip_invisible:!1,
appear:null,load:null,allowIntersectionMode:!0,placeholder:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",pageXOffset:!1,pageYOffset:!1};d&&a.extend(c,d);var l=c.allowIntersectionMode&&"IntersectionObserver"in window&&0===c.event.indexOf("scroll");if(l){d={};c.container!==window&&(d.root="undefined"===typeof c.container[0]?c.container:c.container[0]);var k=new IntersectionObserver(function(a){[].forEach.call(a,function(a){!1!==a.isIntersecting&&(b(a.target),k.unobserve(a.target))})},
d)}else var m=void 0===c.container||c.container===window?g:a(c.container);if(0===c.event.indexOf("scroll")&&!l)m.on(c.event,function(){return f()});this.each(function(){var e=this;e.loaded=!1;null===e.getAttribute("src")&&"IMG"===e.tagName&&(e.src=c.placeholder);if(l)k.observe(e);else{var d=a(e);d.one("appear",function(){if(!this.loaded){if(c.appear){var d=h.length;c.appear.call(e,d,c)}b(e);e.loaded=!0;d=a.grep(h,function(a){return!a.loaded});h=a(d);c.load&&(d=h.length,c.load.call(e,d,c))}});0!==
c.event.indexOf("scroll")&&e.addEventListener(c.event,function(){e.loaded||d.trigger("appear")})}});if(!l){window.addEventListener("resize",function(){f()});if(/(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion))g.on("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&h.each(function(){a(this).trigger("appear")})});a(function(){f()})}return this};a.belowthefold=function(d,b){return(void 0===b.container||b.container===window?k+b.pageYOffset:a(b.container).offset().top+a(b.container).height())<=
a(d).offset().top-b.threshold};a.rightoffold=function(d,b){return(void 0===b.container||b.container===window?f+b.pageXOffset:a(b.container).offset().left+a(b.container).width())<=a(d).offset().left-b.threshold};a.abovethetop=function(d,b){return(void 0===b.container||b.container===window?b.pageYOffset:a(b.container).offset().top)>=a(d).offset().top+b.threshold+d.clientHeight};a.leftofbegin=function(d,b){return(void 0===b.container||b.container===window?b.pageXOffset:a(b.container).offset().left)>=
a(d).offset().left+b.threshold+d.clientWidth}});