incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject git commit: Adding support for legacy plugins
Date Mon, 05 Mar 2012 20:02:38 GMT
Updated Branches:
  refs/heads/master 4ca5fde64 -> 4b94695cf


Adding support for legacy plugins

Putting the addPlugin and addConstructor methods into the cordova object as not to break legacy
plugins. As well creating a PhoneGap variable that points to cordova so the .js files will
not need to be updated.


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/4b94695c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/4b94695c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/4b94695c

Branch: refs/heads/master
Commit: 4b94695cf0d797e1fa5d6623d2ae78a0b10cd7ab
Parents: 4ca5fde
Author: macdonst <simon.macdonald@gmail.com>
Authored: Mon Mar 5 15:02:07 2012 -0500
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Mon Mar 5 15:02:11 2012 -0500

----------------------------------------------------------------------
 lib/cordova.js |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4b94695c/lib/cordova.js
----------------------------------------------------------------------
diff --git a/lib/cordova.js b/lib/cordova.js
index 4b003e0..082f4c6 100644
--- a/lib/cordova.js
+++ b/lib/cordova.js
@@ -191,7 +191,40 @@ var cordova = {
                 delete cordova.callbacks[callbackId];
             }
         }
+    },
+    
+    addPlugin: function(name, obj) {
+        if (!window.plugins[name]) {
+            window.plugins[name] = obj;
+        }
+        else {
+            console.log("Error: Plugin "+name+" already exists.");
+        }
+    },
+    
+    addConstructor: function(func) {
+        channel.onCordovaReady.subscribeOnce(function() {
+            try {
+                func();
+            } catch(e) {
+                console.log("Failed to run constructor: " + e);
+            }
+        });
     }
 };
 
+/** 
+ * Legacy variable for plugin support
+ */
+if (!window.PhoneGap) {
+    window.PhoneGap = cordova;
+}
+
+/**
+ * Plugins object
+ */
+if (!window.plugins) {
+    window.plugins = {};
+}
+
 module.exports = cordova;


Mime
View raw message