# HG changeset patch # User Atul Varma # Date 1241140532 25200 # Node ID 0effc4481d18b44a454b02247ddd90a6a714388b # Parent 1c99c08d2a547d41b518c39a573b1ef31731e4bc refactored display code a bit diff -r 1c99c08d2a54 -r 0effc4481d18 media/css/openwebchat.css --- a/media/css/openwebchat.css Thu Apr 30 17:47:32 2009 -0700 +++ b/media/css/openwebchat.css Thu Apr 30 18:15:32 2009 -0700 @@ -50,6 +50,10 @@ font-variant: small-caps; } +.raw-content { + display: none; +} + #templates { display: none; } diff -r 1c99c08d2a54 -r 0effc4481d18 media/js/openwebchat.js --- a/media/js/openwebchat.js Thu Apr 30 17:47:32 2009 -0700 +++ b/media/js/openwebchat.js Thu Apr 30 18:15:32 2009 -0700 @@ -179,6 +179,24 @@ window.scrollTo(0, $('#bottom').position().top); } + function msg2dom(msg) { + var message = $('
'); + message.append('
'); + message.append('
'); + message.append('
'); + message.append('
'); + + $('.content', message).html(msg.content); + $('.raw-content', message).text(msg.content); + + $('.author', message).text(msg.author); + $('.timestamp', message).text(msg.time); + + return message; + } + + var lastAuthor; + function onMessage(msg, doAnimation) { if (typeof(doAnimation) == "undefined") doAnimation = true; @@ -186,24 +204,20 @@ if (owStorage.get('lastMessage') == msg.content) owStorage.set('lastMessage', ''); - var block = $('#templates .message').clone(); - $('.content', block).html(msg.content); + var message = msg2dom(msg); - var author = msg.author ? msg.author : 'Anonymous'; - if (author != $('#content .author:last').text()) - $('.author', block).text(author); + if (msg.author == lastAuthor) + $('.author', message).hide(); else - $('.author', block).remove(); - - $('.timestamp', block).text(msg.time); + lastAuthor = msg.author; if (doAnimation) - block.hide(); + message.hide(); - $('#incoming-messages').append(block); + $('#incoming-messages').append(message); if (doAnimation) - block.slideDown(scrollToBottom); + message.slideDown(scrollToBottom); } $('#incoming-messages').hide(); diff -r 1c99c08d2a54 -r 0effc4481d18 openwebchat.html --- a/openwebchat.html Thu Apr 30 17:47:32 2009 -0700 +++ b/openwebchat.html Thu Apr 30 18:15:32 2009 -0700 @@ -21,11 +21,6 @@ severed. Please reload this page to reconnect. (Sorry, this will be more user-friendly in the future!) -
-
-
-
-