I'd like to be able to choose which accordion row opens first, not just the first one. The use case is that the second accordion row includes a views_carousel that has a lot of data, and that is the preferred first viewing row of the accordion. However, the first accordion row includes the basic site description, and ideally that would come first in the page so it doesn't get lost after all the carousel items.
Can you think of any way to do this without editing any of the module files? I imagine that what I should do is disable the "Start with first row opened" checkbox, and then have a javascript function that somehow opens the second accordion row after the accordion is active on the page. I'm going to attempt this with my limited javascript knowledge, but thought I'd ask at the same time.
P.S. - Thanks for a great module. I have an accordion working with a custom content type. One node includes a block using the insert_block filter, and another includes a viewscarousel view with a print views_embed_view function. Many thanks!
Comments
Comment #1
manuel garcia commentedI don't think I'll be developing this feature for the module itself, it can get messy with all the views options, and I don't think many people need it. However, this should be fairly easy to accomplish, views_accordion gives you enough css classes to do pretty much anything.
So, assuming that:
Here is the code for your js file:
The item count starts at 0, so 1 should give you the second item - use firebug if in doubt. Also, you may want to use a stricter jquery selector if you are using more accordion views in that same page, or all the second items will start opened. I hope you get the idea.
Good luck, and let me know how it goes.
Also, would you mind posting a link to the site? - It's nice to see how people are using the module =)
Comment #2
manuel garcia commentedComment #3
raystuart commentedWow, I entered the issue just before going into a meeting, and now the solution is there before my eyes thanks to you! I had seen the accordion-item-1 after inspecting the code and thought that was the best bet. Your js got me most of the way there, with just a couple differences. Here's what I used.
We're only using one accordion right now, but I figured adding .front might help to avoid some confusion later if we use the accordion on some other pages. Although, it might be better to be even more specific.
The second line in the function applies the accordion-header-active class that's important for styling the header bar for selected items. Otherwise, the appropriate CSS isn't applied.
Also, instead of using drupal_add_js, I used the .info file to add like so:
That alternative might work for some people, however it will load on every page, so I plan on replacing that with a conditional drupal_add_js like you suggested... unless there is some way to define the scripts[] line for only the front page?
Thanks again for all the help. The site is right now behind an http auth so a link wouldn't help, but it should go live soon so I will ask the client if they don't mind a little publicity here. :)
Thanks again!
Ray
Comment #4
osmanI needed a little bit more specific solution for my problem:
I needed to be able to select a certain tab by using the URL hash. Since there will be direct links to individual tabs
I needed certain individual tabs be opened when you come to accordion page by clicking an anchored link.
I copied views-view-accordion.tpl.php to my theme folder and modified it as below:
Thus, it doesn't effect the other accordion views I have through out the site. And individual tabs can be opened by an anchor link:
Thanks for the heads up.
Osman
Comment #5
manuel garcia commentedThanks for sharing osman, I'm sure it will help other people with the same situation =)
Comment #6
longwaveI wrote this small JQuery script to open the accordion in the relevant place if the view contains a link to the current page. I add this to the view footer HTML on any relevant views, it could also be worked into the module as a new option.
Comment #7
dzandman commentedI am struggling a bit with the Accordion...it was working fine until I tried to add lightbox and videobox within the accordion.
Not only are those links not working, but now all my drawers pop open automatically on load. Any ideas on either problem?
The website is dzandman.com
Thanks!
Comment #8
manuel garcia commented@dzandman : Please open your own support request for your problem.
Comment #9
malc_b commentedI thought I'd post my solution too. What I was constructing was an FAQ page using views to pull together all my FAQ items onto one page displayed nicely with views accordion. First issue was searching the views results page. That was hard so I didn't :-). Instead I let search index the FAQ items (content type of FAQ). Then I changed the urls in the search results with a routing in the theme template.php
I'm running pathauto and have set that so that faq items are /faq-item/[term]/[nid] and my view is faq/%/%. Arg1 is the term for this faq item so I can have multiple faqs. Arg2 is global null in the view. So now my search results point to view and include the nid of the faq item.
I copied views-view-accordion.tpl.php to the theme and add these lines at the start of the code.
This adds the class nid-100 (where 100 is the node nid) to each row. And finally in the view footer I added this code
Which if there is an arg2 fakes a click on the FAQ item. View accordion defaults to opening the first row so if there is no click that stays open, otherwise it opens the row matching the nid of the node of the FAQ item.
Comment #10
manuel garcia commented@malc_b: Although the tags you entered apply to your comment, these tags are set for the whole issue, so don't use them to tag your comment ;)
Comment #11
manuel garcia commentedOK, I have worked on this, and commited this feature.
Please download the latest dev tarball when it comes out, and test the new feature.
Note that the option "Start with the first row opened" has been removed, and replaced with "Start with a row opened", which expands an option to choose which row to open at start, taken from the number of items the view is set to display.
Also note that if yo have configured say, 100 items to display, and choose to open the row 100, but you only have 20 items as results, obviously none will start opened. But well, I don't see a good workflow of handling this, nor do I think it's worth that much effort.
Let me know how it goes ;)
Comment #12
malc_b commentedSorry about the tags, you live and learn.
I'll try the update and report back.