The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
How To Create Collapsable Boxes
This tutorial explains how to create collapsable boxes throughout vBulletin. For the purpose of this tutorial, I will explain how the first part of the 'What's Going On' box is structured (ie WOL on forumhome) and how you can use this technique to create stand alone collapsable boxes or add sections to additional boxes (eg Forum Statistics as part of the What's Going On box) Part One: Decipering the What's Going On box In your forumhome template, the following code exists by default: Code:
<!-- what's going on box --> <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center"> <thead> <tr> <td class="tcat" colspan="2">$vbphrase[whats_going_on]</td> </tr> </thead> <if condition="$show['loggedinusers']"> <!-- logged-in users --> <tbody> <tr> <td class="thead" colspan="2"> <a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_activeusers')"><img id="collapseimg_forumhome_activeusers" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_activeusers].gif" alt="" border="0" /></a> <a href="online.php$session[sessionurl_q]" rel="nofollow">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>) </td> </tr> </tbody> <tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]"> <tr> <td class="alt2"><a href="online.php$session[sessionurl_q]" rel="nofollow"><img src="$stylevar[imgdir_misc]/whos_online.gif" alt="$vbphrase[view_whos_online]" border="0" /></a></td> <td class="alt1" width="100%"> <div class="smallfont"> <div style="white-space: nowrap"><phrase 1="$recordusers" 2="$recorddate" 3="$recordtime">$vbphrase[most_users_ever_online_was_x_y_at_z]</phrase></div> <div>$activeusers</div> </div> </td> </tr> </tbody> <!-- end logged-in users --> </if> Firstly, you will notice that the code starts with a table row, the same as any other table anywhere in vBulletin. This is essential. However, before the Code:
<tr> Code:
<thead> All the code until Code:
</thead> Next we have the condition for the content section to show. For the purposes of this tutorial, the conditional is being disregarded. This is then followed by the following code: Code:
<tbody> <tr> <td class="thead" colspan="2"> <a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_activeusers')"><img id="collapseimg_forumhome_activeusers" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_activeusers].gif" alt="" border="0" /></a> <a href="online.php$session[sessionurl_q]" rel="nofollow">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>) </td> </tr> </tbody> First there is the Code:
<tbody> Code:
<tr> Code:
<td> The next section is essential Code:
<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_activeusers')"><img id="collapseimg_forumhome_activeusers" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_activeusers].gif" alt="" border="0" /></a> Probably the most important section of this code, and the bit that is the cause for most problems are the labels Code:
forumhome_activeusers Code:
collapseimg_forumhome_activeusers Code:
collapseimg_ When you are creating a new collapsable box, you need to give it a name. The length of the name is not important, as long as you ensure that every time it is used, it is identical. In the example used for this tutorial (the WOL on forumhome) the name used is Code:
forumhome_activeusers Some examples of names for collapsable boxes are:
The next section is Code:
<a href="online.php$session[sessionurl_q]" rel="nofollow">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>) </td> </tr> </tbody> The next line is Code:
<tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]"> Code:
collapseobj_forumhome_activeusers This line controls the collapsing of the box by identifying it, and setting the style of the box to match that of the image used earlier. (ie when collapsed the image shows a + and when expanded the image shows a - ) To have the box collapsed by default, you should use Code:
<tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]; display:none"> Finally, we have the content for the collapsable row, followed by the closure tag Code:
</tbody> Code:
</table> Part Two: Creating Standalone Collapsable Boxes Creating a standalone collapsable box (eg the one used for topXstats) is very straightforward. Literally, it involves following all the steps layed out in part one, using the same code and making adjustments as highlighted for the box name and setting the title and content to your requirements. Using the Code:
<thead> Part Three: Adding To Existing Tables You can add a collapsable section to any existing table. You simply use the steps laid out in part one, but omit the table and thead sections. You can place your collapsable section anywhere in a table, providing it is located in the center of the following code Code:
</tr> <tr> Code:
<tbody> You can also add collapsable sections right at the beginning of a table by adding the code immediately after the table tag, or at the end of the table by adding the code directly above the end table tag. An example of a modification that uses this technique is the Who Has Visited Today modification. Part Four: Multiple Items Collapsing With One Control Using the Whats Going On box as a primary example, what if you didn't want everything to be seperate, but rather all collapse apart from the statistics if you click a collapse icon? This is very easy to do, and you simply use the same name for each section that you wish to have collapsed by the one icon. In this case, that would be the WOL section, upcoming events and birthdays. Statistics would retain it's own name otherwise that two would collapse with the rest. I hope that you find this useful, and if you have any questions, please feel free to ask. |
#12
|
||||
|
||||
I hate to dig this up, but how do you make the box collapsed by default? I read something in another thread, it does the job, but then it still shows the "collapse" button by default instead of the "expand" button.
|
#13
|
||||
|
||||
As Kerry-Anne posted above:
Code:
<tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]; display:none"> |
#14
|
||||
|
||||
Quote:
Now I know nothing about javascript, but since this seems to be a JS function, is it possible to do something like toggle_collapse in <body onload>? So it collapses the box when the page loads, and then you'd have to click the button to collapse? |
#15
|
|||
|
|||
I'm hoping that you did read the enitre tutorial, and not literally use that code that Kirk quoted, as that won't work correctly as it is the control for another box.
Can you provide a copy of the code you are using for the box, along with details of where it is and a link to view it on your site, and I'll give it a look over for you. |
#16
|
||||
|
||||
Quote:
Currently you have to be an administrator to view the style I'm working on, and we're also in the process of upgrading to 3.6.0, so I'll get back to you guys later with screenshots. For now here's the code for the box... Code:
<table class="tuser_info" cellpadding="0" cellspacing="0" border="0" width="100%" align="center"> <tbody> <tr> <td class="vbmenu_control" colspan="2"> <a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('postbit_userinfo$post[postcount]')"><img id="collapseimg_postbit_userinfo$post[postcount]" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_postbit_userinfo].gif" alt="" border="0" /></a> User Info </td> </tr> </tbody> <tbody id="collapseobj_postbit_userinfo$post[postcount]" style="$vbcollapse[collapseobj_postbit_userinfo]; display:none"> <tr> <td> <div class="smallfont"> <if condition="$post['joindate']"><div id="profileField">$vbphrase[join_date]: $post[joindate]</div></if> <if condition="$post['field2']"><div id="profileField">$vbphrase[location_perm]: $post[field2]</div></if> <if condition="$post['age']"><div id="profileField">$vbphrase[age]: $post[age]</div></if> <div id="profileField"> $vbphrase[posts]: $post[posts] </div> <if condition="$show['reputation']"><div><if condition="$show['reppower']">$vbphrase[reppower]: $post[reppower]</if>$post[reputationdisplay]</div></if> <if condition="$post['icqicon'] OR $post['aimicon'] OR $post['msnicon'] OR $post['yahooicon'] OR $post['skypeicon']"><div id="profileField">IM: $post[icqicon] $post[aimicon] $post[msnicon] $post[yahooicon] $post[skypeicon]</div></if> </div> </td> </tr> </tbody> </table> |
#17
|
|||
|
|||
ok, there is a simple reason for this. For your id you have
Code:
id="collapseobj_postbit_userinfo$post[postcount]" Code:
src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_postbit_userinfo].gif" Code:
src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_postbit_userinfo$post[postcount]].gif" There isn't anything that you can do about this I'm afraid, unless you want them all to open and close regardless of which post you click on. |
#18
|
||||
|
||||
Quote:
Is there ANY way around this? Is it possible to have any other variable in there? like... Code:
src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_postbit_userinfo$x].gif" |
#19
|
|||
|
|||
I wouldn't think so. You are probably best using a popup menu to achieve the results that you want for this.
|
#20
|
|||
|
|||
wow, thx for this tut mate
|
#21
|
|||
|
|||
the only thing you can do is collapse on load. That is what i did at least.
<script type="text/javascript">toggle_collapse('yourcollapseidhere')</script> Quote:
this should work, i tried it before using text and im pretty sure i did this. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|