Fixes #71 Autoscroll
Conversation view autoscroll triggers on dom change, not storage change, ensuring that we don't scroll before the new element is inserted.
This commit is contained in:
parent
13446e9c17
commit
0956d328da
3 changed files with 9 additions and 7 deletions
|
@ -12,7 +12,6 @@ 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.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
|
||||
|
||||
|
@ -41,13 +40,9 @@ var Whisper = Whisper || {};
|
|||
}
|
||||
},
|
||||
|
||||
scrollToBottom: function() {
|
||||
this.view.$el.scrollTop(this.view.el.scrollHeight);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
Whisper.Layout.setContent(this.$el.show());
|
||||
this.scrollToBottom();
|
||||
this.view.scrollToBottom();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ var Whisper = Whisper || {};
|
|||
if (this.itemView) {
|
||||
var view = new this.itemView({model: model});
|
||||
this.$el.append(view.render().el);
|
||||
this.$el.trigger('add');
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@ var Whisper = Whisper || {};
|
|||
Whisper.MessageListView = Whisper.ListView.extend({
|
||||
tagName: 'ul',
|
||||
className: 'discussion',
|
||||
itemView: Whisper.MessageView
|
||||
itemView: Whisper.MessageView,
|
||||
events: {
|
||||
'add': 'scrollToBottom'
|
||||
},
|
||||
scrollToBottom: function() {
|
||||
this.$el.scrollTop(this.el.scrollHeight);
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue