Permalink
Browse files

Local XHR fix for WP8 CB-1813. This is actually commit: 35d32b75ac6e4…

…901f3309316ea8578faf8fa8869
  • Loading branch information...
purplecabbage committed Nov 30, 2012
1 parent c46b140 commit c9f310fe95b776b1ef73deb0fc837d8627057e84
Showing with 39 additions and 14 deletions.
  1. +39 −14 lib/windowsphone/plugin/windowsphone/XHRPatch.js
@@ -133,7 +133,7 @@ if (!docDomain || docDomain.length === 0) {
newUrl = newUrl.split(":/")[1];
}
// prefix relative urls to our physical root
- if(newUrl.indexOf("app/www/") < 0)
+ if(newUrl.indexOf("app/www/") < 0 && this.getContentLocation() == this.contentLocation.ISOLATED_STORAGE)
{
newUrl = "app/www/" + newUrl;
}
@@ -200,26 +200,51 @@ if (!docDomain || docDomain.length === 0) {
alias.onError(evt.code);
};
- var gotFile = function gotFile(file) {
- var reader = new FileReader();
- reader.onloadend = function (evt) {
- alias.onResult.apply(alias,[evt.target.result]);
+ if (alias.getContentLocation() == this.contentLocation.RESOURCES) {
+ var exec = require('cordova/exec');
+ exec(function(result) {
+ alias.onResult.apply(alias, [result]);
+ },
+ fail,
+ "File", "readResourceAsText", [alias._url]
+ );
+ }
+ else {
+ var gotFile = function gotFile(file) {
+ var reader = new FileReader();
+ reader.onloadend = function (evt) {
+ alias.onResult.apply(alias,[evt.target.result]);
+ };
+ reader.readAsText(file);
};
- reader.readAsText(file);
- };
- var gotEntry = function gotEntry(entry) {
- entry.file(gotFile, fail);
- };
+ var gotEntry = function gotEntry(entry) {
+ entry.file(gotFile, fail);
+ };
- var gotFS = function gotFS(fs) {
- fs.root.getFile(alias._url, null, gotEntry, fail);
- };
+ var gotFS = function gotFS(fs) {
+ fs.root.getFile(alias._url, null, gotEntry, fail);
+ };
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
+ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
+ }
+ }
+ },
+ getContentLocation: function () {
+ if (window.contentLocation === undefined) {
+ window.contentLocation = (navigator.userAgent.toUpperCase().indexOf('MSIE 10') > -1) ?
+ this.contentLocation.RESOURCES : this.contentLocation.ISOLATED_STORAGE;
}
+
+ return window.contentLocation;
},
+
+ contentLocation:{
+ ISOLATED_STORAGE: 0,
+ RESOURCES: 1
+ },
+
status: 404
};
} // if doc domain

0 comments on commit c9f310f

Please sign in to comment.