cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject spec commit: Support loading platform cordova.js files if available
Date Thu, 28 Feb 2013 21:01:01 GMT
Updated Branches:
  refs/heads/master bd72ab303 -> 224aaa4ef


Support loading platform cordova.js files if available


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/224aaa4e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/224aaa4e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/224aaa4e

Branch: refs/heads/master
Commit: 224aaa4efc8212ee5ff63858858dc746af83acde
Parents: bd72ab3
Author: Michal Mocny <mmocny@gmail.com>
Authored: Mon Feb 25 15:59:04 2013 -0500
Committer: Michal Mocny <mmocny@gmail.com>
Committed: Thu Feb 28 16:00:25 2013 -0500

----------------------------------------------------------------------
 cordova.js |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/224aaa4e/cordova.js
----------------------------------------------------------------------
diff --git a/cordova.js b/cordova.js
index 26cb0a1..88aa5ac 100644
--- a/cordova.js
+++ b/cordova.js
@@ -20,8 +20,25 @@
 */
 
 var VERSION='2.5.0';
+var PLAT = /Android/.exec(navigator.userAgent) ? 'android' : 'ios';
+
 var scripts = document.getElementsByTagName('script');
-var cordovaPath = scripts[scripts.length - 1].src.replace('cordova.js', 'cordova-'+VERSION+'.js');
+var currentPath = scripts[scripts.length - 1].src;
+var platformCordovaPath = currentPath.replace("cordova.js", "cordova." + PLAT + ".js");
+var versionCordovaPath = currentPath.replace("cordova.js", "cordova-" + VERSION + ".js");
+var cordovaPath;
+
+(function() {
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", platformCordovaPath, false);
+    xhr.onreadystatechange = function() {
+        if (this.readyState != this.DONE) {
+            return;
+        }
+        cordovaPath = (this.responseText.length > 0) ? platformCordovaPath : versionCordovaPath;
+    };
+    xhr.send(null);
+})();
 
 if (!window._doNotWriteCordovaScript) {
     document.write('<script type="text/javascript" charset="utf-8" src="' + cordovaPath
+ '"></script>');


Mime
View raw message