Permalink
Browse files

Simplify code and start w/ a blank cs-js

  • Loading branch information...
1 parent 06195c1 commit 70626bf830b8f3dd03a0f072ed0331ea177a21cd @macournoyer committed Jan 21, 2010
Showing with 26 additions and 27 deletions.
  1. +1 −2 chat/app.js
  2. +25 −0 chat/public/.chat.js
  3. +0 −25 chat/public/chat.js
View
@@ -10,8 +10,7 @@ configure(function(){
});
get('/', function(){
- this.contentType('html');
- return '<h1>Hello World<h1>';
+ return 'Hello World';
});
get('/*.css', function(file){
View
@@ -0,0 +1,25 @@
+$(function(){
+ // Send message
+
+ $('form').submit(function(){
+ var message = $("#message");
+ $.post('/chat', { message: message.val() }, function(){
+ message.val('');
+ });
+ return false;
+ });
+
+ function poll() {
+ $.getJSON('/chat/poll', function(messages){
+ $('#log').empty();
+
+ $.each(messages, function(i, msg){
+ $('#log').append('<p>' + msg + '</p>');
+ });
+
+ poll();
+ });
+ };
+
+ poll();
+});
View
@@ -1,28 +1,3 @@
$(function(){
- // Send message
- $('form').submit(function(){
- var message = $('input#message');
- $.post('/chat', { message: message.val() }, function(){
- message.val('');
- });
- return false;
- });
-
- // Longpoll
- function poll(){
- $.getJSON('/chat/poll', function(messages){
- // A new message arrived!
- $("#log").empty();
-
- $.each(messages, function(i, msg){
- $('#log').append('<p>' + msg + '</p>');
- });
-
- // Start polling again
- poll();
- });
- }
-
- poll();
});

0 comments on commit 70626bf

Please sign in to comment.