Skip to content

Commit

Permalink
Restore missing TOC code, add anchor links to headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancribbs committed Feb 14, 2011
1 parent 863afcc commit 1dabe3d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 36 deletions.
2 changes: 0 additions & 2 deletions _Layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ <h1><a href="/"><img src="{{ wiki.base_path }}images/logo_wiki.png" alt="basho">

<article>

<div id="toc"></div>

<hgroup>
<h1>{{ page.title }}</h1>
<div class="clearfix"></div>
Expand Down
18 changes: 18 additions & 0 deletions css/wiki_specific.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ div.note div.title {
font-size: 90%;
font-weight: bold;
}

h2 a.toc-anchor,
h3 a.toc-anchor,
h4 a.toc-anchor,
h5 a.toc-anchor,
h6 a.toc-anchor {
text-decoration: none;
color: #eee;
display: none;
}

h2:hover a.toc-anchor,
h3:hover a.toc-anchor,
h4:hover a.toc-anchor,
h5:hover a.toc-anchor,
h6:hover a.toc-anchor {
display: inline;
}
91 changes: 57 additions & 34 deletions js/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
// remap jQuery to $
(function($){

$(document).ready(function()
{

jQuery("#sidebar").find("li").each(function(){
var item = jQuery(this);
if ( item.has("ul").length ) {
var hide = item.has("a[href=\"" + document.location.pathname + "\"]").length == 0;

if ( hide ) {
item.addClass("collapsed");
} else {
item.addClass("expanded");
}

item.click(function(event){
if ( this == event.target ) {
item1 = jQuery(this);
var collapsed = item1.hasClass("collapsed");
item1.removeClass("expanded collapsed")
.addClass(collapsed ? "expanded" : "collapsed")
.children("ul").toggle();
return false;
}
});

if ( hide ) {
item.find("ul").hide();
}

}
});
});
$(document).ready(function()
{

jQuery("#sidebar").find("li").each(function(){
var item = jQuery(this);
if ( item.has("ul").length ) {
var hide = item.has("a[href=\"" + document.location.pathname + "\"]").length == 0;

if ( hide ) {
item.addClass("collapsed");
} else {
item.addClass("expanded");
}

item.click(function(event){
if ( this == event.target ) {
item1 = jQuery(this);
var collapsed = item1.hasClass("collapsed");
item1.removeClass("expanded collapsed")
.addClass(collapsed ? "expanded" : "collapsed")
.children("ul").toggle();
return false;
}
});

if ( hide ) {
item.find("ul").hide();
}

}
});
});

})(this.jQuery);

Expand All @@ -49,8 +49,6 @@ window.log = function(){
}
};



// catch all document.write() calls
(function(doc){
var write = doc.write;
Expand All @@ -60,4 +58,29 @@ window.log = function(){
};
})(document);

(function($){
var cname = function(name) {
return name.replace(/[ \/<>]/g, '-');
}

var list;
if ( $("#toc").length ) {
list = $("<ul />");
$("#toc").append(list);
}


// Anchor all headers
$(":header:not(h1)").each(function(i) {
var current = $(this);
var text = current.text();
var id = cname(text);
current.attr("id", id);
current.append(' <a class=\"toc-anchor\" href=\"#' + encodeURIComponent(id) + '\">#</a>');
if(current.is("h2") && list){
list.append("<li><a href=\"#" + encodeURIComponent(id) + "\">" + text + "</a></li>");
}
});

})(jQuery);

0 comments on commit 1dabe3d

Please sign in to comment.