Skip to content

Commit d0113b2

Browse files
committed
Updating README to reflect recent changes
1 parent 7e31410 commit d0113b2

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,65 @@
33
A minimal, tiny jQuery plugin that will generate a table of contents, drawing from headings on the
44
page.
55

6-
## Usage
6+
The generated TOCs are semantic, nested lists (`ul` or `ol`) with hash-link anchors to the headings.
77

8-
After including jQuery (>= 1.6) and jquery.toc.js on your page, run a script like this:
8+
## Usage
99

10-
$("#toc").toc();
10+
Include jQuery (>= 1.6) and jquery.toc.js on your page. The plugin can then be used either via HTML5
11+
data attributes, or via the programmatic API.
1112

12-
This will generate the TOC from all `h1`, `h2`, `h3`, and `h4` tags on the page, and insert it into
13-
`#toc` (for example, `<div id="toc"></div>`.) The list itself will use `ul` tags, and each heading
14-
on the page will get a nice ID, if it doesn't already have one. The IDs will be based on the text
15-
content of the heading.
13+
### Via data attributes
1614

17-
### Options
15+
Minimal example:
1816

19-
The plugin has two arguments, both optional:
17+
<ul data-toc></ul>
2018

21-
$(...).toc(contentContainer, options);
19+
With options:
2220

23-
`contentContainer` is a selector where the plugin will look for headings to build up the TOC.
21+
<ol data-toc="div.container" data-toc-headings="h2,h3,h4"></ol>
2422

25-
`options` is a hash, with these keys: (all optional)
23+
### Via the JavaScript programmatic API
2624

27-
* `headings` is a string with a comma-separated list of selectors to be used as headings, in the
28-
order which defines their relative heirarchy level. The default value of `"h1,h2,h3,h4"` will
29-
select all `h1`, `h2`, `h3`, and `h4` to build the TOC, with `h1` being a level 1, `h2` a level 2,
30-
and so on. You can use any valid list of jQuery selectors; for example, if you just want `h1` tags
31-
with a specific class, and no `h4` tags, you could use `"h1.title,h2,h3"` for this option.
32-
* `list` is the tag that's created for the lists. Valid options are `"ul"` and `"ol"`.
25+
Minimal example:
3326

34-
The default values are:
27+
<ul id="toc"></ul>
28+
...
29+
<script type="text/javascript">
30+
$("#toc").toc();
31+
</script>
3532

36-
$(...).toc("body", {headings: "h1,h2,h3,h4", list: "ul"});
33+
With options:
3734

38-
### Examples of Usage
35+
<ul id="toc"></ul>
36+
...
37+
<script type="text/javascript">
38+
$("#toc").toc("div.container", "h2,h3,h4");
39+
</script>
3940

40-
Build a TOC using headings from a specific container element:
41+
### Options
4142

42-
$("#toc").toc("#container");
43+
<ul data-toc="contentContainer" data-toc-headings="headings"></ul>
4344

44-
Build a TOC using specific kinds of headings:
45+
$(...).toc(contentContainer, headings);
4546

46-
$("#toc").toc("body", {headings: "h2.title,h3"});
47+
The plugin has two parameters, both optional:
4748

48-
Build a TOC using numbered lists:
49+
* `contentContainer` is a selector where the plugin will look for headings to build up the TOC. The
50+
default value is `"body"`.
51+
* `headings` is a string with a comma-separated list of selectors to be used as headings, in the
52+
order which defines their relative heirarchy level. The default value of `"h1,h2,h3,h4"` will
53+
select all `h1`, `h2`, `h3`, and `h4` to build the TOC, with `h1` being a level 1, `h2` a level 2,
54+
and so on. You can use any valid list of jQuery selectors; for example, if you just want `h1` tags
55+
with a specific class, and no `h4` tags, you could use `"h1.title,h2,h3"` for this parameter.
4956

50-
$("#toc").toc("body", {list: "ol"});
57+
In addition, the plugin will create nested lists of the same type (`ul` or `ol`) as the element that
58+
it's called on.
5159

5260
### Automatic ID generation
5361

5462
The plugin generates hash-links to the headings on the page, to allow users to jump to the heading
5563
by clicking in the generated table of contents. This feature requires that the headings have IDs
56-
assigned; if they do not, the plugin will generate IDs for you.
64+
assigned; if they do not, the plugin will generate and assign IDs automatically.
5765

5866
The generated IDs are based on the text inside the headings, and uses two simple rules:
5967

0 commit comments

Comments
 (0)