Added Snippet ArticleContent

This commit is contained in:
斟酌 鵬兄 2016-04-07 03:42:03 +08:00
parent 2e56b29a1e
commit 2ea98446aa
7 changed files with 163 additions and 18 deletions

View File

@ -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 );
})();

View File

@ -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" );

View File

@ -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 )
{

View File

@ -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" }

View File

@ -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 );
})();

View File

@ -50,7 +50,7 @@
// Popup MessageBox
new MessageBox(
"Insert site file"
"Link to article"
, Dand.wrape([
Dand.wrapc( "v_instruction", "Article id:" )
, v_snippetInput

View File

@ -40,6 +40,7 @@
, "Heading" , ""
, "Footnote" , ""
, "ArticleLink" , ""
, "ArticleContent" , ""
);
var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet.";