Phaser.Device = function (){ this.patchAndroidClearRectBug = false ; this.desktop = false ; this.iOS = false ; this.android = false ; this.chromeOS = false ; this.linux = false ; this.macOS = false ; this.windows = false ; this.canvas = false ; this.file = false ; this.fileSystem = false ; this.localStorage = false ; this.webGL = false ; this.worker = false ; this.touch = false ; this.mspointer = false ; this.css3D = false ; this.arora = false ; this.chrome = false ; this.epiphany = false ; this.firefox = false ; this.ie = false ; this.ieVersion = 0; this.mobileSafari = false ; this.midori = false ; this.opera = false ; this.safari = false ; this.webApp = false ; this.audioData = false ; this.webAudio = false ; this.ogg = false ; this.opus = false ; this.mp3 = false ; this.wav = false ; this.m4a = false ; this.webm = false ; this.iPhone = false ; this.iPhone4 = false ; this.iPad = false ; this.pixelRatio = 0; this._checkAudio(); this._checkBrowser(); this._checkCSS3D(); this._checkDevice(); this._checkFeatures(); this._checkOS(); } ; Phaser.Device.prototype = { _checkOS: function (){ var ua = navigator.userAgent; if (/Android/.test(ua)) { this.android = true ; } else if (/CrOS/.test(ua)) { this.chromeOS = true ; } else if (/iP[ao]d|iPhone/i.test(ua)) { this.iOS = true ; } else if (/Linux/.test(ua)) { this.linux = true ; } else if (/Mac OS/.test(ua)) { this.macOS = true ; } else if (/Windows/.test(ua)) { this.windows = true ; } if (this.windows || this.macOS || this.linux) { this.desktop = true ; } } , _checkFeatures: function (){ this.canvas = !!window.CanvasRenderingContext2D; try { this.localStorage = !!localStorage.getItem; } catch (error) { this.localStorage = false ; } this.file = !!window.File && !!window.FileReader && !!window.FileList && !!window.Blob; this.fileSystem = !!window.requestFileSystem; this.webGL = !!window.WebGLRenderingContext; this.worker = !!window.Worker; if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) { this.touch = true ; } if (window.navigator.msPointerEnabled) { this.mspointer = true ; } } , _checkBrowser: function (){ var ua = navigator.userAgent; if (/Arora/.test(ua)) { this.arora = true ; } else if (/Chrome/.test(ua)) { this.chrome = true ; } else if (/Epiphany/.test(ua)) { this.epiphany = true ; } else if (/Firefox/.test(ua)) { this.firefox = true ; } else if (/Mobile Safari/.test(ua)) { this.mobileSafari = true ; } else if (/MSIE (\d+\.\d+);/.test(ua)) { this.ie = true ; this.ieVersion = parseInt(RegExp.$1); } else if (/Midori/.test(ua)) { this.midori = true ; } else if (/Opera/.test(ua)) { this.opera = true ; } else if (/Safari/.test(ua)) { this.safari = true ; } if (navigator.standalone) { this.webApp = true ; } } , _checkAudio: function (){ this.audioData = !!(window.Audio); this.webAudio = !!(window.webkitAudioContext || window.AudioContext); var audioElement = _AN_Call_createelement('createElement', document, 'audio'); var result = false ; try { if (result = !!audioElement.canPlayType) { if (_AN_Call_replace('replace', audioElement.canPlayType('audio/ogg; codecs="vorbis"'), /^no$/, '')) { this.ogg = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/ogg; codecs="opus"'), /^no$/, '')) { this.opus = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/mpeg;'), /^no$/, '')) { this.mp3 = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/wav; codecs="1"'), /^no$/, '')) { this.wav = true ; } if (audioElement.canPlayType('audio/x-m4a;') || _AN_Call_replace('replace', audioElement.canPlayType('audio/aac;'), /^no$/, '')) { this.m4a = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/webm; codecs="vorbis"'), /^no$/, '')) { this.webm = true ; } } } catch (e) { } } , _checkDevice: function (){ this.pixelRatio = window.devicePixelRatio || 1; this.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1; this.iPhone4 = (this.pixelRatio == 2 && this.iPhone); this.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1; } , _checkCSS3D: function (){ var el = _AN_Call_createelement('createElement', document, 'p'); var has3d; var transforms = { 'webkitTransform': '-webkit-transform', 'OTransform': '-o-transform', 'msTransform': '-ms-transform', 'MozTransform': '-moz-transform', 'transform': 'transform'} ; document.body.insertBefore(el, null ); for (var t in transforms){ if (el.style[t] !== undefined) { el.style[t] = "translate3d(1px,1px,1px)"; has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]); } } document.body.removeChild(el); this.css3D = (has3d !== undefined && _AN_Read_length("length", has3d) > 0 && has3d !== "none"); } , canPlayAudio: function (type){ if (type == 'mp3' && this.mp3) { return true ; } else if (type == 'ogg' && (this.ogg || this.opus)) { return true ; } else if (type == 'm4a' && this.m4a) { return true ; } else if (type == 'wav' && this.wav) { return true ; } else if (type == 'webm' && this.webm) { return true ; } return false ; } , isConsoleOpen: function (){ if (window.console && window.console.firebug) { return true ; } if (window.console) { console.profile(); console.profileEnd(); if (console.clear) { _AN_Call_clear('clear', console); } return _AN_Read_length('length', console.profiles) > 0; } return false ; } } ;