Debian Codegraph @

tools/unicode_comparison/html/scripts.html

raw
1 {{ define "scripts" }}
2
3 currentId = '';
4 currentType = '';
5 currentChunk = '';
6
7 function switchSign(element) {
8 if (!element) return false;
9 if (element.tagName !== "A") return false;
10 if (!element.hasAttribute('href')) return false;
11 if (element.innerHTML[0] == '+') {
12 element.innerHTML = '-' + element.innerHTML.substring(1);
13 return true;
14 } else {
15 element.innerHTML = '+' + element.innerHTML.substring(1);
16 return true;
17 }
18 }
19
20 function recurse(id) {
21 var children = document.getElementsByClassName(id);
22 for (let i = 0; i < children.length; i++) {
23 children[i].classList.toggle("open");
24 if (switchSign(children[i])) {
25 recursive(children[i].getAttribute('href').substring(1));
26 }
27 }
28 }
29
30 document.getElementById("comparison").addEventListener("click", function (e) {
31 if (!e) return;
32 e.preventDefault();
33 if (switchSign(e.target)) {
34 recurse(e.target.getAttribute('href').substring(1));
35 }
36 });
37
38 function hideDiff() {
39 if (currentId == '') {
40 return;
41 }
42
43 let spans = document.querySelectorAll(`#id_${currentId} > td > div > span.${currentType}`);
44 [].forEach.call(spans, function(span) { span.classList.remove(`span_${currentType}`); });
45
46 let inactives = document.querySelectorAll(`#${currentType}_${currentChunk}${currentId}`);
47 [].forEach.call(inactives, function(inactive) { inactive.classList.add('inactive'); });
48
49 let invisibles = document.querySelectorAll(`#id_${currentId} > td > div.${currentType}`);
50 [].forEach.call(invisibles, function(invisible) { invisible.classList.add('invisible'); });
51
52 currentId = '';
53 currentType = '';
54 currentChunk = '';
55 }
56
57 function showDiff(id, type, chunkType) {
58 hideDiff();
59
60 let spans = document.querySelectorAll(`#id_${id} > td > div > span.${type}`);
61 [].forEach.call(spans, function(span) { span.classList.add(`span_${type}`); });
62
63 let inactives = document.querySelectorAll(`#${type}_${chunkType}${id}`);
64 [].forEach.call(inactives, function(inactive) { inactive.classList.remove('inactive'); });
65
66 let invisibles = document.querySelectorAll(`#id_${id} > td > div.${type}`);
67 [].forEach.call(invisibles, function(invisible) { invisible.classList.remove('invisible'); });
68
69 currentId = id;
70 currentType = type;
71 currentChunk = chunkType;
72 }
73
74 {{ end }}