penguin/AstroJS

Javascript framework for my blog

botanjs/src/Astro/Blog/Components/Album.js

raw ยท 2470 bytes

(function(){
	var ns = __namespace( "Astro.Blog.Components" );

	/** @type {System.Cycle} */
	var Cycle                            = __import( "System.Cycle" );
	/** @type {System.utils.IKey} */
	var IKey                             = __import( "System.utils.IKey" );
	/** @type {System.utils.DataKey} */
	var DataKey                          = __import( "System.utils.DataKey" );
	/** @type {Dandelion} */
	var Dand                             = __import( "Dandelion" );
	/** @type {Dandelion.IDOMElement} */
	var IDOMElement                      = __import( "Dandelion.IDOMElement" );
	/** @type {Astro.Bootstrap} */
	var Bootstrap                        = __import( "Astro.Bootstrap" );
	/** @type {System.utils.Perf} **/
	var Perf                             = __import( "System.utils.Perf" );
	/** @type {Astro.Blog.Config} */
	var Conf                             = __import( "Astro.Blog.Config" );

	/** @type {_AstConf_.SiteFile} */
	var config = null;

	var SiteFile = ns[ NS_INVOKE ]( "SiteFile" );

	var Album = function ( id, hash )
	{
		if( !config ) throw new Error( "config is not defined" );
		var stage = Dand.id( id, true );

		var sf = new SiteFile( id, hash );
		if( sf.type != "album" ) return;

		var ostage = stage.element;

		var applyStructure = function( obj )
		{
			// remove loading bubbles
			while( ostage.hasChildNodes() ) ostage.removeChild( ostage.firstChild );

			/** @type {_AstJson_.SiteFile} */
			var finfo = JSON.parse( obj );

			var files = finfo.files;
			var l = files.length;

			// XXX: Not traditional!
			// Maximum of 4 for listing
			if( ostage.parentNode.className == "h_img" && 4 < l )
			{
				l = 4;
			}

			for( var i = 0; i < l; i ++ )
			{
				/** @type {_AstJson_.SiteFile} */
				var file = files[i];
				var uuid = Perf.uuid;

				ostage.appendChild(
					Dand.wrapna( "div", [
						new IKey( "id", uuid )
						, new DataKey( "size", "medium" )
					] )
				);

				Cycle.next( function()
				{
					new SiteFile( this.id, this.hash );
				}.bind({ id: uuid, hash: file.hash }) );
			}

			console.log( finfo );
		};

		var loadFailed = function( obj )
		{
			console.log( obj );
		};

		sf.loadInfo( applyStructure, loadFailed );
	};

	var init = function()
	{
		config = Conf.get( "SiteFile" );
		if( config )
		{
			for( var i in config.files )
			{
				var f = config.files[i];
				new Album( f[0], f[1] );
			}
		}
	};

	Bootstrap.regInit( init );

	ns[ NS_EXPORT ]( EX_CLASS, "Album", Album );
})();