$(document).ready(function() { var showToc = false; var content = $('div.field-content > p'); if(content.size() == 0) { return; } var hc = content[0].childNodes; for (var i = 0; i < hc.length; i++) { if(hc[i].nodeType == 8 && hc[i].nodeValue == 'toc') { showToc = true; break; } } if(!showToc) { return; } var lElem = 'ol'; var headings = new Array(); var counter = 0; var hCounter = 0; var toc = ''; var lastText = null; $('#main :header').each(function() { if(true || $(this).parent()[0].nodeName != 'A') { if(true || counter > 0) { var text = $(this).text(); if(lastText == null || text != lastText && $(this).css('display') != 'none') { var valueHolder = new Array(); valueHolder[0] = this.nodeName; if(this.nodeName != 'H1') { valueHolder[1] = text; headings[hCounter++] = valueHolder; lastText = text; var link = text.replace(/\s+/g, '_'); $(this).html('' + text + ''); var src = '/files/media/images/top.png'; if(location.href.indexOf('/drupal/') != -1) { src = '/drupal/' + src; } var topLink = $('Top'); topLink.css('position', 'relative'); topLink.css('top', '-10px'); $(this).append(topLink); $(this).css('width', '100%'); } } } counter++; } }); var curLevel = 0; var prevLevel = 0; toc += '<' + lElem + '>'; for(var i = 0; i < headings.length; i++) { var valueHolder = headings[i]; var link = valueHolder[1].replace(/\s+/g, '_'); toc += '
  • ' + valueHolder[1] + '
  • '; } toc += ''; $('#main h1.title:last').after(toc); // alert(toc); });