I have been toying with a jQuery port of JSAN
http://www.openjsan.org/doc/c/cw/cwest/JSAN/0.10/lib/JSAN.html

So far I have:
(function(jq){
        jq.extend({
                jsanUse: function(pkg, o){
                        o = jq.extend({
                                includePath: ['/jslib','jslib'],
                                altURL: null,
                                min: false
                        }, o || {});
                        if(o.altURL == null){
                                path = pkg.replace(/\./g, '/');
                                path = 
(o.min)?path.concat('-min.js'):path.concat('.js');
                        }else{
                                path = o.altURL;
                        }
                        try {
                                classdef = eval(pkg);
                                if (typeof classdef != 'undefined') return 
classdef;
                        } catch (e) { /* nice try, eh? */ }
                        for (var i = 0; i < o.includePath.length; i++) {
                                var js;
                                try{
                                var url = o.includePath[i].concat('/' + path);
                                        js  = jQuery.ajax({
                                                url: url,
                                                dataType: "script",
                                                async: false,
                                                success: 
function(js){if(jQuery.browser.safari){eval(js);}}
                                        }).status;
                                } catch (e) {
                                if (i == o.includePath.length - 1) throw e;
                                }
                                if (js != '404') {
                                return;
                                }
                        }
                }
        });
})(jQuery);

Which is by no means a full port, or as flexible as JSAN but is
serving my needs at the moment.  With usages like:
$.jsanUse("com.myrepo.classname");
$.jsanUse("YAHOO",{altURL:"/YAHOO/yahoo_jsan.js"});
$.jsanUse("YAHOO.util.Connect",{min:true});
These check to see if the package is registered first and then if it
is not loads the file.

I would like to eventually incorporate 
http://trainofthoughts.org/blog/2007/04/12/jquery-plugin-xsajax/
to allow cross-domain lazy loading of js libraries.

I think JSAN was going down the right track by doing registration and
package loading in one shot.

Reply via email to