forked from dinbror/blazy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblazy.min.js
6 lines (6 loc) · 5.78 KB
/
blazy.min.js
1
2
3
4
5
6
/*!
hey, [be]Lazy.js - v1.8.2 - 2016.10.25
A fast, small and dependency free lazy load script (https://github.com/dinbror/blazy)
(c) Bjoern Klinggaard - @bklinggaard - http://dinbror.dk/blazy
*/
!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.Blazy=e()}(this,function(){"use strict";function t(t){var o=t._util;o.elements=h(t.options),o.count=o.elements.length,o.destroyed&&(o.destroyed=!1,t.options.container&&b(t.options.container,function(t){g(t,"scroll",o.validateT)}),g(window,"resize",o.saveViewportOffsetT),g(window,"resize",o.validateT),g(window,"scroll",o.validateT)),e(t)}function e(t){for(var e=t._util,n=0;n<e.count;n++){var i=e.elements[n];(o(i,t.options)||v(i,t.options.successClass))&&(t.load(i),e.elements.splice(n,1),e.count--,n--)}0===e.count&&t.destroy()}function o(t,e){var o=t.getBoundingClientRect();if(e.container&&z){var i=t.closest(e.containerClass);if(i){var s=i.getBoundingClientRect();if(n(s,T)){var r=s.top-e.offset,a=s.right+e.offset,c=s.bottom+e.offset,l=s.left-e.offset,f={top:r>T.top?r:T.top,right:a<T.right?a:T.right,bottom:c<T.bottom?c:T.bottom,left:l>T.left?l:T.left};return n(o,f)}return!1}}return n(o,T)}function n(t,e){return t.right>=e.left&&t.bottom>=e.top&&t.left<=e.right&&t.top<=e.bottom}function i(t,e,o){if(!v(t,o.successClass)&&(e||o.loadInvisible||t.offsetWidth>0&&t.offsetHeight>0)){var n=l(t,E)||l(t,o.src);if(n){var i=n.split(o.separator),c=i[x&&i.length>1?1:0],f=l(t,o.srcset),u=d(t,!1);u&&(f=void 0,c=u);var h=p(t,"img"),w=t.parentNode,C=w&&p(w,"picture");if(h||void 0===t.src){var T=new Image,z=function(){o.error&&o.error(t,"invalid"),m(t,o.errorClass),y(T,"error",z),y(T,"load",S)},S=function(){h?C||a(t,c,f):t.style.backgroundImage='url("'+c+'")',s(t,o),y(T,"load",S),y(T,"error",z)};C&&(T=t,b(w.getElementsByTagName("source"),function(t){r(t,O,o.srcset)})),g(T,"error",z),g(T,"load",S),a(T,c,f)}else t.src=c,s(t,o)}else p(t,"video")?(b(t.getElementsByTagName("source"),function(t){r(t,k,o.src)}),t.load(),s(t,o)):(o.error&&o.error(t,"missing"),m(t,o.errorClass))}}function s(t,e){m(t,e.successClass),e.success&&e.success(t),f(t,e.src),f(t,e.srcset),b(e.breakpoints,function(e){f(t,e.src)}),"function"==typeof e.itemLoaded&&e.itemLoaded.call(t,e)}function r(t,e,o){var n=l(t,o);n&&(c(t,e,n),f(t,o))}function a(t,e,o){o&&c(t,O,o),t.src=e}function c(t,e,o){t.setAttribute(e,o)}function l(t,e){return t.getAttribute(e)}function f(t,e){t.removeAttribute(e)}function u(){if(window.matchMedia){var t=window.matchMedia("only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)");return t&&t.matches||window.devicePixelRatio>1}}function d(t,e){var o=l(t,"data-bs-srcset");if(!o)return e;if(o=JSON.parse(o),!o||!o.sizes)return e;var n,i=t.offsetWidth;u()&&(i*=2);for(n in o.sizes)if(parseInt(n)>=i)return o.baseurl+o.sizes[n];return e}function p(t,e){return t.nodeName.toLowerCase()===e}function v(t,e){return-1!==(" "+t.className+" ").indexOf(" "+e+" ")}function m(t,e){v(t,e)||(t.className+=" "+e)}function h(t){for(var e=[],o=t.root.querySelectorAll(t.selector),n=o.length;n--;e.unshift(o[n]));return e}function w(t){T.bottom=(window.innerHeight||document.documentElement.clientHeight)+t,T.right=(window.innerWidth||document.documentElement.clientWidth)+t}function g(t,e,o){t.attachEvent?t.attachEvent&&t.attachEvent("on"+e,o):t.addEventListener(e,o,{capture:!1,passive:!0})}function y(t,e,o){t.detachEvent?t.detachEvent&&t.detachEvent("on"+e,o):t.removeEventListener(e,o,{capture:!1,passive:!0})}function b(t,e){if(t&&e)for(var o=t.length,n=0;o>n&&e(t[n],n)!==!1;n++);}function C(t,e,o){var n=0;return function(){var i=+new Date;e>i-n||(n=i,t.apply(o,arguments))}}var E,T,x,z,k="src",O="srcset";return function(o){if(!document.querySelectorAll){var n=document.createStyleSheet();document.querySelectorAll=function(t,e,o,i,s){for(s=document.all,e=[],t=t.replace(/\[for\b/gi,"[htmlFor").split(","),o=t.length;o--;){for(n.addRule(t[o],"k:v"),i=s.length;i--;)s[i].currentStyle.k&&e.push(s[i]);n.removeRule(0)}return e}}var s=this,r=s._util={};r.elements=[],r.destroyed=!0,s.options=o||{},s.options.error=s.options.error||!1,s.options.offset=s.options.offset||100,s.options.root=s.options.root||document,s.options.success=s.options.success||!1,s.options.selector=s.options.selector||".b-lazy",s.options.separator=s.options.separator||"|",s.options.containerClass=s.options.container,s.options.container=s.options.containerClass?document.querySelectorAll(s.options.containerClass):!1,s.options.errorClass=s.options.errorClass||"b-error",s.options.breakpoints=s.options.breakpoints||!1,s.options.loadInvisible=s.options.loadInvisible||!1,s.options.successClass=s.options.successClass||"b-loaded",s.options.validateDelay=s.options.validateDelay||25,s.options.saveViewportOffsetDelay=s.options.saveViewportOffsetDelay||50,s.options.srcset=s.options.srcset||"data-srcset",s.options.src=E=s.options.src||"data-src",z=Element.prototype.closest,x=window.devicePixelRatio>1,T={},T.top=0-s.options.offset,T.left=0-s.options.offset,s.revalidate=function(){t(s)},s.load=function(t,e){var o=this.options;t&&void 0===t.length?i(t,e,o):b(t,function(t){i(t,e,o)})},s.destroy=function(){var t=s._util;s.options.container&&b(s.options.container,function(e){y(e,"scroll",t.validateT)}),y(window,"scroll",t.validateT),y(window,"resize",t.validateT),y(window,"resize",t.saveViewportOffsetT),t.count=0,t.elements.length=0,t.destroyed=!0},r.validateT=C(function(){e(s)},s.options.validateDelay,s),r.saveViewportOffsetT=C(function(){w(s.options.offset)},s.options.saveViewportOffsetDelay,s),w(s.options.offset),b(s.options.breakpoints,function(t){return t.width>=window.screen.width?(E=t.src,!1):void 0}),setTimeout(function(){t(s)})}});;