I've written some stuff do load dynamic js for my personal library.
// hash of namespace names and functions to execute when a namespace
has loaded
BearLib.loadExecuteQueue = new Hash();
// configuration options
BearLib.Config = {
// location of bearlib folder
libraryPath: [your javascript path]
}
// load a bearlib namespace
// - name: the namespace to load
// - onload: function to execute when the namespace has loaded
BearLib.load = function(){
// generate the path to the namespace file
var src = BearLib.Config.libraryPath + arguments[0] + '.js';
// if the namespace hasn't already been loaded
// -- add a generated script element to the head element
if($$('script[id=bearlib-' + arguments[0] + ']').length == 0){
$$('head')[0].insert(new Element('script', {'src': src, 'id':
'bearlib-' + arguments[0], 'language': 'javascript', 'type': 'text/
javascript'}));
// if the second argument is a function
// -- add it to the load execute queue
if(typeof(arguments[1]) == 'function'){
BearLib.loadExecuteQueue.set(arguments[0], arguments[1]);
};
}
}
// execute the passed function
BearLib.execute = function(){
if(typeof(arguments[0]) == 'function'){
arguments[0]();
}
}
AT THE BOTTOM OF THE SCRIPT FILE BEING LOADED
// alert bearlib that the namespace has loaded
BearLib.execute(BearLib.loadExecuteQueue.get('theme'));
BearLib.loadExecuteQueue.unset('theme');
IN THE PAGE LOADING THE SCRIPT
BearLib.load('theme', function(){
alert('Loaded');
});
Hope you find it useful
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---