This repository has been archived by the owner on Oct 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
93 lines (80 loc) · 2.82 KB
/
main.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
(() => {
document.addEventListener('DOMContentLoaded', () => {
// Do this in javascript so that if it's disabled, we don't collapse everything.
for (let header of document.querySelectorAll('.site-nav > div')) {
header.classList.add('collapsed');
}
// expand things on click.
document.querySelector('.site-nav').addEventListener('click', (e) => {
let target = e.target;
if (target.classList.contains('site-nav') || target.localName == 'a') {
return;
}
while (target.parentNode && !target.parentNode.classList.contains('site-nav')) {
target = target.parentNode;
}
if (!target.parentNode) {
return;
}
target.classList.toggle('collapsed');
});
// Add play/pause buttons to animated images.
document.querySelectorAll('.animated > img').forEach(image => {
let playSource = image.src;
image.src = image.src.replace(/\.gif$/, "-play.png");
image.addEventListener('click', (e) => {
let image = e.target;
if (image.src !== playSource) {
image.src = playSource;
} else {
image.src = image.src.replace(/\.gif$/, "-pause.png");
}
});
});
// Add click-to-copy colours.
document.querySelectorAll('code').forEach(node => {
node.classList.add('copyable');
node.addEventListener('click', e => {
let text = e.target.textContent;
if (!text) {
return;
}
e.preventDefault();
let copyElement = document.createElement('input');
copyElement.setAttribute('type', 'text');
copyElement.setAttribute('value', text);
copyElement = document.body.appendChild(copyElement);
copyElement.select();
document.execCommand('copy');
copyElement.remove();
e.target.classList.add('copied');
setTimeout(() => {e.target.classList.remove('copied')}, 1000);
});
});
document.querySelectorAll('table.colors').forEach(node => {
node.querySelectorAll('td.name').forEach(color => {
color.classList.add('copyable');
});
node.addEventListener('click', e => {
let code;
let text;
if (e.target.classList.contains('name')) {
code = e.target.parentNode.querySelector('td > code');
text = code.textContent;
}
if (!text) {
return;
}
let copyElement = document.createElement('input');
copyElement.setAttribute('type', 'text');
copyElement.setAttribute('value', text);
copyElement = document.body.appendChild(copyElement);
copyElement.select();
document.execCommand('copy');
copyElement.remove();
code.classList.add('copied');
setTimeout(() => {code.classList.remove('copied')}, 1000);
});
});
});
})();