Not logged in. · Lost password · Register
Forum: Customising UNB Modifications and plug-ins RSS
New tag - spoiler
Problem with creating new tag
Avatar
Draghmar #1
Member since Dec 2006 · 63 posts
Group memberships: Members
Show profile · Link to this post
Subject: New tag - spoiler
I tried to create new tag called 'spoiler' because on my forum, we often wrote about films and games and their plots. But it's not the best idea to show something that someone shouldn't see before see it himself. I know that we can use something like this:

SPOILER - lookout!
This is text that you should not read.
The end of SPOILER

But this is not the best solution as you can read it involuntary...So I'd like to have this tag, that should look like this:

[spoiler]This is text that you should not read.[/spoiler]

And it should be converted to div with display: none and instead of it user should see link with some text like Click here to reveal great mysteries. Clicking it should change display: none to display: block with JS.

So where's the problem?
I have no idea how to add some variable to this tag to make it independent from others on page and in same post (id). It's needed for identification different divs so JS could be used. First I thought that I could use $postid or something but if someone will use more then one spoiler in post it will generate errors.
Could someone help me with this? If there is some better way to deal with this problem then I don't mind to use it. :-p

Off Topic:
Oh and Yves...Happy Birthday! :-D
"I have come up with a plan so cunning you could stick a tail on it and call it a weasel."
Avatar
Yves (Administrator) #2
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Thank you... ;)

Well, you could go two ways: Don't use a page-unique element ID to address the element you want to show. You can use DOM functions to find the previous <div> element before your <a> link and operate on that.

The other solution is to count an element ID per page. You'd need to find a nice place (= variable) where to put your counter in, and every time you create the HTML for your BBCode tag, you increase that counter by one. That makes page-unique element IDs by simply counting them. HTH
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
wetnun #3
Member since Nov 2008 · 4 posts · Location: California
Group memberships: Members
Show profile · Link to this post
Did anything ever happen with this?  I was looking at adding similar support to the forum I'm setting up.  I'm sure I can write something myself, but I like to be lazy if possible.  :)
Avatar
Draghmar #4
Member since Dec 2006 · 63 posts
Group memberships: Members
Show profile · Link to this post
No, sry. I was quite busy back then and latter I completely forgot about this. ;)
"I have come up with a plan so cunning you could stick a tail on it and call it a weasel."
wetnun #5
Member since Nov 2008 · 4 posts · Location: California
Group memberships: Members
Show profile · Link to this post
It's all good.  I spent like 10 minutes looking through the code and I figured out how to do it with only modifying the abbc.conf.php file.  Here's the unified diff.  Granted a very basic version, but if the only thing I have to do is edit a conf file then I'm very happy.  You can see it in action here: http://fable2mod.com/forums/forum.php?req=main

--- abbc.conf.php.orig  2008-11-08 02:09:23.000000000 -0500
+++ abbc.conf.php       2008-11-08 02:31:40.000000000 -0500
@@ -35,6 +35,9 @@
 // set of smilies (directory name)
 'smileset' => $ABBC['Config']['smileset'],

+// counter for custom cuts
+'cut_count' => 0,
+
 // some tag's parameters (was more once, is now in ABBC CSS file)
 'custom_a' => false
 );
@@ -339,6 +342,22 @@
 'subset'     => ABBC_SIMPLE
 ),

+'cut' => array(
+'htmlopen1'  => "~'<a href=\"javascript:void()\" onclick=\"document.getElementById('.\"'custcut\".\$ABBC['Config']['cut_count'].\"'\".').style.display='.\"'block'\".';this.style.display='.\"'none'\".';\"><b>CUT: '.abbcq('$1').'</b></a><div id=\"custcut'.\$ABBC['Config']['cut_count']++.'\" style=\"display:none\" class=\"code\">'.",
+'htmlcont1'  => "abbcs('$2').",
+'htmlclose1' => "'</div>'",
+'textcont1'  => '$2',
+'htmlblock'  => false,
+'minparam'   => 1,
+'maxparam'   => 1,
+'openclose'  => true,
+'nocase'     => true,
+'nested'     => true,
+'proccont'   => true,
+'omitempty'  => true,
+'subset'     => ABBC_FONT
+),
+
 'color' => array(
 'htmlopen1'  => "~'<span style=\"color:'.abbcq('$1').'\">'.",
 'htmlcont1'  => "abbcs('$2').",
@@ -643,4 +662,4 @@
        include($ABBC['Config']['smilepath'] . 'config.php');
 }

-?>
\ No newline at end of file
+?>
Avatar
NFG #6
Member since Sep 2006 · 120 posts
Group memberships: Members
Show profile · Link to this post
This looks pretty great, I was trying to work out something similar.

Two quick questions:

1. What's this unified diff stuff?  If it's just an ABBC segment, wouldn't just the additional lines be enough?  My ABBC file is already heavily modified, I imagine even if I found an app that'd combine the two it might not jive with your original source...  Would it be asking a lot to have you post just the lines that need to be added?

2. I notice on your forum it's OPEN ONLY, there's no option to close it again.  Was this by-design, or was there a reason it couldn't be done?

Good work though, very keen to try this out.
wetnun #7
Member since Nov 2008 · 4 posts · Location: California
Group memberships: Members
Show profile · Link to this post
Umm, well #1's because I'm in the habit of doing stuff like that from work.  And yes, it's just some additional lines.  The default for the counter in the config section and then the additional tag definition.  You can just strip out the '+' on the beginning of the additional lines and it will work just fine.

As per #2, that was be design.  It could easily be expanded to do both ways.  You'd just need to leave/edit the link.innerHTML instead of hiding it so people can click it again to toggle the display state.  I simplified it since I was only interested in doing initial hiding to save page space.  But the additional JavaScript should be changed to be a function in the header and a function call on the link if you want to do a two-way toggle.  This makes the tag insertions smaller and makes render time more simple in my opinion.

If you wanted to be really picky, the quick hack I did doesn't support multiple languages either.  You'd need to add that in the tag so when it gets inserted into the rendered page it would display the "CUT" in the correct language.  :)
Avatar
Yves (Administrator) #8
User title: UNB developer & webmaster
Member since Jan 2004 · 3814 posts · Location: Erlangen, Germany
Group memberships: Administrators, Members
Show profile · Link to this post
wetnun, did you know that you can provide additional ABBC tags also as a plugin? The abbctags demo plugin that comes with the UNB archive shows how that works. That way it could be easier for others to install and uninstall your addon.

Also, plugins come with the ability to be translated easily. If you or somebody wanted to translate the visible texts, it could be limited on the plugin files.

And, as a big plus ;) language selection for plugins is independent of the main UNB language. If the entire site is in French and the user's preference is German, but your tag is only translated in English and German, it will be German. (1. user language, 2. board default language, 3. English, 4. first of whatever the plugin has)
♪ ...nanananah, all in all we’re just brilliant thieves, nanananah... ♪♬
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20110527-dev, © 2003-2011 by Yves Goergen
Page created in 197.8 ms (112.2 ms) · 85 database queries in 136.9 ms
Current time: 2012-02-07, 20:15:56 (UTC +01:00)