mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -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:
parent
fa4f66d5f4
commit
54a6cf79d7
1 changed files with 11 additions and 1 deletions
|
@ -35,6 +35,7 @@
|
||||||
initialize: function (options) {
|
initialize: function (options) {
|
||||||
this.$('.content-list-content').scrollClass({target: '.content-list', offset: 10});
|
this.$('.content-list-content').scrollClass({target: '.content-list', offset: 10});
|
||||||
this.listenTo(this.collection, 'remove', this.showNext);
|
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)
|
// 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));
|
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 () {
|
render: function () {
|
||||||
|
var $list = this.$('ol');
|
||||||
|
|
||||||
|
// Clear out any pre-existing subviews.
|
||||||
|
this.removeSubviews();
|
||||||
|
|
||||||
this.collection.each(function (model) {
|
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);
|
||||||
this.showNext();
|
this.showNext();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue