-
Notifications
You must be signed in to change notification settings - Fork 1
/
responsive-elements.min.js
1 lines (1 loc) · 1.81 KB
/
responsive-elements.min.js
1
!function(){return window.re=new function(){var t,e,n,r,o,i,a,u,c;return t=this,t.config={attr:"data-respond",widthAttr:"data-width",refreshRate:50,rootFontSize:parseInt(getComputedStyle(document.documentElement).fontSize),baseFontSize:16,start:100,end:900,interval:50},t.dom={window:window,elements:document.querySelectorAll("["+t.config.attr+"]")},c={debounce:function(t,e,n){return function(){var r,o,i,a,u,c;return i=this,r=arguments,a=function(){var e,o;return o=null,n?void 0:e=t.apply(i,r)},o=n&&!c,clearTimeout(c),c=setTimeout(a,e),o&&(u=t.apply(i,r)),u}}},e=function(){return t.dom.window.addEventListener("load",a),t.dom.window.addEventListener("resize",n)},u=function(){return t.dom.window.removeEventListener("load",a,!1),t.dom.window.removeEventListener("resize",n,!1)},a=function(){var e,n,r,o,a;for(o=t.dom.elements,a=[],n=0,r=o.length;r>n;n++)e=o[n],a.push(i(e));return a},n=c.debounce(a,t.config.refreshRate),i=function(e){var n,i;return i=o(e.getAttribute(t.config.attr)),n=r(e.offsetWidth,i),e.setAttribute(t.config.widthAttr,n.join(" "))},r=function(e,n){var r,o;for(r=[],o=n.interval>n.start?n.interval:~~(n.start/n.interval)*n.interval,e*=t.config.baseFontSize/t.config.rootFontSize;o<=n.end;)e>o&&r.push("gt"+o),o>=e&&r.push("lt"+o),o+=n.interval;return r},o=function(e){var n,r,o,i,a,u;if(i={start:t.config.start,end:t.config.end,interval:t.config.interval},o=e.match(/([a-zA-Z]+|[0-9]+)/g),!o)return i;for(n=a=0,u=o.length;u>a;n=a+=2)switch(r=o[n],r[0].toLowerCase()){case"s":i.start=+o[n+1];break;case"e":i.end=+o[n+1];break;case"i":i.interval=+o[n+1]}return i},t.setConfig=function(e){var n,r;for(n in e)r=e[n],null!=t.config[n]&&(t.config[n]=r);return t.dom.elements=document.querySelectorAll("["+t.config.attr+"]"),t},t.enable=function(){return e(),t},t.disable=function(){return u(),t},t.refresh=function(){return a(),t},t}}();