• Resolved f3rdal

    (@f3rdal)


    Hello, everyone,
    I find the plugin very good. I have a question. Can I include accordions in the table of contents? Would that be possible? If so, how could I successfully set it up.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author LuckyWP

    (@theluckywp)

    Hello!

    What do you mind by “accordions”.
    Show/hide nested items?

    Thread Starter f3rdal

    (@f3rdal)

    Hello and thanks for the answer.
    Yes, indeed. I am looking for a way to show and hide the subitems (h2-h6) with a button.

    Plugin Author LuckyWP

    (@theluckywp)

    Unfortunately, this is not possible now ??
    You may try make this via jQuery + CSS.

    Thread Starter f3rdal

    (@f3rdal)

    Do you have a starting point how I can pack the heading elements h1 into an accordion? My JS knowledge is not that good. I would be very pleased if you could give me an approach.

    Plugin Author LuckyWP

    (@theluckywp)

    On JS need hide all children items and add element before top level items for show/hide childrens.

    Thread Starter f3rdal

    (@f3rdal)

    That seems logical to me. How do I put your short code into this JS? How can I make sure that the accordion works with every TOC.

    Plugin Author LuckyWP

    (@theluckywp)

    Need JS-developer for make this task.

    Thread Starter f3rdal

    (@f3rdal)

    Thanks for the advice. Unfortunately I don’t have a JS developer who can support me currently. Too bad ??

    Plugin Author LuckyWP

    (@theluckywp)

    Try this code.

    JS:

    (function($) {
    	$('.lwptoc_item > .lwptoc_itemWrap').hide().before('<b class="tocToggle tocToggle-hidden"></b>');
    	$('.tocToggle').click(function() {
    		var $this = $(this), $el = $(this).next();
    		if ($this.hasClass('tocToggle-hidden')) {
    			$el.show();
    			$this.removeClass('tocToggle-hidden')
    		} else {
    			$el.hide();
    			$this.addClass('tocToggle-hidden')
    		}
    	});
    })(jQuery);

    CSS:

    .lwptoc .lwptoc_item { position: relative; }
    .tocToggle { position: absolute; left: -24px; top: 0; cursor: pointer; }
    .tocToggle:before { content: '▲'; }
    .tocToggle-hidden:before { content: '▼'; }
    Thread Starter f3rdal

    (@f3rdal)

    Thank you very much. Let me try the code.

    Thread Starter f3rdal

    (@f3rdal)

    Unfortunately your script/css does not work. The accordion is not visible on the page. I call the script after jquery was loaded. Too bad ??

    Plugin Author LuckyWP

    (@theluckywp)

    Show page URL.

    Thread Starter f3rdal

    (@f3rdal)

    Hello, unfortunately I cannot show you the site because it is under development. I have changed the code structure after a long time of trial and error – actually there shouldn’t be any difference, but there was.
    Now it works with the accordions – thanks for your help

    jQuery(document).ready(function () {
    
    	jQuery('.lwptoc_item > .lwptoc_itemWrap').hide().before('<b class="tocToggle tocToggle-hidden"></b>');
    	jQuery('.tocToggle').click(function () {
    		var $this = jQuery(this),
    			$el = jQuery(this).next();
    		if ($this.hasClass('tocToggle-hidden')) {
    			$el.show();
    			$this.removeClass('tocToggle-hidden')
    		} else {
    			$el.hide();
    			$this.addClass('tocToggle-hidden')
    		}
    	});
    	
    })
    Plugin Author LuckyWP

    (@theluckywp)

    Good! I glad what your task is resolved ??

    @f3rdal If you have a time, please rate the plugin here: https://www.ads-software.com/support/plugin/luckywp-table-of-contents/reviews/#new-post

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Accordions in Toc’ is closed to new replies.