Skip to content
Browse files

Backport a JavaScript TOC fix from CDS

  • Loading branch information...
1 parent 11d00f2 commit d180c42726846caa50bb38cb575f1fc17cd61fd8 @michaelklishin michaelklishin committed Nov 10, 2012
Showing with 12 additions and 16 deletions.
  1. +12 −16 assets/javascripts/toc.js
View
28 assets/javascripts/toc.js
@@ -9,24 +9,27 @@ jQuery.fn.toc = function () {
var level = 2;
$(document).ready(function() {
- $(":header").each(function(index, el) {
-
- if(parseInt(el.tagName[1]) === 1)
- return;
+ $(":header").filter(function(idx, el) {
+ // filter out H1
+ return !(parseInt(el.tagName[1]) === 1);
+ }).
+ each(function(index, el) {
+ var currentLevel = parseInt(el.tagName[1]);
var text = $(el).text();
-
var anchor = text.replace(/[^a-zA-Z 0-9]+/g,'').replace(/\s/g, "_").toLowerCase();
- $(el).attr('id', anchor);
- var currentLevel = parseInt(el.tagName[1]);
+ $(el).attr('id', anchor);
if(currentLevel > level) {
var nextLevelList = $("<ul class='nav nav-list'/>");
nextLevelList.appendTo(listStack.last().children("li").last());
listStack.push(nextLevelList);
} else if(currentLevel < level) {
- listStack.pop();
+ var delta = level - currentLevel;
+ for(var i = 0; i < delta; i ++) {
+ listStack.pop();
+ }
}
level = currentLevel;
@@ -37,14 +40,7 @@ jQuery.fn.toc = function () {
});
});
};
-// $($(".highlight")[2]).text().match(/(.*)\.(.*)/)
-// "AMQP::Channel.direct".match(/(.*)\.(.*)/)
-// "AMQP::Channel#direct".match(/(.*)#(.*)/)
-jQuery.fn.yardLink = function () {
- var class_method = /(.*)\.(.*)/;
- var instance_method = /(.*)#(.*)/;
-};
$(document).ready(function() {
$(".well.sidebar-nav").toc();
-});
+});

0 comments on commit d180c42

Please sign in to comment.
Something went wrong with that request. Please try again.