gfranko / jquery.tocify.js

A jQuery Table of Contents plugin that can be themed with Twitter Bootstrap or jQueryUI.
http://gregfranko.com/jquery.tocify.js/
MIT License
927 stars 217 forks source link

ToC incorrectly nested when 4 header selectors are used and headers jump a level #23

Closed buro9 closed 11 years ago

buro9 commented 11 years ago

For the given HTML:

<h1>Depth 1</h1>
<h2>Depth 2</h2>
<h3>Depth 3</h3>
<h4>Depth 4</h4>
<h5>Depth 5</h5>
<h3>Depth 3</h3>
<h2>Depth 2</h2>

And ToCify configured thus:

var toc = $("#toc").tocify({ selectors: "h2, h3, h4, h5" }).data("toc-tocify");

The generated menu will incorrectly nest the second Depth 3 as a sibling to Depth 4, rather than as a sibling to Depth 3.

I believe in the unminised code the bug is on line 411, but I don't know how to fix it.

buro9 commented 11 years ago

Actually, the headers need no jump a level... this also exhibits the bug:

<h1>Depth 1</h1>
<h2>Depth 2</h2>
<h3>Depth 3</h3>
<h4>Depth 4</h4>
<h5>Depth 5</h5>
<h4>Depth 4</h4>
<h3>Depth 3</h3>
<h2>Depth 2</h2>

Maybe it's just having 4 header levels in the selector.

gfranko commented 11 years ago

This should now be fixed in the latest release!