This repository was archived by the owner on Jan 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathImager.min.js
More file actions
2 lines (2 loc) · 6.06 KB
/
Imager.min.js
File metadata and controls
2 lines (2 loc) · 6.06 KB
1
2
!function(t,e){"use strict";var i=function(){return e.addEventListener?function(t,e,i){return t.addEventListener(e,i,!1)}:function(t,e,i){return t.attachEvent("on"+e,i)}}(),s=[96,130,165,200,235,270,304,340,375,410,445,485,520,555,590,625,660,695,736],a="function"==typeof Object.keys?Object.keys:function(t){var e,i=[];for(e in t)i.push(e);return i},n=function(t,e){for(var i=0,s=t.length,a=[];s>i;i++)a[i]=e(t[i],i);return a},r=function(t){return t},o=function(){},l=function(){return!0},h=function(t,e){var i;return function(){var s=this,a=arguments,n=function(){i=null,t.apply(s,a)};clearTimeout(i),i=setTimeout(n,e)}},c=function(t,i){var n=this,l=e;i=i||{},void 0!==t&&("string"==typeof t?(i.selector=t,t=void 0):"undefined"==typeof t.length&&(i=t,t=void 0)),this.viewportHeight=l.documentElement.clientHeight,this.selector=t?null:i.selector||".delayed-image-load",this.className=i.className||"image-replace",this.gif=l.createElement("img"),this.gif.src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7",this.gif.className=this.className,this.gif.alt="",this.lazyloadOffset=i.lazyloadOffset||0,this.scrollDelay=i.scrollDelay||250,this.onResize=i.hasOwnProperty("onResize")?i.onResize:!0,this.lazyload=i.hasOwnProperty("lazyload")?i.lazyload:!1,this.scrolled=!1,this.availablePixelRatios=i.availablePixelRatios||[1,2],this.availableWidths=i.availableWidths||s,this.onImagesReplaced=i.onImagesReplaced||o,this.widthsMap={},this.refreshPixelRatio(),this.widthInterpolator=i.widthInterpolator||r,this.gif.removeAttribute("height"),this.gif.removeAttribute("width"),"function"!=typeof this.availableWidths&&("number"==typeof this.availableWidths.length?this.widthsMap=c.createWidthsMap(this.availableWidths,this.widthInterpolator,this.devicePixelRatio):(this.widthsMap=this.availableWidths,this.availableWidths=a(this.availableWidths)),this.availableWidths=this.availableWidths.sort(function(t,e){return t-e})),this.divs=[],this.add(t||this.selector),this.ready(i.onReady),setTimeout(function(){n.init()},0)};c.prototype.add=function(t){t=t||this.selector;var i="string"==typeof t?e.querySelectorAll(t):t;if(i&&i.length){var s=n(i,r);this.changeDivsToEmptyImages(s),this.divs=this.divs.concat(s)}},c.prototype.scrollCheck=function(){var e=this,i=0,s=[];this.scrolled&&(n(this.divs,function(t){e.isPlaceholder(t)&&(++i,e.isThisElementOnScreen(t)&&s.push(t))}),0===i&&t.clearInterval(e.interval),this.changeDivsToEmptyImages(s),this.scrolled=!1)},c.prototype.init=function(){var t=this;this.initialized=!0;var e=l;this.lazyload?(this.registerScrollEvent(),this.scrolled=!0,t.scrollCheck(),e=function(e){return t.isPlaceholder(e)===!1}):this.checkImagesNeedReplacing(this.divs),this.onResize&&this.registerResizeEvent(e),this.onReady()},c.prototype.ready=function(t){this.onReady=t||o},c.prototype.createGif=function(t){if(t.className.match(new RegExp("(^| )"+this.className+"( |$)")))return t;var e=t.getAttribute("data-class"),i=t.getAttribute("data-width"),s=this.gif.cloneNode(!1);return i&&(s.width=i,s.setAttribute("data-width",i)),s.className=(e?e+" ":"")+this.className,s.setAttribute("data-src",t.getAttribute("data-src")),s.setAttribute("alt",t.getAttribute("data-alt")||this.gif.alt),t.parentNode.replaceChild(s,t),s},c.prototype.changeDivsToEmptyImages=function(t){var e=this;n(t,function(i,s){t[s]=e.createGif(i)}),this.initialized&&this.checkImagesNeedReplacing(t)},c.prototype.isPlaceholder=function(t){return t.src===this.gif.src},c.prototype.isThisElementOnScreen=function(t){var e=0,i=c.getPageOffset()+this.lazyloadOffset;if(t.offsetParent)do e+=t.offsetTop;while(t=t.offsetParent);return e<this.viewportHeight+i},c.prototype.checkImagesNeedReplacing=function(t,e){var i=this;e=e||l,this.isResizing||(this.isResizing=!0,this.refreshPixelRatio(),n(t,function(t){e(t)&&i.replaceImagesBasedOnScreenDimensions(t)}),this.isResizing=!1,this.onImagesReplaced(t))},c.prototype.replaceImagesBasedOnScreenDimensions=function(t){var e,i;i=c.getNaturalWidth(t),e="function"==typeof this.availableWidths?this.availableWidths(t):this.determineAppropriateResolution(t),t.width=e,!this.isPlaceholder(t)&&i>=e||(t.src=this.changeImageSrcToUseNewImageDimensions(t.getAttribute("data-src"),e),t.removeAttribute("width"),t.removeAttribute("height"))},c.prototype.determineAppropriateResolution=function(t){return c.getClosestValue(t.getAttribute("data-width")||t.parentNode.clientWidth,this.availableWidths)},c.prototype.refreshPixelRatio=function(){this.devicePixelRatio=c.getClosestValue(c.getPixelRatio(),this.availablePixelRatios)},c.prototype.changeImageSrcToUseNewImageDimensions=function(t,e){return t.replace(/{width}/g,c.transforms.width(e,this.widthsMap)).replace(/{pixel_ratio}/g,c.transforms.pixelRatio(this.devicePixelRatio))},c.getPixelRatio=function(e){return(e||t).devicePixelRatio||1},c.createWidthsMap=function(t,e,i){for(var s={},a=t.length;a--;)s[t[a]]=e(t[a],i);return s},c.transforms={pixelRatio:function(t){return 1===t?"":"-"+t+"x"},width:function(t,e){return e[t]||t}},c.getClosestValue=function(t,e){var i=e.length,s=e[i-1];for(t=parseFloat(t);i--;)t<=e[i]&&(s=e[i]);return s},c.prototype.registerResizeEvent=function(e){var s=this;i(t,"resize",h(function(){s.checkImagesNeedReplacing(s.divs,e)},100))},c.prototype.registerScrollEvent=function(){var s=this;this.scrolled=!1,this.interval=t.setInterval(function(){s.scrollCheck()},s.scrollDelay),i(t,"scroll",function(){s.scrolled=!0}),i(t,"resize",function(){s.viewportHeight=e.documentElement.clientHeight,s.scrolled=!0})},c.getPageOffsetGenerator=function(i){return i?function(){return t.pageYOffset}:function(){return e.documentElement.scrollTop}},c.getNaturalWidth=function(){return"naturalWidth"in new Image?function(t){return t.naturalWidth}:function(t){var i=e.createElement("img");return i.src=t.src,i.width}}(),c.getPageOffset=c.getPageOffsetGenerator(Object.prototype.hasOwnProperty.call(t,"pageYOffset")),c.applyEach=n,c.addEvent=i,c.debounce=h,"object"==typeof module&&"object"==typeof module.exports?module.exports=exports=c:"function"==typeof define&&define.amd?define(function(){return c}):"object"==typeof t&&(t.Imager=c)}(window,document);
//# sourceMappingURL=./Imager.map.js