Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
labmlai
GitHub Repository: labmlai/annotated_deep_learning_paper_implementations
Path: blob/master/docs/ja/interactive.js
4934 views
1
var Highlighter = /** @class */ (function () {
2
function Highlighter() {
3
var _this = this;
4
this.onClick = function (e) {
5
var t = e.currentTarget.textContent;
6
if (!(t in _this.nodes)) {
7
console.log(e.currentTarget);
8
return;
9
}
10
if (_this.highlighted == t) {
11
_this.unhighlight();
12
}
13
else {
14
if (_this.highlighted != '') {
15
_this.unhighlight();
16
}
17
_this.highlightWord(t);
18
}
19
};
20
this.nodes = {};
21
this.highlighted = '';
22
this.addNodes(document.querySelectorAll('.highlight .n'));
23
this.addNodes(document.querySelectorAll('.highlight .nn'));
24
this.addNodes(document.querySelectorAll('.highlight .nc'));
25
this.addNodes(document.querySelectorAll('.highlight .nf'));
26
for (var k in this.nodes) {
27
for (var _i = 0, _a = this.nodes[k]; _i < _a.length; _i++) {
28
var n = _a[_i];
29
n.addEventListener('click', this.onClick);
30
}
31
}
32
}
33
Highlighter.prototype.unhighlight = function () {
34
for (var _i = 0, _a = this.nodes[this.highlighted]; _i < _a.length; _i++) {
35
var n = _a[_i];
36
n.classList.remove('clicked');
37
}
38
this.highlighted = '';
39
document.body.classList.remove('lights-off');
40
};
41
Highlighter.prototype.highlightWord = function (t) {
42
for (var _i = 0, _a = this.nodes[t]; _i < _a.length; _i++) {
43
var n = _a[_i];
44
n.classList.add('clicked');
45
}
46
document.body.classList.add('lights-off');
47
this.highlighted = t;
48
};
49
Highlighter.prototype.addNodes = function (nodes) {
50
for (var i = 0; i < nodes.length; ++i) {
51
var name_1 = nodes[i].textContent;
52
if (!(name_1 in this.nodes)) {
53
this.nodes[name_1] = [];
54
}
55
this.nodes[name_1].push(nodes[i]);
56
}
57
};
58
return Highlighter;
59
}());
60
var KatexHighlighter = /** @class */ (function () {
61
function KatexHighlighter() {
62
var _this = this;
63
this.onClick = function (e) {
64
e.preventDefault();
65
e.stopPropagation();
66
var t = KatexHighlighter.getName(e.currentTarget);
67
// console.log('clicked', t)
68
if (!(t in _this.nodes)) {
69
console.log(e.currentTarget);
70
return;
71
}
72
if (_this.highlighted == t) {
73
_this.unhighlight();
74
}
75
else {
76
if (_this.highlighted != '') {
77
_this.unhighlight();
78
}
79
_this.highlightWord(t);
80
}
81
};
82
this.nodes = {};
83
this.highlighted = '';
84
this.addNodes(document.querySelectorAll('.coloredeq'));
85
for (var k in this.nodes) {
86
for (var _i = 0, _a = this.nodes[k]; _i < _a.length; _i++) {
87
var n = _a[_i];
88
n.addEventListener('click', this.onClick);
89
}
90
}
91
}
92
KatexHighlighter.prototype.unhighlight = function () {
93
for (var _i = 0, _a = this.nodes[this.highlighted]; _i < _a.length; _i++) {
94
var n = _a[_i];
95
n.classList.remove('clicked');
96
}
97
this.highlighted = '';
98
document.body.classList.remove('lights-off');
99
};
100
KatexHighlighter.prototype.highlightWord = function (t) {
101
for (var _i = 0, _a = this.nodes[t]; _i < _a.length; _i++) {
102
var n = _a[_i];
103
n.classList.add('clicked');
104
}
105
document.body.classList.add('lights-off');
106
this.highlighted = t;
107
};
108
KatexHighlighter.getName = function (node) {
109
var name = '';
110
for (var i = 0; i < node.classList.length; ++i) {
111
var cn = node.classList[i];
112
if (cn.substr(0, 2) === 'eq') {
113
name = cn.substr(2);
114
}
115
}
116
return name;
117
};
118
KatexHighlighter.prototype.addNodes = function (nodes) {
119
for (var i = 0; i < nodes.length; ++i) {
120
var name_2 = KatexHighlighter.getName(nodes[i]);
121
console.log(nodes[i]);
122
if (!(name_2 in this.nodes)) {
123
this.nodes[name_2] = [];
124
}
125
this.nodes[name_2].push(nodes[i]);
126
}
127
};
128
return KatexHighlighter;
129
}());
130
function addListeners() {
131
var h = new Highlighter();
132
var k = new KatexHighlighter();
133
}
134
if (document.readyState == "complete") {
135
addListeners();
136
}
137
else {
138
document.onreadystatechange = function () {
139
if (document.readyState == "complete") {
140
addListeners();
141
}
142
};
143
}
144
145