Hello!

First thanks to stBorchert for that nice js.

I want to have nice collapse effect for panels. The goal of the js from stBorchert is to convert the panel title into a link that collapse and expand the panel.
But it seems there is a bug and stBorchert doesn't have much time atm to fix that. Maybe this js could be a starting point for a collapsible panel module.

I am using D6.8 and jquery.
What you habe to do is to load the js and (in panel creation) to name the panel css class (panels2) "collapsible".

The Bug: panel is collapsing but after that it will not expand anymore.

Here comes the script:

/**
 * Toggle the visibility of a panel using smooth animations
 */
Drupal.togglePanel = function(panel) {
  if ($(panel).is('.collapsed')) {
    // Action div containers are processed separately because of a IE bug
    // that alters the default submit button behavior.
    var content = $('> div:not(.action)', panel);
    $(panel).removeClass('collapsed');
    content.hide();
    content.slideDown( {
      duration: 'fast',
      easing: 'linear',
      complete: function() {
        Drupal.collapseScrollIntoView(this.parentNode);
        this.parentNode.animating = false;
        $('div.action', panel).show();
      },
      step: function() {
        // Scroll the fieldset into view
        Drupal.collapseScrollIntoView(this.parentNode);
      }
    });
  }
  else {
    $('div.action', panel).hide();
    var content = $('> div:not(.action)', panel).slideUp('fast', function() {
      $(this.parentNode).addClass('collapsed');
      this.parentNode.animating = false;
    });
  }
};
 
Drupal.behaviors.collapsePanel = function (context) {
  $('div.panel-pane.collapsible > h2:not(.collapse-processed)', context).each(function() {
    var panel = $(this.parentNode);
    // Expand if there are errors inside
    if ($('input.error, textarea.error, select.error', panel).size() > 0) {
      panel.removeClass('collapsed');
    }
 
    // Turn the h2 into a clickable link and wrap the contents of the panel
    // in a div for easier animation
    var text = this.innerHTML;
      $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() {
        var panel = $(this).parents('div.panel-pane:first')[0];
        // Don't animate multiple times
        if (!panel.animating) {
          panel.animating = true;
          Drupal.togglePanel(panel);
        }
        return false;
      }))
      .after($('<div class="panel-wrapper"></div>')
      .append(panel.children(':not(h2):not(.action)')))
      .addClass('collapse-processed');
  });
};

Comments

joachim’s picture

Hi

Just to say I was looking for the same thing and have coded a simple module that uses the basic jQuery slideToggle.
http://drupal.org/project/panels_collapse -- only for D5 at the moment as I'm flat out on a project that needs it. But as Panels2 for 5 and 6 is pretty similar, I don't imagine a patch for D6 would be too hard :)

rc2020’s picture

Has there been any progress on this issue? Is there any chance of a patch for this item?

Thanks!

joachim’s picture

There's an issue open for this but I don't have time to look at it myself.

laurentb’s picture

i'm a little newbie, i do some change and this script work for me

/**
* Toggle the visibility of a panel using smooth animations
*/
Drupal.togglePanel = function(panel) {
  if ($(panel).is('.collapsed')) {
    // Action div containers are processed separately because of a IE bug
    // that alters the default submit button behavior.
    var content = $('> div:not(.action)', panel);
    $(panel).removeClass('collapsed');
    content.show();
    content.slideDown( {
      duration: 'fast',
      easing: 'linear',
      complete: function() {
     //   Drupal.collapseScrollIntoView(this.parentNode);
        this.parentNode.animating = false;
        $('div.action', panel).show();
      },
      step: function() {
        // Scroll the fieldset into view
      //  Drupal.collapseScrollIntoView(this.parentNode);
      }
    });
  }
  else {
    $('div.action', panel).hide();
    var content = $('> div:not(.action)', panel).slideUp('fast', function() {
      $(this.parentNode).addClass('collapsed');
      this.parentNode.animating = false;
    });
  }
};

Drupal.behaviors.collapsePanel = function (context) {
  $('div.panel-pane.collapsible > h2:not(.collapse-processed)', context).each(function() {
    var panel = $(this.parentNode);
    // Expand if there are errors inside
    if ($('input.error, textarea.error, select.error', panel).size() > 0) {
      panel.removeClass('collapsed');
    }

    // Turn the h2 into a clickable link and wrap the contents of the panel
    // in a div for easier animation
    var text = this.innerHTML;
      $(this).empty().append($('<a href="javascript:">'+ text +'</a>').click(function() {
        var panel = $(this).parents('div.panel-pane:first')[0];
        // Don't animate multiple times
        if (!panel.animating) {
          panel.animating = true;
          Drupal.togglePanel(panel);
        }
        return false;
      }))
      .after($('<div class="panel-wrapper"></div>')
      .append(panel.children(':not(h2):not(.action)')))
      .addClass('collapse-processed');
  });
};
bryancasler’s picture

Thanks for posting this. How would I go about implementing your script? Where should I add it?

bryancasler’s picture

We're working on this exact issue over here in the "Collapsing Panels Style" issue que. Please come contribute, I've done as much as I can.

D7 #1108620: Drupal 7.x version? <--Needs to be ported from the D6 module.
D6 #365519: Drupal 6.x version? <--Working but needs review.