This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed app loading on android, updates to readme, split out app js fro…
…m helpers
- Loading branch information
Fil Maj
committed
Dec 19, 2011
1 parent
295a443
commit e92cd60
Showing
5 changed files
with
77 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// constants | ||
var BUILD_URL = 'https://build.phonegap.com'; | ||
|
||
// Dom helpers | ||
function $(s) { return document.getElementById(s); } | ||
|
||
// Extend the String object for simple templating | ||
String.prototype.format = function(){ | ||
var args = arguments; | ||
obj = (args.length == 1 && (typeof args[0] == 'object')) ? args[0] : args; | ||
return this.replace(/\{(\w+)\}/g, function(m, i){ | ||
return obj[i]; | ||
}); | ||
} | ||
|
||
// helper for XHR | ||
function xhr(url, options) { | ||
var xhr = new XMLHttpRequest(); | ||
|
||
if (options && options.username && typeof options.password != 'undefined') { | ||
var schemeSeparator = "://"; | ||
var extractToIndex = url.indexOf(schemeSeparator) + schemeSeparator.length; | ||
var scheme = url.substring(0, extractToIndex); | ||
var rhs = url.substring(extractToIndex); | ||
url = scheme + encodeURIComponent(options.username) + ':' + encodeURIComponent(options.password) + '@' + rhs; | ||
} | ||
|
||
xhr.open('GET', url, (options && typeof options.async != 'undefined'?options.async:true)); | ||
|
||
if (options && options.headers) { | ||
// Lifted from xui source; github.com/xui/xui/blob/master/src/js/xhr.js | ||
for (var key in options.headers) { | ||
if (options.headers.hasOwnProperty(key)) { | ||
xhr.setRequestHeader(key, options.headers[key]); | ||
} | ||
} | ||
} | ||
|
||
xhr.setRequestHeader("Accept", "application/json"); | ||
|
||
xhr.onreadystatechange = function(){ | ||
if ( xhr.readyState == 4 ) { | ||
if ( xhr.status == 200 || xhr.status == 0) { | ||
options.callback.call(xhr); | ||
} else { | ||
alert('XHR error, status: ' + xhr.status); | ||
} | ||
} | ||
}; | ||
xhr.send((options && options.data? options.data : null)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters