Loader

Rather than loading an entire App at once, we can do it on demand when a given feature is needed. The Loader allows us to asynchronously load JavaScripts and StyleSheets.

Load scripts
Loading a simple script can be achieved using the approach below.

Fit.Loader.LoadScript("Script.js", function(src)
{
    alert("Script " + src + " has been loaded and is ready to be used");
});

Chain loading multiple scripts is also possible. Rather than using LoadScript, we use LoadScripts (plural).

Fit.Loader.LoadScripts(
[
    {
        // The source:string property is required
        source: "extensions/test/menu.js",

        // The loaded:function callback is optional.
        // It takes the configuration object as an argument, e.g.
        // { source: "..", loaded: function() { .. }, customProp1: "some custom data", ... }
        loaded: function(cfg) { alert("JavaScript " + cfg.source + " loaded"); }
    },
    {
        source: "http://cdn.domain.com/chat.js",
        loaded: function(cfg) { alert("JavaScript " + cfg.source + " loaded"); }
    }
],
function(cfgs)
{
    // This callback is invoked when all files have been loaded and are ready for use.
    // The cfgs variable contains the entire configuration array passed to LoadScripts.
    alert("All files loaded");
});


Load stylesheets
Loading stylesheets can be done in the exact same way, except LoadScript is replaced by LoadStyleSheet, and LoadScripts (plural) is replaced by LoadStyleSheets (plural). The arguments, callbacks, and behaviour is exactly the same.
Fit.UI is open source (LGPL) - download or fork it on GitHub - website powered by Sitemagic CMS