-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtrivia.js
71 lines (63 loc) · 1.9 KB
/
trivia.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
var wavesurfer = window.wavesurfer;
var GLOBAL_ACTIONS = {
play: function() {
wavesurfer.playPause();
},
back: function() {
wavesurfer.skipBackward();
},
forth: function() {
wavesurfer.skipForward();
},
'toggle-mute': function() {
wavesurfer.toggleMute();
}
};
// Bind actions to buttons and keypresses
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('keydown', function(e) {
var map = {
32: 'play', // space
37: 'back', // left
39: 'forth' // right
};
var action = map[e.keyCode];
if (action in GLOBAL_ACTIONS) {
if (document == e.target || document.body == e.target) {
e.preventDefault();
}
GLOBAL_ACTIONS[action](e);
}
});
[].forEach.call(document.querySelectorAll('[data-action]'), function(el) {
el.addEventListener('click', function(e) {
var action = e.currentTarget.dataset.action;
if (action in GLOBAL_ACTIONS) {
e.preventDefault();
GLOBAL_ACTIONS[action](e);
}
});
});
});
// Misc
document.addEventListener('DOMContentLoaded', function() {
// Web Audio not supported
if (!window.AudioContext && !window.webkitAudioContext) {
var demo = document.querySelector('#demo');
if (demo) {
demo.innerHTML = '<img src="/example/screenshot.png" />';
}
}
// Navbar links
var ul = document.querySelector('.nav-pills');
var pills = ul.querySelectorAll('li');
var active = pills[0];
if (location.search) {
var first = location.search.split('&')[0];
var link = ul.querySelector('a[href="' + first + '"]');
if (link) {
active = link.parentNode;
}
}
active && active.classList.add('active');
});