This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/mixins/load-more.js.es6
Dan Ungureanu 3650c64bca
FIX: Ensure load-more considers current position (#8357)
The loadMore action was not called if user was already at the bottom
of the page.
2019-11-18 15:09:47 +02:00

33 lines
901 B
JavaScript

import Eyeline from "discourse/lib/eyeline";
import Scrolling from "discourse/mixins/scrolling";
import { on } from "discourse-common/utils/decorators";
import Mixin from "@ember/object/mixin";
// Provides the ability to load more items for a view which is scrolled to the bottom.
export default Mixin.create(Scrolling, {
scrolled() {
const eyeline = this.eyeline;
return eyeline && eyeline.update();
},
loadMoreUnlessFull() {
if (this.screenNotFull()) {
this.send("loadMore");
}
},
@on("didInsertElement")
_bindEyeline() {
const eyeline = new Eyeline(this.eyelineSelector + ":last");
this.set("eyeline", eyeline);
eyeline.on("sawBottom", () => this.send("loadMore"));
eyeline.update(); // update once to consider current position
this.bindScrolling();
},
@on("willDestroyElement")
_removeEyeline() {
this.unbindScrolling();
}
});