I've been working on porting an existing Drupal 6.x installation into Drupal 7, and I've identified the need for the expand/contract all feature to work. I've developed a solution based on an entry I found in the jQuery UI forum (http://forum.jquery.com/topic/accordion-multiple-sections-open-at-once).

I have inserted the following jQuery UI extensions and helper functions into views-accordion.js:

/* extension to allow multiple accordion lists to be selected */
      $.extend($.ui.accordion.prototype.options,{multiple: false});
      var _toggle = $.ui.accordion.prototype._toggle;
      var _clickHandler = $.ui.accordion.prototype._clickHandler;
      $.extend($.ui.accordion.prototype,{
        _toggle: function(toShow, toHide, data, clickedIsActive, down){
          if (this.options.collapsible && this.options.multiple && toShow.is(':visible')) {
            arguments[1] = arguments[0];
            arguments[3] = true;
          }
          else if (this.options.collapsible && this.options.multiple) {
            arguments[1] = $([]);			
          }
          _toggle.apply(this,arguments);
        },
        _clickHandler: function(event, target){
          if ($(target).next().is(':visible:not(:animated)')) {
            this.active = $(target);
          }
          _clickHandler.apply(this,arguments)
        }
      });
      
      /* function to manually expand accordion lists */
      accordion_expand = function(target){
        target.accordion('option', 'multiple', true);
        target.find('.ui-state-default').removeClass( "ui-state-default ui-corner-all" )
            .addClass( "ui-state-active ui-corner-top" );
        target.find('.ui-accordion-content').addClass( "ui-accordion-content-active" ).css('display', 'block');
        target.find('.ui-icon-triangle-1-e').addClass( "ui-icon-triangle-1-s" ).removeClass("ui-icon-triangle-1-e");
      }
      
      /* function to manually contract accordion lists */
      accordion_collapse = function(arg){
        target.accordion('option', 'multiple', false);
        arg.find('.ui-state-active').addClass( "ui-state-default ui-corner-all" )
            .removeClass( "ui-state-active ui-corner-top" );
        target.find('.ui-accordion-content').removeClass( "ui-accordion-content-active" ).css('display', 'none');
        target.find('.ui-icon-triangle-1-s').removeClass( "ui-icon-triangle-1-s" ).addClass("ui-icon-triangle-1-e");
        target.accordion('activate',false);
      }

This modification is by no means a finished solution, as I haven't added the necessary triggers into the view rendering code or configuration options, but I think that a patch based on this (combined with the re-addition of the expand/collapse buttons) could improve the module's functionality nonetheless.

Do you think this could be legitimately useful, and if so, should I create and submit a patch?

CommentFileSizeAuthor
views-accordion.js_.zip1.91 KBuncommented
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Manuel Garcia’s picture

In order for everyone to be able to colaborate on this, a patch against 7.x-1.x would realy make a difference, so that others can easily apply it, expand on it etc.

I'm sure you are not the only one who would find this feature useful - thanks @uncommented for taking the time to share this with the rest of the community. Seems like the way to go about doing this.

jelo’s picture

I would definitely be interested in this feature. In fact, I had already posted about this a couple of months ago not finding this issue at that time:
https://www.drupal.org/node/2395169

Manuel Garcia’s picture

Status: Needs review » Needs work

Marked #2395169: Open All / Close All as duplicate of this one.

sgohil1’s picture

Hey, any update on this feature request? I am pretty much interested in this feature.