Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Script to load widget classes on client demand.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Widget Loader

Just a script that loads classes and initializes the objects that need them on demand.



Include the loader.js file in the HTML page. The loader sits in a Javascript module called Loader but does nothing by itself so make sure to trigger load when the page is ready.

jQuery(function(){ window.Loader.load(); });

Now the DOM element <div class='widget clock'></div> will be initialized as a Clock widget, provided a clock.js file can be found in the widget folder with a Javascript class called Clock in it.

Customize loading call

Some customizations can be done when calling ´Loader.load´ to better adjust it to the needs of your project.

  • selector (default 'widget') Lets you decide the class that will be interpreted as a widget by the Loader.
  • scope (default 'body') A jQuery selector that allows us to reduce the area to be processed by the Loader.
  • folder (default '') Allows us to customize the folder where to search for the widget classes.
  • garbageLapse (default 3000) Time in milliseconds between garbage collector's swipes. Pass ´false´ to skip the collector.

Initial loading

Once included and initialized, the Loader will look for all dom elements with a class widget, try to load a script located in widget which name would be the second class in the element and initialize said DOM element as a member of that class. All objects greated this way are stored in a global Javascript object called ´widget´. You can see an example of the expected folder hierarchy expected by default in the tests but it can also be configured.

Future loading

If jQuery.livequery is included in the page, all future dom elements that are added to the DOM even after initial loading will receive the same treatment as the ones that were present form the start. jQuery.liveQuery is included in the package and you can find out more about it at

"Garbage collector"

Like stated before, all widget objects are listed in a global Javascript object called widget. However, as the user manipulates the page or time of execution passes, some of these widgets can be made to be removed or at least their representation in the DOM, causing an inconsistency between the widget global collection and the reality of the page. To avoid this, a garbage collector is available that at regular intervals will do mainteinance on the widget object to remove those which DOM element doesn't exist anymore.

Something went wrong with that request. Please try again.