-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoimgsizes.min.js
1 lines (1 loc) · 1.84 KB
/
autoimgsizes.min.js
1
!function(t,e){"use strict";if(e.getElementsByClassName){var i,r=/^img$/i,n=1;t.devicePixelRatio&&(n=t.devicePixelRatio);var a,d=function(t,e){if(r.test(t.nodeName)){if(!e||"auto"==t.getAttribute(i.autoAttr)&&"true"!=t.getAttribute(i.heightAttr)){if(null!=t.getAttribute("src")&&t.getAttribute("src").length>0)return}else t.setAttribute("src","");if(t.getAttribute(i.srcAttr)&&0==t.getAttribute(i.srcAttr).indexOf("http")&&t.getAttribute(i.originSizeAttr)){var d=t.getAttribute(i.originSizeAttr).split("x");a={},a.width=parseFloat(d[0]),a.height=parseFloat(d[1]);var h=t.parentNode.getBoundingClientRect();if(0!=h.width){var o={width:h.width*n,height:h.height*n},g="?imageMogr2/",s="auto"==t.getAttribute(i.autoAttr);s?(g+="thumbnail/"+o.width+"x",t.style.width="100%","true"==t.getAttribute(i.heightAttr)&&(t.style.height=o.width*a.height/a.width/n+"px")):(g+=a.width/a.height>o.width/o.height?"thumbnail/x"+o.height:"thumbnail/"+o.width+"x",g+="/gravity/Center/crop/"+o.width+"x"+o.height,t.style.width=o.width/n+"px",t.style.height=o.height/n+"px"),t.setAttribute("src",t.getAttribute(i.srcAttr)+g)}}}},h=function(t){var r=e.getElementsByClassName(i.autoImgClass),n=r.length;if(n)for(var a=0;n>a;a++)r[a]&&d(r[a],t)},o=function(){h(!1)},g=function(){h(!0)};!function(){var r,n={srcAttr:"data-src",autoAttr:"data-auto",originSizeAttr:"data-origin-size",autoImgClass:"autoImgSizes",heightAttr:"data-height"};i=t.autoImgSizeConfig||t.autoImgSizeConfig||{};for(r in n)r in i||(i[r]=n[r]);/d$|^c/.test(e.readyState)?o():(t.addEventListener("load",o,!0),e.addEventListener("DOMContentLoaded",o)),["focus","mouseover","click","load"].forEach(function(t){e.addEventListener(t,o,!0)}),t.addEventListener("resize",g,!0),t.addEventListener("scroll",o,!0),e.documentElement.addEventListener("DOMNodeInserted",o,!0),e.documentElement.addEventListener("DOMAttrModified",o,!0)}()}}(window,document);