Created
August 24, 2012 00:02
-
-
Save sprice/3443783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/chatroom.js b/chatroom.js | |
index df3d7c4..cdaccc6 100644 | |
--- a/chatroom.js | |
+++ b/chatroom.js | |
@@ -16,7 +16,7 @@ Drupal.chatroom.initialiseChat = function(chat) { | |
var chat = Drupal.settings.chatroom.chats[this.id.replace(/^edit-chatroom-message-entry-box-/, '')]; | |
var messageText = $('#edit-chatroom-message-entry-box-' + chat.cid).val().replace(/^\s+|\s+$/g, ''); | |
var anonNameText = ''; | |
- if (messageText && e.keyCode == 13 && !e.shiftKey && !e.ctrlKey) { | |
+ if (messageText && e.keyCode === 13 && !e.shiftKey && !e.ctrlKey) { | |
Drupal.chatroom.postMessage(messageText, anonNameText, chat); | |
$('#edit-chatroom-message-entry-box-' + chat.cid).val('').focus(); | |
} | |
@@ -44,7 +44,7 @@ Drupal.chatroom.initialiseChat = function(chat) { | |
Drupal.chatroom.getPreviousMessages(chat.cid, chat.prevMsgId); | |
} | |
}); | |
-} | |
+}; | |
/** | |
* Provide js API functions for modules that want to create chatrooms | |
@@ -70,7 +70,7 @@ Drupal.chatroom.createChat = function(options, callback) { | |
formId: Drupal.settings.chatroom.createChatFormId | |
} | |
}); | |
-} | |
+}; | |
/** | |
* We depend on the Nodejs module successfully create a socket for us. | |
@@ -78,7 +78,9 @@ Drupal.chatroom.createChat = function(options, callback) { | |
Drupal.Nodejs.connectionSetupHandlers.chatroom = { | |
connect: function () { | |
for (var cid in Drupal.settings.chatroom.chats) { | |
- Drupal.chatroom.initialiseChat(Drupal.settings.chatroom.chats[cid]); | |
+ if(Drupal.settings.chatroom.chats.hasOwnProperty(cid)) { | |
+ Drupal.chatroom.initialiseChat(Drupal.settings.chatroom.chats[cid]); | |
+ } | |
} | |
Drupal.chatroom.initialised = true; | |
} | |
@@ -105,7 +107,7 @@ Drupal.chatroom.postMessage = function(message, anonName, chat) { | |
formId: formId | |
} | |
}); | |
-} | |
+}; | |
Drupal.chatroom.getPreviousMessages = function(cid, cmid, limit) { | |
if (limit === undefined) limit = 20; | |
@@ -123,7 +125,9 @@ Drupal.chatroom.getPreviousMessages = function(cid, cmid, limit) { | |
*/ | |
var currentTop = $('#chatroom-board-' + cid).children().first(); | |
for (var message in data) { | |
- Drupal.chatroom.addPreviousMessageToBoard(data[message]); | |
+ if(data.hasOwnProperty(message)) { | |
+ Drupal.chatroom.addPreviousMessageToBoard(data[message]); | |
+ } | |
} | |
var previousHeight = 0; | |
currentTop.prevAll().each(function() { | |
@@ -132,28 +136,28 @@ Drupal.chatroom.getPreviousMessages = function(cid, cmid, limit) { | |
$('#chatroom-board-' + cid).animate({scrollTop: '+='+ previousHeight +'px'}, 10); | |
} | |
}); | |
-} | |
+}; | |
Drupal.chatroom.updateUserList = function(message) { | |
- if ($('#chatroom-user-' + message.cid + '-' + message.uid).length == 0) { | |
+ if ($('#chatroom-user-' + message.cid + '-' + message.uid).length === 0) { | |
var userHtml = '<li style="display: none;" id="chatroom-user-' | |
+ message.cid + '-' + message.uid + '"><a href="/user/' | |
+ message.uid + '">' + message.name + '</a></li>'; | |
$(userHtml).hide().appendTo($('#chatroom-irc-user-list-' + message.cid)).show('normal'); | |
} | |
-} | |
+}; | |
Drupal.chatroom.addMessageToBoard = function(message) { | |
$('#chatroom-board-' + message.cid).append(message.msg); | |
Drupal.chatroom.scrollToLatestMessage(message.cid); | |
-} | |
+}; | |
Drupal.chatroom.addPreviousMessageToBoard = function(message) { | |
var chat = Drupal.settings.chatroom.chats[message.cid]; | |
chat.prevMsgId = message.cmid; | |
Drupal.settings.chatroom.chats[message.cid] = chat; | |
$('#chatroom-board-' + message.cid).prepend(message.msg); | |
-} | |
+}; | |
Drupal.chatroom.scrollToLatestMessage = function(cid) { | |
var boardOffset = $('#chatroom-board-' + cid).offset().top; | |
@@ -161,7 +165,7 @@ Drupal.chatroom.scrollToLatestMessage = function(cid) { | |
var scrollAmount = targetOffset - boardOffset; | |
$('#chatroom-board-' + cid).animate({scrollTop: '+='+ scrollAmount +'px'}, 250); | |
$('#chatroom-board-' + cid + ' .new-message').removeClass('new-message'); | |
-} | |
+}; | |
Drupal.Nodejs.callbacks.chatroomMessageHandler = { | |
callback: function (message) { | |
@@ -177,9 +181,9 @@ Drupal.Nodejs.callbacks.chatroomUserOnlineHandler = { | |
Drupal.Nodejs.contentChannelNotificationCallbacks.chatroom = { | |
callback: function (message) { | |
- if (message.data.type == 'disconnect') { | |
+ if (message.data.type === 'disconnect') { | |
var cid = message.channel.replace(/^chatroom_/, ''); | |
- if ($('#chatroom-user-' + cid + '-' + message.data.uid).length == 1) { | |
+ if ($('#chatroom-user-' + cid + '-' + message.data.uid).length === 1) { | |
$('#chatroom-user-' + cid + '-' + message.data.uid).hide('normal', function () { | |
$('#chatroom-user-' + cid + '-' + message.data.uid).remove(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment