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 2013/06/28 16:15:30 UTC
[06/26] 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.
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/89127a80
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/89127a80
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/89127a80
Branch: refs/heads/2.9.x
Commit: 89127a803e91719fe30076b6e35548146aa74f56
Parents: 1fd26e1
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Jun 19 14:35:26 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Jun 19 14:35:26 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/89127a80/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));