forked from Botanical/BotanJS
Heading snippet
This commit is contained in:
177
botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Heading.js
Normal file
177
botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Heading.js
Normal file
@@ -0,0 +1,177 @@
|
||||
(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 compileProp = ns[ NS_INVOKE ]( "compileProp" );
|
||||
|
||||
var heading = function ( insertSnippet, snippetWrap, createContext, override )
|
||||
{
|
||||
var temp, i, j
|
||||
, Sizes = IKey.quickDef(
|
||||
"h1", "h1"
|
||||
, "h2", "h2"
|
||||
, "h3", "h3"
|
||||
, "h4", "h4"
|
||||
, "h5", "h5"
|
||||
)
|
||||
|
||||
// Private methods
|
||||
, compileListItems = function ()
|
||||
{
|
||||
var arr = [];
|
||||
for ( i in Sizes )
|
||||
{
|
||||
arr[ arr.length ] = Dand.wrapne(
|
||||
"option"
|
||||
, Sizes[i].keyName
|
||||
, new IKey( "value", Sizes[i].keyValue )
|
||||
);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Snippet Class structure: handler & visualizer
|
||||
, handler = function ()
|
||||
{
|
||||
// Input fields
|
||||
var v_snippetInput = Dand.wrap('input', null, "v_snippet_input_single", null, new IKey("type", "text") )
|
||||
, v_headingsize = Dand.wrap( "select", null, "v_select flsf", compileListItems() );
|
||||
|
||||
if ( this._stage )
|
||||
{
|
||||
if ( this._size )
|
||||
{
|
||||
for ( i = 0; i < Sizes.length; i ++ )
|
||||
{
|
||||
if ( Sizes[i].keyValue == this._size )
|
||||
{
|
||||
v_headingsize.selectedIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v_snippetInput.value = this._content || "";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remember the last choice
|
||||
if ( typeof( this.pSnippeHeadingChoice ) == "number" )
|
||||
v_headingsize.selectedIndex = this.pSnippeHeadingChoice;
|
||||
}
|
||||
|
||||
// Popup MessageBox
|
||||
new MessageBox(
|
||||
( this._stage ? "Edit" : "Insert" ) + " heading text"
|
||||
, Dand.wrapc(
|
||||
"v_trimmer"
|
||||
, [
|
||||
v_snippetInput
|
||||
, Dand.wrapc( "v_instruction", v_headingsize )
|
||||
]
|
||||
)
|
||||
, "OK", "Cancel"
|
||||
// Switcher
|
||||
, visualizer.bind({ heading:v_snippetInput, size: v_headingsize, stage: this._stage })
|
||||
).show();
|
||||
}
|
||||
|
||||
, visualizer = function ( submitted, override )
|
||||
{
|
||||
var size, heading
|
||||
, stage = this.stage;
|
||||
|
||||
if ( override )
|
||||
{
|
||||
size = override.size;
|
||||
heading = override.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = this.size[this.pSnippeHeadingChoice = this.size.selectedIndex].value;
|
||||
heading = this.heading.value;
|
||||
}
|
||||
|
||||
var size;
|
||||
for( var i in Sizes )
|
||||
{
|
||||
if( Sizes[i].keyValue == size )
|
||||
{
|
||||
size = Sizes[i].keyName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( submitted && heading )
|
||||
{
|
||||
if ( !stage )
|
||||
{
|
||||
// Visualize component
|
||||
temp = Dand.wrapne( "span", Dand.wrapne( size, heading ), [
|
||||
new DataKey( "value", heading )
|
||||
, new DataKey( "size", size )
|
||||
]);
|
||||
|
||||
insertSnippet( j = snippetWrap( "Heading", temp ), Boolean( override ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
IDOMElement( stage ).setAttribute([
|
||||
new DataKey( "value", heading )
|
||||
, new DataKey( "size", size )
|
||||
]);
|
||||
|
||||
stage.removeChild( stage.firstChild );
|
||||
stage.appendChild( Dand.wrapne( size, heading ) );
|
||||
|
||||
temp = stage;
|
||||
}
|
||||
|
||||
i = { _size: size, _content: heading, _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 )
|
||||
{
|
||||
var element = IDOMElement( stage )
|
||||
, props = [ "size" ];
|
||||
|
||||
return "[heading"
|
||||
+ compileProp( element, props )
|
||||
+ "]"
|
||||
+ escapeStr( element.getDAttribute( "value" ) )
|
||||
+ "[/heading]"
|
||||
;
|
||||
};
|
||||
|
||||
__static_method( heading, "compile", compile );
|
||||
|
||||
ns[ NS_EXPORT ]( EX_CLASS, "Heading", heading );
|
||||
})();
|
@@ -37,6 +37,7 @@
|
||||
, "AcquireLib" , "background: black;"
|
||||
, "Html" , "background: coral;"
|
||||
, "SiteFile" , "background: royalblue;"
|
||||
, "Heading" , ""
|
||||
);
|
||||
|
||||
var snippetNs = "Astro.Blog.AstroEdit.Visualizer.Snippet.";
|
||||
|
Reference in New Issue
Block a user