-
Notifications
You must be signed in to change notification settings - Fork 4
/
res.min.js
1 lines (1 loc) · 3.55 KB
/
res.min.js
1
!function(){function e(e,i){i=i||{bubbles:!1,cancelable:!1,detail:void 0};var t=document.createEvent("CustomEvent");return t.initCustomEvent(e,i.bubbles,i.cancelable,i.detail),t}e.prototype=window.Event.prototype,window.CustomEvent=e}();var res=function(e){var i=this;this.uagent=navigator.userAgent.toLowerCase(),this.state=void 0,this.input=void 0,this.orient=void 0,this.device=void 0,this.os=void 0,this.browser=void 0,this.version=void 0,this.width=0,this.grid={},this.viewports={},this.gridsettings={};for(var t=0,n=0;n<e.length;n++)i.viewports[e[n].state]=[t+1,e[n].breakpoint],void 0!==e[n].cols&&void 0!==e[n].margin&&void 0!==e[n].gutter&&(i.gridsettings[e[n].state]=[e[n].cols,e[n].margin,e[n].gutter]),t=e[n].breakpoint;this.init()};res.prototype={setState:function(){var e=this;"desktop"===e.device?e.width=window.innerWidth:"desktop"!==e.device&&("portrait"===e.orient?e.width=screen.width:"landscape"===e.orient&&(e.width=screen.height));for(var i in e.viewports)if(e.viewports.hasOwnProperty(i)&&e.width>=e.viewports[i][0]&&e.width<=e.viewports[i][1]&&e.state!=i)return e.state=i,e.state},inputCheck:function(){var e=this;"ios"===e.os||"android"===e.os||"winphone"===e.os?e.input="touch":e.input="mouse"},browserCheck:function(){var e,i=this,t=i.uagent.match(/(edge|opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];return i.uagent.match(/(edge(?=\/))\/?\s*(\d+)/i)?(t=i.uagent.match(/(edge(?=\/))\/?\s*(\d+)/i),i.browser="edge",i.version=t[2],"Edge "+(t[2]||"")):/trident/i.test(t[1])?(e=/\brv[ :]+(\d+)/g.exec(i.uagent)||[],i.browser="msie",i.version=e[1],"IE "+(e[1]||"")):"Chrome"===t[1]&&(e=i.uagent.match(/\bOPR\/(\d+)/),null!=e)?(i.browser="opera",i.version=e[1],"Opera "+e[1]):(t=t[2]?[t[1],t[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(e=i.uagent.match(/version\/(\d+)/i))&&t.splice(1,1,e[1]),i.browser=t[0],i.version=t[1],t.join(" "))},osCheck:function(){var e=this;-1!=navigator.appVersion.indexOf("Win")?(e.os="windows",e.device="desktop"):-1!=navigator.appVersion.indexOf("Mac")&&null==navigator.userAgent.match(/(iPhone|iPod|iPad)/)?(e.os="osx",e.device="desktop"):navigator.userAgent.indexOf("Android")>-1?(e.os="android",navigator.userAgent.indexOf("Mobile")>-1?e.device="mobile":e.device="tablet"):navigator.userAgent.indexOf("windows phone")>0?(e.os="windows",e.device="mobile"):-1!=navigator.appVersion.indexOf("X11")?(e.os="unix",e.device="desktop"):-1!=navigator.appVersion.indexOf("Linux")?(e.os="linux",e.device="desktop"):null!==navigator.userAgent.match(/(iPhone|iPod|iPad)/)&&navigator.userAgent.match(/(iPhone|iPod|iPad)/).length>0?(e.os="ios",e.uagent.indexOf("iphone")>0&&(e.device="iphone"),e.uagent.indexOf("ipod")>0&&(e.device="ipod"),e.uagent.indexOf("ipad")>0&&(e.device="ipad")):e.os="unknown"},gridHelper:function(e){var i,t,n,o,r,s=this,a=[],d=[];r=s.gridsettings[e][0],n=s.gridsettings[e][1],o=s.gridsettings[e][2],i=[],t=[],width=window.innerWidth-2*n+o,columnWidth=width/r-o;for(var h=0;r>h;h++)t=0===h?0:columnWidth*h+o*(h-1),i=width/r*h+n,a.push(i),d.push(t),h===r-1&&(t=columnWidth*(h+1)+o*h,d.push(t));return{cols:r,col:a,colSpan:d,width:width,margin:n,gutter:o}},resize:function(){var e=this;return window.innerHeight>window.innerWidth?e.orient="portrait":e.orient="landscape",e.setState(),e.gridsettings.hasOwnProperty(e.state)&&(e.grid=e.gridHelper(e.state)),e.stateChange=new CustomEvent("stateChange",{bubbles:!1,cancelable:!0}),window.dispatchEvent(e.stateChange),e},init:function(){var e=this;e.osCheck(),e.inputCheck(),e.browserCheck(),window.onorientationchange=function(){e.resize()},window.onresize=function(){e.resize()},e.resize()}};