penguin/AstroJS

Javascript framework for my blog

botanjs/src/Astro/Blog/AstroEdit/_this.js

raw ยท 3249 bytes

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

	/** @type {System.Cycle} */
	var Cycle                                      = __import( "System.Cycle" );
	/** @type {Dandelion} */
	var Dand                                       = __import( "Dandelion" );
	/** @type {Astro.Bootstrap} */
	var Bootstrap                                  = __import( "Astro.Bootstrap" );
	/** @type {Astro.Blog.Config} */
	var Config                                     = __import( "Astro.Blog.Config" );
	/** @type {Astro.Blog.AstroEdit.Article} */
	var Article                                    = __import( "Astro.Blog.AstroEdit.Article" );
	/** @type {Astro.Blog.AstroEdit.Draft} */
	var Draft                                      = __import( "Astro.Blog.AstroEdit.Draft" );
	/** @type {Astro.Blog.AstroEdit.Flag} */
	var Flag                                        = __import( "Astro.Blog.AstroEdit.Flag" );
	/** @type {Astro.Blog.AstroEdit.Visualizer} */
	var Visualizer                                 = __import( "Astro.Blog.AstroEdit.Visualizer" );
	/** @type {Astro.Blog.AstroEdit.Uploader} */
	var Uploader                                   = __import( "Astro.Blog.AstroEdit.Uploader" );
	/** @type {Astro.Blog.AstroEdit.SiteLibrary} */
	var SiteLibrary                                = __import( "Astro.Blog.AstroEdit.SiteLibrary" );

	var wh, ww, cw, html, article;

	var init = function ()
	{
		//// Component initializations
		/** @type {_AstConf_.AstroEdit} */
		var a_conf = Config.get( "AstroEdit" );
		var base_path = Config.get( "BasePath" );

		Cycle.next(
			function()
			{
				article.load(
					a_conf.article_id
					, function( obj, id )
					{
						window.history.replaceState( obj, "", base_path + "astroedit/" + id + "/" );
					}
				);
			}
		);

		article = new Article(
			a_conf.paths.set_article
			, [
				new Flag( "tags", "ae_tags", a_conf.paths.tags )
				, new Flag( "section", "ae_secs", a_conf.paths.sections )
			]
		);

		// Article modules
		new Draft( article, a_conf.paths.get_drafts );
		new Visualizer(
			article
			, Dand.id( "ae_visual_snippets" )
			, Config.get( "ServiceUri" )
		);

		// Independent modules
		new Uploader( a_conf.paths.set_file );
		new SiteLibrary(
			Config.get( "BasePath" )
			, a_conf.paths.get_files
			, a_conf.paths.set_file
		);

		var title = Dand.id("ae_title");
		var content = Dand.id("ae_content");

		// content height
		content.style.minHeight = String(screen.availHeight) + "px";

		html = document.body.parentNode;

		window.onresize = adjustLayout;

		// Setting event handlers
		title.onblur = content.onblur = function () { Dand.id("ae_bgdimmer").style.background = ""; };
		content.onfocus = content.onfocus = function ()
		{
			Dand.id("ae_bgdimmer").style.background = "rgba(255, 255, 255, 0.2)";
		};

		Dand.id( "ae_publish_btn" ).onclick = function () { article.saveAndPublish(); };
		Dand.id( "ae_preview_btn" ).onclick = function () { article.preview(); };
		Dand.id( "ae_drop_btn" ).onclick = function () { article.drop(); };;

		adjustLayout();
	};

	var adjustLayout  = function ()
	{
		ww = html.clientWidth;
		wh = html.clientHeight;
		cw = ww - 300;
		Dand.id("ae_body").style.width = String(cw) + "px";
	};

	Bootstrap.regInit( init );
})();