Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author malihu

    (@malihu)

    This should be doable but it depends on the way the accordion script works.
    You will have to insert a custom script in your theme though (not sure if this is an option for you) in order to make the 2 plugins communicate.

    ‘Page scroll to id’ provides a callback function but the exact code to run depends on how exactly accordion script switches tabs.

    I’m posting such (jQuery) script which should be placed at the end of the HTML (probably in footer.php or via functions.php). The script should appear after ‘Page scroll to id’ scripts. For example, if you insert it in footer.php, it should be added after wp_footer() function.

    <script>
    (function($){
    	$(window).load(function(){
    		$(document).data("mPS2id").onComplete=function(){
    			//get the clicked link
    			var elem=$(".mPS2id-clicked"),
    				//get the id value of the clicked link (without the hash)
    				val=elem.attr("href").split("#")[1];
    			//check if the id value exists as an accordion element and set/change the URL hash accordingly
    			if($("#"+val).length && $("#"+val).parents(".accordion").length){
    				//set the value as location hash in the address bar
    				if(history.replaceState){
    					//if supported, avoid registering the URL change in borwser's history
    					history.replaceState(null,null,"#"+val);
    				}else{
    					location.hash="#"+val;
    				}
    			}
    		}
    	});
    })(jQuery);
    </script>

    Let me know ??

    Thread Starter rickykpg

    (@rickykpg)

    Hello,

    Thank you for replying!

    I placed the code below <?php wp_footer(); ?> in footer.php but sadly it didn’t work.

    Plugin Author malihu

    (@malihu)

    Well, I’d have to see your page/code in order to help. Can you send me a link?

    Thread Starter rickykpg

    (@rickykpg)

    Sure,
    https://jmediamanager.org/faq/

    I’m using the last link on the menu, “How Do I Backup My Collection?” to test it.

    Plugin Author malihu

    (@malihu)

    Try changing:

    if(history.replaceState){
    	//if supported, avoid registering the URL change in borwser's history
    	history.replaceState(null,null,"#"+val);
    }else{
    	location.hash="#"+val;
    }

    to simply:

    location.hash="#"+val;

    If this doesn’t work, try triggering the click event on the accordion titles, e.g. replacing of the code above with:

    $("#"+val).trigger("click");
    Thread Starter rickykpg

    (@rickykpg)

    Hello,

    Thank you very much! Changing the block of text to

    location.hash="#"+val;

    worked perfectly!

    Marking as resolved, again thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Open Accordion On ID’ is closed to new replies.