npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.tree

v0.0.5

Published

Automatic table of contents generation

Downloads

15

Readme

jQuery.tree

jQuery.tree enables automatic generation of "table of contents" -style lists.

Installation

Grab jquery.tree.min.js from the GitHub repo, upload it to a server, and add it to your document's head:

<script src="jquery.tree.min.js"></script>

With Bower

jQuery.tree is available as a Bower package.

bower install jquery.tree --save

Usage

With no configuration (use sensible defaults):

$('.content-area').tree();

Or, pass an options object:

$('.content-area').tree({
  'listContainer':  '.list-container', // Specify list container
  'prepend':        false // Don't prepend list
});

Like .map, .tree returns the generated list object, and so cannot be chained.

By default, the generated list is appended to the beginning of the target object. You can override this behavior with the listContainer option, which can be any valid parameter to the jQuery constructor. Alternatively, you can set the prepend option to false and manipulate the returned list object however you like in your own code.

To further specify which elements should appear in the list, use the filter option, which accepts the same parameters as jQuery's .filter. For instance, if you only want headers h1 and h2 to appear in your table of contents:

$('.content-area').tree({
  'filter':  'h1, h2', // Only go two levels deep
});

The default is :header, which matches all header elements. A future release will allow the use non-header elements, but for now, only h1 through h6 elements are supported. (Non-headers won't break the plugin -- they just won't generate list items.)

TODO

  • Improve scroll spy
  • Improve the docs
  • Add support for non-header elements
  • Add unit tests

License

Copyright 2014 Parisleaf

Licensed under the MIT License