Collapse contents in Drupal

tags: Drupal   javascript  
drupal tags: blocks   content  
To show and hide contents in Drupal we can use the javascript library in the core and obtain the same effect that we get by default in the collapsible fields of Drupal forms. All is needed is to invoke the script collapse.js in the body of the content (node or block) we are creating: <script type="text/javascript" src="/misc/collapse.js"></script> and insert the collapsible content in a fieldset to which we will add the class collapsible collapsed:
<fieldset class="collapsible collapsed">
<legend>Title of collapsible content</legend>
<div>Hidden text</div>
</fieldset>
Select Full HTML for the input format and submit your content. The result will be the following:

Similar:

Thank you for your tutorial.

Thank you for your tutorial. At the beginning i had few small problems but i`ve done it. Thanks

I can't seem to get this

I can't seem to get this working under Drupal 6.13. It works fine in preview mode as I'm editing the page, but when I save the page, the collapsed content is gone (collapsed, I guess) but there's no link to expand it.

I've got collapse.js, jquery.js, and drupal.js all included, and I'm using a "raw HTML" mode (no translation of linebreaks or URLs).

Maybe a theme problem?

I've tried to use this but

I've tried to use this but it doesn't work for anonymous users. But when I'm logged in the field becomes collapsible. How can I make to work with anonymous users?

collapse login?

After enabling OpenID support on my login block, it takes up a a huge portion of the right side bar. Is there a way to use this on a Drupal block. I've seen options to hide a block, but I would love to collapse it to save screen space.

You need to include the

You need to include the following javascript also

<script type="text/javascript" src="/misc/jquery.js"></script>
<script type="text/javascript" src="/misc/drupal.js"></script>

very much appreciate

thanks for providing this code

thank you

Thank you for explanations. I had no idea that the collapse.js file is responsible for this action.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <h4> <img> <hr>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
Are you human (question to prevent spam)?
Twitter
Add to Technorati Favorites

Featured:

Archives

March 2010
SunMonTueWedThuFriSat
123456
78910111213
14151617181920
21222324252627
28293031
PureDivs Drupal Themes Conversions