mirror of
https://github.com/photonstorm/phaser
synced 2024-12-25 20:43:26 +00:00
48 lines
1,014 B
JavaScript
48 lines
1,014 B
JavaScript
|
/**
|
||
|
* @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;
|