incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [5/12] js commit: [CB-276] getJSON on local file, resolve path to app/www/* when XHR to local file, and return string data
Date Thu, 21 Jun 2012 00:00:56 GMT
[CB-276] getJSON on local file, resolve path to app/www/* when XHR to local file, and return
string data


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

Branch: refs/heads/master
Commit: 170affbd5fe60e8bbc97cc4dd452386a6826070b
Parents: 745b196
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Mon Jun 11 18:10:51 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed Jun 13 09:14:09 2012 -0700

----------------------------------------------------------------------
 lib/wp7/plugin/wp7/XHRPatch.js |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/170affbd/lib/wp7/plugin/wp7/XHRPatch.js
----------------------------------------------------------------------
diff --git a/lib/wp7/plugin/wp7/XHRPatch.js b/lib/wp7/plugin/wp7/XHRPatch.js
index 14a8575..a16c4ef 100644
--- a/lib/wp7/plugin/wp7/XHRPatch.js
+++ b/lib/wp7/plugin/wp7/XHRPatch.js
@@ -105,12 +105,18 @@ if (!docDomain || docDomain.length === 0) {
                 return this.wrappedXHR.open(reqType, uri, isAsync, user, password);
             }
             else {
+                console.log("url is " + uri);
                 // x-wmapp1://app/www/page2.html
                 // need to work some magic on the actual url/filepath
                 var newUrl = uri;
                 if (newUrl.indexOf(":/") > -1) {
                     newUrl = newUrl.split(":/")[1];
                 }
+                // prefix relative urls to our physical root
+                if(newUrl.indexOf("app/www/") < 0)
+                {  
+                    newUrl = "app/www/" + newUrl;
+                }
 
                 if (newUrl.lastIndexOf("/") === newUrl.length - 1) {
                     newUrl += "index.html"; // default page is index.html, when call is to
a dir/ ( why not ...? )
@@ -140,6 +146,15 @@ if (!docDomain || docDomain.length === 0) {
         responseXML: "",
         onResult: function (res) {
             this.status = 200;
+            console.log("onResult XHR :: " + res);
+            console.log("typeof = " + typeof res);
+            if(typeof res == "object")
+            {   // callback result handler may have already parsed this from a string->
a JSON object,
+                // if so, we need to restore it's stringyness, as handlers are expecting
string data.
+                // especially if used with jQ -> $.getJSON
+                console.log("re-stringing the guitar");
+                res = JSON.stringify(res);
+            }
             this.responseText = res;
             this.responseXML = res;
             this.changeReadyState(this.DONE);


Mime
View raw message