You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/09/18 16:47:24 UTC

[1/6] js commit: [android] Hide window.online/offline events that are triggered by exec()

Updated Branches:
  refs/heads/master 9878d97f7 -> 34239a8c1


[android] Hide window.online/offline events that are triggered by exec()

This relates to native bridge issue:
https://issues.apache.org/jira/browse/CB-638

As well as online events issue:
https://issues.apache.org/jira/browse/CB-1269


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/951136b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/951136b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/951136b9

Branch: refs/heads/master
Commit: 951136b9974fc06e99ff7f8b98468ad7bb8358c0
Parents: b25e91d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Sep 5 16:50:41 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Tue Sep 18 10:46:48 2012 -0400

----------------------------------------------------------------------
 lib/android/exec.js |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/951136b9/lib/android/exec.js
----------------------------------------------------------------------
diff --git a/lib/android/exec.js b/lib/android/exec.js
index d5b2c1e..b9d3ad5 100644
--- a/lib/android/exec.js
+++ b/lib/android/exec.js
@@ -153,10 +153,27 @@ function androidExec(success, fail, service, action, args) {
     }
 }
 
-function onOnLineEvent(e) {
-    while (polling.pollOnce());
+function hookOnlineApis() {
+    function onOnLineEvent(e) {
+        while (polling.pollOnce());
+    }
+    function proxyEvent(e) {
+        cordova.fireWindowEvent(e.type);
+    }
+    // The network module takes care of firing online and offline events.
+    // It currently fires them only on document though, so we bridge them
+    // to window here (while first listening for exec()-releated online/offline
+    // events).
+    window.addEventListener('online', onOnLineEvent, false);
+    window.addEventListener('offline', onOnLineEvent, false);
+    cordova.addWindowEventHandler('online');
+    cordova.addWindowEventHandler('offline');
+    document.addEventListener('online', proxyEvent, false);
+    document.addEventListener('offline', proxyEvent, false);
 }
 
+hookOnlineApis();
+
 androidExec.jsToNativeModes = jsToNativeModes;
 androidExec.nativeToJsModes = nativeToJsModes;
 
@@ -176,9 +193,6 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
         polling.stop();
     } else if (nativeToJsBridgeMode == nativeToJsModes.HANGING_GET) {
         callback.stop();
-    } else if (nativeToJsBridgeMode == nativeToJsModes.ONLINE_EVENT) {
-        window.removeEventListener('online', onOnLineEvent, false);
-        window.removeEventListener('offline', onOnLineEvent, false);
     }
 
     nativeToJsBridgeMode = mode;
@@ -189,9 +203,6 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
         polling.start();
     } else if (mode == nativeToJsModes.HANGING_GET) {
         callback.start();
-    } else if (mode == nativeToJsModes.ONLINE_EVENT) {
-        window.addEventListener('online', onOnLineEvent, false);
-        window.addEventListener('offline', onOnLineEvent, false);
     }
 };