/** * @preserve SlothyLoader - v2.0.0 - 2019-03-06 * @preserve LaziestLoader - v0.7.3 - 2016-01-03 * An lazy loader based on Josh Williams’s * LaziestLoader, but without jQuery dependency * v2.0, now with IntersectionObserver * See: http://sjwilliams.github.io/laziestloader/ * Copyright (c) 2016 Josh Williams; Licensed MIT */ var slothyLoader=function(options,callback){function getSource($el){var source,slug,data=$el.dataset;if(data.pattern&&data.widths&&Array.isArray(JSON.parse(data.widths))){source=retina3x?data.patternRetina3x:retina?data.patternRetina:data.pattern,source=source||data.patternRetina||data.pattern;var parsedWidths=JSON.parse(data.widths);if("object"==typeof parsedWidths[0])slug=function(){for(var widths=parsedWidths.map(function(val){return val.size}),bestFitWidth=bestFit($el.offsetWidth,widths),i=parsedWidths.length-1;i>=0;i--)if(parsedWidths[i].size===bestFitWidth)return parsedWidths[i].slug}(),source=source.replace(options.sizePattern,slug);else{var bestFitWidth=bestFit($el.offsetWidth,parsedWidths);retina3x?bestFitWidth*=3:retina&&(bestFitWidth*=2),source=source.replace(options.sizePattern,bestFitWidth)}}else source=retina3x?data.srcRetina3x:retina?data.srcRetina:data.src,source=source||data.src;return source}function onLoad($el){addClass($el,"ll-loaded"),removeClass($el,"ll-notloaded"),"function"==typeof callback&&callback.call($el)}function slHandler($el){var source;$el.dataset.ratio&&setHeight.call($el),options.setSourceMode&&(source=options.getSource($el))&&$el.getAttribute("src")!==source&&$el.setAttribute("src",source),addClass($el,"ll-loadstarted"),!options.setSourceMode||"IMG"!==$el.nodeName&&"VIDEO"!==$el.nodeName&&"AUDIO"!==$el.nodeName?onLoad($el):"IMG"===$el.nodeName?$el.onload=function(){onLoad($el)}:$el.onloadstart=function(){onLoad($el)}}function slHandleIntersection(entries){var entry=entries[0],$el=entry.target;(entry.intersectionRatio>0||entry.intersectionRatio<=0&&(entry.boundingClientRect.top<0||entry.boundingClientRect.y<0))&&slHandler($el)}function slLegacyEvListener(e){slHandler(this)}function bindLegacyLoader(){for(var i=0;i<$elements.length;++i){$elements[i].addEventListener("slothyloader",slLegacyEvListener)}}function unbindLegacyLoader(){for(var i=0;i<$elements.length;++i){$elements[i].removeEventListener("slothyloader",slLegacyEvListener)}}function slothyloader(){for(var docEl=document.documentElement,wHeight=window.innerHeight||docEl.clientHeight,wWidth=window.innerWidth||docEl.clientWidth,threshold=options.threshold,$inview=[],i=0;i<$elements.length;++i){var el=$elements[i];if(!includesElement($loaded,el)){var rect=el.getBoundingClientRect();rect.bottom+threshold>0&&rect.right+threshold>0&&rect.left0&&($el.style.height=newHeight+"px")}}function hasClass(el,className){for(var classList=className.split(" "),i=0;i>>0;if(0===len)return!1;for(var n=0|fromIndex,k=Math.max(n>=0?n:len-Math.abs(n),0);k1,retina3x=window.devicePixelRatio>2,didScroll=!1,observers=[],defaultOptions={selector:".dvz-lazy",threshold:0,sizePattern:/{{SIZE}}/gi,getSource:getSource,event:"scroll",scrollThrottle:250,sizeOffsetPercent:0,setSourceMode:!0};const intersectionObserverOpts={root:null,threshold:[0,.25,.5,.75],rootMargin:void 0!==options&&void 0!==options.threshold?options.threshold:defaultOptions.threshold+"px"};void 0===options&&(options={});for(var x in defaultOptions)void 0!==defaultOptions[x]&&void 0===options[x]&&(options[x]=defaultOptions[x]);$elements=document.querySelectorAll(options.selector);for(var useNativeScroll="string"==typeof options.event&&0===options.event.indexOf("scroll"),bestFit=slothyLoader.bestFit=function(targetWidth,widths){var selectedWidth=widths[widths.length-1],i=widths.length,offset=targetWidth*(options.sizeOffsetPercent/100);for(widths.sort(function(a,b){return a-b});i--;)targetWidth-offset<=widths[i]&&(selectedWidth=widths[i]);return selectedWidth},i=0;i<$elements.length;++i){var el=$elements[i];addClass(el,"ll-init ll-notloaded"),setHeight.call(el)}return!function(){return"undefined"!=typeof window&&("IntersectionObserver"in window&&"IntersectionObserverEntry"in window)}()?(bindLegacyLoader(),useNativeScroll?(window.addEventListener("scroll",function(){didScroll=!0}),setInterval(function(){didScroll&&(didScroll=!1,slothyloader())},options.scrollThrottle)):"function"==typeof options.event?options.event(slothyloader):window.addEventListener(options.event,function(){slothyloader()})):function(){for(var i=0;i<$elements.length;++i){var el=$elements[i],observer=new IntersectionObserver(slHandleIntersection,intersectionObserverOpts);observer.observe(el),observers.push(observer)}}(),window.addEventListener("resize",function(){$loaded=[],unbindLegacyLoader(),bindLegacyLoader(),slothyloader()}),window.addEventListener("DOMContentLoaded",function(){slothyloader()}),this};!function(){function CustomEvent(event,params){params=params||{bubbles:!1,cancelable:!1,detail:void 0};var evt=document.createEvent("CustomEvent");return evt.initCustomEvent(event,params.bubbles,params.cancelable,params.detail),evt}if("function"==typeof window.CustomEvent)return!1;CustomEvent.prototype=window.Event.prototype,window.CustomEvent=CustomEvent}(),"undefined"!=typeof module&&(module.exports=slothyLoader);