Is it possible with the current module to maintain the collapsed/expanded state between page loads. I'm using the feature for an online newsletter table of contents and when the user navigates from an article back to the main page, the accordian is always collapsed, even they had previously 'expanded all'.

If this is not yet possible, could you point me in the general direction with regard to the proper way to implement the feature?

I appreciate your help and your work on this great module.

Comments

manuel garcia’s picture

Version: 6.x-1.2-beta3 » 6.x-1.x-dev
Status: Active » Closed (won't fix)

This not something that the module does, sorry. I would not use it for a table of contents, perhaps you should implement that as a menu, and use dhtml_menu for this? As far as I can remember it does retain the status of the menu through a cookie, though I haven't used it in a while.

Unless someone provides a clean patch to get this done, I don't see the feature happening sorry, nor do I think it's necessary for the use case of an accordion, so for now I'm setting the status to won't fix. If someone wants to work on this feature, feel free to submit a patch of course.

P.S. Feature requests are made against the development version of modules ;)

tommyk’s picture

Here's a use case where maintaining the state would be very useful:

A link to a PDF file is contained in the expanded content. A user clicks on the PDF and it opens in the same window/tab. The user clicks the back button to the page with the accordion on it and loses where they were.

I don't know how to implement a cookie to remember the state, but I just wanted to say that this feature could be very useful.

If I can learn how or find someone to help, I'll get this contributed.

surgeonbor’s picture

I just ran into the same issue. You can use a preprocess function to programmatically set which accordion is expanded, and thereby maintain the state. Make a custom template for views-view-accordion.tpl.php (e.g. views-view-accordion--name-of-view.tpl.php), and in its preprocess function change the values of the style plugin variables.

function yourtheme_preprocess_views_view_accordion__name_of_view(&$vars) {

  $row = 2; //the 0-based index of the row you want to be expanded
  $vars['view']->style_plugin->options['start-open'] = 1;  //boolean 1 or 0
  $vars['view']->style_plugin->options['row-start-open'] = $row;

}
manuel garcia’s picture

You can already choose which row starts opened when the accordion loads through the views UI surgeonbor, this thread is about something else.

surgeonbor’s picture

I understand that, but in the preprocess function you can programmatically determine which one opens first. Instead of simply writing

$row = 2;

you can do some logic based on whatever variables are available and set $row appropriately. In my case, I set $row based on the node type indicated by the value of arg(1), and therefore maintain the expanded/collapsed state. This can't be accomplished in the Views UI.

manuel garcia’s picture

That's stil outside of the scope of this issue, this issue is about maintaining the opened item that the user last opened when they clicked to go to another page.

What you talk about might be useful in some cases, and that's why we used a preprocess function, but this issue is about something else.

RAWDESK’s picture

Issue summary: View changes

@surgeonbor You don't explicitly need to override the tpl file to have the theme hook triggered.

function yourtheme_preprocess_views_view_accordion(&$vars) {}

will do the trick also.