You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2013/06/20 00:19:40 UTC
wp7 commit: updating cordovajs with xhr patch for windows phone
Updated Branches:
refs/heads/2.9.x 7d9a6b940 -> 81d297532
updating cordovajs with xhr patch for windows phone
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/81d29753
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/81d29753
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/81d29753
Branch: refs/heads/2.9.x
Commit: 81d297532fb73fc4ed22e8f2f84c4bb64e9d67bf
Parents: 7d9a6b9
Author: Benn Mapes <be...@gmail.com>
Authored: Wed Jun 19 15:06:59 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Wed Jun 19 15:09:23 2013 -0700
----------------------------------------------------------------------
templates/standalone/www/cordova.js | 90 ++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/81d29753/templates/standalone/www/cordova.js
----------------------------------------------------------------------
diff --git a/templates/standalone/www/cordova.js b/templates/standalone/www/cordova.js
index 83f579e..3bf1738 100644
--- a/templates/standalone/www/cordova.js
+++ b/templates/standalone/www/cordova.js
@@ -1,5 +1,5 @@
// Platform: windowsphone
-// 2.9.0rc1-0-g11df4b7
+// 2.9.0rc1-0-g002f33d
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -19,7 +19,7 @@
under the License.
*/
;(function() {
-var CORDOVA_JS_BUILD_LABEL = '2.9.0rc1-0-g11df4b7';
+var CORDOVA_JS_BUILD_LABEL = '2.9.0rc1-0-g002f33d';
// file: lib\scripts\require.js
var require,
@@ -6645,11 +6645,21 @@ window.cordova = require('cordova');
}
}
+ function scriptErrorCallback(err) {
+ // Open Question: If a script path specified in cordova_plugins.js does not exist, do we fail for all?
+ // this is currently just continuing.
+ scriptCounter--;
+ if (scriptCounter === 0) {
+ onScriptLoadingComplete && onScriptLoadingComplete();
+ }
+ }
+
// Helper function to inject a <script> tag.
function injectScript(path) {
scriptCounter++;
var script = document.createElement("script");
script.onload = scriptLoadedCallback;
+ script.onerror = scriptErrorCallback;
script.src = path;
document.head.appendChild(script);
}
@@ -6661,10 +6671,10 @@ window.cordova = require('cordova');
context.cordova.require('cordova/channel').onPluginsReady.fire();
}
- // Handler for the cordova_plugins.json content.
+ // Handler for the cordova_plugins.js content.
// See plugman's plugin_loader.js for the details of this object.
// This function is only called if the really is a plugins array that isn't empty.
- // Otherwise the XHR response handler will just call finishPluginLoading().
+ // Otherwise the onerror response handler will just call finishPluginLoading().
function handlePluginsObject(modules, path) {
// First create the callback for when all plugins are loaded.
var mapper = context.cordova.require('cordova/modulemapper');
@@ -6672,25 +6682,30 @@ window.cordova = require('cordova');
// Loop through all the plugins and then through their clobbers and merges.
for (var i = 0; i < modules.length; i++) {
var module = modules[i];
- if (!module) continue;
+ if (module) {
+ try {
+ if (module.clobbers && module.clobbers.length) {
+ for (var j = 0; j < module.clobbers.length; j++) {
+ mapper.clobbers(module.id, module.clobbers[j]);
+ }
+ }
- if (module.clobbers && module.clobbers.length) {
- for (var j = 0; j < module.clobbers.length; j++) {
- mapper.clobbers(module.id, module.clobbers[j]);
- }
- }
+ if (module.merges && module.merges.length) {
+ for (var k = 0; k < module.merges.length; k++) {
+ mapper.merges(module.id, module.merges[k]);
+ }
+ }
- if (module.merges && module.merges.length) {
- for (var k = 0; k < module.merges.length; k++) {
- mapper.merges(module.id, module.merges[k]);
+ // Finally, if runs is truthy we want to simply require() the module.
+ // This can be skipped if it had any merges or clobbers, though,
+ // since the mapper will already have required the module.
+ if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
+ context.cordova.require(module.id);
+ }
+ }
+ catch(err) {
+ // error with module, most likely clobbers, should we continue?
}
- }
-
- // Finally, if runs is truthy we want to simply require() the module.
- // This can be skipped if it had any merges or clobbers, though,
- // since the mapper will already have required the module.
- if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
- context.cordova.require(module.id);
}
}
@@ -6714,6 +6729,33 @@ window.cordova = require('cordova');
break;
}
}
+
+ 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() {
@@ -6732,14 +6774,16 @@ window.cordova = require('cordova');
}
};
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();
};
- var plugins_json = path + 'cordova_plugins.json';
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){
- finishPluginLoading();
+ injectPluginScript();
}
}(window));