Hash: Assets

Provides methods for the dynamic loading and management of JavaScript, CSS, and image files.

Assets Method: javascript

Injects a script tag into the head section of the document, pointing to the src specified.

Синтаксис:

var myScript = Asset.javascript(source[, properties]);

Аргументы:

  1. source - (string) The location of the JavaScript file to load.
  2. properties - (object, optional) Additional attributes to be included into the script Element.

Возвращает:

  • (element) A new script Element.

Примеры:

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

Assets Method: css

Injects a css file in the page.

Синтаксис:

var myCSS = new Asset.css(source[, properties]);

Аргументы:

  1. source - (string) The path of the CSS file.
  2. properties - (object) Some additional attributes you might want to add to the link Element.

Возвращает:

  • (element) A new link Element.

Примеры:

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

Assets Method: image

Preloads an image and returns the img element.

Синтаксис:

var myImage = new Asset.image(source[, properties]);

Аргументы:

  1. source - (string) The path of the image file.
  2. properties - (object) Some additional attributes you might want to add to the img Element including the onload/onerror/onabout events.

Возвращает:

  • (element) A new HTML img Element.

Примеры:

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

Notes:

  • Does not inject the image into the page.
  • WARNING: DO NOT use addEvent for load/error/abort on the returned element, give them as onload/onerror/onabort in the properties argument.

Assets Method: images

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

Синтаксис:

var myImages = new Asset.images(source[, options]);

Аргументы:

  1. sources - (mixed) An array or a string, of the paths of the image files.
  2. options - (object, optional) See below.

Options:

onComplete

  • (function) Executes when all image files are loaded.

Signature:

onComplete()

onProgress

  • (function) Executes when one image file is loaded.

Signature:

onProgress(counter, index)

Аргументы:

  1. counter - (number) The number of loaded images.
  2. index - (number) The index of the loaded image.

Возвращает:

Examples:

var myImages = new Asset.images(['/images/myImage.png', '/images/myImage2.gif'], {

    onComplete: function(){
        alert('All images loaded!');
    }
});


Эта документация распостраняется на правах Attribution-NonCommercial-ShareAlike 3.0 License.
Оригинал документации на английском.
© Linux.ria.ua, 2008-2024