Constructor Attributes | Constructor Name and Description |
---|---|
JQLoader()
Unique instance of
JQLoader plugin. |
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 filesstitched together. |
|
register(key, classConst)
Register a class in JQLoader.
|
|
run(src, options)
Loads and executes a class.
|
|
version()
Returns the current version 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
be added to the helper’s queue.
entry
object that willbe added to the helper’s queue.
1 2 3 4 5 6 |
$.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
the property that matches that
the entire
key
is passed to this method,the property that matches that
key
will be returned. If no key
is passedthe entire
info
will be returned instead.
1 2 3 4 5 6 7 |
// 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.
1 2 3 4 5 6 7 8 9 10 11 12 |
// 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 thebaseURL
. - {Function} options
- callback method to be invoked once the requested file (
src
) and its
dependencies have been loaded. Theoptions
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 thatload
is called. - {Function} options.ready
- callback method to be invoked once the requested file (
src
) and its
dependencies have been loaded. Theoptions
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 theerror
object you will find amessage
and atype
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 thebaseURL
value.
publish(src, options)
Loads the
stitched together. The purpose of this method is to overcome making several HTTP requests to load
the main
src
file and its dependencies and return a String
with all the filesstitched together. The purpose of this method is to overcome making several HTTP requests to load
the main
src
file dependencies.
1 2 3 4 |
$.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 thebaseURL
. - {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 anObject
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
parameter provided in this method. Only one class can be associated to a
class tries to use a existing key/name-space, the
method will return
key
parameter provided in this method. Only one class can be associated to a
key
. If anotherclass tries to use a existing key/name-space, the
register
call will be ignore and themethod 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 caseregister
will create
a constructor and attach theObject
properties and methods to it.
- Returns:
- {Boolean}
run(src, options)
Loads and executes a class.
in one class and and adding a lot of code in you HTML file. your main class must meet the following conditions:
run
will allow you to write your initialization codein 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 insidemain
1 2 3 4 5 6 7 8 9 10 11 |
// 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. Unlikeload
orpublish
, theoptions
parameter in this case cannot be aFunction
.
- See:
- JQLoader#load
{String}
version()
Returns the current version of JQLoader plugin.
1 2 3 4 5 |
<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}