Phaser.DOM = { getOffset: function (element, point){ point = point || new Phaser.Point(); var box = element.getBoundingClientRect(); var scrollTop = Phaser.DOM.scrollY; var scrollLeft = Phaser.DOM.scrollX; var clientTop = document.documentElement.clientTop; var clientLeft = document.documentElement.clientLeft; point.x = box.left + scrollLeft - clientLeft; point.y = box.top + scrollTop - clientTop; return point; } , getBounds: function (element, cushion){ if (cushion === undefined) { cushion = 0; } element = element && !element.nodeType? element[0]: element; if (!element || element.nodeType !== 1) { return false ; } else { return this.calibrate(element.getBoundingClientRect(), cushion); } } , calibrate: function (coords, cushion){ cushion = + cushion || 0; var output = { width: 0, height: 0, left: 0, right: 0, top: 0, bottom: 0} ; output.width = (output.right = coords.right + cushion) - (output.left = coords.left - cushion); output.height = (output.bottom = coords.bottom + cushion) - (output.top = coords.top - cushion); return output; } , getAspectRatio: function (object){ object = null == object? this.visualBounds: 1 === object.nodeType? this.getBounds(object): object; var w = object.width; var h = object.height; if (typeof w === 'function') { w = w.call(object); } if (typeof h === 'function') { h = h.call(object); } return w / h; } , inLayoutViewport: function (element, cushion){ var r = this.getBounds(element, cushion); return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= this.layoutBounds.width && r.left <= this.layoutBounds.height; } , getScreenOrientation: function (primaryFallback){ var screen = window.screen; var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation; if (orientation && typeof orientation.type === 'string') { return orientation.type; } else if (typeof orientation === 'string') { return orientation; } var PORTRAIT = 'portrait-primary'; var LANDSCAPE = 'landscape-primary'; if (primaryFallback === 'screen') { return (screen.height > screen.width)? PORTRAIT: LANDSCAPE; } else if (primaryFallback === 'viewport') { return (this.visualBounds.height > this.visualBounds.width)? PORTRAIT: LANDSCAPE; } else if (primaryFallback === 'window.orientation' && typeof window.orientation === 'number') { return (window.orientation === 0 || window.orientation === 180)? PORTRAIT: LANDSCAPE; } else if (window.matchMedia) { if (window.matchMedia("(orientation: portrait)").matches) { return PORTRAIT; } else if (window.matchMedia("(orientation: landscape)").matches) { return LANDSCAPE; } } return (this.visualBounds.height > this.visualBounds.width)? PORTRAIT: LANDSCAPE; } , visualBounds: new Phaser.Rectangle(), layoutBounds: new Phaser.Rectangle(), documentBounds: new Phaser.Rectangle()} ; Phaser.Device.whenReady(function (device){ var scrollX = window && ('pageXOffset' in window)? function (){ return window.pageXOffset; } : function (){ return document.documentElement.scrollLeft; } ; var scrollY = window && ('pageYOffset' in window)? function (){ return window.pageYOffset; } : function (){ return document.documentElement.scrollTop; } ; Object.defineProperty(Phaser.DOM, "scrollX", { get: scrollX} ); Object.defineProperty(Phaser.DOM, "scrollY", { get: scrollY} ); Object.defineProperty(Phaser.DOM.visualBounds, "x", { get: scrollX} ); Object.defineProperty(Phaser.DOM.visualBounds, "y", { get: scrollY} ); Object.defineProperty(Phaser.DOM.layoutBounds, "x", { value: 0} ); Object.defineProperty(Phaser.DOM.layoutBounds, "y", { value: 0} ); var treatAsDesktop = device.desktop && (document.documentElement.clientWidth <= window.innerWidth) && (document.documentElement.clientHeight <= window.innerHeight); if (treatAsDesktop) { var clientWidth = function (){ return Math.max(window.innerWidth, document.documentElement.clientWidth); } ; var clientHeight = function (){ return Math.max(window.innerHeight, document.documentElement.clientHeight); } ; Object.defineProperty(Phaser.DOM.visualBounds, "width", { get: clientWidth} ); Object.defineProperty(Phaser.DOM.visualBounds, "height", { get: clientHeight} ); Object.defineProperty(Phaser.DOM.layoutBounds, "width", { get: clientWidth} ); Object.defineProperty(Phaser.DOM.layoutBounds, "height", { get: clientHeight} ); } else { Object.defineProperty(Phaser.DOM.visualBounds, "width", { get: function (){ return window.innerWidth; } } ); Object.defineProperty(Phaser.DOM.visualBounds, "height", { get: function (){ return window.innerHeight; } } ); Object.defineProperty(Phaser.DOM.layoutBounds, "width", { get: function (){ var a = document.documentElement.clientWidth; var b = window.innerWidth; return a < b? b: a; } } ); Object.defineProperty(Phaser.DOM.layoutBounds, "height", { get: function (){ var a = document.documentElement.clientHeight; var b = window.innerHeight; return a < b? b: a; } } ); } Object.defineProperty(Phaser.DOM.documentBounds, "x", { value: 0} ); Object.defineProperty(Phaser.DOM.documentBounds, "y", { value: 0} ); Object.defineProperty(Phaser.DOM.documentBounds, "width", { get: function (){ var d = document.documentElement; return Math.max(d.clientWidth, d.offsetWidth, d.scrollWidth); } } ); Object.defineProperty(Phaser.DOM.documentBounds, "height", { get: function (){ var d = document.documentElement; return Math.max(d.clientHeight, d.offsetHeight, d.scrollHeight); } } ); } , null , true );