-
Notifications
You must be signed in to change notification settings - Fork 0
/
W.min.js
1 lines (1 loc) · 1.79 KB
/
W.min.js
1
!function(e,t,n){"undefined"!=typeof module&&module.exports?module.exports=n:"function"==typeof define&&define.amd?define(n):e[t]=n}(this,"W",function(){function e(){return"orientation"in window?window.orientation?"landscape":"portrait":r.clientWidth>r.clientHeight?"landscape":"portrait"}function t(t){var n,i,o,r,d=[{width:screen.availWidth,height:screen.availHeight},{width:window.outerWidth,height:window.outerHeight},{width:window.innerWidth,height:window.innerHeight}];if(/(iPad|iPhone|iPod)/g.test(navigator.userAgent)&&"landscape"==e()?(n=screen.height,i=screen.width,d[2].width=n):(n=screen.width,i=screen.height),t)return{width:n,height:i};for(o=0,r=d.length;r>o;++o)d[o].width>n||d[o].height>i||!d[o].width||!d[o].height?d[o].note=0:d[o].note=n-d[o].width+(i-d[o].height);return d.sort(function(e,t){return t.note-e.note}),{width:d[0].width,height:d[0].height}}var n,i,o,r=document.documentElement,d=[],h=!1,a=16;return window.addEventListener?"onorientationchange"in window?window.addEventListener("orientationchange",function(){h=!0},!1):window.addEventListener("resize",function(){h=!0},!1):window.attachEvent("onresize",function(){h=!0}),i=document.createElement("p"),i.style.position="absolute",i.style.textIndent="100%",i.style.whiteSpace="nowrap",i.style.overflow="hidden",i.style.color="transparent",i.innerHTML="W",r.appendChild(i),o=i.offsetWidth,setInterval(function(){if(n=i.offsetWidth,n!=o&&(h=!0),h&&r.clientWidth){a=o/n*a,o=n;for(var e=0,t=d.length;t>e;++e)d[e].func();h=!1}},10),{px2em:function(e){return e/a},getViewportWidth:function(e){return t(e).width},getViewportHeight:function(e){return t(e).height},getOrientation:function(){return e()},addListener:function(e,t){return d.push({func:e,key:t}),e},removeListener:function(e){for(var t=0,n=d.length;n>t;++t)if(d[t].key==e){d.splice(t,1);break}}}}());