Commit 05062be8 authored by Sergey Lyubka's avatar Sergey Lyubka

Fix for issue 257

parent ba6c01e6
...@@ -16,6 +16,11 @@ chat.normalizeText = function(text) { ...@@ -16,6 +16,11 @@ chat.normalizeText = function(text) {
}; };
chat.refresh = function(data) { chat.refresh = function(data) {
if (data === undefined) {
return;
}
$.each(data, function(index, entry) { $.each(data, function(index, entry) {
var row = $('<div>').addClass('message-row').appendTo('#mml'); var row = $('<div>').addClass('message-row').appendTo('#mml');
var timestamp = (new Date(entry.timestamp * 1000)).toLocaleTimeString(); var timestamp = (new Date(entry.timestamp * 1000)).toLocaleTimeString();
...@@ -42,7 +47,7 @@ chat.refresh = function(data) { ...@@ -42,7 +47,7 @@ chat.refresh = function(data) {
} }
}; };
chat.getMessages = function() { chat.getMessages = function(enter_loop) {
$.ajax({ $.ajax({
dataType: 'jsonp', dataType: 'jsonp',
url: chat.backendUrl + '/ajax/get_messages', url: chat.backendUrl + '/ajax/get_messages',
...@@ -51,7 +56,9 @@ chat.getMessages = function() { ...@@ -51,7 +56,9 @@ chat.getMessages = function() {
error: function() { error: function() {
}, },
}); });
window.setTimeout(chat.getMessages, chat.getMessagesIntervalMs); if (enter_loop) {
window.setTimeout('chat.getMessages(true)', chat.getMessagesIntervalMs);
}
}; };
chat.handleMenuItemClick = function(ev) { chat.handleMenuItemClick = function(ev) {
...@@ -81,7 +88,7 @@ chat.handleMessageInput = function(ev) { ...@@ -81,7 +88,7 @@ chat.handleMessageInput = function(ev) {
success: function(ev) { success: function(ev) {
input.value = ''; input.value = '';
input.disabled = false; input.disabled = false;
chat.getMessages(); chat.getMessages(false);
}, },
error: function(ev) { error: function(ev) {
chat.showError('Error sending message'); chat.showError('Error sending message');
...@@ -93,7 +100,7 @@ chat.handleMessageInput = function(ev) { ...@@ -93,7 +100,7 @@ chat.handleMessageInput = function(ev) {
$(document).ready(function() { $(document).ready(function() {
$('.menu-item').click(chat.handleMenuItemClick); $('.menu-item').click(chat.handleMenuItemClick);
$('.message-input').keypress(chat.handleMessageInput); $('.message-input').keypress(chat.handleMessageInput);
chat.getMessages(); chat.getMessages(true);
}); });
// vim:ts=2:sw=2:et // vim:ts=2:sw=2:et
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment