MyBB Community Forums

Full Version: [MyCode] Spoiler with names
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2012-12-12, 01:00 PM)Beardy Wrote: [ -> ]Can anybody actually see my first post in this thread or is it simply invisible?

Instead of being rude, why not just post the code for that MyCode (instead of a picture that hides part of the code) so that I and others might actually learn something instead of just having the satisfying feeling of being wrong? :s
(2012-12-12, 10:49 PM)Wildcard Wrote: [ -> ]
(2012-12-12, 01:00 PM)Beardy Wrote: [ -> ]Can anybody actually see my first post in this thread or is it simply invisible?

Instead of being rude, why not just post the code for that MyCode (instead of a picture that hides part of the code) so that I and others might actually learn something instead of just having the satisfying feeling of being wrong? :s

You quoted me in a post where I explicitly mention my first post and you still managed to ignore it? Go and read it, I provided the MyCode about three hours before that post. Don't blame me for your ignorance and oversight, next time try actually paying more attention.

Just in case you're still struggling, you can find it here.
The replacement would be nice. [Image: facepalm.gif]

You think that I am being snippy, but I am not. I tried to make a MyCode to handle both titled and non-titled spoilers for a long time (see http://community.mybb.com/thread-125946.html ) and would really like to see how it works, but you keep droning on about your first post and a question mark after an equals sign . . .

Okay, lesson 1 is learned . . . can I just haz the replacement plox?
(2012-12-12, 11:13 PM)Wildcard Wrote: [ -> ]Okay, lesson 1 is learned . . . can I just haz the replacement plox?

I didn't change the replacement, you can use the same replacement from OPs post. The reason it works fine for his is because he has a 'show/hide' button alongside the title, whereas you're using the title as the 'show' button.

I'm sure with enough javascript a blank title could be replaced with the word 'Show'.



Edit: done it for you:

Regular Expression:
\[spoiler=?([^'^"^\\]*?)\](.*?)\[/spoiler\]
When placing the caret (^) before a character inside a character set, it excludes that character from the selection range, meaning you end up with a 'match all except X, Y or Z' regular expression.

Replacement:
<div><div style="height:20px;margin-bottom:2px; font-size: 12px"><input id="spoiler_title_$1" type="button" value="$1" style="font-size: 14px; margin: 0px; padding: 3px;" onClick="var spoiler_title = ('$1'.length) ? '$1' : 'Show'; 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 = spoiler_title; }"><script type='text/javascript'>document.getElementById("spoiler_title_").value = "Show"; document.getElementById("spoiler_title_").id = "";</script>
</div>
<div class="alt2" style="margin: 0px; padding: 6px;">
<div style="display: none;">$2</div>
</div></div>

This should allow any title that doesn't include quotes or a backslash. Spoilers with blank titles will be replaced with 'Show'.

Basically, I added id="spoiler_title_$1" so that if no input was passed for $1, the ID would end up as 'spoiler_title_'. I then added some javascript to set the value of the element with that ID as "Show" and clear the ID so it doesn't clash with any more non-titled spoilers the user might add.

Inside the onClick, it was just a case of using a ternary operator to see if '$1' was blank and setting the variable as 'Show' instead.

I could look into getting nested spoilers to work too, but not right now.
Thanks and +1 you grumpy genius Big Grin

Seriously, that is clever.

(2012-12-12, 11:45 PM)Beardy Wrote: [ -> ]I could look into getting nested spoilers to work too, but not right now.

I really don't think it is possible and your code above just gives me another reason to stick with my custom spoiler plugin. Relying that heavily on JavaScript is cool in theory, but with the plugin the logic is simpler and nesting is easy.

Thanks again Beardy (and apologies to the OP for thread hijacking Sad )
(2012-12-13, 01:24 PM)Wildcard Wrote: [ -> ]I really don't think it is possible

I'm inclined to agree. The little I tried to make it work just brought up problems with the parsing order.

(2012-12-13, 01:24 PM)Wildcard Wrote: [ -> ]grumpy

I guess I can be a little blunt and forward at times, but I enjoy sarcasm way too much to change.
The one I run on ZEJ uses pure HTML and CSS, and sort of supports nesting. There's a few bugs to do with nesting named spoilers (ie it doesn't seem to work. At all.), but as I did it with two MyCodes with the same tag, JS wasn't necessary, only a few modifications to the first one was. Nesting otherwise works, however. I'll post a thread with mine!
Pages: 1 2