Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[HOW TO - vB4] Making Boxes Collapsible
cellarius's Avatar
cellarius
Join Date: Aug 2005
Posts: 1,987

 

Show Printable Version Email this Page Subscription
cellarius cellarius is offline 08-22-2009, 10:00 PM

Start:

OK, here's a small guide how to make a boxes/layers collapsible. Let's say, you have a simple div-container you want to make collapsible. The css ids and classes assigned to the elements are completely arbitrary.

Code:
<div id="test" class="anything">
    <h2 class="blockhead">
        <span>Collapse it!</span>
    </h2>
    <div class="blockrow">
        <p>Let's add a button to collapse this box :-)</p>
     </div>
</div>



Step 1: Adding "collapse"-class to surrounding container


Code:
<div id="test" class="anything collapse">
The next line in the example establishes the container's header, in this case by means of a level 2 heading. This header will not be collapsed with the rest of the box but remain visible. This line can be left untouched.


Step 2: Adding id to what we want to hide

As a second step we have to add an unique id to the element that contains what we want to dissapear. Note: This element can be almost any html-tag that can be hidden (div, ul, ol, p, a - you get the idea). Note also: The element has to have an id that needs to be unique not only on the page, but on the whole site. So make sure you use some unique prefix, suffix or something like that (marked in blue).

Code:
<div class="blockrow" id="cel_dummy">



Step 3: Adding collapse-button

Inside the header add the code for the collapse-button. You'll have to adapt it according to the id you assigned in step 2 (adaptions needed marked in blue). Make sure the part you add inside the image name variable is not the exact same as the id you added to the container that you want to hide. If you add the exact same, the button will vanish under certain circumstances, too:

Code:
<a class="collapse" id="collapse_cel_dummy" href="{vb:raw relpath}#top"><img src="{vb:stylevar imgdir_button}/collapse{vb:raw vbcollapse.collapseimg_cel_dummy_img}_40b.png" alt="{vb:rawphrase collapse_this_category}" /></a>



Result:

In the end, the code will look like that:

Code:
<div id="test" class="block collapse">
    <h2 class="blockhead">
        <span>Collapse it!</span>
        <a class="collapse" id="collapse_cel_dummy" href="{vb:raw relpath}#top"><img src="{vb:stylevar imgdir_button}/collapse{vb:raw vbcollapse.collapseimg_cel_dummy_img}_40b.png" alt="{vb:rawphrase collapse_this_category}" /></a>
    </h2>
    <div class="blockrow"  id="cel_dummy">
        <p>Let's add a button to collapse this box :-)</p>
     </div>
</div>



Collapsed as default? Yes, but...

There is a way default the box to be collapsed by default. But this it's quick and dirty, and really not recommended to use. Basically, you have to add display:none to the style of the collapsing container, like so:

Code:
<div class="blockrow"  id="cel_dummy" style="display: none;">
Now, there are two major drawbacks:
  • any user with javascript disabled will not be able to open the box, and the box will show the wrong icon.
  • vB at this point only saves information on closed boxes to a cookie; so if you reload the page, the box will always be closed, because vB will not remember that it has been opened.


Collapse more than one box at a time? Yes, but...

Now, functionally this is perfectly possible - just use the same id for every element you want to collapse together. But beware: for valid code you can't use duplicate ids on a page. So if you do that, your code will break xhtml validation!

I hope this will be useful for some of you!
-c

Please note that this article has been written first for alpha 1 version and been updated for beta 3. There still may be changes until gold. For example the button used is clearly marked as beta (_40b in the file name).
Reply With Quote
  #52  
Old 06-25-2010, 07:18 PM
BRotondi BRotondi is offline
 
Join Date: Sep 2008
Location: Zurich
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cellarius View Post
To avoid confusion: You export as xml.
Oups... Thanks for the hint! (repaired)

Another Question: Is there a simple way to make a div collapsed by default?
Reply With Quote
  #53  
