BotanJS/botanjs/src/Astro/Blog/Components/Spoiler.js
2015-08-14 21:42:25 +08:00

50 lines
1.2 KiB
JavaScript

(function(){
var ns = __namespace( "Astro.Blog.Components.Spoiler" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Astro.Bootstrap} */
var Bootstrap = __import( "Astro.Bootstrap" );
/** @type {Astro.Blog.Config} */
var Config = __import( "Astro.Blog.Config" );
var Spoiler = function( id )
{
var sp_stage = Dand.id( "spoiler_" + id );
var sp_display = ( sp_stage.nodeName == "span" ) ? "inline-block" : "block";
var ostage = IDOMElement( sp_stage );
var sp_title = ostage.first( "DIV" );
var sp_content = ostage.last( "DIV" );
sp_title.onclick = function ()
{
var s_style = sp_content.style;
if( s_style.display == sp_display )
{
s_style.display = "none";
sp_title.removeAttribute( "clicked" );
}
else
{
s_style.display = sp_display;
sp_title.setAttribute( "clicked", "" );
}
};
sp_stage.hasAttribute( "expanded" ) && sp_title.onclick();
};
var sps = Config.get( "Spoiler" );
Bootstrap.regInit(function() {
for( var i in sps )
{
new Spoiler( sps[i] );
}
});
})();