More reliable document ready detection.

This commit is contained in:
Ian Gulliver
2014-06-09 23:04:18 -07:00
parent 8af50befbe
commit 1904d6bf50

View File

@@ -134,7 +134,7 @@ var Cosmopolite = function(
if (document.readyState == 'complete') {
this.init_();
} else {
document.addEventListener('DOMContentLoaded', this.init_.bind(this));
document.addEventListener('readystatechange', this.init_.bind(this));
}
};
@@ -508,6 +508,10 @@ Cosmopolite.prototype.trackEvent = function(var_args) {
* @private
*/
Cosmopolite.prototype.init_ = function() {
if (document.readyState != 'complete') {
return;
}
/**
* @type {Promise}
* @private