Phaser.Device = function (game){ this.game = game; this.desktop = false ; this.iOS = false ; this.cocoonJS = false ; this.ejecta = false ; this.crosswalk = false ; this.android = false ; this.chromeOS = false ; this.linux = false ; this.macOS = false ; this.windows = false ; this.windowsPhone = 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.pointerLock = false ; this.typedArray = false ; this.vibration = false ; this.getUserMedia = false ; this.quirksMode = false ; this.arora = false ; this.chrome = false ; this.epiphany = false ; this.firefox = false ; this.ie = false ; this.ieVersion = 0; this.trident = false ; this.tridentVersion = 0; this.mobileSafari = false ; this.midori = false ; this.opera = false ; this.safari = false ; this.webApp = false ; this.silk = 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.littleEndian = false ; this.support32bit = false ; this.fullscreen = false ; this.requestFullscreen = ''; this.cancelFullscreen = ''; this.fullscreenKeyboard = false ; this._checkOS(); this._checkAudio(); this._checkBrowser(); this._checkCSS3D(); this._checkDevice(); this._checkFeatures(); } ; Phaser.Device.LITTLE_ENDIAN = false ; 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 (/Windows Phone/i.test(ua)) { this.windowsPhone = true ; } } if (this.windows || this.macOS || (this.linux && this.silk === false )) { this.desktop = true ; } if (this.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) { this.desktop = false ; } } , _checkFeatures: function (){ this.canvas = !!window.CanvasRenderingContext2D || this.cocoonJS; 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 = (function (){ try { var canvas = _AN_Call_createelement('createElement', document, 'canvas'); return !!window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')); } catch (e) { return false ; } } )(); if (this.webGL === null || this.webGL === false ) { this.webGL = false ; } else { this.webGL = true ; } this.worker = !!window.Worker; if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 1)) { this.touch = true ; } if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) { this.mspointer = true ; } this.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; this.quirksMode = (document.compatMode === 'CSS1Compat')? false : true ; this.getUserMedia = !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); } , checkFullScreenSupport: function (){ var fs = ['requestFullscreen', 'requestFullScreen', 'webkitRequestFullscreen', 'webkitRequestFullScreen', 'msRequestFullscreen', 'msRequestFullScreen', 'mozRequestFullScreen', 'mozRequestFullscreen'] ; for (var i = 0; i < _AN_Read_length('length', fs); i++ ){ if (this.game.canvas[fs[i]]) { this.fullscreen = true ; this.requestFullscreen = fs[i]; break ; } } var cfs = ['cancelFullScreen', 'exitFullscreen', 'webkitCancelFullScreen', 'webkitExitFullscreen', 'msCancelFullScreen', 'msExitFullscreen', 'mozCancelFullScreen', 'mozExitFullscreen'] ; if (this.fullscreen) { for (var i = 0; i < _AN_Read_length('length', cfs); i++ ){ if (document[cfs[i]]) { this.cancelFullscreen = cfs[i]; break ; } } } if (window.Element && Element.ALLOW_KEYBOARD_INPUT) { this.fullscreenKeyboard = 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 (/AppleWebKit/.test(ua) && this.iOS) { this.mobileSafari = true ; } else if (/MSIE (\d+\.\d+);/.test(ua)) { this.ie = true ; this.ieVersion = parseInt(RegExp.$1, 10); } else if (/Midori/.test(ua)) { this.midori = true ; } else if (/Opera/.test(ua)) { this.opera = true ; } else if (/Safari/.test(ua)) { this.safari = true ; } else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua)) { this.ie = true ; this.trident = true ; this.tridentVersion = parseInt(RegExp.$1, 10); this.ieVersion = parseInt(RegExp.$3, 10); } if (/Silk/.test(ua)) { this.silk = true ; } if (navigator.standalone) { this.webApp = true ; } if (navigator.isCocoonJS) { this.cocoonJS = true ; } if (typeof window.ejecta !== "undefined") { this.ejecta = true ; } if (/Crosswalk/.test(ua)) { this.crosswalk = 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; if (typeof Int8Array !== 'undefined') { this.typedArray = true ; } else { this.typedArray = false ; } if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') { this.littleEndian = this._checkIsLittleEndian(); Phaser.Device.LITTLE_ENDIAN = this.littleEndian; } this.support32bit = (typeof ArrayBuffer !== "undefined" && typeof Uint8ClampedArray !== "undefined" && typeof Int32Array !== "undefined" && this.littleEndian !== null && this._checkIsUint8ClampedImageData()); navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { this.vibration = true ; } } , _checkIsLittleEndian: function (){ var a = new ArrayBuffer(4); var b = new Uint8Array(a); var c = new Uint32Array(a); b[0] = 161; b[1] = 178; b[2] = 195; b[3] = 212; if (c[0] == 3569595041) { return true ; } if (c[0] == 2712847316) { return false ; } else { return null ; } } , _checkIsUint8ClampedImageData: function (){ if (typeof Uint8ClampedArray === "undefined") { return false ; } var elem = _AN_Call_createelement("createElement", document, 'canvas'); var ctx = elem.getContext('2d'); if (!ctx) { return false ; } var image = ctx.createImageData(1, 1); return image.data instanceof Uint8ClampedArray; } , _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); } if (console.profiles) { return _AN_Read_length('length', console.profiles) > 0; } } return false ; } } ; Phaser.Device.prototype.constructor = Phaser.Device;