Skip to content
Browse files

Restore missing TOC code, add anchor links to headers.

  • Loading branch information...
1 parent 863afcc commit 1dabe3dd483b3746d25fa69ec95edc681d4732ad @seancribbs seancribbs committed Feb 14, 2011
Showing with 75 additions and 36 deletions.
  1. +0 −2 _Layout.html
  2. +18 −0 css/wiki_specific.css
  3. +57 −34 js/plugins.js
View
2 _Layout.html
@@ -94,8 +94,6 @@
<article>
- <div id="toc"></div>
-
<hgroup>
<h1>{{ page.title }}</h1>
<div class="clearfix"></div>
View
18 css/wiki_specific.css
@@ -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;
+}
View
91 js/plugins.js
@@ -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);
@@ -49,8 +49,6 @@ window.log = function(){
}
};
-
-
// catch all document.write() calls
(function(doc){
var write = doc.write;
@@ -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.
Something went wrong with that request. Please try again.