cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vi...@apache.org
Subject cordova-windows git commit: CB-8481 adding default cordova backbutton handling (close #129)
Date Wed, 04 Nov 2015 08:04:59 GMT
Repository: cordova-windows
Updated Branches:
  refs/heads/master a36a2c6cb -> 3a812ba62


CB-8481 adding default cordova backbutton handling (close #129)


Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/3a812ba6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/3a812ba6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/3a812ba6

Branch: refs/heads/master
Commit: 3a812ba62f5bffac015f6f8eeccf0f6b3a2c9d35
Parents: a36a2c6
Author: Viras- <viras@users.sourceforge.net>
Authored: Sat Oct 24 18:22:00 2015 +0200
Committer: Wolfgang Koller <viras@users.sourceforge.net>
Committed: Wed Nov 4 09:04:01 2015 +0100

----------------------------------------------------------------------
 cordova-js-src/platform.js | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/3a812ba6/cordova-js-src/platform.js
----------------------------------------------------------------------
diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js
index 216b14b..fc668f0 100644
--- a/cordova-js-src/platform.js
+++ b/cordova-js-src/platform.js
@@ -59,6 +59,30 @@ module.exports = {
                 cordova.fireDocumentEvent('activated', platform.activationContext, true);
             };
 
+            // preserve reference to original backclick implementation
+            var defaultBackButtonHandler = app.onbackclick;
+            // create document event handler for backbutton
+            var backButtonChannel = cordova.addDocumentEventHandler('backbutton');
+
+            // inject new back button handler
+            app.onbackclick = function (e) {
+                // check if listeners are registered, if yes use custom backbutton event
+                // NOTE: backbutton handlers have to throw an exception in order to exit
the app
+                if (backButtonChannel.numHandlers >= 1) {
+                    try {
+                        cordova.fireDocumentEvent('backbutton', e, true);
+                        return true;
+                    }
+                    catch (e) {
+                        return false;
+                    }
+                }
+                // if not listeners are active, use default implementation (backwards compatibility)
+                else {
+                    return defaultBackButtonHandler.apply(app, arguments);
+                }
+            };
+
             app.addEventListener("checkpoint", checkpointHandler);
             app.addEventListener("activated", activationHandler, false);
             Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", resumingHandler,
false);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message