Skip to content

Commit

Permalink
Add js/css/html files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmw511 committed Sep 19, 2015
1 parent 8f36af1 commit 25eb22c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chat/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
width: 100%;
height: 100%;
}

#chat {
width: 100%;
color: #000000;
font-size: 12pt;
overflow: auto;
}
23 changes: 23 additions & 0 deletions chat/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div id="chat"></div>
<form id="input">
<input type="text" id="message" size="50"/>
<input type="submit" value="Send" />
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-2.1.4.min.js"><\/script>')</script>
<script src="js/main.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions chat/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$(function() {
var inputField = $("#message");
var chat = $("#chat");

var socket = new WebSocket("ws://WEBSOCKET_URL");
socket.onclose = function(evt) {
$("<p><b>Connection closed.</b></p>").appendTo(chat);
}
socket.onmessage = function(evt) {
$("<p>" + evt.data + "</p>").appendTo(chat);
}

$("#input").submit(function() {
if (socket == null) return false;
if (inputField.val() == null) return false;

socket.send(inputField.val());
inputField.val("");

return false
});
});

0 comments on commit 25eb22c

Please sign in to comment.