Skip to content

Commit

Permalink
chat now hides!
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnsmith0508 committed Oct 30, 2015
1 parent c4884bd commit ec4d161
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
5 changes: 4 additions & 1 deletion client.js
Expand Up @@ -3,7 +3,7 @@ var scene, camera, renderer, container;
var geometry, material, clientMaterial, mesh, planeGeom, planeMaterial;
var socket = new io();
var stats = new Stats();
var key = {w:false,a:false,s:false,d:false,q:false,e:false,space:false,shift: false,keyPressed:0};
var key = {w:false,a:false,s:false,d:false,q:false,e:false,t:false,space:false,shift: false,keyPressed:0};
var height = 7;
var size = 3;
var userName;
Expand Down Expand Up @@ -182,6 +182,9 @@ var buttonHandler = function(keyPressed,status)
case 32:
key.space = status;
break;
case 84:
key.t = status;
break;
}
if (keyPressed.shiftKey)
{
Expand Down
20 changes: 2 additions & 18 deletions index.html
Expand Up @@ -20,28 +20,12 @@ <h1>Enter a user name</h1>
</div>
<div id="main_window" hidden>
<script src="/client.js"></script>
<script src="/js/chatlogic.js"></script>
<div id="threeJsRenderWindow"></div>
<div class="chat">
<div class="chat" hidden>
<ul id="messages"></ul>
<input id="msgIn" autocomplete="off"/>
<button id="send">Send</button>

<script>
$('#send').on('click',function(){
socket.emit('chat message', $('#msgIn').val());
$('#msgIn').val('');
return false;
});
$('#msgIn').on('keyup',function(e)
{
if(e.keyCode == 13) {
$('#send').trigger('click');
}
});
socket.on('chat message', function(payload){
$('#messages').append($('<li>').text(payload.name + ': ' + payload.msg));
});
</script>
</div>
</div>
</body>
Expand Down
26 changes: 26 additions & 0 deletions js/chatlogic.js
@@ -0,0 +1,26 @@
$('#send').on('click',function(){
socket.emit('chat message', $('#msgIn').val());
$('#msgIn').val('');
$(".chat").hide();
});
$('#msgIn').on('keyup',function(e)
{
if(e.keyCode == 13) {
$('#send').trigger('click');
}
});
socket.on('chat message', function(payload){
$('#messages').append($('<li>').text(payload.name + ': ' + payload.msg));
$(".chat").show();
setTimeout(function(){
$(".chat").hide();
},5000);
});

$(document).on('keyup',function(e)
{
if(e.which == 84)
{
$(".chat").show();
}
});
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "socket-chat-example",
"version": "1.0",
"version": "1.0.0",
"description": "my first socket.io app",
"dependencies": {
"express": "^4.13.3",
Expand Down

1 comment on commit ec4d161

@Johnsmith0508
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy detected an issue:

Message: "$" is not defined.

Occurred on:

Currently on:

Please sign in to comment.