Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Client-side js cleanup

  • Loading branch information...
commit 03d949571ce3477b9ddd6d782f95bcc3d1a55e8d 1 parent 3623c71
@robrighter authored
Showing with 28 additions and 104 deletions.
  1. +24 −25 project/app.js
  2. +0 −78 project/static/js/site.js
  3. +4 −1 project/views/index.ejs
View
49 project/app.js
@@ -1,9 +1,10 @@
+//setup Dependencies
require('../lib/setup').ext( __dirname + "/../lib").ext( __dirname + "/../lib/express/support");
var connect = require('connect');
var sys = require('sys');
var io = require('socket.io-node');
-
+//Setup Express
var server = require('express').createServer();
server.configure(function(){
server.set('views', __dirname + '/views');
@@ -11,39 +12,37 @@ server.configure(function(){
server.use(server.router);
server.use(connect.staticProvider('./static'));
});
-
var port = 8765;
server.listen( port);
+
+//Setup Socket.IO
+var io = io.listen(server);
+io.on('connection', function(client){
+ console.log('Client Connected');
+ client.on('message', function(message){
+ client.broadcast(message);
+ client.send(message);
+ });
+ client.on('disconnect', function(){
+ console.log('Client Disconnected.');
+ });
+});
+
console.log('Listening on http://0.0.0.0:' + port )
-server.get('/test', function(req,res){
+
+//Routes
+server.get('/', function(req,res){
res.render('index.ejs', {
locals : {
- header: 'This is a header'
- ,footer: 'This is a footer'
- ,title : 'A Test Page'
- ,description: 'Description Here'
+ header: '#Header#'
+ ,footer: '#Footer#'
+ ,title : 'Page Title'
+ ,description: 'Page Description'
,author: 'Your Name'
- ,analyticssiteid: 'XXXXXXX'
- ,info: 'And this is info'
+ ,analyticssiteid: 'XXXXXXX'
}
});
- res.send("HELLO");
});
-var io = io.listen(server);
-
-io.on('connection', function(client){
- console.log('WE GOT A CONNECTION!!!!!!!');
-
- client.on('message', function(message){
- console.log('Recieved Message:\n' + sys.inspect(message));
- client.broadcast(message);
- client.send(message);
- console.log('Brodcasted the following message: ' + message);
- });
- client.on('disconnect', function(){
- console.log('WE GOT A DISCONNECT!!!!!!!!!!');
- });
-});
View
78 project/static/js/site.js
@@ -1,78 +0,0 @@
-var colorList = ['#FFDC48', '#F67F7F', '#FD6BA6', '#67D384', '#B0C9E8'];
-
-var setNameColor = function(color){
- currentcolor = color;
- $('#name').css("background-color", color);
- };
-
- var grabRandomColor = function(){
- return colorList[Math.floor(Math.random()*colorList.length)];
- };
-
- var changeColor = function(){
- setNameColor(grabRandomColor());
- };
-
-var formatMessageHtml = function(messagejson){
- if(messagejson.hasOwnProperty('color') && messagejson.hasOwnProperty('name') && messagejson.hasOwnProperty('comment')){
- var t = _.template("<div class='messageitem' style='display : none;'><span class='name' style='color: <%= color %>;'><%= name %>:</span> <span class='comment'><%= comment %></span></div>");
- return t(messagejson);
- }
- else {
- return "";
- }
-
-};
-
-var insertMessage = function(messagejson){
- socket.send(JSON.stringify(messagejson));
- $('#comment').val('');
-};
-
-var incomingMessage = function(messagejson){
- var toadd = $(formatMessageHtml(messagejson));
- $('#chatfeed').append(toadd);
- toadd.slideDown(200);
- $('#chatfeed').animate({ scrollTop: $('#chatfeed').attr("scrollHeight") }, 200);
-};
-
-var packageJsonMessage = function(){
- return { color : currentcolor
- , name : $('#name').val()
- , comment : $('#comment').val()
- };
-};
-
-var currentcolor = grabRandomColor();
-
-var socket;
-
-$(document).ready(function() {
- $('#sendbutt').bind('click', function() {
- insertMessage(packageJsonMessage());
- });
-
- $('#talkform').submit(function(){
- insertMessage(packageJsonMessage());
- return false;
- });
-
- $('#changecolor').bind('click', function(){
- changeColor();
- return false;
- });
-
- setNameColor(currentcolor);
-
-
- io.setPath('/client/');
- socket = new io.Socket(null, { port: 8765
- , transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
- });
- socket.connect();
-
- socket.on('message', function(data){
- incomingMessage(JSON.parse(data));
- });
-
- });
View
5 project/views/index.ejs
@@ -1 +1,4 @@
-<p>HELLO, Body Here <%= info %></p>
+<p>
+ <a id="sender">send a message</a>
+ <ul id="reciever"></ul>
+</p>
Please sign in to comment.
Something went wrong with that request. Please try again.