allow for passing multiple files to Ox.getJSON

This commit is contained in:
rlx 2012-04-19 11:23:24 +00:00
parent cf943e6466
commit a943d00e20

View file

@ -29,15 +29,27 @@ Ox.get = function(url, callback) {
Ox.getJSON <f> Get and parse a remote JSON file Ox.getJSON <f> Get and parse a remote JSON file
# fixme: remote? same-origin-policy? jsonp? # fixme: remote? same-origin-policy? jsonp?
(url, callback) -> <u> undefined (url, callback) -> <u> undefined
url <s> Remote URL url <s|[s]> One or more remote URLs
callback <f> Callback function callback <f> Callback function
data <s> The parsed contents of the remote resource data <s|o> The parsed contents of the remote resource(s)
For multiple URLs, keys are file names, values are contents
@*/ @*/
Ox.getJSON = function(url, callback) { Ox.getJSON = (function() {
function getJSON(url, callback) {
Ox.get(url, function(data) { Ox.get(url, function(data) {
callback(JSON.parse(data)); callback(JSON.parse(data));
}); });
}
return function(url, callback) {
var urls = Ox.toArray(url), data = {}, i = 0, n = urls.length;
urls.forEach(function(url) {
getJSON(url, function(data_) {
data[url] = data_;
++i == n && callback(n == 1 ? data[url] : data);
});
});
}; };
}());
/*@ /*@
Ox.getJSONC <f> Get and parse a remote JSONC file Ox.getJSONC <f> Get and parse a remote JSONC file
@ -154,7 +166,7 @@ Ox.loadFiles = (function() {
files = Ox.toArray(files); files = Ox.toArray(files);
var i = 0, n = files.length, images = {}; var i = 0, n = files.length, images = {};
Ox.toArray(files).forEach(function(file) { Ox.toArray(files).forEach(function(file) {
loadFile(file, function(image) { Ox.loadFile(file, function(image) {
if (image) { if (image) {
images[file] = image; images[file] = image;
} }