Skip to content

Commit

Permalink
autoscroll and history sorting issue #51
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Aug 19, 2013
1 parent bb09c18 commit dbe8fa8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions activity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def get_context_data(self, **kwargs):

class HistoryView(LoginRequiredMixin, JSONResponseMixin, AjaxResponseMixin, View):
def get_ajax(self, request, *args, **kwargs):
history = Event.objects.all().order_by("timestamp")[:10]
history = Event.objects.all().order_by("-timestamp")[:10]
json_dict = {"history": []}
for event in history:
for event in reversed(history):
json_dict["history"].append({
'message': m.html(event.message),
'user': event.user.username,
Expand Down
3 changes: 2 additions & 1 deletion static/chat.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#events{
margin-top: 20px;
min-height: 400px;
height: 580px;
overflow-y: auto;
}
#chat_send{
float: right;
Expand Down
6 changes: 4 additions & 2 deletions static/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ $(function(){
}

function ws_handler(data) {
console.log(data);
// console.log(data);
data.now = new Date(data.timestamp);
$("#events").append(templates[data.type](data));
var ev = $("#events");
ev.append(templates[data.type](data));
ev.animate({scrollTop: ev.prop("scrollHeight")}, 500);
}

websocket_init(ws_handler);
Expand Down

0 comments on commit dbe8fa8

Please sign in to comment.