ndabas / toc

Table of Contents jQuery Plugin - A minimal, tiny jQuery plugin that will generate a table of contents, drawing from headings on the page.
https://ndabas.github.io/toc/
Apache License 2.0
84 stars 24 forks source link

Provide option to ignore certain classes #10

Closed rikki-iki closed 7 years ago

rikki-iki commented 7 years ago

Needed to be able to ignore elements based on their class or their parents class

ndabas commented 7 years ago

This is not needed. You already have this functionality in the current version because you can specify exclusions using the jQuery selector syntax. For example, to ignore all H3 elements with the class 'ignored', you can do this:

$("#toc").toc({content: "div.container", headings: "h2,h3:not('.ignored'),h4"})

You can also use data attributes:

<ol data-toc="div.container" data-toc-headings="h2,h3:not('.ignored'),h4"></ol>

The documentation makes it pretty clear that you can use any valid jQuery selectors in this context.

rikki-iki commented 7 years ago

Oh of course!! lol sorry I didn't even think of that. My use case needs the parents part anyway so not a complete waste of time, but it probably is an edge case.

ndabas commented 7 years ago

Sure, no problem!

You could also pass in a jQuery selector or selection object to the content argument, if you can craft your exclusions that way. This library looks for the headings within the content selection so that should do the trick if you want to ignore a container class or whatever from all headings.

ndabas commented 7 years ago

Just thought I'd mention that I am closing this now, because like you said it's an edge case, and being minimal is one of the design goals of this library.