MyBB Community Forums

Full Version: Improve this Spoiler MyCode with Title
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need help on improving this MyCode for the spoiler tag.

I want it to support titles.

ex.

[spoiler=TITLE HERE]YOUR TEXT HERE[/spoiler]

Regular Expression
\[spoiler\](.*?)\[/spoiler\]

Replacement
<div><div style="margin-bottom:2px; font-size: 12px"><b>Spoiler</b>: <input type="button" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }">
</div>
<div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;">
<div style="display: none;">$1</div>
</div></div>
Create a new MyCode

[spoiler=TITLE HERE]YOUR TEXT HERE[/spoiler]

Regular Expression
\[spoiler=(.*?)\](.*?)\[/spoiler\]

Replacement
<div><div style="margin-bottom:2px; font-size: 12px"><b>Spoiler</b>: $1<input type="button" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onClick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }">
</div>
<div class="alt2" style="margin: 0px; padding: 6px; border: 1px inset;">
<div style="display: none;">$2</div>
</div></div>
I believe that code requires a title for it to work. I'd like it to work both ways.
I don't think you can do it for both in the same mycode, you need two.
Thanks so much for this. I was looking for a button spoiler that the user can customize! Smile I edited it so that the custom text is on the button instead of beside it and now it works perfectly!

Thanks again and +1 Omar