Added in the final DOM level functions.

This commit is contained in:
Richard Davey 2016-11-25 02:08:33 +00:00
parent 970dea20f5
commit 36ca61dddb
9 changed files with 127 additions and 4 deletions

View file

@ -66,6 +66,10 @@ function Config (config)
this.forceSetTimeOut = getValue(config, 'forceSetTimeOut', false);
this.transparent = getValue(config, 'transparent', false);
this.pixelArt = getValue(config, 'pixelArt', false);
}
Config.prototype.constructor = Config;

View file

@ -9,6 +9,7 @@ var CHECKSUM = require('../checksum');
var Config = require('./Config');
var DebugHeader = require('./DebugHeader');
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
var DOMContentLoaded = require('../dom/DOMContentLoaded');
var Game = function (config)
{
@ -69,9 +70,7 @@ var Game = function (config)
// this.device.whenReady(this.boot, this);
DebugHeader(this);
console.log(CHECKSUM.build);
DOMContentLoaded(this.boot.bind(this));
};
@ -79,6 +78,17 @@ Game.prototype.constructor = Game;
Game.prototype = {
boot: function ()
{
DebugHeader(this);
console.log(CHECKSUM.build);
// Add in ability to specify pre-init and post-init callbacks in the config
this.raf.start();
},
update: function (timestamp)
{
// console.log(timestamp);

View file

@ -1,5 +1,6 @@
module.exports = {
// Doing this makes it available under Phaser.Game
Game: require('./Game')
};

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '9d525b60-b2af-11e6-8aab-1f6b9d8fd351'
build: '8fd01380-b2b2-11e6-b621-1f12dc04eec3'
};
module.exports = CHECKSUM;

View file

@ -0,0 +1,8 @@
function AddEventListener (target, event, listener, useCapture)
{
if (useCapture === undefined) { useCapture = false; }
target.addEventListener(event, listener, useCapture);
}
module.exports = AddEventListener;

38
v3/src/dom/AddToDOM.js Normal file
View file

@ -0,0 +1,38 @@
function AddToDOM (element, parent, overflowHidden)
{
if (overflowHidden === undefined) { overflowHidden = true; }
var target;
if (parent)
{
if (typeof parent === 'string')
{
// Hopefully an element ID
target = document.getElementById(parent);
}
else if (typeof parent === 'object' && parent.nodeType === 1)
{
// Quick test for a HTMLelement
target = parent;
}
}
// Fallback, covers an invalid ID and a non HTMLelement object
if (!target)
{
target = document.body;
}
if (overflowHidden && target.style)
{
target.style.overflow = 'hidden';
}
target.appendChild(element);
return element;
}
module.exports = AddToDOM;

View file

@ -0,0 +1,47 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var isBooted = false;
function DOMContentLoaded (callback)
{
if (isBooted)
{
return;
}
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
isBooted = true;
callback();
return;
}
var check = function ()
{
isBooted = true;
document.removeEventListener('deviceready', check, true);
document.removeEventListener('DOMContentLoaded', check, true);
window.removeEventListener('load', check, true);
callback();
};
if (!document.body)
{
window.setTimeout(check, 20);
}
else
{
document.addEventListener('DOMContentLoaded', check, true);
window.addEventListener('load', check, true);
}
}
module.exports = DOMContentLoaded;

View file

@ -0,0 +1,6 @@
function RemoveEventListener (target, event, listener)
{
target.removeEventListener(event, listener);
}
module.exports = RemoveEventListener;

View file

@ -0,0 +1,9 @@
function RemoveFromDOM (element)
{
if (element.parentNode)
{
element.parentNode.removeChild(element);
}
}
module.exports = RemoveFromDOM;