Thought I'd share this:
Here's how I made the Block Div's hidable using javascript (and scriptaculous.js). Put it somewhere in the page, or in a separate file, that gets included in the page..

<script language="javascript" type="text/javascript">
// make blocks collapse by clicking on title.
blocks=document.getElementsByTagName("div");
blocks=$A(blocks);
blocks.each (
 function(block){
  if (block.className=='block') {
   title=block.childNodes[1];
   title.onclick = function () {
    content=this.parentNode.childNodes[3];
    content.style.display!='none' ? content.style.display='none' : content.style.display='block';	
  }
 }
}
);
</script>

(To add: some cookie stuff to let the browser remember which blocks you've got hiding/showing.)

Prototype-ish approach to the script; it requires Prototype 1.6.
<script language="javascript" type="text/javascript">
// Assuming jQuery.noConflict is already called.
if (Drupal.jsEnabled) {
$(document).observe('dom:loaded', function() {
$$('div.block h2').invoke('observe', 'click', function() {
  $(this).up().down('div.content').invoke('toggle');
});
});
}
</script>
jQuery approach, which is supposed to work with Drupal 5.
<script language="javascript" type="text/javascript">
if (Drupal.jsEnabled) {
(function($) {
$('div.block h2').click(function() {
  $(this).parent().find('div.content').slideToggle();
});
})(jQuery);
}
</script>

More info: See 'Collapsiblock' under jstools module for a full-blown and configurable version of this task. I think it's cookied by now.

Comments

iantresman’s picture

Drupal 6 users can use Javascript Tools Collapsiblock to achieve the same.

gagarine’s picture

Actually Collapsiblock is a separate project.

https://interface-network.com - Interface Network is an action and research technology governance agency.

gurtner’s picture

This solution worked for me in drupal 7 with ctools (I can't imagine a drupal 7 site not using ctools).

If you're trying to make all sidebar blocks collapsible, create a new file in your theme's templates folder called "block--sidebar-first.tpl.php". Or if you're trying to make only a specific block collapsible, for example a views block, create a new file named "block--views--my-view-name-my-display-name.tpl.php".

In you're new tpl file, just add the following PHP snippet:

  print theme(
    'ctools_collapsible',
    array(
      'handle' => $block->subject, 
      'content' => $content, 
      'collapsed' => TRUE
    )
  );

and clear cache. ctools will do the rest :-)

danielgurtner.com

thomas1977’s picture

Hi dangswiss

Thanks for your suggestion/solution - however, I cannot make it work. I have a view named 'Pending users', which I insert into Panels using display 'Block'. So, I create af .php file named:

block--views—pending-users-block.tpl.php

with the snipped that you provided. I clear the cache, but no change, nothing to click on, not collapsible.

What am I doing wrong here? Thanks in advance!

Best,
Thomas