Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java-Like Javascript Library Container //Javascript Object

DZone's Guide to

Java-Like Javascript Library Container //Javascript Object

·
Free Resource

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com

libraryControl = {
	baseURI: '',
	packs: {},

	register: function( pack ){
		for( var _, m, p = this.packs, pack = ( m = pack.split( '.' ) ).pop(); _ = m.shift(); p = p[_] || ( p[_]={} ) );
		( p['%files%'] || ( p['%files%'] = {} ) )[pack] = {included:false,loaded:false};
	},

	findPackage: function( pack ){
		for( var m, p = this.packs, pack = ( m = pack.split( '.' ) ).pop(); m.length && ( p = p[ m.shift() ] ); );
		return !m.length && (p=p['%files%']) ? p[pack] : null;
	},

	isIncluded: function( pack ){
		with( {x:this.findPackage( pack )} ) return x && x.included;
	},

	isLoaded: function( pack ){
		with( {x:this.findPackage( pack )} ) return x && x.loaded;
	},

	include: function( pack ) {
		var p = this.findPackage( pack ), pack = this.baseURI + pack.split( '.' ).join( '/' ) + '.js';
		if( p ){
			if( !document.body )
				document.write( '
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}