0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fix duplication of entries in infinite scroll

Fixes #1242

- Switched to render each new item as its added to the collection when
retrieving via scroll checks.
- Added check to remove all subviews whenever `render` is called on
`ContentList` as a preventative measure.
- Cached the jquery reference to the ordered list in `render`.
This commit is contained in:
William Dibbern 2013-10-24 01:19:09 -05:00
parent fa4f66d5f4
commit 54a6cf79d7

View file

@ -35,6 +35,7 @@
initialize: function (options) {
this.$('.content-list-content').scrollClass({target: '.content-list', offset: 10});
this.listenTo(this.collection, 'remove', this.showNext);
this.listenTo(this.collection, 'add', this.renderPost);
// Can't use backbone event bind (see: http://stackoverflow.com/questions/13480843/backbone-scroll-event-not-firing)
this.$('.content-list-content').scroll($.proxy(this.checkScroll, this));
},
@ -102,9 +103,18 @@
});
},
renderPost: function (model) {
this.$('ol').append(this.addSubview(new ContentItem({model: model})).render().el);
},
render: function () {
var $list = this.$('ol');
// Clear out any pre-existing subviews.
this.removeSubviews();
this.collection.each(function (model) {
this.$('ol').append(this.addSubview(new ContentItem({model: model})).render().el);
$list.append(this.addSubview(new ContentItem({model: model})).render().el);
}, this);
this.showNext();
}