From 443b17926d06dc1458888e4b9246770d9b18a446 Mon Sep 17 00:00:00 2001 From: yomguy Date: Mon, 19 Nov 2012 09:09:20 +0100 Subject: [PATCH] add day of the week to message header --- jqchat/models.py | 2 +- jqchat/static/jqchat/jqchat.js | 14 +++++++++++++- jqchat/views.py | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jqchat/models.py b/jqchat/models.py index 1299eda..fd3ab2a 100644 --- a/jqchat/models.py +++ b/jqchat/models.py @@ -100,7 +100,7 @@ class messageManager(models.Manager): m = Message(user=user, room=room, event=event_id) - m.text = "%s %s
" % (user, m.get_event_display()) + m.text = '%s %s
' % (user, m.get_event_display()) m.save() return m diff --git a/jqchat/static/jqchat/jqchat.js b/jqchat/static/jqchat/jqchat.js index 03713b0..bd64a34 100644 --- a/jqchat/static/jqchat/jqchat.js +++ b/jqchat/static/jqchat/jqchat.js @@ -1,3 +1,4 @@ + //Handles the csrf_token for ajax posts, taken from: // https://docs.djangoproject.com/en/dev/ref/contrib/csrf/ @@ -39,6 +40,17 @@ $(document).ajaxSend(function(event, xhr, settings) { }); +jQuery.fn.urlize = function( base ) { + var x = this.html(); + list = x.match( /\b(http:\/\/|www\.|http:\/\/www\.)[^ ]{2,100}\b/g ); + if ( list ) { + for ( i = 0; i < list.length; i++ ) { + x = x.replace( list[i], ""+ list[i] + "" ); + } + this.html(x); + } +}; + // Chat client code. @@ -73,7 +85,7 @@ function processResponse(payload) { // Get the timestamp, store it in global variable to be passed to the server on next call. timestamp = payload.time; for(message in payload.messages) { - $("#chatwindow").append(payload.messages[message].text); + $("#chatwindow").append(payload.messages[message].text).urlize( "/" ); } // Scroll down if messages fill up the div. var objDiv = document.getElementById("chatwindow"); diff --git a/jqchat/views.py b/jqchat/views.py index 0f8a0bd..4689f25 100644 --- a/jqchat/views.py +++ b/jqchat/views.py @@ -14,7 +14,7 @@ try: DATE_FORMAT = settings.JQCHAT_DATE_FORMAT except: # Use default format. - DATE_FORMAT = "H:i:s" + DATE_FORMAT = "D-H:i:s" # How many messages to retrieve at most. JQCHAT_DISPLAY_COUNT = getattr(settings, 'JQCHAT_DISPLAY_COUNT', 100) -- 2.39.5