Autoscroll conversation views
Scroll to the bottom (most recent) message in the conversation when it is opened, when we send a message, and when we receive a message.
This commit is contained in:
parent
4675cdf3f2
commit
d362d0d978
1 changed files with 8 additions and 5 deletions
|
@ -12,10 +12,12 @@ var Whisper = Whisper || {};
|
|||
this.$el.html(Mustache.render(this.template));
|
||||
|
||||
this.view = new Whisper.MessageListView({collection: this.model.messages()});
|
||||
this.listenTo(this.model.messages(), 'add', this.scrollToBottom);
|
||||
|
||||
this.model.messages().fetch({reset: true});
|
||||
this.$el.find('.discussion-container').append(this.view.el);
|
||||
window.addEventListener('storage', (function(){
|
||||
this.fetch();
|
||||
this.model.messages().fetch();
|
||||
}).bind(this));
|
||||
},
|
||||
events: {
|
||||
|
@ -23,10 +25,6 @@ var Whisper = Whisper || {};
|
|||
'close': 'remove'
|
||||
},
|
||||
|
||||
fetch: function() {
|
||||
this.model.messages().fetch({reset: true});
|
||||
},
|
||||
|
||||
sendMessage: function(e) {
|
||||
e.preventDefault();
|
||||
var input = this.$el.find('.send input');
|
||||
|
@ -36,8 +34,13 @@ var Whisper = Whisper || {};
|
|||
}
|
||||
},
|
||||
|
||||
scrollToBottom: function() {
|
||||
this.view.$el.scrollTop(this.view.el.scrollHeight);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
Whisper.Layout.setContent(this.$el.show());
|
||||
this.scrollToBottom();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue