Collapsible Table of Contents

Collapsible Table of Contents

by Perry Lavergne -
Number of replies: 13

Hi,

Has anyone implemented a collapsible table of contents for the Book module?

Once you reach a certain amount of content the TOC becomes unusably long.

Regards,

Perry


Average of ratings: -
In reply to Perry Lavergne

Re: Collapsible Table of Contents

by studyingroup com -
a "collapsible" or a "scrollable" table of contents?
I've already tweaked the Table of contents to make it "sticky" (i.e always visible even when you scroll down) by using a custom css (in Dashboard > Site administration > Appearance > Themes > Moove):
and in the "advanced", "raw CSS" box, I've put
.block-region.yui3-dd-drop {
position: sticky;
top: 75px;
z-index: 1020;
}
So I guess for a scrollable, you only need to put inside this block:
overflow: scroll;
In reply to studyingroup com

Re: Collapsible Table of Contents

by Perry Lavergne -
Thank you.
I will try it out and let you know how it works.
In reply to Perry Lavergne

Re: Collapsible Table of Contents

by studyingroup com -
Has it worked?
In reply to studyingroup com

Re: Collapsible Table of Contents

by Perry Lavergne -
Unfortunately I only have the Boost and Classic themes available to me.

My understanding is that with the platform of Moodle I am using I am unable to upload additional themes, so I can not upload the Moove theme.
In reply to Perry Lavergne

Re: Collapsible Table of Contents

by studyingroup com -
No, you don't need additional theme, it's a customization which is available on every theme.
Go to : site administration > Appearance > and in the bottom, choose the name of your current theme (all are working the same).
go to the tab "advanced" (or "advanced settings") and in the box "Raw Initial SCSS" paste that:

.block-region.yui3-dd-drop {
overflow: scroll;
}
In reply to studyingroup com

Re: Collapsible Table of Contents

by Perry Lavergne -
You are correct found it, thank you.

I pasted the SCSS code but my table of contents in the book is not collapsing.

I have attached images of the code and the table of contents after the change.

SCSS Code
Table of contents
In reply to Perry Lavergne

Re: Collapsible Table of Contents

by studyingroup com -
You can add a "max-height". When the TOC is longer than a given height, a vertical scrollbar is added.
For example:

.block-region.yui3-dd-drop {
overflow-y: auto;
max-height: 500px;
}
In reply to studyingroup com

Re: Collapsible Table of Contents

by Perry Lavergne -
It does not appear to have any affect on the TOC.
In reply to Perry Lavergne

Re: Collapsible Table of Contents

by studyingroup com -
My bad, I was in the "editing mode", where it's working.
Then put into the box:

.block-region.yui3-dd-drop, .card-body.p-3 {
overflow-y: auto;
max-height: 500px;
}
Average of ratings: Useful (2)
In reply to studyingroup com

Re: Collapsible Table of Contents

by Deb Rymer -
Hi there. I was able to implement your suggestion. Thanks for sharing the code. However, I would really like to have a collapsible TOC. Do you know of any way to do that?