Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMicheil Smith <micheil@brandedcode.com>2010-11-18 04:26:37 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-11-18 04:38:54 +0300
commit8d27393aa20afe9e0cba211e08957183587540e4 (patch)
tree5fb8e96cd44ccf4177273e7e8469ce35cebf3008 /doc
parent8591057fa3b141da61849ebbb310bed96e0d03de (diff)
Generate Table of Contents at compile time.
Diffstat (limited to 'doc')
-rw-r--r--doc/api_assets/core.js70
1 files changed, 10 insertions, 60 deletions
diff --git a/doc/api_assets/core.js b/doc/api_assets/core.js
index 3625b2dcece..c185a770621 100644
--- a/doc/api_assets/core.js
+++ b/doc/api_assets/core.js
@@ -1,63 +1,13 @@
$(function(){
highlight(undefined, undefined, 'pre');
- var $headings = $("h2, h3, h4, h5, h6");
-
- if(! $("body").hasClass("index") && $headings.size() > 2){
- var current_level
- , last_level = 0
- , toc = [
- '<div id="toc">',
- '<h2>Table Of Contents <a id="toggler" href="#toc">Hide</a></h2>'
- ];
-
- for(var i=0, hl=$headings.size()+1; i < hl; i++) {
- var heading = $headings[i] || false;
- if(heading) {
- current_level = heading.tagName.substr(1,1);
-
- console.log(current_level, last_level, $(heading).text());
-
- if(last_level != 0 && current_level <= last_level) {
- toc.push("</li>");
- }
-
- if(current_level > last_level) {
- toc.push("<ul>");
- toc.push("<li>");
- } else if(current_level < last_level) {
- console.log(last_level-current_level);
- for(var c=last_level-current_level; 0 < c ; c-- ){
- toc.push("</ul>");
- toc.push("</li>");
- }
- }
-
- if(current_level == last_level || current_level < last_level) {
- toc.push("<li>");
- }
-
- toc.push('<a href="#'+$(heading).attr("id")+'">'+$(heading).text()+'</a>');
- last_level = current_level;
- } else {
- toc.push("</li>");
- toc.push("</ul>");
- }
- }
-
- toc.push("</li>");
- toc.push("</ul>");
- toc.push("<hr />");
- toc.push("</div>");
-
- $("#container header").after(toc.join("\n"));
- $("#toggler").toggle(function(e){
- $("#toc ul").hide();
- $(this).text("show");
- e.preventDefault();
- }, function(e){
- $("#toc ul").show();
- $(this).text("hide");
- e.preventDefault();
- });
- }
+
+ $('<a href="#toc">Hide</a>').appendTo($("#toc h2")).toggle(function(e){
+ $("#toc ul").hide();
+ $(this).text("Show");
+ e.preventDefault();
+ }, function(e){
+ $("#toc ul").show();
+ $(this).text("Hide");
+ e.preventDefault();
+ });
});