forked from Botanical/BotanJS
Astro Classes
This commit is contained in:
131
botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Link.js
Normal file
131
botanjs/src/Astro/Blog/AstroEdit/Visualizer/Snippet/Link.js
Normal file
@@ -0,0 +1,131 @@
|
||||
(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 link = 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"))
|
||||
, input_a = Dand.wrap('input', null, "v_snippet_input_single", null, new IKey("type", "text"));
|
||||
|
||||
if (this._stage)
|
||||
{
|
||||
input_text.value = this._text;
|
||||
input_a.value = this._href;
|
||||
}
|
||||
|
||||
// Popup MessageBox
|
||||
new MessageBox(
|
||||
(this._stage ? "Edit" : "Insert") + " link",
|
||||
Dand.wrape([
|
||||
Dand.wrapc("v_instruction flsf", "Text")
|
||||
, 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();
|
||||
}
|
||||
|
||||
, visualizer = function (submitted, override)
|
||||
{
|
||||
var src, href
|
||||
, stage = this.stage;
|
||||
|
||||
if (override)
|
||||
{
|
||||
src = override.value;
|
||||
href = override.href;
|
||||
}
|
||||
else
|
||||
{
|
||||
src = this.text.value;
|
||||
href = this.href.value;
|
||||
}
|
||||
|
||||
if (submitted && src && href)
|
||||
{
|
||||
|
||||
// Shared clause
|
||||
|
||||
if (!stage)
|
||||
{
|
||||
if (!src) return;
|
||||
|
||||
|
||||
// Visualize component
|
||||
temp =
|
||||
Dand.wrapne('span', src
|
||||
, [
|
||||
new DataKey("value", src)
|
||||
, new DataKey("href", href)
|
||||
]
|
||||
);
|
||||
insertSnippet(j = snippetWrap("Link", temp, false, 'span'), Boolean(override));
|
||||
}
|
||||
else
|
||||
{
|
||||
IDOMElement(stage).setAttribute
|
||||
(
|
||||
[
|
||||
new DataKey("value", src)
|
||||
, new DataKey("href", href)
|
||||
]
|
||||
);
|
||||
|
||||
stage.removeChild(stage.firstChild);
|
||||
stage.appendChild(Dand.textNode(src));
|
||||
|
||||
// set temp back to stage
|
||||
temp = stage;
|
||||
}
|
||||
|
||||
i = {_text: src, _href: href, _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)
|
||||
{
|
||||
// [link href=\"" + this.href.value + "\"]" + text + "[/link]
|
||||
var element = IDOMElement(stage)
|
||||
, href = element.getDAttribute("href");
|
||||
|
||||
return "[link" + (href ? (" href=\"" + href + "\"") : "") + "]" + element.getDAttribute("value") + "[/link]";
|
||||
};
|
||||
|
||||
|
||||
__static_method( link, "compile", compile );
|
||||
|
||||
ns[ NS_EXPORT ]( EX_CLASS, "Link", link );
|
||||
})();
|
Reference in New Issue
Block a user