Categories

JQLoader Documentation

The following text summarizes the public API of jQLoader plugin.
Constructor Attributes Constructor Name and Description
 
Unique instance of JQLoader plugin.

Method Summary
Method Attributes Method Name and Description
 
get(key)
Returns the class associated to the specified key.
 
include(src)
Includes a new javascript library.
 
info(key)
Returns information about the JQLoader plugin.
 
load(src, options, options)
Load a file will will contain a class or a dependency of a class.
 
publish(src, options)
Loads the src file and its dependencies and return a String with all the files
stitched together.
 
register(key, classConst)
Register a class in JQLoader.
 
run(src, options)
Loads and executes a class.
 
Returns the current version of JQLoader plugin.

Class Detail
JQLoader()
Unique instance of JQLoader plugin.

Method Detail

{Function}
get(key)

Returns the class associated to the specified key.

Parameters:
{Object} key

Unique identifier of a class added to jqloader using the
register API.
Returns:
{Function}
See:
JQLoader#register

include(src)

Includes a new javascript library. This method will create an entry object that will
be added to the helper’s queue.

?View Code JAVASCRIPT
$.jqloader.include('/src/com/sanraul/demo/lib.js');
$.jqloader.register('com.sanraul.demo.MyClass', {
	constructor: function(){
		// constructor code goes here
	}
}
Parameters:
{String} src

URL of the javascript file.
See:

{Object}
info(key)

Returns information about the JQLoader plugin. If a key is passed to this method,
the property that matches that key will be returned. If no key is passed
the entire info will be returned instead.

?View Code JAVASCRIPT
// Example #1
var version = $.jqloader.info('version');
alert(version);
 
// Example #2
var info = $.jqloader.info();
alert(info.appName +' - '+ info.copyright);
Parameters:
{String} key

Returns:
{Object}
See:

load(src, options, options)

Load a file will will contain a class or a dependency of a class.

?View Code JAVASCRIPT
// EXAMPLE #1 Load a file an nitify when is ready
$.jqloader.load('/src/com/jqloader/demo/Application.js', function(opt){
	alert('Application Ready');
});
 
// EXAMPLE #2 Using a custom 'options'
var options = {ready: function(opt){
		alert('Application Ready');
	},
	baseURL: '/src/com/jqloader/demo'
};
$.jqloader.load('Application.js' options)
Parameters:
{String} src

URL of the file that will be loaded. src can be absolute
relative to the baseURL.
{Function} options

callback method to be invoked once the requested file (src) and its
dependencies have been loaded. The options will be is passed to the
ready callback method.
{Object} options

New settings for the JQLoader. Values in the options object
can be overridden every time that load is called.
{Function} options.ready

callback method to be invoked once the requested file (src) and its
dependencies have been loaded. The options will be is passed to the
ready callback method.
{Function} options.error

callback method to handle errors. An error object will be passes
to the callback error method. In the error object you will find a message
and a type properties.
{String} options.baseURL

a base path that will be prepend to the src URL value and all the and
all the dependencies. No ‘slash’ is required at the end of the baseURL value.
See:
JQLoader#publish
JQLoader#run

publish(src, options)

Loads the src file and its dependencies and return a String with all the files
stitched together. The purpose of this method is to overcome making several HTTP requests to load
the main src file dependencies.

?View Code JAVASCRIPT
$.jqloader.publish('/src/com/jqloader/demo/Application.js', function(params){
	var outElem = document.getElementById('out');
	outElem.innerHTML = params.output;
});
Parameters:
{Object} src

URL of the file that will be loaded. src can be absolute
relative to the baseURL.
{Object|Function} options

If this value is a Function, it represents the callback method to be invoked
once the requested file (src) and its dependencies have been loaded.
If the value is an Object it should contain the new settings for the JQLoader.
See:
JQLoader#load

{Boolean}
register(key, classConst)

Register a class in JQLoader. Basically class are store and associated to the key
parameter provided in this method. Only one class can be associated to a key. If another
class tries to use a existing key/name-space, the register call will be ignore and the
method will return false.

Parameters:
{Object} key

Name-space of the class that needs to be registered.
{Function|Object} classConst

Constructor of the class. This parameter can also be an Object
with properties and methods. When this is the case register will create
a constructor and attach the Object properties and methods to it.
Returns:
{Boolean}

run(src, options)

Loads and executes a class. run will allow you to write your initialization code
in one class and and adding a lot of code in you HTML file. your main class must meet the following conditions:

  • The class must be register as Application (i.e $.jqloader('Application', {...});).
  • Must implement a method named main, which will be invoked from thr constructor.
  • You should not override the constructor method. Place initialization code inside main
?View Code JAVASCRIPT
// Example #1 Simple call
$.jqloader.run('/src/com/jqloader/demo/AppRunner.js');
 
// Example #2 Passing Custom Options
var options {
	baseURL: '/src/com/jqloader/demo',
	error: function(opt){
		alert('opps!');
	}
};
$.jqloader.run('AppRunner.js', options);
Parameters:
{Object} src

URL of the class that needs to be executed.
{Object} options

Custom values to override default settings. If a ready callback function is
specified, it will be ignored. Unlike load or publish, the options
parameter in this case cannot be a Function.
See:
JQLoader#load

{String}
version()

Returns the current version of JQLoader plugin.

<script src="lib/jquery/jquery-1.3.2.min.js"></script>
<script src="lib/jqloader/jqloader-0.1.0.js"></script>
<script>
	alert($.jqloader.version()); // Returns a string (i.e. '0.1.0')
</script>
Returns:
{String}


Related Links