cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject js commit: [CB-3393] plugin_loader fix for pages in subdirectories.
Date Fri, 17 May 2013 02:26:57 GMT
Updated Branches:
  refs/heads/master 757fa3c93 -> 1a148c0af


[CB-3393] plugin_loader fix for pages in subdirectories.


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

Branch: refs/heads/master
Commit: 1a148c0af8b9e7bcc76d3096889ac1c1d4ad77e4
Parents: 757fa3c
Author: Fil Maj <maj.fil@gmail.com>
Authored: Thu May 16 19:26:51 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Thu May 16 19:26:51 2013 -0700

----------------------------------------------------------------------
 lib/scripts/plugin_loader.js |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/1a148c0a/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index 357f8a7..892bd76 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -54,7 +54,7 @@
     // 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().
-    function handlePluginsObject(modules) {
+    function handlePluginsObject(modules, path) {
         // First create the callback for when all plugins are loaded.
         var mapper = context.cordova.require('cordova/modulemapper');
         onScriptLoadingComplete = function() {
@@ -88,11 +88,21 @@
 
         // Now inject the scripts.
         for (var i = 0; i < modules.length; i++) {
-            injectScript(modules[i].file);
+            injectScript(path + modules[i].file);
         }
     }
 
-
+    // Find the root of the app
+    var path = '';
+    var scripts = document.getElementsByTagName('script');
+    var term = 'cordova.js';
+    for (var n = scripts.length-1; n>-1; n--) {
+        var src = scripts[n].src;
+        if (src.indexOf(term) == (src.length - term.length)) {
+            path = src.substring(0, src.length - term.length);
+            break;
+        }
+    }
     // Try to XHR the cordova_plugins.json file asynchronously.
     var xhr = new XMLHttpRequest();
     xhr.onload = function() {
@@ -105,7 +115,7 @@
             // obj will be undefined.
         }
         if (Array.isArray(obj) && obj.length > 0) {
-            handlePluginsObject(obj);
+            handlePluginsObject(obj, path);
         } else {
             finishPluginLoading();
         }
@@ -113,8 +123,9 @@
     xhr.onerror = function() {
         finishPluginLoading();
     };
+    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', 'cordova_plugins.json', true); // Async
+        xhr.open('GET', plugins_json, true); // Async
         xhr.send();
     } catch(err){
         finishPluginLoading();


Mime
View raw message