Skip to content

Commit

Permalink
A safer way to dispatch DOM events from cordova_loader.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava committed Aug 25, 2014
1 parent 4f54e31 commit d7cc32c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tools/client/meteor_cordova_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,30 @@

(function () {

var evt = new Event("meteor-cordova-loaded");
var loadedEvent = (function () {
var usingEventConstructor = false;

// some browsers don't support the Event constructor
// eg Cordova on Android JellyBean
if (window.Event) {
usingEventConstructor = true;
}

var eventName = 'meteor-cordova-loaded';
var event;
if (usingEventConstructor) {
event = new Event(eventName);
} else {
event = document.createEvent('Event');
event.initEvent(eventName, true, true);
}

return {
dispatch: function () {
document.dispatchEvent(event);
}
};
})();

var readFile = function (url, cb) {
window.resolveLocalFileSystemURL(url,
Expand Down Expand Up @@ -82,7 +105,7 @@
});

queue.push(function () {
document.dispatchEvent(evt);
loadedEvent.dispatch();
});

launchNext();
Expand Down

0 comments on commit d7cc32c

Please sign in to comment.