MyBB Community Forums

Full Version: Expander collapsed by default?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys.....

I was wondering if you could help me with a small matter.
(And I hope I have posted this in the correct section)

On my board I have given select members and groups permission to post HTML.
I would like to have a "Previews Box" that uses the expander.
However, I want it to be collapsed by default so that the content is hidden.
Is that possible?

Thanks heaps for your help!

Owen

<table width="100%" cellpadding="6" cellspacing="1" border="0" class="tborder">
<tbody>
            <tr>
                <td class="thead" colspan="2">
<div class="expcolimage"><img src="{$theme['imgdir']}/collapse{$collapsedimg['newbox_e']}.gif" id="newbox_img" class="expander" alt="[-]" title="[-]" /></div>
              <strong>Previews</strong>
                </td>
            </tr>
        </tbody>
        <tbody style="{$collapsed['newbox_e']}" id="newbox_e">  
            <tr>
                <td class="trow1">Test Content
                </td>
            </tr>
        </tbody>
    </table>
<br />
The way I'd do it is with cookies. MyBB responds to the 'collapsed' cookie. Doing this somewhere like global.php should auto-collapse the box.

my_setcookie("collapsed", "".$mybb->cookies['collapsed']."|newbox_img");

Where 'newbox_img' is the id of the div. Remember that it can get complicated - take into account that users might already have collapsed categories...
Wow Tomm M!
Thank you for replying here and giving me a glimmer of hope!

I have a couple of questions:

1. Is 'newbox_img' a unique expression across the MyBB code?
I just copied the code from this post here: http://community.mybboard.net/thread-490...newbox_img
Basically, will setting a cookie for 'newbox' affect all the categories on my board?

2. Where would I add Tomm's code to global.php?
I had a look at global.php and I dont think it is a matter of just pasting it in anywhere I want.

Thanks for your help on this guys!

Owen
Bah, I didn't mean to put newbox_img, I meant to put newbox_e. For example, if you add |newbox_e into the collapsed cookie, then it will automatically collapse the table with the tbody id of newbox_e. In your code, the following will "collapse"

        <tbody style="{$collapsed['newbox_e']}" id="newbox_e">  
            <tr>
                <td class="trow1">Test Content
                </td>
            </tr>
        </tbody>

I made a plugin that will automatically collapse the quick-reply box, so it needs to do this. I'm not sure if there's an easy way to load one closed, I just imagined cookies are the easiest way...

	$cookie = $mybb->cookies['collapsed'];
		if(!my_strpos($cookie,'quickreply')){
	$expo = explode("|",$cookie); for ($i=0; $i<count($expo);$i++){ if($expo[$i] == "quickreply"){ $qurep = 1; }}
	if(!$qurep){ my_setcookie("collapsed", "".$mybb->cookies['collapsed']."|quickreply"); }}

That's the code I used (bit dirty, but hey), and I put it just before the global_end hook. It still works too... Smile

I would imagine that if you replaced references to "quickreply" and replace it with what tbody id it is you're trying to collapse, it would work for you too.
Wish i knew what you were banging on about, really want to add this to my board.
Thanks,