Spoiler Macro

This is a Velocity macro, which isn't bundled with any XWiki product by default.
Macro contributed by Thomas Eveilleau.
This macro cannot currently be downloaded separately.

Spoiler Macro

Allow you to add hidden elements in the content of a page

Usage

#spoilerInit()  ## Allow you to add as many #spoiler() as you want on a page

#spoiler("Link text" "Hidden content")

Parameters definition

For #spoilerInit()

Warning: No parameters

For #spoiler()

NameOptionalAllowed valuesDefault valueDescription
Link textnostring / imagenoneText on which users will click to display the hidden part
Hidden contentnostring / imagenoneHidden content

Example

#spoilerInit()

#spoiler("Show me the truth" "At the end of the last episode of Lost season 3, Jack is attacked by 3 bears coming from Jupiter !")

Result

lostspoiler.png

Installation

This a Velocity macro. Since it's not bundled by default you'll have to copy/paste the following code to use it:

#macro(spoilerInit)
#set ($i = 0)
<script>
function visibilite(thingId)
{
var targetElement;
targetElement = document.getElementById(thingId) ;
if (targetElement.style.display == "none")
{
targetElement.style.display = "" ;
} else {
targetElement.style.display = "none" ;
}
}
</script>
#end

#macro(spoiler $linktext $hiddentext) <a href="javascript:visibilite('spoiler_$i');">$linktext</a> <div id="spoiler_$i" style="display:none;border:1px solid grey;background-color:#FEFF9F;padding:5px;font-style:italic;">$hiddentext</div> #set ($i = $i + 1) #end

Tags:
Created by Thomas Eveilleau on 2008/05/06 18:32
Last modified by Vincent Massol on 2008/09/30 10:15

This wiki is licensed under a Creative Commons license
2.2.1.27354