Help with Spoiler Tag for 1.1 Beta 3

Started by Yonkey, September 15, 2005, 03:07:12 PM

Previous topic - Next topic

Yonkey

I am trying to make a custom bbc spoiler tag for 1.1 Beta 3, but I don't want it to be dependant on the faster parsecode mod.  Everything is working great so far when there's only one spoiler per page.  When there's more than one, I need to be able to give each div a unique id in order for the JavaScript to know which div to hide or not.  I'm not sure how to set this unique id variable.

Here is my mod so far:


<edit file>
$themedir/index.template.php
</edit file>

<search>
   // ]]></script>
   <title>', $context['page_title'], '</title>
</search>

<replace>
   // ]]></script>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function visi(nr)
{
   if (document.layers)
   {
      vista = (document.layers[nr].visibility == \'hide\') ? \'show\' : \'hide\'
      document.layers[nr].visibility = vista;
   }
   else if (document.all)
   {
      vista = (document.all[nr].style.visibility == \'hidden\') ? \'visible\'   : \'hidden\';
      document.all[nr].style.visibility = vista;
   }
   else if (document.getElementById)
   {
      vista = (document.getElementById(nr).style.visibility == \'hidden\') ? \'visible\' : \'hidden\';
      document.getElementById(nr).style.visibility = vista;

   }
}

function show(nr)
{
   if (document.layers)
   {
      document.layers[nr].visibility = \'show\';
   }
   else if (document.all)
   {
      document.all[nr].style.visibility = \'visible\';
   }
   else if (document.getElementById)
   {
      document.getElementById(nr).style.visibility = \'visible\';
   }
}

function hide(nr)
{
   if (document.layers)
   {
      document.layers[nr].visibility = \'hide\';
   }
   else if (document.all)
   {
      document.all[nr].style.visibility = \'hidden\';
   }
   else if (document.getElementById)
   {
      document.getElementById(nr).style.visibility = \'hidden\';
   }
}
// -->
</SCRIPT>
   <title>', $context['page_title'], '</title>
</replace>

<edit file>
Sources/Subs.php
</edit file>

<search>
   static $bbc_codes = array(), $itemcodes = array(), $disabled;
</search>

<replace>
   static $bbc_codes = array(), $itemcodes = array(), $disabled;
   static $fseed = 0;
</replace>

<search>
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</search>
<replace>
         array(
            'tag' => 'spoiler',
            'before' => '<div class="quoteheader"><span style="color: #FFCC00;" onClick="visi(\'fade' . $fseed . '\');">Spoiler (mouse over to reveal):</span></div><div class="quote" onMouseOver="show(\'fade' . $fseed .'\');" onMouseOut="hide(\'fade' . $fseed . '\');"><div id="fade' . $fseed . '" width="100%" style="visibility: hidden;" onClick="show(\'fade' . $fseed . '\');" onMouseOver="show(\'fade' . $fseed++ . '\');">',
            'after' => '</div></div>',
            'disallow_children' => array('spoiler'),
            'block_level' => true,
         ),
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</replace>


However, $fseed is always 0, resulting in JavaScript errors.

Yonkey

I just tried adding:

<search>
         $message = substr($message, 0, $pos) . $tag['before'] . substr($message, $pos1);
</search>
<replace>
         if ($tag['tag'] == 'spoiler')
            $fseed++;
         $message = substr($message, 0, $pos) . $tag['before'] . substr($message, $pos1);
</replace>


But it had no effect.  Does anyone know where each tag gets processed?  If I can find that, I could add $fseed++; just before it.

Thanks :)

Yonkey

Thanks to azatoth, I was able to get a spoiler tag without having to worry about ID's! :D  You can see it in action over here: http://www.kqix.com/forum/index.php?topic=2727.msg116647#msg116647

And here's the code:

<edit file>
Sources/Subs.php
</edit file>

<search>
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</search>
<replace>
         array(
            'tag' => 'spoiler',
            'before' => '<fieldset class="quoteheader" onMouseOver="this.lastChild.style.display = \'block\';" onMouseOut="this.lastChild.style.display=\'none\'"><legend class="quoteheader" style="color: #FFCC00;">Spoiler (mouse over to reveal):</legend><div class="quote" style="display:none">',
            'after' => '</div></fieldset>',
            'disallow_children' => array('spoiler'),
            'block_level' => true,
         ),
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</replace>


Enjoy! :)

Delayed

Quote from: Yonkey on September 20, 2005, 04:10:40 PM
Thanks to azatoth, I was able to get a spoiler tag without having to worry about ID's! :D  You can see it in action over here: http://www.kqix.com/forum/index.php?topic=2727.msg116647#msg116647 [nofollow]

And here's the code:

<edit file>
Sources/Subs.php
</edit file>

<search>
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</search>
<replace>
         array(
            'tag' => 'spoiler',
            'before' => '<fieldset class="quoteheader" onMouseOver="this.lastChild.style.display = \'block\';" onMouseOut="this.lastChild.style.display=\'none\'"><legend class="quoteheader" style="color: #FFCC00;">Spoiler (mouse over to reveal):</legend><div class="quote" style="display:none">',
            'after' => '</div></fieldset>',
            'disallow_children' => array('spoiler'),
            'block_level' => true,
         ),
         array(
            'tag' => 'sub',
            'before' => '<sub>',
            'after' => '</sub>',
         ),
</replace>


Enjoy! :)

Here is another option if some people don't want the mouse over.  This works in RC2.  I am on a Mac but I would imagine it will work on a PC.

Replacing it with the below code will put Spoiler: in front of blackened out text that just needs to be highlighted to reveal the spoiler.


<replace>
              array(
            'tag' => 'spoiler',
            'before' =>'<b>Spoiler:</b> <FONT style="BACKGROUND-COLOR: black;">',
            'after' => '</FONT>',
         ),
</replace>

Advertisement: