From 5eb86b55ead727960d1d4ecbca658b0b53bbdd39 Mon Sep 17 00:00:00 2001 From: Pawel Andruszkiewicz Date: Wed, 2 Dec 2015 15:30:06 +0100 Subject: [PATCH] [Events] Removed code specific for browser platform. [Verification] Pass rate did not change. Change-Id: Id7ecee1b9f3b368fdf0ecb8d99b98c577fe85a23 Signed-off-by: Pawel Andruszkiewicz --- src/events/cordova_events_api.js | 9 +++++---- src/lib/cordova-5.1.1.js | 11 ----------- src/lib/plugins/cordova-plugin-events/www/register.js | 8 +++++++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/events/cordova_events_api.js b/src/events/cordova_events_api.js index c99afc9..a407271 100755 --- a/src/events/cordova_events_api.js +++ b/src/events/cordova_events_api.js @@ -34,10 +34,11 @@ EventHandler.prototype.stopListener = function() { }; //////////////////////////// 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); @@ -46,7 +47,7 @@ WindowEventHandler.prototype.constructor = WindowEventHandler; 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); } @@ -54,7 +55,7 @@ WindowEventHandler.prototype.startListener = function(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); @@ -96,7 +97,7 @@ function VisibilityEventHandler(name, hidden) { }; } - WindowEventHandler.call(this, name, visibility_event, callback); + WindowEventHandler.call(this, name, visibility_event, callback, document); } VisibilityEventHandler.prototype = Object.create(WindowEventHandler.prototype); diff --git a/src/lib/cordova-5.1.1.js b/src/lib/cordova-5.1.1.js index 135bba3..b6b1965 100644 --- a/src/lib/cordova-5.1.1.js +++ b/src/lib/cordova-5.1.1.js @@ -1338,17 +1338,6 @@ module.exports = { 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 } }; diff --git a/src/lib/plugins/cordova-plugin-events/www/register.js b/src/lib/plugins/cordova-plugin-events/www/register.js index c8c25a6..d0b95fc 100644 --- a/src/lib/plugins/cordova-plugin-events/www/register.js +++ b/src/lib/plugins/cordova-plugin-events/www/register.js @@ -26,7 +26,13 @@ var handled_events = {}; 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); } -- 2.34.1