-
Notifications
You must be signed in to change notification settings - Fork 0
/
back.html
69 lines (58 loc) · 2.5 KB
/
back.html
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
<!-- See ginger51011/prty-shortcut-cards for full source -->
<div class="note">
<div class="title-container">
<span class="title-text">
{{Software}}
{{^Software}}
Unspecified Software
{{/Software}}
</span>
</div>
<div class="front-container">
{{Action}}
</div>
<!-- Front of card ends -->
<hr class="card-divider"/>
<!-- Back of card begins -->
<span id="shortcut-combo-1" hidden>{{Key Combination}}</span>
<span id="shortcut-combo-2" hidden>{{Extra Key Combination}}</span>
<!-- Is unhidden when element is ready -->
<div id="formatted-shortcut" class="shortcut-container" hidden>
{{^Key Combination}}
<i>Fill field shortcut in form `Ctrl Shift P` to format!</i>
{{/Key Combination}}
</div>
<script>
// Block so const will go out of scope when appropriate
{
const shortcutText = document.getElementById('shortcut-combo-1').innerText;
const extracomboText = document.getElementById('shortcut-combo-2').innerText;
const shortcutContainer = document.getElementById('formatted-shortcut');
const shortcutArray = shortcutText.split(' ');
appendKbd(shortcutArray, shortcutContainer);
if (extracomboText && extracomboText.length !== 0) {
// Add space before next combination
shortcutContainer.append(' ');
const extraArray = extracomboText.split(' ');
appendKbd(extraArray, shortcutContainer);
}
// Was hidden until now, so building of element cannot be seen
shortcutContainer.removeAttribute('hidden');
/**
* Appends a combo of keys, properly formatted as `<kbd>` elements
*/
function appendKbd(comboArray, container) {
comboArray.forEach((key, index) => {
if (index !== 0) {
// Prepend a plus, this is not the first in a combo. Add
// word boundaries to allow for wrapping
container.append(document.createElement('wbr'), '+', document.createElement('wbr'));
}
const newElement = document.createElement('kbd');
newElement.innerText = key;
container.append(newElement);
});
}
}
</script>
</div>