Repository

Loader

A loader class that manage the loading of datas from url. This is mainly used internally to manage the preLoad method in users script. Users should usually use this class methods to load datas and obtain the result encapsulated in a LoadRequest object.

Static Method Summary

Static Public Methods
public static

load(url: String, callback: Function, responseType: String, processData: Function): *

Loads data from a URL.

public static

loadArrayBuffer(url: String, callback: Function)

Loads an arraybuffer from a URL.

public static

loadBlob(url: String, callback: Function)

Loads a blob from a URL.

public static

loadImage(url: String, callback: Function)

Loads an image from a URL.

public static

loadJSON(url: String, callback: Function)

Loads a JavaScript object, parsed from a JSON string from a URL.

public static

loadScript(url: String, callback: Function)

Loads a script from a URL.

public static

loadText(url: String, callback: Function)

Loads a text from a URL.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

events: *

public
public
public

onLoad: *

Private Members
private
private

_requests: *[]

private

Method Summary

Public Methods
public

Consume (executes) all the requests

public

load(url: String, onStart: Function, onLoad: Function, onError: Function, responseType: String, processData: Function): LoadRequest

Load a data from the URL given in parameters.

public

loadArrayBuffer(params: Object): LoadRequest

Loads an ArrayBuffer from a URL.

public

loadBlob(params: Object): LoadRequest

Loads a blob from a URL.

public

loadImage(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest

Load an image from the URL given in parameters.

public

loadJSON(params: Object): LoadRequest

Loads a JavaScript object, parsed from a JSON string from a URL.

public

loadScript(objectPattern: {"url": *, "onStart": *, "onLoad": *, "onError": *}): *

public

loadText(params: Object): LoadRequest

Loads a text from a URL.

public

loadVideo(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest

Load a video from the URL given in parameters.

Private Methods
private

Helper method to update the status and trigger the complete event

Static Public Methods

public static load(url: String, callback: Function, responseType: String, processData: Function): * source

Loads data from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

callback.resultMixed

The load result if successful

callback.errorString

The load error if unsuccessful

responseTypeString
  • optional

The type of the respons to return from the Ajax call

processDataFunction
  • optional

function definning what to do with the data coming from the promise

Return:

*

public static loadArrayBuffer(url: String, callback: Function) source

Loads an arraybuffer from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

callback.resultMixed

The load result if successful

callback.errorString

The load error if unsuccessful

public static loadBlob(url: String, callback: Function) source

Loads a blob from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

public static loadImage(url: String, callback: Function) source

Loads an image from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

callback.resultMixed

The load result if successful

callback.errorString

The load error if unsuccessful

public static loadJSON(url: String, callback: Function) source

Loads a JavaScript object, parsed from a JSON string from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

callback.resultMixed

The load result if successful

callback.errorString

The load error if unsuccessful

public static loadScript(url: String, callback: Function) source

Loads a script from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

public static loadText(url: String, callback: Function) source

Loads a text from a URL. This static method must be provided a callback method.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

callbackFunction

callback function that the user wants to call on load completion

callback.resultMixed

The load result if successful

callback.errorString

The load error if unsuccessful

Public Constructors

public constructor(params: Object) source

Params:

NameTypeAttributeDescription
paramsObject

Parameters object, given by the constructor.

params.onLoadFunction
params.onErrorFunction
params.onCompleteFunction

Public Members

public events: * source

public onComplete: * source

public onError: * source

public onLoad: * source

Private Members

private _complete: number source

private _requests: *[] source

private _status: * source

Public Methods

public consumeAll() source

Consume (executes) all the requests

public load(url: String, onStart: Function, onLoad: Function, onError: Function, responseType: String, processData: Function): LoadRequest source

Load a data from the URL given in parameters. ResponseType is the default one of an Ajax object, that is String.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

onStartFunction
  • optional
  • default: null

A function to be called when the loading starts

onLoadFunction
  • optional
  • default: null

A function to be called when the loading finishes

onErrorFunction
  • optional
  • default: null

A function to be called when the loading fails

responseTypeString
  • optional

The type of the respons to return from the Ajax call

processDataFunction

function definning what to do with the data coming from the promise

Return:

LoadRequest

the LoadRequest object is incomplete at call and will be filled by the inner promise manager, when fulfilled.

public loadArrayBuffer(params: Object): LoadRequest source

Loads an ArrayBuffer from a URL.

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the load function.

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled

public loadBlob(params: Object): LoadRequest source

Loads a blob from a URL.

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the load function.

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled

public loadImage(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest source

Load an image from the URL given in parameters. The Image Object is given as the returned LoadRequest's value.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

onStartFunction
  • optional
  • default: null

A function to be called when the loading starts

onLoadFunction
  • optional
  • default: null

A function to be called when the loading finishes

onErrorFunction
  • optional
  • default: null

A function to be called when the loading fails

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled

public loadJSON(params: Object): LoadRequest source

Loads a JavaScript object, parsed from a JSON string from a URL.

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the load function.

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled

public loadScript(objectPattern: {"url": *, "onStart": *, "onLoad": *, "onError": *}): * source

Params:

NameTypeAttributeDescription
objectPattern{"url": *, "onStart": *, "onLoad": *, "onError": *}
  • optional
  • default: {}

Return:

*

public loadText(params: Object): LoadRequest source

Loads a text from a URL.

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the load function.

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled

public loadVideo(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest source

Load a video from the URL given in parameters. The Video Object is given as the returned LoadRequest's value.

Params:

NameTypeAttributeDescription
urlString

the URL to load data from

onStartFunction
  • optional
  • default: null

A function to be called when the loading starts

onLoadFunction
  • optional
  • default: null

A function to be called when the loading finishes

onErrorFunction
  • optional
  • default: null

A function to be called when the loading fails

Return:

LoadRequest

a LoadRequest who's value is incomplete at first and will be filled once the request is fulfilled

Private Methods

private doComplete() source

Helper method to update the status and trigger the complete event