-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
39 lines (39 loc) · 1.26 KB
/
javascript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Generates table of Contents dynamically from header tags.
* @param int start - Beginning header level
* @param int deep - How many levels deep to parse
* @param string target - Target that contains headings to parse
* @param bool linkOnly - Display only headings that can be linked to? (contain id)
* @author Carl <[email protected]>
*/
function toc(start,deep,target,linkOnly){
var level = parseInt(start);
rreturn = "<div id='tableOfContents'>Table of Contents";
rreturn += '<ul>';
jQuery(target+' :header').each(function() {
var objLevel = this.nodeName.substring(1,2);
if(objLevel <= deep && objLevel >= start && (jQuery(this).attr('id') || linkOnly==false)){
if(objLevel > level){
while (objLevel > level){
rreturn += '<li><ul>';
level = parseInt(level) + 1;
}
level = parseInt(objLevel);
}else if(objLevel < level){
while (objLevel < level){
rreturn += '</ul></li>';
level = parseInt(level) - 1;
}
level = parseInt(objLevel);
}
rreturn += '<li>';
rreturn += "<a href='#"+jQuery(this).attr('id')+"'>";
rreturn += jQuery(this).text();
rreturn += '</a>';
rreturn += '</li>';
}
});
rreturn += '</ul>';
rreturn += '</div>';
return rreturn;
}