Assets.js

provides dynamic loading for images, css and javascript files.

License

MIT-style license.

Summary
Assets.jsprovides dynamic loading for images, css and javascript files.
Properties
javascriptInjects a javascript file in the page.
cssInjects a css file in the page.
imagePreloads an image and returns the img element.
imagesPreloads an array of images (as strings) and returns an array of img elements.

Properties

javascript

Injects a javascript file in the page.

Arguments

sourcethe path of the javascript file
propertiessome additional attributes you might want to add to the script element

Example

new Asset.javascript('/scripts/myScript.js', {id: 'myScript'});

css

Injects a css file in the page.

Arguments

sourcethe path of the css file
propertiessome additional attributes you might want to add to the link element

Example

new Asset.css('/css/myStyle.css', {id: 'myStyle', title: 'myStyle'});

image

Preloads an image and returns the img element. does not inject it to the page.

Arguments

sourcethe path of the image file
propertiessome additional attributes you might want to add to the img element

Example

new Asset.image('/images/myImage.png', {id: 'myImage', title: 'myImage', onload: myFunction});

Returns

the img element. you can inject it anywhere you want with Element.injectInside/Element.injectAfter/Element.injectBefore

images

Preloads an array of images (as strings) and returns an array of img elements. does not inject them to the page.

Arguments

sourcesarray, the paths of the image files
optionsobject, see below

Options

onCompletea function to execute when all image files are loaded in the browser’s cache
onProgressa function to execute when one image file is loaded in the browser’s cache

Example

new Asset.images(['/images/myImage.png', '/images/myImage2.gif'], {
    onComplete: function(){
        alert('all images loaded!');
    }
});

Returns

the img elements as $$. you can inject them anywhere you want with Element.injectInside/Element.injectAfter/Element.injectBefore

Same as Element.injectBefore, but inserts the element inside.
Same as Element.injectBefore, but inserts the element after.
Inserts the Element before the passed element.

Documentation by Aaron Newton & Mootools Developers, generated by NaturalDocs and GeSHi