First, my thanks for all your hard work on this very useful module.
Second, I believe I tracked this bug down, but my jQuery-fu has limits, so no patch. I'll point out what I was able to find out. I attached a screen-shot highlighting the bug.
I'm using the latest version of Drupal 6 (6.14) and Views (6.x-2.6), as well as the tendu theme (a Zen variation, 6.x-2.1-beta5).
The bug occurs on pages where there are multiple views. In my case I have a single Views Accordion block view in my main content area (created by one View) and three HTML List block views in the sidebar (all 3 created by a second View). Even though none of the sidebar views is (or ever was) defined as an accordion view, one of them, always just one of them, gets a duplicate "Open All | Close All" link belonging to Views Accordion. Of course these links don't belong on an HTML List View. The attached screen-shot should make this problem clearer.
At first glance it seems a little random, but further investigation seems to point to Views Accordion targeting a div class created by views, but that can be duplicated in other views.
So let me clarify what I found. First the short version. The links are set through jQuery targeting a Views div tag, but Views sets the same tag twice, once for each View. This results in Views Accordion targeting a non-Views Accordion block because it is targeting a generic views dic class, not a Views Accordion div class.
Now, the long version. The links are being set through jQuery from views-accordion.js (Line 49)
$viewcontent.prepend('<span class="toggleAccordion"><a class="open-all-accordion" href="#">' + Drupal.t('Open All') + '</a> | <a class="close-all-accordion" href="#">' + Drupal.t('Close All') + '</a></span>');
$viewcontent is being set based on the variable usegroupheader (this.usegroupheader - zero in my case), from line 27.
var $viewcontent = usegroupheader ? $(displaySelector + ' div.view-content').parent() : $(displaySelector + ' div.view-content');
It would seem that the variable displaySelector is the one at the core of the problem (set to this.display). It points to the div tag that can be duplicated in every view on the page. In my example there are two views and both have a block view with the same class name, a variation of "view-display-id-", one of them the Views Accordion view and the other an HTML List view with the same class (in my case both are, view-display-id-block_1). For this reason the jQuery prepend targets more than it should.
This may be a Views issue, but it does not appear to be a bug in Views, affecting apparently only this scenario that I know of. The class name is built in views, from line 23 of views/theme/views-view.tpl.php:
<div class="view view-<?php print $css_name; ?> view-id-<?php print $name; ?> view-display-id-<?php print $display_id; ?> view-dom-id-<?php print $dom_id; ?>">
Specifically this piece:
view-display-id-<?php print $display_id; ?>
$display_id itself seems to be getting set to the same value twice ("block_1" in my case), once for each view. However this seems to indicate that Views Accordion will only work when there are not two views on the same page with overlapping block ids.
Hopefully all this waffle was useful. The solution is not obvious to me because my JS and jQuery are not strong, but likely would be some way of essentially asking specifically, "Does this parent div have a child Accordion View div?" or more likely by directly targeting a div class that belongs to Views Accordion and not to Views, for example the class "views-accordion" or variations of "views-accordion-program_contents-" (in my case "views-accordion-program_contents-block_1"). I tried hacking a test in the JS by changing displaySelector from "div.view-display-id-block_1" to "div.views-accordion-program_contents-block_1" but could not get it to work. Seems to be something to do with a jQuery.extend command, but here's where I'm getting out of my depth and not sure it's worth pursuing as I'm only guessing at the solution you might pick anyway.
| Comment | File | Size | Author |
|---|---|---|---|
| views_accordion_bug.jpg | 110.12 KB | grantkruger |
Comments
Comment #1
manuel garcia commentedI will check on this tomorrow, it's kinda late here at the moment, but I believe this should be fixed already in the latest dev release, specifically in this commit: http://drupal.org/cvs?commit=221368
Can you test out the latest dev and see if you still see this?
P.S. Thanks for the detailed bug report, I wish everyone took as much interest in doing so!
Comment #2
grantkrugerI tried out the latest Dev version and it does fix this. I should have tried that first I guess ;).
On the detailed report, you're welcome. I try to do that whenever I can. Sometimes I can even offer a bug fix ;).