};
//////////////////////////// WindowEventHandler
-function WindowEventHandler(name, event_type, callback) {
+function WindowEventHandler(name, event_type, callback, target) {
EventHandler.call(this, name);
this.event_type = event_type;
this.callback = callback;
+ this.target = target || window;
}
WindowEventHandler.prototype = Object.create(EventHandler.prototype);
WindowEventHandler.prototype.startListener = function(l) {
if (this.callback) {
this.listener = l;
- window.addEventListener(this.event_type, this.callback);
+ this.target.addEventListener(this.event_type, this.callback);
} else {
Object.getPrototypeOf(WindowEventHandler.prototype).startListener.call(this, l);
}
WindowEventHandler.prototype.stopListener = function() {
if (this.callback) {
- window.removeEventListener(this.event_type, this.callback);
+ this.target.removeEventListener(this.event_type, this.callback);
this.listener = undefined;
} else {
Object.getPrototypeOf(WindowEventHandler.prototype).stopListener.call(this);
};
}
- WindowEventHandler.call(this, name, visibility_event, callback);
+ WindowEventHandler.call(this, name, visibility_event, callback, document);
}
VisibilityEventHandler.prototype = Object.create(WindowEventHandler.prototype);
channel.onNativeReady.fire();
- // FIXME is this the right place to clobber pause/resume? I am guessing not
- // FIXME pause/resume should be deprecated IN CORDOVA for pagevisiblity api
- document.addEventListener('webkitvisibilitychange', function() {
- if (document.webkitHidden) {
- channel.onPause.fire();
- }
- else {
- channel.onResume.fire();
- }
- }, false);
-
// End of bootstrap
}
};
function fireEventListener(e) {
if (handled_events[e]) {
- cordova.fireDocumentEvent(e);
+ if ('pause' === e) {
+ // pause event needs to be fired synchronously, otherwise it will appear
+ // after the application is resumed
+ cordova.fireDocumentEvent(e, null, true);
+ } else {
+ cordova.fireDocumentEvent(e);
+ }
} else {
console.error('Unknown event: ' + e);
}