From a5e0be3221e00a58e6158e7e0b0c9b164617c8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Mon, 6 Mar 2017 20:28:39 +0800 Subject: [PATCH] Added Meta Snippet --- .../Visualizer/Snippet/AcquireLib.js | 37 +++--- .../Blog/AstroEdit/Visualizer/Snippet/Html.js | 29 +++-- .../Blog/AstroEdit/Visualizer/Snippet/Meta.js | 105 ++++++++++++++++++ .../Astro/Blog/AstroEdit/Visualizer/_this.js | 29 ++--- 4 files changed, 150 insertions(+), 50 deletions(-) create mode 100644 botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Meta.js diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/AcquireLib.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/AcquireLib.js index f4d29f3..b7ab016 100644 --- a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/AcquireLib.js +++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/AcquireLib.js @@ -13,21 +13,21 @@ /** @type {Components.MessageBox} */ var MessageBox = __import( "Components.MessageBox" ); - + var acquirelib = function(insertSnippet, snippetWrap, createContext, override) { var temp, i, j - + , handler = function () { // Input fields var input_text = Dand.wrap('input', null, "v_snippet_input_single", null, new IKey("type", "text")); - + if (this._stage) { input_text.value = this._text; } - + // Popup MessageBox new MessageBox( "Acquire library" + ( this._stage ? " (Edit)" : "" ) @@ -36,26 +36,23 @@ , visualizer.bind({ text:input_text, stage: this._stage }) ).show(); } - + , visualizer = function (submitted, override) { var src = override ? override.value : this.text.value , stage = this.stage; - + if (submitted && src) { // Shared clause - + if (!stage) { if (!src) return; - - + // Visualize component temp = Dand.wrap( - 'span' - , null - , "flsf" + 'span', null, "flsf" , "AcquireLib: " + src , [ new DataKey( "value", src ) @@ -69,22 +66,21 @@ else { IDOMElement(stage).setAttribute( new DataKey("value", src) ); - + stage.removeChild(stage.firstChild); stage.appendChild(Dand.textNode("AcquireLib: " + src)); - + // set temp back to stage temp = stage; } - + i = {_text: src, _stage: temp}; - + // Set context menu createContext(i, j, handler); } - } - ; - + }; + if (override) { visualizer(true, override); @@ -96,11 +92,10 @@ } return true; }; - + var compile = function (stage) { var element = IDOMElement(stage); - return "[acquirelib]" + element.getDAttribute("value") + "[/acquirelib]"; }; diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Html.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Html.js index ad01f10..35a2ab9 100644 --- a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Html.js +++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Html.js @@ -19,17 +19,17 @@ var html = 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 Html snippet" @@ -38,14 +38,13 @@ , 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) @@ -67,22 +66,22 @@ 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 ); @@ -92,10 +91,10 @@ { return handler; } + return true; - }; - + var compile = function (stage) { // [html][/html] diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Meta.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Meta.js new file mode 100644 index 0000000..62d1ffc --- /dev/null +++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Meta.js @@ -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 ); +})(); diff --git a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js index 0e85f6c..414d6f9 100644 --- a/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js +++ b/botanjs/src/Astro/Blog/AstroEdit/Visualizer/_this.js @@ -27,20 +27,21 @@ var Config = __import( "Astro.Blog.Config" ); var snippetList = IKey.quickDef( - "Code" , "background: white; color: cornflowerblue;" - , "Image" , "background: #ff0084;" - , "Sound" , "background: YellowGreen;" - , "Video" , "background: Crimson;" - , "Spoiler" , "background: cornflowerblue;" - , "Swf" , "background: #333;" - , "Link" , "background: blue;" - , "AcquireLib" , "background: black;" - , "Html" , "background: coral;" - , "SiteFile" , "background: royalblue;" - , "Heading" , "" - , "Footnote" , "" - , "ArticleLink" , "" - , "ArticleContent" , "" + "Code" , "background: white; color: cornflowerblue;" + , "Image" , "background: #ff0084;" + , "Sound" , "background: YellowGreen;" + , "Video" , "background: Crimson;" + , "Spoiler" , "background: cornflowerblue;" + , "Swf" , "background: #333;" + , "Link" , "background: blue;" + , "AcquireLib" , "background: black;" + , "Html" , "background: coral;" + , "SiteFile" , "background: royalblue;" + , "Heading" , "" + , "Footnote" , "" + , "Meta" , "" + , "ArticleLink" , "" + , "ArticleContent" , "" ); var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet.";