Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1059362

    lyubozar
    Participant

    Hello, I’m using WordPress 4.5.3 running X theme version 4.5.2 and Cornerstone 1.2.4 on the website I’m developing (http://fbb.bg).
    I want to make some of the main menu options to link to certain tabs in the accordions (which was easy using # deep links) and then set it open. Setting the tab in an open state is what I still can’t figure out. Is it possible, at all?
    By default most of these tab should be closed and I don’t want to set them open in advance, but I’d rather have everything closed but the one that the user is redirected to via the deep link.
    Regards,
    Lyubozar

    #1059363

    lyubozar
    Participant
    This reply has been marked as private.
    #1059577

    Rue Nel
    Moderator

    Hello There,

    Thanks for writing in! To open the accordion section when your link is pointing to it, please add the following JS code in the customizer, Appearance > Customize > Custom > Javascript

    (function($){
      var pageAddress = window.location.hash;
    
      if ( pageAddress || pageAddress != '' ) {
    
        console.log(pageAddress);
    
        var navbar = $('.x-navbar').outerHeight();
        var yloc = $(pageAddress).offset().top - 160;
        console.log($(pageAddress).offset().top);
        console.log('tab: ' + pageAddress + ', yloc: ' + yloc);
        
        $('.x-accordion-toggle[href^="' + pageAddress + '"').trigger('click');
    
        $('html, body').animate({
            scrollTop: yloc
          }, 850, 'easeInOutExpo');
      }
      
    })(jQuery);

    We would loved to know if this has work for you. Thank you.

    #1060052

    lyubozar
    Participant

    Hello,
    Thanks for your reply!
    I’ve added the script. Unfortunately, it’s not working.

    #1060056

    lyubozar
    Participant

    When I use this script

    jQuery(document).ready(function($) {
    $(‘.open_accordion’).click(function(e) {

    var $this = $(this);
    var thisHref = $this.attr(‘href’);
    var accordion = $(thisHref).find(‘.x-accordion-toggle’);

    if ( accordion.length && $(thisHref).hasClass(‘x-accordion-group’) ) {
    e.preventDefault();

    accordion.trigger(‘click’);
    window.location.replace(thisHref);
    }

    });
    });

    I add this as a class to a button and then and then it is doing fine but not from the main menu items.
    My aim is accordion tab opening to work from the main menu items.

    #1060061

    Christopher
    Moderator

    Hi there,

    Did you try to add open_accordion class to menu items?

    Thanks.

    #1060156

    lyubozar
    Participant

    Of course. This way:

    Attachments:
    You must be logged in to view attached files.
    #1060410

    Rad
    Moderator

    Hi there,

    When adding class to menu item, it applies to the <li></li> and not directly to the link.

    Change this,

    $('.open_accordion')

    to this,

    $('.open_accordion a, a.open_accordion')

    Hope that helps.

    #1060730

    lyubozar
    Participant

    Oh yes,
    Now it is ok! Thank you!

    #1060813

    Rue Nel
    Moderator

    You’re welcome! We’re happy to help you out.
    If you need anything else we can help you with, don’t hesitate to open another thread.