aboutsummaryrefslogtreecommitdiffstats
path: root/examples/example_chat.html
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-07 01:18:33 +0900
committeripknHama <ipknhama@gmail.com>2014-08-07 01:18:33 +0900
commit031615ac866cc3c8f1900dd4b4aae2106ad31230 (patch)
treeb8b7206ffbd2043368580ec269c97436929fe452 /examples/example_chat.html
parenta0c93f5b84cc11b30bc6320ac26127832ef8bf7a (diff)
downloadcrow-031615ac866cc3c8f1900dd4b4aae2106ad31230.tar.gz
crow-031615ac866cc3c8f1900dd4b4aae2106ad31230.zip
source resturcturing + CMake
Diffstat (limited to 'examples/example_chat.html')
-rw-r--r--examples/example_chat.html54
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/example_chat.html b/examples/example_chat.html
new file mode 100644
index 0000000..233e093
--- /dev/null
+++ b/examples/example_chat.html
@@ -0,0 +1,54 @@
+<html>
+<head>
+<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
+</head>
+<body>
+<input id="msg" type="text">
+<button id="send">Send</button>
+<div id="logs">
+</div>
+<script>
+$(document).ready(function(){
+ $("#send").click(function(){
+ var msg = $("#msg").val();
+ console.log(msg);
+ if (msg.length > 0)
+ $.post("/send", msg);
+ $("#msg").val("");
+ });
+ $("#msg").keyup(function(event){
+ if(event.keyCode == 13){
+ $("#send").click();
+ }
+ });
+ var lastLog = 0;
+ var updateLog;
+ updateLog = function(data)
+ {
+ console.log("recv ");
+ console.log(data);
+ var lastLog = data.last*1;
+ console.log("lastLog: " + lastLog);
+ var s = "";
+ function htmlEncode(s)
+ {
+ return s.replace(/&(?!\w+([;\s]|$))/g, "&amp;")
+ .replace(/</g, "&lt;").replace(/>/g, "&gt;");
+ }
+ for(var x in data.msgs)
+ {
+
+ s = htmlEncode(data.msgs[x]) + "<BR>" + s;
+ }
+ $("#logs").html(s+$("#logs").html());
+ var failFunction;
+ failFunction = function(){
+ $.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
+ };
+ $.getJSON("/logs/"+lastLog, updateLog).fail(failFunction);
+ }
+ $.getJSON("/logs", updateLog);
+});
+</script>
+</body>
+</html>