'use strict'; /*@ Ox.get Get a remote file # fixme: remote? same-origin-policy? jsonp? (url, callback) -> undefined url Remote URL callback Callback function data The contents of the remote resource @*/ Ox.get = function(url, callback) { var req = new XMLHttpRequest(); req.open('GET', url, true); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { callback(req.responseText); } else { throw new Error( 'Cannot get URL "' + url + '" (Status: ' + req.status + ')' ); } } }; req.send(); }; /*@ Ox.getJSON Get and parse one or more remote JSON files # fixme: remote? same-origin-policy? (url, callback) -> undefined url One or more remote URLs callback Callback function data The parsed contents of the remote resource(s) For multiple URLs, keys are file names, values are contents @*/ Ox.getJSON = function(url, callback) { var urls = Ox.makeArray(url); Ox.loadAsync(urls, function(url, callback) { Ox.get(url, function(data) { var result = {}; result[url] = JSON.parse(data); callback(result); }); }, function(results) { callback(urls.length == 1 ? results[url] : results); }); } /*@ Ox.getJSONP Get and parse one or more remote JSONP files (url, callback) -> undefined url One or more remote URLs, {callback} gets replaced with jsonp callback function name callback Callback function data The parsed contents of the remote resource(s) For multiple URLs, keys are file names, values are contents @*/ Ox.getJSONP = function(url, callback) { var urls = Ox.makeArray(url); Ox.loadAsync(urls, function(url, callback) { var id = 'callback' + Ox.uid(); Ox.getJSONP[id] = function(data) { delete Ox.getJSONP[id]; callback(data); } Ox.$('body').append(Ox.$('