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

Nested selectors #4

Closed egeloen closed 12 years ago

egeloen commented 12 years ago

Hey! First, thanks for your jQuery plugin! :)

I'm currently trying to integrate your lib into a build-in Sphinx documentation. All works fine except for nested selectors.

The context use by the plugin follow this structure:

<div id="context">
    <h1>First level title</h1>
    <div>
        <h2>Second level title</h2>
        <div>
            <h3>Third level title</h3>
        </div>
        <h2>Second level title</h2>
        <div>
            <h3>Third level title</h3>
        </div>
    </div>
    <h1>First level title</h1>
    <div>
        <h2>Second level title</h2>
        <div>
            <h3>Third level title</h3>
        </div>
    </div>
</div>

The javascript use in order to tocify the context is:

$(selector).tocify({
    "context":    "#context",
    "selectors":  "h1,h2,h3"
});

The TOC only shows h1.

It seems selectors are defined on the same level in the demo. I don't know if it is the reason of the issue. Anyway, is there a solution?

gfranko commented 12 years ago

Right now, all TOC headers need to be defined at the same hierarchy level. This is due to the way I am using certain jQuery selectors. I will leave this issue open as I spend some time finding a better solution. Feel free to make a pull request as well =)

Also, I just released Tocify v0.7.0. Make sure to upgrade, as I fixed a show/hide bug!

The below HTML hierarchy will work as you expect:

  <div id="context">
    <h1>First level title</h1>
        <h2>Second level title</h2>
            <h3>Third level title</h3>
        <h2>Second level title</h2>
            <h3>Third level title</h3>
    <h1>First level title</h1>
        <h2>Second level title</h2>
            <h3>Third level title</h3>
  </div>
gfranko commented 12 years ago

@egeloen I just released Tocify v0.8.0, so try that out. Everything should work for you now.

egeloen commented 12 years ago

Just try it and all works fine :) Thanks!