-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
103 lines (68 loc) · 2.17 KB
/
script.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var documentation = {};
documentation.Document = function () {
};
documentation.Document.prototype.render = function () {
this.renderTableOfContents();
this.renderTableOfFigures();
};
documentation.Document.prototype.renderTableOfContents = function () {
var headers = $('h2'),
toc = $('#toc'),
i, j, node, id, chapter, li, childs, ol;
// skip first two headers (Abstract, TOC)
headers = headers.slice(2);
headers.each(function(i, element) {
element = $(element);
i = i + 1;
id = 'chapter-' + i;
li = documentation.createListItem(element, id, i);
childs = element.closest('.chapter').find('h3');
ol = $('<ol>');
childs.each(function (j, child) {
child = $(child);
j = j + 1;
id = 'chapter-' + i + '-' + j;
sli = documentation.createListItem(child, id, i, j);
ol.append(sli);
});
li.append(ol);
toc.append(li);
});
};
documentation.createListItem = function (node, id, chapter, subChapter) {
var li, a, spanChapter, spanTitle;
node.attr('id', id);
li = $('<li>');
a = $('<a>').attr('href', '#' + id);
chapter = '' + chapter;
if (typeof subChapter != 'undefined') {
chapter += '.' + subChapter;
}
$('<span>').appendTo(a).attr('class', 'chapter').text(chapter);
spanTitle = $('span');
spanTitle
spanTitle
$('<span>').appendTo(a).attr('class', 'title').text(node.text());
li.append(a);
return li;
};
documentation.Document.prototype.renderTableOfFigures = function () {
var captions = $('figcaption'),
figures = $('#figures'),
figure, li, a;
captions.each(function(i, caption) {
caption = $(caption);
figure = caption.parents('figure');
id = 'figure-' + i;
figure.attr('id', id);
caption.prepend('<span>Abb. ' + (i + 1) + ' </span>');
li = $('<li>');
a = $('<a>').attr('href', '#' + id).text(caption.text());
li.append(a);
figures.append(li);
});
};
$(function () {
var document = new documentation.Document();
document.render();
});