diff options
Diffstat (limited to 'static/script.js')
-rw-r--r-- | static/script.js | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/static/script.js b/static/script.js index d6cad6e..d96650c 100644 --- a/static/script.js +++ b/static/script.js @@ -2,26 +2,9 @@ var player; var litColor = '#eee'; var dimmedColor = '#555'; var interval; +var timestamp = '0'; + $(document).ready(function () { - var poller = new Worker('/static/poller.js'); - poller.onmessage = function (e) { - for (var i = 0; i < e.data.updates.length; i++) { - update = e.data.updates[i]; - switch (update.action) { - case 0: // see updates.go:addAction - drawAdd(update); - break; - case 1: - drawRemove(update.yid); - break; - case 2: - case 3: - drawMove(update.yid, update.action); - break; - } - } - } - poller.postMessage({pid: pid}); $('body').click(function (e) { if (e.target.id !== 'results') { $('#results').slideUp(100); @@ -36,8 +19,44 @@ $(document).ready(function () { for (var i = 0; i < ids.length; i++) { drawBar(ids[i]); } + getUpdates(); }); +function getUpdates() { + $.ajax({ + url: '/poll/', + dataType: 'json', + data: {pid: pid, timestamp: timestamp}, + success: handleUpdates, + complete: getUpdates + }); +} + +function handleUpdates(data) { + var updates = []; + for (var i = 0; i < data.length; i++) { + timestamp = data[i].Timestamp; + var update = { + 'action': data[i].Action, + 'yid': data[i].Song.Yid, + 'title': data[i].Song.Title, + 'user': data[i].Song.User + } + switch (update.action) { + case 0: // see updates.go:addAction + drawAdd(update); + break; + case 1: + drawRemove(update.yid); + break; + case 2: + case 3: + drawMove(update.yid, update.action); + break; + } + } +} + function drawBar(id) { var canvas = document.getElementById('c_' + id); if (!canvas) return; |