-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·73 lines (65 loc) · 1.37 KB
/
script.js
File metadata and controls
executable file
·73 lines (65 loc) · 1.37 KB
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
$(function(){
poll();
thinking_overlay('Loading');
remove_overlay();
window.setInterval(function(){poll()},3000);
$('#skip').on('click',function(){
skip();
});
$('.song-btn').on('click',function(){
vote($(this).attr('song-id'), $(this).find('.song-name').html());
});
});
function remove_overlay(){
$('html').removeClass("loading");
}
function thinking_overlay(message){
$('.modal h1').html(message);
$('html').addClass("loading");
}
function poll(){
$.ajax({
url: 'rpc.php',
type: 'POST',
data: {action: 'poll'},
})
.done(function(result) {
$.each(result.payload, function( index, value ) {
$('#' + index).find('.song-name').html(value.btn_label);
$('#' + index).find('.song-votes').html(value.votes);
$('#' + index).attr('song-id', value.song_id);
});
});
}
function vote(song_id, title){
thinking_overlay('casting vote for<br/>' + title);
$.ajax({
url: 'rpc.php',
type: 'POST',
async: false,
data: {song_id: song_id, action: 'vote'},
})
.done(function() {
poll();
})
.fail(function() {
remove_overlay();
});
setTimeout(function(){remove_overlay()}, 2000);
}
function skip(){
thinking_overlay('skipping vote');
$.ajax({
url: 'rpc.php',
type: 'POST',
async: false,
data: {action: 'skip'},
})
.done(function() {
poll();
})
.fail(function() {
remove_overlay();
});
setTimeout(function(){remove_overlay()}, 2000);
}