├── README.md ├── bookmarklet.js ├── jquery.planize.js └── index.html /README.md: -------------------------------------------------------------------------------- 1 | jqPlanize 2 | ========= 3 | 4 | The planize [jQuery](http://jquery.com/) plugin adds some hierarchical data organization features to given DOM node containing HTML headings: 5 | 6 | * adds numerotation and anchors in front of all headings, 7 | * generates an HTML table of contents, 8 | * degrades gracefully if javascript is not available/enabled. 9 | 10 | You can see the plugin in action on [this page](http://prendreuncafe.com/work/jqplanize/index.html). 11 | 12 | How does this work? 13 | ------------------- 14 | 15 | The plugin parse the given DOM node children to find existing headings, and renumerote them according to their hierarchical structure. 16 | 17 | Have you got some examples? 18 | --------------------------- 19 | 20 | For example, if you have this HTML structure: 21 | 22 |
' + config.toc_none + '
' : ''; 115 | } 116 | jQuery(config.toc_elem ? config.toc_elem : 'body').append(toc); 117 | } 118 | 119 | processed = true; 120 | }; 121 | 122 | /** 123 | * Logs a message into the firebug or opera console if available 124 | * 125 | */ 126 | var log = function() { 127 | if (!config.debug) { 128 | return; 129 | } 130 | try { 131 | console.log.apply(console, arguments); 132 | } catch(e) { 133 | try { 134 | opera.postError.apply(opera, arguments); 135 | } catch(e){} 136 | } 137 | } 138 | 139 | process(); 140 | 141 | if (config.callback) { 142 | config.callback(config.toc_elem); 143 | } 144 | 145 | return jQuery(this); 146 | }; 147 | 148 | })(jQuery); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |The planize jQuery plugin adds some hierarchical data organization features to given DOM node containing HTML headings (you know, the h1 .. h6 tags).
As an example, how is hard to browse this long page without a table of content? Now click . Now, you see?
52 |The source code and an issue tracker are hosted at Google.
53 | 54 |The examples below will run on the current page HTML source code. At any time you can .
56 | 57 |$('html *').planize();
59 |
60 |
61 | H2$('html *').planize({ min_level: 2 });
63 |
64 |
65 | H2, with a custom number suffix$('html *').planize({ min_level: 2, number_suffix: ')' });
67 |
68 |
69 | H2 headings and Table of Contents generation$('html *').planize({ min_level: 2, generate_toc: true, toc_elem: $('#toc') });
71 |
72 |
73 | H2 headings enumeration only, and Table of Contents generation$('html *').planize({ min_level: 2, max_level: 2, generate_toc: true, toc_elem: $('#toc') });
75 |
76 |
77 | Installation is fairly simple. Just add these lines within the <head> tag of your HTML document:
80 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script> 81 | <script type="text/javascript" src="http://jqplanize.googlecode.com/svn/trunk/jquery.planize.js"></script> 82 |83 |
Note: Maybe storing your own local copy of the jquery.planize.js would be a great idea.
This is a jQuery plugin, so you can apply a custom method to a DOM element or a collection of DOM elements matching a jQuery selector call:
87 |
88 | $('#myDiv').planize(); // Will match the div with the "myDiv" id in the page
89 | $('div.pageblock').planize(); // Will match all divs with class "pageblocks"
90 | etc.
91 |
92 | Configuring jqplanize is done by passing a Javascript object to the planize() function:
94 | $('#myDiv').planize({ generate_toc: true });
95 |
96 | Here are the available configuration object parameters:
97 |generate_toc is set to true)toc_elem object will be passed back as an argument.) in 1.2.3). in 1.2.3)You can drag the bookmarklet below to your personal bookmark bar, so you'll be able to generate the table of content on (quite) every page you browse on the web:
129 | 130 | 131 |This plugin is licensed under the MIT license. That means:
154 |155 |173 | 174 |Permission is hereby granted, free of charge, to any person obtaining a copy 156 | of this software and associated documentation files (the "Software"), to deal 157 | in the Software without restriction, including without limitation the rights 158 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 159 | copies of the Software, and to permit persons to whom the Software is 160 | furnished to do so, subject to the following conditions:
161 | 162 |The above copyright notice and this permission notice shall be included in 163 | all copies or substantial portions of the Software.
164 | 165 |THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 166 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 167 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 168 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 169 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 170 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 171 | THE SOFTWARE.
172 |
My name is Nicolas Perriault, I'm a french developer based near Paris. Feel free to browse my blog, mainly in french.
176 | 177 | 180 | 181 | --------------------------------------------------------------------------------