SmartInput for back quoted text

This commit is contained in:
2016-02-22 03:08:07 +08:00
parent 82451a41b9
commit 82ef981d0a
14 changed files with 297 additions and 50 deletions

View File

@@ -0,0 +1,12 @@
.v_boundary[data-inline="on"][data-type="Code"] {
display: inline-block;
background-color: #EEE;
}
.v_box[data-inline="on"] .v_description {
display: none;
}
.v_box[data-inline="on"] {
min-height: 0;
}

View File

@@ -14,6 +14,7 @@
var MessageBox = __import( "Components.MessageBox" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var code = function ( insertSnippet, snippetWrap, createContext, override )
{
@@ -34,7 +35,7 @@
, "JavaScript" , "js"
, "SQL" , "sql"
)
// Private methods
, compileListItems = function ()
{
@@ -55,7 +56,8 @@
{
// Input fields
var v_snippetInput = Dand.wrap( "textarea", null, "v_snippet_input" )
, v_codelang = Dand.wrap( "select", null, "v_select flsf", compileListItems() );
, v_codelang = Dand.wrap( "select", null, "v_select flsf", compileListItems() )
, input_inline = Dand.wrapna('input', new IKey("type", "checkbox") );
if ( this._stage )
{
@@ -69,8 +71,9 @@
}
}
}
v_snippetInput.value = this._content || "";
input_inline.checked = ( this._inline == "on" );
}
else
{
@@ -87,29 +90,31 @@
, [
Dand.wrapc( "v_instruction", v_codelang )
, v_snippetInput
, Dand.wrape([ input_inline, Dand.textNode( "Inline" ) ])
]
)
, "OK", "Cancel"
// Switcher
, visualizer.bind({ code:v_snippetInput, lang: v_codelang, stage: this._stage })
, visualizer.bind({ code:v_snippetInput, inline: input_inline, lang: v_codelang, stage: this._stage })
).show();
}
, visualizer = function ( submitted, override )
{
var lang, code
var lang, code, inline
, stage = this.stage;
if ( override )
{
lang = override.lang;
code = override.value;
inline = override.inline;
}
else
{
lang = this.lang[this.pSnippeCodeChoice = this.lang.selectedIndex].value;
code = this.code.value;
inline = this.inline.checked ? "on" : "";
}
var langName;
@@ -124,7 +129,7 @@
if ( submitted && code )
{
if (!stage)
if ( !stage )
{
// Visualize component
temp = Dand.wrapc(
@@ -136,8 +141,10 @@
, [
new DataKey( "value", code )
, new DataKey( "lang", lang )
, new DataKey( "inline", inline )
]
);
insertSnippet( j = snippetWrap( "Code", temp ), Boolean( override ) );
}
else
@@ -146,9 +153,10 @@
[
new DataKey( "value", code )
, new DataKey( "lang", lang )
, new DataKey( "inline", inline )
]
);
temp = stage.firstChild;
temp.removeChild( temp.firstChild );
stage.firstChild.appendChild( Dand.textNode( code ) );
@@ -160,9 +168,12 @@
temp = stage;
}
i = { _lang: lang, _content: code, _stage: temp };
i = { _inline: inline, _lang: lang, _content: code, _stage: temp };
// Set the inline style
IDOMElement( j ).setAttribute( new DataKey( "inline", inline ) );
// Set context menu
createContext( i, j, handler );
}
@@ -185,10 +196,11 @@
{
// [code lang=\"" + lang + "\"]" + code + "[/code]"
var element = IDOMElement( stage )
, lang = element.getDAttribute( "lang" );
, props= [ "lang", "inline" ];
return "[code"
+ (lang ? (" lang=\"" + lang + "\"") : "") + "]"
+ compileProp( element, props )
+ "]"
+ escapeStr( element.getDAttribute( "value" ) )
+ "[/code]"
;

View File

@@ -31,11 +31,11 @@
, input_preferred = Dand.wrapna('input', new IKey("type", "checkbox"))
;
if (this._stage)
if ( this._stage )
{
input_url.value = this._url;
input_a.value = this._href;
input_preferred.checked = (this._preferred == "on");
input_preferred.checked = ( this._preferred == "on" );
}
// Popup MessageBox

View File

@@ -37,8 +37,7 @@
, input_text
, Dand.wrapc("v_instruction flsf", "Link to:")
, input_a
]
)
])
, "OK", "Cancel", visualizer.bind({text:input_text, href:input_a, stage: this._stage})).show();
}
@@ -100,8 +99,7 @@
// Set context menu
createContext(i, j, handler);
}
}
;
};
if (override)
{