Old 06-25-2010, 08:06 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BRotondi View Post
Another Question: Is there a simple way to make a div collapsed by default?
You may want to read the article
Reply With Quote
  #54  
Old 06-25-2010, 09:07 PM
BRotondi BRotondi is offline
 
Join Date: Sep 2008
Location: Zurich
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oups... Sorry... I should have asked "Did anyone found a non-dirty quick solution?" (but anyway the answer will be "no", since it would be written in the article...)
Reply With Quote
  #55  
Old 06-26-2010, 08:38 AM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by BRotondi View Post
(but anyway the answer will be "no", since it would be written in the article...)
at least if I knew of it
Reply With Quote
  #56  
Old 06-26-2010, 11:43 AM
BRotondi BRotondi is offline
 
Join Date: Sep 2008
Location: Zurich
Posts: 346
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

O.K. here an example with an own script: When registering, "Additional Infos" will be collapsed:

Replace in Template register
Code:
<h3 class="blocksubhead">{vb:rawphrase additional_information}</h3>
with
Code:
<script type="text/javascript">
    function RegistryDetailsOn (setcookie) {
        $("#registry_details").css({ "display": "" });
        $("#registry_details_link").css({ "background": "url('images/buttons/collapse_40b.png') no-repeat scroll 0 0 transparent","padding-left": "17px"});

        _set_cookie('RegistryDetails_visible', 1, setcookie);
    }
    function RegistryDetailsOff (setcookie) {
        $("#registry_details").css({ "display": "none" });
        $("#registry_details_link").css({ "background": "url('images/buttons/collapse_40b_collapsed.png') no-repeat scroll 0 0 transparent","padding-left": "17px" });
    
        _set_cookie('RegistryDetails_visible', 0, setcookie);
    }
    function RegistryDetailsInit () {
        t = fetch_cookie('RegistryDetails_visible');
        if (t=="1") {
            RegistryDetailsOn(0);
        } else {
            RegistryDetailsOff(0);
        }
    }
    function RegistryDetailsSwitch () {
        if ($("#registry_details").css("display") == "none") {
            RegistryDetailsOn();
        } else {
            RegistryDetailsOff();
        }
    }
    function _set_cookie(variable, wert, setzen) {
        if (!(setzen==0)) {
            set_cookie(variable, wert);
        }
    }
    $(document).ready(function(){
        RegistryDetailsInit();
    });
</script>

<h3 class="blocksubhead"><a href="javascript:RegistryDetailsSwitch()" id="registry_details_link">{vb:rawphrase additional_information}</a></h3>
<div id="registry_details">
and
Code:
            {vb:raw customfields_other}
        </div>
with
Code:
            {vb:raw customfields_other}
        </div>
        </div>
This Solution uses jQuery and the vB-Cookie-Routines. The Script could be reduced to one switch-line, but this way you have all possibilities for more extended issues.

Regards, Bruno
Reply With Quote
  #57  
Old 10-26-2010, 01:26 PM
emath emath is offline
 
Join Date: Sep 2008
Posts: 252
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how do i combine it within a table?

like, i dont want to use div, to insert the classes and everything to the <table class=..
Reply With Quote
  #58  
Old 10-26-2010, 06:14 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wrap a div around your table.
Reply With Quote
  #59  
Old 11-23-2010, 06:18 PM
dtorreci dtorreci is offline
 
Join Date: Sep 2005
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi all,

just a quick question I would like to make my postbit fields collapsable, I have follow the steps provided at page 1 and well it works but only with first post how should I proceed to make it work with all post ?

TIA
Reply With Quote
  #60  
Old 11-23-2010, 06:45 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would have to add something unique to the collapsing id (cel_dummy in the example). You coud try the postid (cel_dummy_{vb:raw post.postid}).
Reply With Quote
  #61  
Old 07-15-2011, 07:12 PM
MyLibary MyLibary is offline
 
Join Date: May 2011
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how do i add id for blocks in vbCMS 4.1.4?, they dont have any id..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:06 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04546 seconds
  • Memory Usage 2,339KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (10)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (9)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete