Implement webchat and badge notifications

This commit is contained in:
Trever Fischer
2012-10-23 13:10:06 -04:00
parent c5d644371d
commit 6b8239eb3f
7 changed files with 137 additions and 8 deletions

View File

@@ -1,8 +1,21 @@
function sendChat(message) {
$.post('/api/chat', {'message': message}, function(data) {
$('#chat-line').val('');
$('#chat-line').disabled = false;
});
}
$(document).ready(function() {
$('#server-interaction .drawer').each(function() {
var canvas = $(this).children('.canvas');
$(this, '.drawer-label').click(function() {
$(this).children('.drawer-label').click(function() {
canvas.slideToggle("blind");
});
});
$('#chat-line').keypress(function(evt) {
if (evt.charCode == 13) {
$('#chat-line').disabled = true;
sendChat($('#chat-line').val());
}
});
});

View File

@@ -1,12 +1,23 @@
function pollMessages() {
$.get('/api/poll/0', function(data) {
function pollMessages(id) {
$.get('/api/poll/'+id, function(data) {
if (id == 0)
$('#chat-display').html('');
$('#balance-display').html(data['user-info']['balance']);
$(data['events']).each(function(idx, evt) {
if (evt['type'] == "chat") {
$('#chat-display').append("<li>"+evt['payload']['sender']+": "+evt['payload']['message']);
} else if (evt['type'] == 'join') {
$('#chat-display').append("<li><em>"+evt['payload']['player']+" has joined</em></li>");
} else if (evt['type'] == 'quit') {
$('#chat-display').append("<li><em>"+evt['payload']['player']+" has quit</em></li>");
}
});
window.setTimeout(function() {pollMessages(data['poll-id'])}, 1);
});
}
function poll() {
pollMessages();
window.setTimeout(pollMessages, 3000);
pollMessages(0);
}
$(document).ready(function () {