/***************************************************************** * * $.toc() * by rebecca murphey * rmurphey gmail com * * This function is called on its own and takes as an argument * a list of selectors with which it will build a table of * contents. * * The first selector will make up the top level of the TOC; * the second selector will make up the second level of the TOC; * etc. * * This function returns a div containing nested unordered lists; * each list item is linked to an anchor tag added before the item * on the page. * * usage: $.toc('h1,h2,h3').prependTo('body'); * ************************************************************************/ (function($) { $.toc = function(tocList) { $(tocList).addClass('jquery-toc'); var tocListArray = tocList.split(','); $.each(tocListArray, function(i,v) { tocListArray[i] = $.trim(v); }); var $elements = $('.jquery-toc'); $('body').append('
'); var $toc = $('body div:last'); var lastLevel = 1; $toc.append('