cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject js commit: moved plugin loader script injection to a function so it can also be called when xhr fails just because the json file is not present.
Date Wed, 19 Jun 2013 21:42:23 GMT
Updated Branches:
  refs/heads/2.9.x e2020c3c4 -> 002f33ded


moved plugin loader script injection to a function so it can also be called when xhr fails
just because the json file is not present.


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

Branch: refs/heads/2.9.x
Commit: 002f33dedb0c9f1e9b11319dbb3826af7c4fcdd9
Parents: e2020c3
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed Jun 19 14:35:26 2013 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jun 19 14:41:12 2013 -0700

----------------------------------------------------------------------
 lib/scripts/plugin_loader.js | 50 +++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/002f33de/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index b27216b..d9bea0a 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -121,6 +121,30 @@
 
     var plugins_json = path + 'cordova_plugins.json';
     var plugins_js = path + 'cordova_plugins.js';
+
+    // One some phones (Windows) this xhr.open throws an Access Denied exception
+    // So lets keep trying, but with a script tag injection technique instead of XHR
+    var injectPluginScript = function injectPluginScript() {
+        try {
+            var script = document.createElement("script");
+            script.onload = function(){
+                var list = cordova.require("cordova/plugin_list");
+                handlePluginsObject(list,path);
+            };
+            script.onerror = function() {
+                // Error loading cordova_plugins.js, file not found or something
+                // this is an acceptable error, pre-3.0.0, so we just move on.
+                finishPluginLoading();
+            };
+            script.src = plugins_js;
+            document.head.appendChild(script);
+
+        } catch(err){
+            finishPluginLoading();
+        }
+    } 
+
+
     // Try to XHR the cordova_plugins.json file asynchronously.
     var xhr = new XMLHttpRequest();
     xhr.onload = function() {
@@ -139,32 +163,16 @@
         }
     };
     xhr.onerror = function() {
-        finishPluginLoading();
+        // In this case, the json file was not present, but XHR was allowed, 
+        // so we should still try the script injection technique with the js file
+        // in case that is there.
+        injectPluginScript();
     };
     try { // we commented we were going to try, so let us actually try and catch
         xhr.open('GET', plugins_json, true); // Async
         xhr.send();
     } catch(err){
-        // One some phones (Windows) this xhr.open throws an Access Denied exception
-        // So lets keep trying, but with a script tag injection technique instead of XHR
-        try {
-            
-            var script = document.createElement("script");
-            script.onload = function(){
-                var list = cordova.require("cordova/plugin_list");
-                handlePluginsObject(list,path);
-            };
-            script.onerror = function() {
-                // Error loading cordova_plugins.js, file not found or something
-                // this is an acceptable error, pre-3.0.0, so we just move on.
-                finishPluginLoading();
-            };
-            script.src = plugins_js;
-            document.head.appendChild(script);
-
-        } catch(err){
-            finishPluginLoading();
-        }
+        injectPluginScript();
     }
 }(window));
 


Mime
View raw message