diff --git a/source/Ox/js/Request.js b/source/Ox/js/Request.js index 2bb29076..2e0b30f9 100644 --- a/source/Ox/js/Request.js +++ b/source/Ox/js/Request.js @@ -57,9 +57,10 @@ Ox.getJSONC = function(url, callback) { Ox.loadFile <f> Loads a file (image, script or stylesheet) (file="script.js", callback) -> <u> undefined (file="stylesheet.css", callback) -> <u> undefined - (file="image.png", callback) -> <e> DOM element + (file="image.png", callback) -> <u> undefined file <s> Local path or remote URL callback <f> Callback function + image <e> DOM element (if the file is an image) @*/ Ox.loadFile = (function() { // fixme: this doesn't handle errors yet @@ -137,3 +138,37 @@ Ox.loadFile = (function() { } }; }()); + +/*@ +Ox.loadFiles <f> Loads multiple files (images, scripts or stylesheets) + (files, callback) -> <u> undefined + files <[s]|[[s]]> Array of files, or array of arrays of files + Multiple files in the same array will be loaded simultaneously, but + multiple arrays of files will be loaded in that order. + callback <f> Callback function + images <o> DOM elements (if any file was an image) + Keys are the file names, values are the DOM elements +@*/ +Ox.loadFiles = (function() { + function loadFiles(files, callback) { + files = Ox.toArray(files); + var i = 0, n = files.length, images = {}; + Ox.toArray(files).forEach(function(file) { + loadFile(file, function(image) { + if (image) { + images[file] = image; + } + ++i == n && callback(images); + }); + }); + } + return function(files, callback) { + var i = 0, n = files.length, images = {}; + files.forEach(function(file) { + loadFiles(files, function(images_) { + Ox.extend(images, images_) + ++i == n && callback(Ox.len(images) ? images : void 0); + }); + }); + }; +}()); \ No newline at end of file