penguin/AstroJS

Javascript framework for my blog

commit 2ea98446aab0e855bea26628120e0ac3f63adf9f

author斟酌 鵬兄 <tgckpg@gmail.com>
date2016-04-06T19:42:03Z
subjectAdded Snippet ArticleContent
commit 2ea98446aab0e855bea26628120e0ac3f63adf9f
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2016-04-06T19:42:03Z

    Added Snippet ArticleContent
---
 .../SmartInput/CandidateAction/ArticleContent.js   |  25 ++++
 .../SmartInput/CandidateAction/ArticleReference.js |   8 --
 .../SmartInput/CandidateAction/Heading.js          |   9 --
 .../src/Astro/Blog/AstroEdit/SmartInput/_this.js   |   1 +
 .../AstroEdit/Visualizer/Snippet/ArticleContent.js | 135 +++++++++++++++++++++
 .../AstroEdit/Visualizer/Snippet/ArticleLink.js    |   2 +-
 .../src/Astro/Blog/AstroEdit/Visualizer/_this.js   |   1 +
 7 files changed, 163 insertions(+), 18 deletions(-)

diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleContent.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleContent.js
new file mode 100644
index 0000000..4b2606f
--- /dev/null
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleContent.js
@@ -0,0 +1,25 @@
+(function ()
+{
+	var ns = __namespace( "Astro.Blog.AstroEdit.SmartInput.CandidateAction" );
+
+	var ArticleRefs = ns[ NS_INVOKE ]( "ArticleReference" );
+
+	/** @type {Astro.Blog.AstroEdit.SmartInput.ICandidateAction} */
+	var ArticleContent = function ( visualizer, key )
+	{
+		ArticleRefs.call( this, visualizer, key );
+	};
+
+	__extends( ArticleContent, ArticleRefs );
+
+	ArticleContent.prototype.Process = function( key )
+	{
+		var cand = this.__cands[ key ];
+		if( !cand ) return false;
+
+		this.visualizer.insertSnippet( "articlecontent", { value: cand.id } );
+		return true;
+	};
+
+	ns[ NS_EXPORT ]( EX_CLASS, "ArticleContent", ArticleContent );
+})();
diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleReference.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleReference.js
index a87f8fe..cf9a22d 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleReference.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/ArticleReference.js
@@ -2,14 +2,6 @@
 {
 	var ns = __namespace( "Astro.Blog.AstroEdit.SmartInput.CandidateAction" );
 
-	/** @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 {Astro.Blog.Config} */
 	var Config                           = __import( "Astro.Blog.Config" );
 
diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
index aea1df3..db99aeb 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/CandidateAction/Heading.js
@@ -2,15 +2,6 @@
 {
 	var ns = __namespace( "Astro.Blog.AstroEdit.SmartInput.CandidateAction" );
 
-	/** @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 {Astro.Blog.AstroEdit.SmartInput.ICandidateAction} */
 	var Heading = function ( visualizer, key )
 	{
diff --git a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
index 6b5eada..4aabb63 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/SmartInput/_this.js
@@ -460,6 +460,7 @@
 	{
 		var Cands = {
 			"Article Reference": { module: "ArticleReference", desc: "Links to other article" }
+			, "Article Content": { module: "ArticleContent", desc: "Put contents of an article" }
 			, "facts": { module: "Facts", desc: "Facts, a fact bubble popup when mouseover" }
 			, "footnote": { module: "Footnote", desc: "Footnote, a footnote displayed at the end of article" }
 			, "h1": { module: "Heading", options: 1, desc: "Heading, size 1" }
diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleContent.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleContent.js
new file mode 100644
index 0000000..310d024
--- /dev/null
+++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleContent.js
@@ -0,0 +1,135 @@
+(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 );
+
+})();
diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleLink.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleLink.js
index d4ff1b7..00d79e9 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleLink.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/ArticleLink.js
@@ -50,7 +50,7 @@
 
 			// Popup MessageBox
 			new MessageBox(
-				"Insert site file"
+				"Link to article"
 				, Dand.wrape([
 					Dand.wrapc( "v_instruction", "Article id:" )
 					, v_snippetInput
diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js
index 4280507..ab2eb3f 100644
--- a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js
+++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js
@@ -40,6 +40,7 @@
 		 , "Heading"     , ""
 		 , "Footnote"     , ""
 		 , "ArticleLink" , ""
+		 , "ArticleContent" , ""
 	);
 
 	var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet.";