phaser/v3/src/dom/DOMContentLoaded.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* @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;
2016-11-25 04:33:48 +00:00
function DOMContentLoaded (callback, OS)
{
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);
}
2016-11-25 04:33:48 +00:00
else if (OS.cordova && !OS.cocoonJS)
{
// Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready
document.addEventListener('deviceready', check, false);
}
else
{
document.addEventListener('DOMContentLoaded', check, true);
window.addEventListener('load', check, true);
}
}
module.exports = DOMContentLoaded;