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
# fixme: remote? same-origin-policy? jsonp?
(url, callback) -> <u> undefined
url <s> Remote URL
url <s|[s]> One or more remote URLs
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.get(url, function(data) {
callback(JSON.parse(data));
});
};
Ox.getJSON = (function() {
function getJSON(url, callback) {
Ox.get(url, function(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
@ -154,7 +166,7 @@ Ox.loadFiles = (function() {
files = Ox.toArray(files);
var i = 0, n = files.length, images = {};
Ox.toArray(files).forEach(function(file) {
loadFile(file, function(image) {
Ox.loadFile(file, function(image) {
if (image) {
images[file] = image;
}