Various bug fixes & Preferred option for SiteFile

This commit is contained in:
2015-10-27 07:50:11 +08:00
parent 1b11a1dff0
commit 07ceb117da
9 changed files with 153 additions and 83 deletions

View File

@@ -13,6 +13,8 @@
/** @type {Components.MessageBox} */
var MessageBox = __import( "Components.MessageBox" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var image = function( insertSnippet, snippetWrap, createContext, override )
{
var temp, i, j
@@ -25,12 +27,15 @@
)
, input_a = Dand.wrap(
"input", null, "v_snippet_input_single", null, new IKey( "type", "text" )
);
)
, input_preferred = Dand.wrapna('input', new IKey("type", "checkbox"))
;
if (this._stage)
{
input_url.value = this._url;
input_a.value = this._href;
input_preferred.checked = (this._preferred == "on");
}
// Popup MessageBox
@@ -41,27 +46,30 @@
, input_url
, Dand.wrapc( "v_instruction flsf", "Ancohr link(optional):" )
, input_a
, Dand.wrape([ input_preferred, Dand.textNode( "Preferred" ) ])
]
)
, "OK", "Cancel"
, visualizer.bind({ url:input_url, href:input_a, stage: this._stage })
, visualizer.bind({ url:input_url, href:input_a, stage: this._stage, preferred: input_preferred })
).show();
}
, visualizer = function ( submitted, override )
{
var src, href
var src, href, preferred
, stage = this.stage;
if ( override )
{
src = override.value;
href = override.href;
preferred = override.preferred ? "on" : "";
}
else
{
src = this.url.value;
href = this.href.value;
preferred = this.preferred.checked ? "on" : "";
}
if ( submitted && src )
@@ -82,16 +90,17 @@
Dand.wrapna(
"img"
, [
new IKey("src", src)
, new IKey("style", "max-width: 100%")
new IKey( "src", src )
, new IKey( "style", "max-width: 100%" )
]
)
// caption
, Dand.wrapc( "v_description", i )
]
, [
new DataKey("value", src)
, new DataKey("href", href)
new DataKey( "value", src )
, new DataKey( "href", href )
, new DataKey( "preferred", preferred )
]
);
insertSnippet( j = snippetWrap( "Image", temp ), Boolean( override ) );
@@ -102,6 +111,7 @@
([
new DataKey( "value", src )
, new DataKey( "href", href )
, new DataKey( "preferred", preferred )
]);
stage.firstChild.setAttribute("src", src);
@@ -114,7 +124,12 @@
temp = stage;
}
i = { _url: src, _href: href, _stage: temp };
i = {
_url: src
, _href: href
, _preferred: preferred || "off"
, _stage: temp
};
// Set context menu
createContext( i, j, handler );
@@ -138,10 +153,10 @@
{
// [img href=\"" + this.href.value + "\"]" + this.url.value + "[/img]
var element = IDOMElement( stage )
, href = element.getDAttribute( "href" );
, props = [ "href", "preferred" ]
return "[img"
+ ( href ? (" href=\"" + href + "\"") : "" )
+ compileProp( element, props )
+ "]"
+ element.getDAttribute( "value" ) + "[/img]"
;

View File

@@ -19,8 +19,8 @@
/** @type {Astro.utils.Date} */
var XDate = __import( "Astro.utils.Date" );
var escapeStr = ns[ NS_INVOKE ]( "escapeStr" );
var compileProp = ns[ NS_INVOKE ]( "compileProp" );
var getData = __import( "System.Net.getData" );
@@ -37,10 +37,27 @@
, handler = function ()
{
// Input fields
var v_snippetInput = Dand.wrap("input", null, "v_snippet_input_single", null, new IKey("type", "text"));
var v_snippetInput = Dand.wrap("input", null, "v_snippet_input_single", null, new IKey("type", "text"))
, input_preferred = Dand.wrapna('input', new IKey("type", "checkbox"))
;
if ( this._stage )
{
v_snippetInput.value = this._content;
input_preferred.checked = ( this._preferred == "on" );
}
// Popup MessageBox
new MessageBox("Insert site file", v_snippetInput, "OK", "Cancel", visualizer.bind({code: v_snippetInput})).show();
new MessageBox("Insert site file"
, Dand.wrape([
v_snippetInput
, Dand.wrape([ input_preferred, Dand.textNode( "Preferred" ) ])
])
, "OK", "Cancel", visualizer.bind({
code: v_snippetInput
, preferred: input_preferred
, stage: this._stage
})).show();
}
, __applyData = function (e)
@@ -143,33 +160,66 @@
, visualizer = function ( submitted, override )
{
var hash = override ? override.value : this.code.value
, _obj = {file: hash};
var hash, _obj, stage = this.stage;
if( override )
{
hash = override.value;
preferred = override.preferred ? "on" : "";
}
else
{
hash = this.code.value;
preferred = this.preferred.checked ? "on" : "";
}
_obj = { file: hash };
if ( submitted && hash )
{
// Visualize component
if (!stage)
{
temp = Dand.wrapc("v_box"
, [
Dand.wrape("Getting information from Server ...")
, Dand.wrapc("v_description", "Site file (hash): " + hash)
]
, [
new DataKey( "value", hash )
, new DataKey( "size", ( override && override.size ) || "large" )
, new IKey( "style", "max-height: 150px;" )
, new DataKey( "preferred", preferred )
]
);
temp = Dand.wrapc("v_box"
, [
Dand.wrape("Getting information from Server ...")
, Dand.wrapc("v_description", "Site file (hash): " + hash)
]
, [
// Get data from site library
getData( config.path.info + hash, __applyData.bind({stage: temp, hash: hash}), loadFailed );
insertSnippet(
j = snippetWrap( "SiteFile", temp )
, !!override
);
}
else
{
IDOMElement( stage ).setAttribute([
new DataKey( "value", hash )
, new DataKey( "size", ( override && override.size ) || "large" )
, new IKey( "style", "max-height: 150px;" )
]
);
, new DataKey( "preferred", preferred )
]);
getData( config.path.info + hash, __applyData.bind({stage: temp, hash: hash}), loadFailed );
}
// Get data from site library
getData( config.path.info + hash, __applyData.bind({stage: temp, hash: hash}), loadFailed );
insertSnippet(j = snippetWrap("SiteFile", temp), Boolean(override));
// Set context menu
createContext(null, j);
}
i = {
_content: hash
, _preferred: preferred || "off"
, _stage: temp
};
// Set context menu
createContext( i, j, handler );
};
if (override)
@@ -199,6 +249,10 @@
{
options += " size=\"" + opt + "\"";
}
if( opt = stage.getDAttribute( "preferred" ) )
{
options += " preferred=\"" + opt + "\"";
}
return "[sitefile" + options + "]"
+ escapeStr( stage.getDAttribute( "value" ) )

View File

@@ -92,13 +92,11 @@
else
{
IDOMElement(stage).setAttribute
(
[
new DataKey("value", content)
, new DataKey("title", title)
, new DataKey("expanded", expanded)
]
);
([
new DataKey("value", content)
, new DataKey("title", title)
, new DataKey("expanded", expanded)
]);
temp = stage.firstChild;
temp.removeChild(temp.firstChild);