Okay this one is a bit weird - I have a page view with a views accordion on it and I would like to open a specific accordion drawer based on a URL argument (or the link used, or whatever will work). So I might add &drawer=2 and have the second drawer opened by default.

Is there any simple way to accomplish this?

Thanks!

Comments

manuel garcia’s picture

Well, it depends on you definition of 'simple', if by simple you mean no custom coding, then no, there's no way, at least in d6. In D7 since we are using jquery ui's accordion, it should be possible, since it supports it. I havent tested it yet though.

As far as how to go about it with custom code, you would need to setup some kind of convention (perhaps using a hashtag), and then process that hashtag from the url using custom js to trigger the click event on the right row header.

I realy can't help out further than this, though if you give it a try and run into questions as to how to what to trigger the click event on, let me know.

Hope this helps =)

amalaer’s picture

In D7 the following works for me:

  • In the accordion view
    • Add an excluded field (in my case nid)
    • Output first not-excluded field (designated header) as link to a unique anchor, i.e., with # at the beginning and unique id (in my case nid), cf. attached screenshot
    • Doesn't work without modification described in #1062710: Choose correct field as header (skip excluded fields)
    • In Style: Views Accordion settings check Navigation (If set, looks for the anchor that matches location.href ...), cf. attached screenshot
  • Comment out line 31 in views-accordion.js
  • Links to the accordion view page with the anchor name appended (in my case mysite.com/accordion-page#case-studies-40) open the respective accordion item

@Manuel: I would actually suggest to change the else in views-accordion.js to not touch links if they start with a # and overwrite them otherwise (like it is now). What do you think?

manuel garcia’s picture

Version: 6.x-1.4 » 7.x-1.x-dev
Component: Miscellaneous » Code
Category: support » feature

It's an interesting idea, but we have to account for when people link on other hash links that are NOT accordion items, and this complicates things very much.

I would accept patches in this direction, but I can tell you right now it's not going to be an easy task, and it would have to be maintainable and very well tested.

I suggest you use the normal hashes for opening specific rows that the module provides.

amalaer’s picture

Thanks for your feedback. I'll give it a try as soon as I have time.

I suggest you use the normal hashes for opening specific rows that the module provides.

I would if I could, but I don't see how I can achieve the following:
on several topic pages I have a view that shows the case studies (just links) related to that topic, the case study links link to the complete list of case studies on an accordion view page and open the corresponding item there. I must be able to generate the links on the related case studies view, that's why I use custom hashes.

Jonttue’s picture

Version: 7.x-1.x-dev » 6.x-1.4

Is there any progress on this feature? I am trying to do the same feature on D6, no luck so far.

amalaer’s picture

I haven't worked on it, but it's still on my todo list. However, I'll work on the D7 version first. Time permitting I'll look into the D6 version.

How critical/urgent is this feature for you?

Jonttue’s picture

It's not critical but a nice to have feature I'd really like to get.

I almost found a way to do it with help of http://drupal.org/node/475552 . I inherited my own template for accordion as done in the example. The only problem left is to pass Node ID (nid) to the template with PHP. I have Node ID as excluded views field.. The example only provides id, for accordion row.

any ideas?

Jonttue’s picture

And just few minutes after I found the solution from the very same thread http://drupal.org/node/475552 .

Using first the template described in the #4 using "$view->result[$id]->nid" instead of "$id" in the line " print 'A'. $id; " worked like a charm.

The solution is done using hash making my url look like:
http://my.site/?q=jobs#job-15

amalaer’s picture

Good to hear that it worked using #475552: Ability to choose which accordion row is open by default, not just first.

I'll post updates on D7 as soon as I have something.

ilyasmdgh’s picture

#2 was not working for me.
I have "Link this field to the original piece of content " selected.
Once unselecting that worked . Thanks amalear

ilyasmdgh’s picture

#2 did work for me, but this does not seem to be working in chrome browser. Any thoughts

knalstaaf’s picture

Issue summary: View changes

I could pull it off with this script:

<script type="text/javascript">
    jQuery.noConflict();
    jQuery(function() {
      var defaultPanel = parseInt(getParam('opentab'));
      jQuery( ".ui-accordion" ).accordion(
          {active: defaultPanel}
      );
    });

    function getParam(name) {
      var query = location.search.substring(1);
      if (query.length) {
        var parts = query.split('&');
        for (var i = 0; i < parts.length; i++) {
          var pos = parts[i].indexOf('=');
          if (parts[i].substring(0,pos) == name) {
            return parts[i].substring(pos+1);
          }
        }
      } // return 0;
    }
  </script>

This is what the link on an (external) page looks like to load the accordion with the third tab open:

domain.com/about?opentab=2 (<- zerobased)

(Source)

cprofessionals’s picture

#12 worked for me. I just put the above code in the footer of the view. THANKS!

manuel garcia’s picture

Status: Active » Closed (won't fix)

Closing now due to 6.x no longer supported.