Template:UCSF/Header
From 2010.igem.org
(Difference between revisions)
Line 36: | Line 36: | ||
</style> | </style> | ||
+ | <script> | ||
<script> | <script> | ||
function getElementsByTagNames(list,obj) { | function getElementsByTagNames(list,obj) { | ||
Line 62: | Line 63: | ||
return resultArray; | return resultArray; | ||
} | } | ||
+ | |||
+ | function createTOC() { | ||
+ | var y = document.createElement('div'); | ||
+ | y.id = 'innertoc'; | ||
+ | var a = document.createElement('a'); | ||
+ | a.innerHTML="<b>Page Content -</b>"; | ||
+ | a.id = 'contentheader'; | ||
+ | a.onclick = showhideTOC; | ||
+ | y.appendChild(a); | ||
+ | var z = y.appendChild(document.createElement('div')); | ||
+ | z.id='tocDIV'; | ||
+ | var bodycon = document.getElementById('Main'); | ||
+ | var toBeTOCced = getElementsByTagNames('h3,h4,h5',bodycon); | ||
+ | if (toBeTOCced.length < 2) return false; | ||
+ | |||
+ | for (var i=0;i<toBeTOCced.length;i++) { | ||
+ | var tmp = document.createElement('a'); | ||
+ | var reg = /<b>([^<]+)<\/b>/; | ||
+ | var str = toBeTOCced[i].innerHTML; | ||
+ | var result = reg.exec(str); | ||
+ | tmp.innerHTML = result[1]; | ||
+ | tmp.className = 'page'; | ||
+ | z.appendChild(tmp); | ||
+ | z.appendChild(document.createElement('br')); | ||
+ | if (toBeTOCced[i].nodeName == 'H4') | ||
+ | tmp.className += ' indent'; | ||
+ | if (toBeTOCced[i].nodeName == 'H5') | ||
+ | tmp.className += ' extraindent'; | ||
+ | var headerId = result[1]; | ||
+ | tmp.href = '#' + headerId; | ||
+ | toBeTOCced[i].id = headerId; | ||
+ | if (toBeTOCced[i].nodeName == 'H2') { | ||
+ | tmp.innerHTML = 'Top'; | ||
+ | tmp.href = '#top'; | ||
+ | toBeTOCced[i].id = 'top'; | ||
+ | } | ||
+ | } | ||
+ | return y; | ||
+ | } | ||
+ | |||
var TOCstate = 'block'; | var TOCstate = 'block'; | ||
+ | |||
+ | function showhideTOC() { | ||
+ | TOCstate = (TOCstate == 'none') ? 'block' : 'none'; | ||
+ | var newText = (TOCstate == 'none') ? 'Page Content +' : 'Page Content -'; | ||
+ | document.getElementById('contentheader').innerHTML = '<strong>'+newText+'</strong>'; | ||
+ | document.getElementById('innertoc').lastChild.style.display = TOCstate; | ||
+ | } | ||
+ | |||
</script> | </script> | ||
<style> | <style> |
Latest revision as of 09:47, 23 October 2010