Phaser.Device = function (){ this.deviceReadyAt = 0; this.initialized = false ; this.desktop = false ; this.iOS = false ; this.iOSVersion = 0; this.cocoonJS = false ; this.cocoonJSApp = false ; this.cordova = false ; this.node = false ; this.nodeWebkit = false ; this.electron = 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.canvasBitBltShift = null ; this.webGL = false ; this.file = false ; this.fileSystem = false ; this.localStorage = false ; this.worker = false ; this.css3D = false ; this.pointerLock = false ; this.typedArray = false ; this.vibration = false ; this.getUserMedia = true ; this.quirksMode = false ; this.touch = false ; this.mspointer = false ; this.wheelEvent = null ; this.arora = false ; this.chrome = false ; this.chromeVersion = 0; this.epiphany = false ; this.firefox = false ; this.firefoxVersion = 0; 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.oggVideo = false ; this.h264Video = false ; this.mp4Video = false ; this.webmVideo = false ; this.vp9Video = false ; this.hlsVideo = false ; this.iPhone = false ; this.iPhone4 = false ; this.iPad = false ; this.pixelRatio = 0; this.littleEndian = false ; this.LITTLE_ENDIAN = false ; this.support32bit = false ; this.fullscreen = false ; this.requestFullscreen = ''; this.cancelFullscreen = ''; this.fullscreenKeyboard = false ; } ; Phaser.Device = new Phaser.Device(); Phaser.Device.onInitialized = new Phaser.Signal(); Phaser.Device.whenReady = function (callback, context, nonPrimer){ var readyCheck = this._readyCheck; if (this.deviceReadyAt || !readyCheck) { callback.call(context, this); } else if (readyCheck._monitor || nonPrimer) { readyCheck._queue = readyCheck._queue || [] ; readyCheck._queue.push([callback, context] ); } else { readyCheck._monitor = readyCheck.bind(this); readyCheck._queue = readyCheck._queue || [] ; readyCheck._queue.push([callback, context] ); var cordova = typeof window.cordova !== 'undefined'; var cocoonJS = navigator.isCocoonJS; if (document.readyState === 'complete' || document.readyState === 'interactive') { _AN_Call_settimeout('setTimeout', window, readyCheck._monitor, 0); } else if (cordova && !cocoonJS) { document.addEventListener('deviceready', readyCheck._monitor, false ); } else { document.addEventListener('DOMContentLoaded', readyCheck._monitor, false ); window.addEventListener('load', readyCheck._monitor, false ); } } } ; Phaser.Device._readyCheck = function (){ var readyCheck = this._readyCheck; if (!document.body) { _AN_Call_settimeout('setTimeout', window, readyCheck._monitor, 20); } else if (!this.deviceReadyAt) { this.deviceReadyAt = Date.now(); document.removeEventListener('deviceready', readyCheck._monitor); document.removeEventListener('DOMContentLoaded', readyCheck._monitor); window.removeEventListener('load', readyCheck._monitor); this._initialize(); this.initialized = true ; this.onInitialized.dispatch(this); var item; while ((item = readyCheck._queue.shift())){ var callback = item[0]; var context = item[1]; callback.call(context, this); } this._readyCheck = null ; this._initialize = null ; this.onInitialized = null ; } } ; Phaser.Device._initialize = function (){ var device = this; function _checkOS(){ var ua = navigator.userAgent; if (/Playstation Vita/.test(ua)) { device.vita = true ; } else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua)) { device.kindle = true ; } else if (/Android/.test(ua)) { device.android = true ; } else if (/CrOS/.test(ua)) { device.chromeOS = true ; } else if (/iP[ao]d|iPhone/i.test(ua)) { device.iOS = true ; (navigator.appVersion).match(/OS (\d+)/); device.iOSVersion = parseInt(RegExp.$1, 10); } else if (/Linux/.test(ua)) { device.linux = true ; } else if (/Mac OS/.test(ua)) { device.macOS = true ; } else if (/Windows/.test(ua)) { device.windows = true ; } if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua)) { device.android = false ; device.iOS = false ; device.macOS = false ; device.windows = true ; device.windowsPhone = true ; } var silk = /Silk/.test(ua); if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS) { device.desktop = true ; } if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) { device.desktop = false ; } } function _checkFeatures(){ device.canvas = !!window.CanvasRenderingContext2D || device.cocoonJS; try { device.localStorage = !!localStorage.getItem; } catch (error) { device.localStorage = false ; } device.file = !!window.File && !!window.FileReader && !!window.FileList && !!window.Blob; device.fileSystem = !!window.requestFileSystem; device.webGL = (function (){ try { var canvas = _AN_Call_createelement('createElement', document, 'canvas'); canvas.screencanvas = false ; return !!window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')); } catch (e) { return false ; } } )(); device.webGL = !!device.webGL; device.worker = !!window.Worker; device.pointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document; device.quirksMode = (document.compatMode === 'CSS1Compat')? false : true ; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; _AN_Write_url('URL', window, false , _AN_Read_url('URL', window) || window.webkitURL || window.mozURL || window.msURL); device.getUserMedia = device.getUserMedia && !!navigator.getUserMedia && !!_AN_Read_url('URL', window); if (device.firefox && device.firefoxVersion < 21) { device.getUserMedia = false ; } if (!device.iOS && (device.ie || device.firefox || device.chrome)) { device.canvasBitBltShift = true ; } if (device.safari || device.mobileSafari) { device.canvasBitBltShift = false ; } } function _checkInput(){ if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1)) { device.touch = true ; } if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) { device.mspointer = true ; } if (!device.cocoonJS) { if ('onwheel' in window || (device.ie && 'WheelEvent' in window)) { device.wheelEvent = 'wheel'; } else if ('onmousewheel' in window) { device.wheelEvent = 'mousewheel'; } else if (device.firefox && 'MouseScrollEvent' in window) { device.wheelEvent = 'DOMMouseScroll'; } } } function _checkFullScreenSupport(){ var fs = ['requestFullscreen', 'requestFullScreen', 'webkitRequestFullscreen', 'webkitRequestFullScreen', 'msRequestFullscreen', 'msRequestFullScreen', 'mozRequestFullScreen', 'mozRequestFullscreen'] ; var element = _AN_Call_createelement('createElement', document, 'div'); for (var i = 0; i < _AN_Read_length('length', fs); i++ ){ if (element[fs[i]]) { device.fullscreen = true ; device.requestFullscreen = fs[i]; break ; } } var cfs = ['cancelFullScreen', 'exitFullscreen', 'webkitCancelFullScreen', 'webkitExitFullscreen', 'msCancelFullScreen', 'msExitFullscreen', 'mozCancelFullScreen', 'mozExitFullscreen'] ; if (device.fullscreen) { for (var i = 0; i < _AN_Read_length('length', cfs); i++ ){ if (document[cfs[i]]) { device.cancelFullscreen = cfs[i]; break ; } } } if (window.Element && Element.ALLOW_KEYBOARD_INPUT) { device.fullscreenKeyboard = true ; } } function _checkBrowser(){ var ua = navigator.userAgent; if (/Arora/.test(ua)) { device.arora = true ; } else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone) { device.chrome = true ; device.chromeVersion = parseInt(RegExp.$1, 10); } else if (/Epiphany/.test(ua)) { device.epiphany = true ; } else if (/Firefox\D+(\d+)/.test(ua)) { device.firefox = true ; device.firefoxVersion = parseInt(RegExp.$1, 10); } else if (/AppleWebKit/.test(ua) && device.iOS) { device.mobileSafari = true ; } else if (/MSIE (\d+\.\d+);/.test(ua)) { device.ie = true ; device.ieVersion = parseInt(RegExp.$1, 10); } else if (/Midori/.test(ua)) { device.midori = true ; } else if (/Opera/.test(ua)) { device.opera = true ; } else if (/Safari/.test(ua) && !device.windowsPhone) { device.safari = true ; } else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua)) { device.ie = true ; device.trident = true ; device.tridentVersion = parseInt(RegExp.$1, 10); device.ieVersion = parseInt(RegExp.$3, 10); } if (/Silk/.test(ua)) { device.silk = true ; } if (navigator.standalone) { device.webApp = true ; } if (typeof window.cordova !== "undefined") { device.cordova = true ; } if (typeof process !== "undefined" && typeof require !== "undefined") { device.node = true ; } if (device.node && typeof process.versions === 'object') { device.nodeWebkit = !!process.versions["node-webkit"] ; device.electron = !!process.versions.electron; } if (navigator.isCocoonJS) { device.cocoonJS = true ; } if (device.cocoonJS) { try { device.cocoonJSApp = (typeof CocoonJS !== "undefined"); } catch (error) { device.cocoonJSApp = false ; } } if (typeof window.ejecta !== "undefined") { device.ejecta = true ; } if (/Crosswalk/.test(ua)) { device.crosswalk = true ; } } function _checkVideo(){ var videoElement = _AN_Call_createelement("createElement", document, "video"); var result = false ; try { if (result = !!videoElement.canPlayType) { if (_AN_Call_replace("replace", videoElement.canPlayType('video/ogg; codecs="theora"'), /^no$/, '')) { device.oggVideo = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"'), /^no$/, '')) { device.h264Video = true ; device.mp4Video = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/webm; codecs="vp8, vorbis"'), /^no$/, '')) { device.webmVideo = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('video/webm; codecs="vp9"'), /^no$/, '')) { device.vp9Video = true ; } if (_AN_Call_replace('replace', videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"'), /^no$/, '')) { device.hlsVideo = true ; } } } catch (e) { } } function _checkAudio(){ device.audioData = !!(window.Audio); device.webAudio = !!(window.AudioContext || window.webkitAudioContext); 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$/, '')) { device.ogg = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/ogg; codecs="opus"'), /^no$/, '') || _AN_Call_replace('replace', audioElement.canPlayType('audio/opus;'), /^no$/, '')) { device.opus = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/mpeg;'), /^no$/, '')) { device.mp3 = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/wav; codecs="1"'), /^no$/, '')) { device.wav = true ; } if (audioElement.canPlayType('audio/x-m4a;') || _AN_Call_replace('replace', audioElement.canPlayType('audio/aac;'), /^no$/, '')) { device.m4a = true ; } if (_AN_Call_replace('replace', audioElement.canPlayType('audio/webm; codecs="vorbis"'), /^no$/, '')) { device.webm = true ; } } } catch (e) { } } function _checkDevice(){ device.pixelRatio = window.devicePixelRatio || 1; device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1; device.iPhone4 = (device.pixelRatio == 2 && device.iPhone); device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1; if (typeof Int8Array !== 'undefined') { device.typedArray = true ; } else { device.typedArray = false ; } if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') { device.littleEndian = _checkIsLittleEndian(); device.LITTLE_ENDIAN = device.littleEndian; } device.support32bit = (typeof ArrayBuffer !== "undefined" && typeof Uint8ClampedArray !== "undefined" && typeof Int32Array !== "undefined" && device.littleEndian !== null && _checkIsUint8ClampedImageData()); navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate; if (navigator.vibrate) { device.vibration = true ; } } function _checkIsLittleEndian(){ 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 ; } } function _checkIsUint8ClampedImageData(){ if (Uint8ClampedArray === undefined) { return false ; } var elem = PIXI.CanvasPool.create(this, 1, 1); var ctx = elem.getContext('2d'); if (!ctx) { return false ; } var image = ctx.createImageData(1, 1); PIXI.CanvasPool.remove(this); return image.data instanceof Uint8ClampedArray; } function _checkCSS3D(){ 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); device.css3D = (has3d !== undefined && _AN_Read_length("length", has3d) > 0 && has3d !== "none"); } _checkOS(); _checkAudio(); _checkVideo(); _checkBrowser(); _checkCSS3D(); _checkDevice(); _checkFeatures(); _checkFullScreenSupport(); _checkInput(); } ; Phaser.Device.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 === 'opus' && this.opus) { return true ; } else if (type === 'wav' && this.wav) { return true ; } else if (type === 'webm' && this.webm) { return true ; } return false ; } ; Phaser.Device.canPlayVideo = function (type){ if (type === 'webm' && (this.webmVideo || this.vp9Video)) { return true ; } else if (type === 'mp4' && (this.mp4Video || this.h264Video)) { return true ; } else if ((type === 'ogg' || type === 'ogv') && this.oggVideo) { return true ; } else if (type === 'mpeg' && this.hlsVideo) { return true ; } return false ; } ; Phaser.Device.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.isAndroidStockBrowser = function (){ var matches = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/); return matches && matches[1] < 537; } ;