You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1023 B
35 lines
1023 B
/**
|
|
* // call this after the page has loaded
|
|
* htmlTableOfContents();
|
|
* I've refactored this to support older browsers such as ie8 and ie7. What a life.
|
|
*/
|
|
|
|
function htmlTableOfContents () {
|
|
var toc = document.getElementById('toc');
|
|
var headings;
|
|
|
|
if( navigator.userAgent.indexOf("MSIE") != -1 ) {
|
|
headings = document.getElementsByTagName('h2');
|
|
} else {
|
|
headings = document.querySelectorAll("h2");
|
|
}
|
|
|
|
var list = document.createElement('ul');
|
|
var heading = document.createElement('h2');
|
|
|
|
for(var i = 0, n = headings.length; i < n; i ++) {
|
|
var listItem = document.createElement('li');
|
|
var link = document.createElement('a');
|
|
link.href = '#' + headings[i].id;
|
|
link.innerText = headings[i].innerText.replace(' #','');
|
|
listItem.appendChild(link);
|
|
list.appendChild(listItem);
|
|
}
|
|
|
|
heading.id = "contents";
|
|
heading.innerText = 'Contents';
|
|
toc.appendChild(heading);
|
|
toc.appendChild(list);
|
|
}
|
|
|
|
htmlTableOfContents(); |