Added Meta Snippet

This commit is contained in:
斟酌 鵬兄 2017-03-06 20:28:39 +08:00
parent 28a15f031e
commit a5e0be3221
4 changed files with 150 additions and 50 deletions

View File

@ -13,21 +13,21 @@
/** @type {Components.MessageBox} */ /** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" ); var MessageBox = __import( "Components.MessageBox" );
var acquirelib = function(insertSnippet, snippetWrap, createContext, override) var acquirelib = function(insertSnippet, snippetWrap, createContext, override)
{ {
var temp, i, j var temp, i, j
, handler = function () , handler = function ()
{ {
// Input fields // Input fields
var input_text = Dand.wrap('input', null, "v_snippet_input_single", null, new IKey("type", "text")); var input_text = Dand.wrap('input', null, "v_snippet_input_single", null, new IKey("type", "text"));
if (this._stage) if (this._stage)
{ {
input_text.value = this._text; input_text.value = this._text;
} }
// Popup MessageBox // Popup MessageBox
new MessageBox( new MessageBox(
"Acquire library" + ( this._stage ? " (Edit)" : "" ) "Acquire library" + ( this._stage ? " (Edit)" : "" )
@ -36,26 +36,23 @@
, visualizer.bind({ text:input_text, stage: this._stage }) , visualizer.bind({ text:input_text, stage: this._stage })
).show(); ).show();
} }
, visualizer = function (submitted, override) , visualizer = function (submitted, override)
{ {
var src = override ? override.value : this.text.value var src = override ? override.value : this.text.value
, stage = this.stage; , stage = this.stage;
if (submitted && src) if (submitted && src)
{ {
// Shared clause // Shared clause
if (!stage) if (!stage)
{ {
if (!src) return; if (!src) return;
// Visualize component // Visualize component
temp = Dand.wrap( temp = Dand.wrap(
'span' 'span', null, "flsf"
, null
, "flsf"
, "AcquireLib: " + src , "AcquireLib: " + src
, [ , [
new DataKey( "value", src ) new DataKey( "value", src )
@ -69,22 +66,21 @@
else else
{ {
IDOMElement(stage).setAttribute( new DataKey("value", src) ); IDOMElement(stage).setAttribute( new DataKey("value", src) );
stage.removeChild(stage.firstChild); stage.removeChild(stage.firstChild);
stage.appendChild(Dand.textNode("AcquireLib: " + src)); stage.appendChild(Dand.textNode("AcquireLib: " + src));
// set temp back to stage // set temp back to stage
temp = stage; temp = stage;
} }
i = {_text: src, _stage: temp}; i = {_text: src, _stage: temp};
// Set context menu // Set context menu
createContext(i, j, handler); createContext(i, j, handler);
} }
} };
;
if (override) if (override)
{ {
visualizer(true, override); visualizer(true, override);
@ -96,11 +92,10 @@
} }
return true; return true;
}; };
var compile = function (stage) var compile = function (stage)
{ {
var element = IDOMElement(stage); var element = IDOMElement(stage);
return "[acquirelib]" + element.getDAttribute("value") + "[/acquirelib]"; return "[acquirelib]" + element.getDAttribute("value") + "[/acquirelib]";
}; };

View File

@ -19,17 +19,17 @@
var html = function( insertSnippet, snippetWrap, createContext, override ) var html = function( insertSnippet, snippetWrap, createContext, override )
{ {
var temp, i, j var temp, i, j
, handler = function () , handler = function ()
{ {
// Input fields // Input fields
var v_snippetInput = Dand.wrap( "textarea", null, "v_snippet_input" ); var v_snippetInput = Dand.wrap( "textarea", null, "v_snippet_input" );
if ( this._stage ) if ( this._stage )
{ {
v_snippetInput.value = this._code; v_snippetInput.value = this._code;
} }
// Popup MessageBox // Popup MessageBox
new MessageBox( new MessageBox(
"Insert Html snippet" "Insert Html snippet"
@ -38,14 +38,13 @@
, visualizer.bind({ code: v_snippetInput, stage: this._stage }) , visualizer.bind({ code: v_snippetInput, stage: this._stage })
).show(); ).show();
} }
, visualizer = function( submitted, override ) , visualizer = function( submitted, override )
{ {
var code, stage = this.stage; var code, stage = this.stage;
code = override ? unescapeStr( override.value ) : this.code.value; code = override ? unescapeStr( override.value ) : this.code.value;
if (submitted && code) if (submitted && code)
{ {
if (!stage) if (!stage)
@ -67,22 +66,22 @@
else else
{ {
IDOMElement( stage ).setAttribute(new DataKey( "value", code )); IDOMElement( stage ).setAttribute(new DataKey( "value", code ));
temp = stage.firstChild; temp = stage.firstChild;
temp.removeChild(temp.firstChild); temp.removeChild(temp.firstChild);
stage.firstChild.appendChild(Dand.textNode( code )); stage.firstChild.appendChild(Dand.textNode( code ));
temp = stage; temp = stage;
} }
i = { _code: code, _stage: temp }; i = { _code: code, _stage: temp };
// Set context menu // Set context menu
createContext( i, j, handler ); createContext( i, j, handler );
} }
}; };
if ( override ) if ( override )
{ {
visualizer( true, override ); visualizer( true, override );
@ -92,10 +91,10 @@
{ {
return handler; return handler;
} }
return true; return true;
}; };
var compile = function (stage) var compile = function (stage)
{ {
// [html][/html] // [html][/html]

View File

@ -0,0 +1,105 @@
(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" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
var meta = function( insertSnippet, snippetWrap, createContext, override )
{
var temp, i, j
, handler = function ()
{
// Input fields
var v_snippetInput = Dand.wrap( "textarea", null, "v_snippet_input" );
if ( this._stage )
{
v_snippetInput.value = this._code;
}
// Popup MessageBox
new MessageBox(
"Insert Meta Tags"
, v_snippetInput
, "OK", "Cancel"
, visualizer.bind({ code: v_snippetInput, stage: this._stage })
).show();
}
, visualizer = function( submitted, override )
{
var code, stage = this.stage;
code = override ? unescapeStr( override.value ) : this.code.value;
if (submitted && code)
{
if (!stage)
{
// Visualize component
temp = Dand.wrap(
'span', null, "flsf"
, "Meta Tags"
, [
new DataKey( "value", code )
, new IKey(
"style", "background-color: #444; color: white; padding: 0.2em 0.5em;"
)
]
);
insertSnippet(j = snippetWrap( "Meta", temp, false, "span" ), Boolean(override));
}
else
{
IDOMElement( stage ).setAttribute(new DataKey( "value", code ));
temp = stage.firstChild;
temp.removeChild(temp.firstChild);
stage.firstChild.appendChild(Dand.textNode( code ));
temp = stage;
}
i = { _code: code, _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)
{
return "[meta]" + escapeStr( IDOMElement(stage).getDAttribute("value") ) + "[/meta]";
};
__static_method( meta, "compile", compile );
ns[ NS_EXPORT ]( EX_CLASS, "Meta", meta );
})();

View File

@ -27,20 +27,21 @@
var Config = __import( "Astro.Blog.Config" ); var Config = __import( "Astro.Blog.Config" );
var snippetList = IKey.quickDef( var snippetList = IKey.quickDef(
"Code" , "background: white; color: cornflowerblue;" "Code" , "background: white; color: cornflowerblue;"
, "Image" , "background: #ff0084;" , "Image" , "background: #ff0084;"
, "Sound" , "background: YellowGreen;" , "Sound" , "background: YellowGreen;"
, "Video" , "background: Crimson;" , "Video" , "background: Crimson;"
, "Spoiler" , "background: cornflowerblue;" , "Spoiler" , "background: cornflowerblue;"
, "Swf" , "background: #333;" , "Swf" , "background: #333;"
, "Link" , "background: blue;" , "Link" , "background: blue;"
, "AcquireLib" , "background: black;" , "AcquireLib" , "background: black;"
, "Html" , "background: coral;" , "Html" , "background: coral;"
, "SiteFile" , "background: royalblue;" , "SiteFile" , "background: royalblue;"
, "Heading" , "" , "Heading" , ""
, "Footnote" , "" , "Footnote" , ""
, "ArticleLink" , "" , "Meta" , ""
, "ArticleContent" , "" , "ArticleLink" , ""
, "ArticleContent" , ""
); );
var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet."; var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet.";