Permalink
Browse files

Cleanup.

  • Loading branch information...
1 parent 42544f3 commit 7df7132a156f6202588f18864850b1f09c282c79 @scottgonzalez committed Apr 11, 2010
Showing with 40 additions and 24 deletions.
  1. +40 −24 demo/client.js
View
@@ -1,27 +1,35 @@
(function($) {
-var colors = ["green","orange","yellow","red","fuschia","blue"],
+var colors = ["green", "orange", "yellow", "red", "fuschia", "blue"],
channel = nodeChat.connect("/chat"),
scroll = true,
log,
- message ;
+ message;
// TODO: Turn off auto scrolling if user has scrolled up from the bottom
-$(function(){
+$(function() {
log = $("#chat-log");
message = $("#message");
// Add a button that can be easily styled
- $("<a />", {id:"submit", text: "Send", href: "#", click: function(e){
- e.preventDefault();
- $(this).closest('form').submit();
- }}).appendTo("#entry fieldset");
+ $("<a></a>", {
+ id: "submit",
+ text: "Send",
+ href: "#",
+ click: function(event) {
+ event.preventDefault();
+ $(this).closest("form").submit();
+ }
+ })
+ .appendTo("#entry fieldset");
// Add a message indicator when a nickname is clicked
- $("#users").delegate("li", "click", function(){
- message.val( $(this).text() + ": " + message.val()).focus();
- })
+ $("#users").delegate("li", "click", function() {
+ message
+ .val($(this).text() + ": " + message.val())
+ .focus();
+ });
});
// new message posted to channel
@@ -76,7 +84,10 @@ $(channel).bind("nodechat-msg", function(event, message) {
// - add to the user list
.bind("nodechat-join", function(event, message) {
var added = false,
- nick = $("<li />", {'class':colors[0], text: message.nick });
+ nick = $("<li></li>", {
+ "class": colors[0],
+ text: message.nick
+ });
colors.push(colors.shift());
$("#users > li").each(function() {
if (message.nick == this.innerHTML) {
@@ -114,7 +125,7 @@ $(channel).bind("nodechat-msg", function(event, message) {
.addClass("chat-text")
.text("left the room")
.appendTo(row);
-
+
row.appendTo(log);
})
// another user left the channel
@@ -130,7 +141,7 @@ $(channel).bind("nodechat-msg", function(event, message) {
// Auto scroll list to bottom
.bind("nodechat-join nodechat-part nodechat-msg", function(){
- window.setTimeout(function(){
+ window.setTimeout(function() {
log.scrollTop(log[0].scrollHeight);
}, 10);
});
@@ -139,27 +150,32 @@ $(channel).bind("nodechat-msg", function(event, message) {
$(function() {
var login = $("#login");
login.submit(function() {
- $(this).one('ajaxSuccess.login', function(){
- login.unbind('ajaxError.login');
- $("body").removeClass("login").addClass("channel");
- $("#message").focus();
- }).one('ajaxError.login', function(){
- login.unbind('ajaxSuccess.login')
- .find('label').text("Nickname in use. Please choose another:").end()
- .addClass("error")
- .find('input').focus();
+ $(this).one("ajaxSuccess.login", function() {
+ login.unbind("ajaxError.login");
+ $("body")
+ .removeClass("login")
+ .addClass("channel");
+ message.focus();
+ }).one("ajaxError.login", function() {
+ login
+ .unbind("ajaxSuccess.login")
+ .addClass("error")
+ .find("label")
+ .text("Nickname in use. Please choose another:")
+ .end()
+ .find("input")
+ .focus();
});
channel.join($("#nick").val());
return false;
});
- login.find('input').focus();
+ login.find("input").focus();
});
// handle sending a message
$(function() {
- var message = $("#message");
$("#channel form").submit(function() {
channel.send(message.val());
message.val("").focus();

0 comments on commit 7df7132

Please sign in to comment.