Results 1 to 2 of 2

Thread: Open specific accordion from link

  1. #1
    New user
    Join Date
    12-04-17.
    Posts
    1

    Default Open specific accordion from link

    What I need to do is have a specific accordion (on a page with many accordions) open from a link on another page. So rather than telling people to go to a certain page and then click on a specific accordion link on that page, I just want to be able to give them a link that will go to that page with only that accordion open.

  2. #2
    User Andreas's Avatar
    Join Date
    07-11-09.
    Location
    Mönchengladbach
    Posts
    499

    Default

    If you're talkin bout the jquery accordion:

    This also has been asked and solved in the german forum https://community.contao.org/de/show...l=1#post388650

    In general we manualy open an accordion with the index of the targeted accordion starting by 0.
    PHP Code:
    $(document).accordion('option''active'3); // 3 is the index of our accordion here 
    Here is my j_accordion-mod template you can try to use.
    PHP Code:
    //...snip

    // original j_accordion Contao 3.5.15 above

          /**
           * open appropriate accordion if link hash target matches an accordion ID
           * or an element ID within an accordion
           */
          
    var
            
    myAccordions = $('.toggler'),
            
    closestAccordion = $(document.location.hash).closest('.ce_accordion').find('.toggler')
          ;

          
    // open appropriate accordion if hash is in page URL and hash matches ID
          
    if(closestAccordion.length) {
            $(
    document).accordion('option''active'myAccordions.index(closestAccordion));
          }

          
    // all anchors
          
    $('a').each(function() {
            var 
    hash = $(this).prop('hash');

            
    // all anchors with a hash
            
    if(hash) {
              
    // search for an accordion with id=hash or including an element with id=hash
              
    var closestAccordion = $(hash).closest('.ce_accordion').find('.toggler');

              
    // click event for all affected anchors
              
    if(closestAccordion.length) {
                $(
    this).click(function() {
                  
    // open the appropriate accordion
                  
    $(document).accordion('option''active'myAccordions.index(closestAccordion));
                });
              }
            }
          });

    // original j_accordion Contao 3.5.15 below
        
    });
      })(
    jQuery);
    </script> 
    Web-Development, Freelancer, Burgtech, XHTML, HTML5, CSS, PHP, Javascript, MooTools, MySQL and more
    Amazon wishlist

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •