Spoiler Code Help

I’d like to add something to this spoiler code which would allow a Show All/Hide All functionality.

If you take a look at http://blog.credoreference.com/2010/12/credo-reference-friday-brainteaser-–-who-wrote-that-music/, you can see that currently, all the spoiler links work individually. Is there any way I could add something which allow me to create one link on the page which would Show All/Hide All the answers when clicked?

Thanks!

[code]*/

// add filter hook
add_filter(‘the_content’, ‘yk_spoiler’, 2);
add_filter(‘the_content’, ‘yk_spoiler2’, 2);
add_filter(‘comment_text’, ‘yk_spoiler’, 4);
add_filter(‘comment_text’, ‘yk_spoiler2’, 4);

function yk_spoiler($content)
{
srand((double) microtime()100000);
return preg_replace_callback(
"%<spoiler.
(?:’([^’])’)?\s(?:’([^’])’)?\s>(.*)%isU",
“yk_callback”,
$content);
}

function yk_spoiler2($content)
{
srand((double) microtime()100000);
return preg_replace_callback(
"%[spoiler.
(?:/([^’/])/)?\s(?:/([^’/])/)?\s](.*)[/spoiler]%isU",
“yk_callback”,
$content);
}

function yk_callback($m)
{
// show and hide text
$spoiler_show_text = ($m[1] ? $m[1]." ▼" : “Show the Answer ▼”);
$spoiler_hide_text = ($m[2] ? $m[2]." ▲" : “Hide the Answer ▲”);
$rand = “SID”.rand();
return “<a href=“javascript:void(null);” onclick=“s_toggleDisplay(document.getElementById(’”.$rand.”’), this, ‘$spoiler_show_text’, ‘$spoiler_hide_text’);">$spoiler_show_text\n

\n".
$m[3]."\n
";
}

function add_spoiler_header($text)
{
echo "
";
return $text;
}

add_action(‘wp_head’, ‘add_spoiler_header’);
?>[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service