From 6f8751b479acfb78599a252dd9277feedea870aa Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Fri, 7 Feb 2014 13:04:02 +0000 Subject: [PATCH] chat server is going to be in its own dir --- .../web_root}/favicon.ico | Bin .../web_root}/index.html | 0 .../web_root}/jquery.js | 0 .../web_root}/login.html | 0 .../web_root}/logo.png | Bin .../web_root}/main.js | 16 ++++++++-------- .../web_root}/style.css | 0 7 files changed, 8 insertions(+), 8 deletions(-) rename examples/{chat_html_root => chat_server/web_root}/favicon.ico (100%) rename examples/{chat_html_root => chat_server/web_root}/index.html (100%) rename examples/{chat_html_root => chat_server/web_root}/jquery.js (100%) rename examples/{chat_html_root => chat_server/web_root}/login.html (100%) rename examples/{chat_html_root => chat_server/web_root}/logo.png (100%) rename examples/{chat_html_root => chat_server/web_root}/main.js (92%) rename examples/{chat_html_root => chat_server/web_root}/style.css (100%) diff --git a/examples/chat_html_root/favicon.ico b/examples/chat_server/web_root/favicon.ico similarity index 100% rename from examples/chat_html_root/favicon.ico rename to examples/chat_server/web_root/favicon.ico diff --git a/examples/chat_html_root/index.html b/examples/chat_server/web_root/index.html similarity index 100% rename from examples/chat_html_root/index.html rename to examples/chat_server/web_root/index.html diff --git a/examples/chat_html_root/jquery.js b/examples/chat_server/web_root/jquery.js similarity index 100% rename from examples/chat_html_root/jquery.js rename to examples/chat_server/web_root/jquery.js diff --git a/examples/chat_html_root/login.html b/examples/chat_server/web_root/login.html similarity index 100% rename from examples/chat_html_root/login.html rename to examples/chat_server/web_root/login.html diff --git a/examples/chat_html_root/logo.png b/examples/chat_server/web_root/logo.png similarity index 100% rename from examples/chat_html_root/logo.png rename to examples/chat_server/web_root/logo.png diff --git a/examples/chat_html_root/main.js b/examples/chat_server/web_root/main.js similarity index 92% rename from examples/chat_html_root/main.js rename to examples/chat_server/web_root/main.js index 6204d1ad..00c3e63f 100644 --- a/examples/chat_html_root/main.js +++ b/examples/chat_server/web_root/main.js @@ -3,7 +3,7 @@ var chat = { // Backend URL, string. // 'http://backend.address.com' or '' if backend is the same as frontend - backendUrl: '', + backendUrl: 'api.lp', maxVisibleMessages: 10, errorMessageFadeOutTimeoutMs: 2000, errorMessageFadeOutTimer: null, @@ -20,7 +20,7 @@ chat.refresh = function(data) { if (data === undefined) { return; } - + $.each(data, function(index, entry) { var row = $('
').addClass('message-row').appendTo('#mml'); var timestamp = (new Date(entry.timestamp * 1000)).toLocaleTimeString(); @@ -49,9 +49,7 @@ chat.refresh = function(data) { chat.getMessages = function(enter_loop) { $.ajax({ - dataType: 'jsonp', - url: chat.backendUrl + '/ajax/get_messages', - data: {last_id: chat.lastMessageId}, + data: {last_id: chat.lastMessageId, cmd: 'get_messages'}, success: chat.refresh, error: function() { }, @@ -82,9 +80,7 @@ chat.handleMessageInput = function(ev) { return; //input.disabled = true; $.ajax({ - dataType: 'jsonp', - url: chat.backendUrl + '/ajax/send_message', - data: {text: input.value}, + data: { text: input.value, cmd: 'send_message' }, success: function(ev) { input.value = ''; input.disabled = false; @@ -98,6 +94,10 @@ chat.handleMessageInput = function(ev) { }; $(document).ready(function() { + $.ajaxSetup({ + dataType: 'json', + url: chat.backendUrl + }); $('.menu-item').click(chat.handleMenuItemClick); $('.message-input').keypress(chat.handleMessageInput); chat.getMessages(true); diff --git a/examples/chat_html_root/style.css b/examples/chat_server/web_root/style.css similarity index 100% rename from examples/chat_html_root/style.css rename to examples/chat_server/web_root/style.css