Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init is fired twice #34

Closed
peterbenoit opened this issue May 26, 2017 · 2 comments
Closed

Init is fired twice #34

peterbenoit opened this issue May 26, 2017 · 2 comments

Comments

@peterbenoit
Copy link

I'm not sure if this is an issue with the implementation or something I'm doing.

I want to run some code prior to initializing Toc, and I want to run it after the document is ready, so it looks something like this:

$( function() {
    var $thing = $('#otp');
    Toc.init( $thing );
} );

The thing is, this creates the Toc nav which is then created again when the document ready method in your library is fired - so I'm ending up with multiple UL's in the nav creating repeating headings.

Do you have any suggestions on what I should do?

@afeld
Copy link
Owner

afeld commented May 29, 2017

See #21 (comment) - let me know if that doesn't do the trick!

@peterbenoit
Copy link
Author

Just to follow up, this ended up being an order of operations issue. I called init prior to your library running its document.ready function, so the page contained a nav data-toggle="toc" (since your lib adds that attribute) at the time even when the default HTML markup only contained a <nav id="toc"></nav>.

Totally my fault, but I'm wondering if there's a way to safeguard against my error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants