How is it supposed to work - I tried to enable this feature in every possible way I could imagine with no result, no hash is getting added to HTML output - is it a bug or or is it how it's supposed to work? Can anyone shred some light on this matter?

Comments

manuel garcia’s picture

Just turn on the option "Navigation" in the accordion settings, then when you open links like:
http://drupal7/frontpage#clone_of_front_page-page-5 will open onload the element 5 of the accordion.

See jquery ui accordion documentation for more details.

silentbob’s picture

Is there a way to override the anchor tags with the node id ?

Anonymous’s picture

Or the TID... Or does anyone have any creative ways to manage this?

weblitz’s picture

Issue summary: View changes

It works from another page, not in the same page. The page needs to be reloaded, right?

manuel garcia’s picture

Status: Active » Closed (fixed)

@All jquery.ui accordion only supports opening / closing items by their index in the accordion, so as far as I know, using node-id or any other drupal id is not possible. That said, it's theoretically possible to come up with some extra code that would provide the mapping by adding some data attributes or what not to the accordion elements, and then figure out its index that way. I however will not be adding such functionality to this module, as I'd like to keep it as purely integrating with jquery.ui.accordion.

@weblitz, The event is triggered onload so yes.
If you want to trigger opening an accordion item via JS on the same page, for whatever reason, yo can use the set the active option:
http://api.jqueryui.com/accordion/#option-active
Alternatively you can use the activate event as well, which I believe does the same thing, see this fiddle: http://jsfiddle.net/tuando/CA8KV/1/

crutch’s picture

#2 at this post and just the js from this post works, but if there is no anchor in the URL then the last accordion always opens which is unwanted. If there is no anchor in the URL then no accordion should open.

also @#2, the line to comment out was 34 $link.get(0).href = hash; then your custom hash will be loaded in the view.

This js works to open the correct accordion, and does not open an accordion if anchor isn't present in the url

<script type = "text/javascript">
jQuery ( document ).ready( function($){
  
var accordion_hash = window.location.hash.split('-');

if ( accordion_hash[0] !== '#accordion' && ( accordion_hash[1] == '' || accordion_hash[1] == undefined ) ) return false;

   var accordionElement = $('.views-accordion-header:has(a[href$='+location.hash+'])').click();
   
});
</script>

ref: https://theme.co/forum/t/link-to-specific-accordion-on-different-page/53...