[Events] Removed code specific for browser platform.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 2 Dec 2015 14:30:06 +0000 (15:30 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 2 Dec 2015 14:30:06 +0000 (15:30 +0100)
[Verification] Pass rate did not change.

Change-Id: Id7ecee1b9f3b368fdf0ecb8d99b98c577fe85a23
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/events/cordova_events_api.js
src/lib/cordova-5.1.1.js
src/lib/plugins/cordova-plugin-events/www/register.js

index c99afc9..a407271 100755 (executable)
@@ -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);
index 135bba3..b6b1965 100644 (file)
@@ -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
  }
 };
index c8c25a6..d0b95fc 100644 (file)
@@ -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);
   }