kotarok
7/25/2010 - 10:27 PM

jquery.require.js

/**
 * $.require('foo.js');
 * $.require(['foo.js','baa.js','moo/muu.js]);
 */

jQuery.require= (function(){
	var jspath = $('script[src]:last').attr('src');
	var dirpath = /.+\//.exec(jspath)[0]

	return function(jsfiles){
		if(typeof(jsfiles) == "array"){
			for(var i=0,l=jsfiles.length;i<l;i++){
				document.write('<script type="text/javascript" src="' + dirpath + jsfiles[i] + '"><\/script>');
			}
		}else{
			document.write('<script type="text/javascript" src="' + dirpath + jsfiles + '"><\/script>');
		}
	}
})()