penguin/AstroJS

Javascript framework for my blog

botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleContent.js

raw ยท 3154 bytes

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

	/** @type {System.utils.IKey} */
	var IKey                              = __import( "System.utils.IKey" );
	/** @type {System.utils.DataKey} */
	var DataKey                           = __import( "System.utils.DataKey" );
	/** @type {Dandelion.IDOMElement} */
	var IDOMElement                       = __import( "Dandelion.IDOMElement" );
	/** @type {Dandelion} */
	var Dand                              = __import( "Dandelion" );
	/** @type {Components.MessageBox} */
	var MessageBox                        = __import( "Components.MessageBox" );
	/** @type {Astro.Blog.Config} */
	var Config                            = __import( "Astro.Blog.Config" );
	/** @type {System.utils.Perf} */
	var Perf                              = __import( "System.utils.Perf" );
	/** @type {Astro.utils.Date} */
	var XDate                             = __import( "Astro.utils.Date" );

	var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
	var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
	var compileProp = ns[ NS_INVOKE ]( "compileProp" );

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

	var ArticleContent = function ( insertSnippet, snippetWrap, createContext, override )
	{
		config = Config.get( "AstroEdit" );
		if( !config ) throw new Error( "config is not defined" );

		var temp, i, j

		, handler = function ()
		{
			// Input fields
			var v_snippetInput = Dand.wrap( "input", null, "v_snippet_input_single", null, new IKey( "type", "text" ) );

			if ( this._stage )
			{
				v_snippetInput.value = this._id;
			}

			// Popup MessageBox
			new MessageBox(
				"ArticleContent"
				, Dand.wrape([
					Dand.wrapc( "v_instruction", "ArticleContent id:" )
					, v_snippetInput
				])
				, "OK", "Cancel"
				, visualizer.bind({
					id: v_snippetInput
					, stage: this._stage
				})
			).show();
		}

		, visualizer = function ( submitted, override )
		{

			var id, stage = this.stage;

			if( override )
			{
				id = unescapeStr( override.value );
			}
			else
			{
				id = this.id.value;
			}

			if ( submitted && id )
			{
				// Visualize component
				if (!stage)
				{
					temp =  Dand.wrapne( "span"
						, "ArticleContent[" + id + "]"
						, new DataKey( "value", id )
					);

					insertSnippet(
						j = snippetWrap( "ArticleContent", temp, false, "span" )
						, !!override
					);
				}
				else
				{
					stage.firstChild.textContent = "ArticleContent[" + id + "]";

					IDOMElement( stage ).setAttribute( new DataKey( "value", id ) );
				}

				i = {
					_id: id
					, _stage: temp
				};

				// Set context menu
				createContext( i, j, handler );
			}
		};

		if ( override )
		{
			visualizer( true, override );
			override = false;
		}
		else
		{
			return handler;
		}
		return true;

	};

	var compile = function ( stage )
	{
		stage = IDOMElement( stage );
		var options = "";
		var opt;

		return "[articlecontent]"
			+ escapeStr( stage.getDAttribute( "value" ) )
			+ "[/articlecontent]";
	};

	__static_method( ArticleContent, "compile", compile );

	ns[ NS_EXPORT ]( EX_CLASS, "ArticleContent", ArticleContent );

})();