Created
May 29, 2015 02:49
-
-
Save samnang/cb9515ffcf5b0ab03f8f to your computer and use it in GitHub Desktop.
TOC of Github's README
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tocLink(heading, title, href) { | |
var ele = '<li class="tooltipped tooltipped-w" aria-label="'+title+'">'+ | |
'<a href="'+href+'" aria-label="'+title+'"'+ | |
'class="js-selected-navigation-item sunken-menu-item">'+ | |
'<span class="full-word">'+title+'</span></a></li>' | |
return ele; | |
} | |
var header = "<li class='tooltipped tooltipped-w'><strong> Table of Contents</strong></li>" | |
var rows = []; | |
$('a[class=anchor').each(function(i, anchor) { | |
$anchor = $(anchor); | |
$heading = $anchor.parent(); | |
rows.push( | |
tocLink( | |
$heading.prop("tagName").toLowerCase(), | |
$heading.text(), | |
$anchor.attr('href') | |
) | |
); | |
}) | |
var template = "<div class='repository-sidebar'><nav class='sunken-menu repo-nav' role='navigation'><div class='sunken-menu-separator'></div><ul class='sunken-menu-group'>"+ | |
header+rows.join('')+"</ul></nav></div>" | |
$($('.repository-with-sidebar.with-full-navigation .repository-sidebar')[0]).append(template); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment