forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOMContentLoaded.js
More file actions
60 lines (49 loc) · 1.39 KB
/
Copy pathDOMContentLoaded.js
File metadata and controls
60 lines (49 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var OS = require('../device/OS');
var isBooted = false;
/**
* [description]
*
* @function Phaser.Dom.DOMContentLoaded
* @since 3.0.0
*
* @param {function} callback - The callback to be invoked when the device is ready and the DOM content is loaded.
*
* @return {boolean} Returns `false` if the document is already loaded, otherwise `true` if the callback is pending.
*/
var DOMContentLoaded = function (callback)
{
if (isBooted)
{
return false;
}
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
isBooted = true;
callback();
return true;
}
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 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);
}
return true;
};
module.exports = DOMContentLoaded;