forked from Botanical/BotanJS
98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
(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 {function(...?): Dandelion.IDOMElement} */
|
|
var IDOMElement = __import( "Dandelion.IDOMElement" );
|
|
/** @type {typeof Dandelion} */
|
|
var Dand = __import( "Dandelion" );
|
|
/** @type {Components.MessageBox} */
|
|
var MessageBox = __import( "Components.MessageBox" );
|
|
|
|
var unescapeStr = ns[ NS_INVOKE ]( "unescapeStr" );
|
|
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
|
|
|
|
var footnote = 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._mText;
|
|
}
|
|
|
|
// Popup MessageBox
|
|
new MessageBox(
|
|
"Insert Footnote"
|
|
, v_snippetInput
|
|
, "OK", "Cancel"
|
|
, visualizer.bind({ mText: v_snippetInput, stage: this._stage })
|
|
).show();
|
|
}
|
|
|
|
, visualizer = function( submitted, override )
|
|
{
|
|
var mText, stage = this && this.stage;
|
|
|
|
mText = override ? unescapeStr( override.value ) : this.mText.value;
|
|
|
|
if (submitted && mText)
|
|
{
|
|
if (!stage)
|
|
{
|
|
// Visualize component
|
|
temp = Dand.wrapne( "span", "^", [
|
|
new DataKey( "value", mText )
|
|
]);
|
|
|
|
insertSnippet(
|
|
j = snippetWrap( "Footnote", temp, false, "span" )
|
|
, Boolean( override )
|
|
);
|
|
}
|
|
else
|
|
{
|
|
IDOMElement( stage ).setAttribute(new DataKey( "value", mText ));
|
|
temp = stage;
|
|
}
|
|
|
|
i = { _mText: mText, _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)
|
|
{
|
|
// [footnote][/footnote]
|
|
return "[footnote]" + escapeStr( IDOMElement(stage).getDAttribute("value") ) + "[/footnote]";
|
|
};
|
|
|
|
__static_method( footnote, "compile", compile );
|
|
|
|
ns[ NS_EXPORT ]( EX_CLASS, "Footnote", footnote );
|
|
})();
|