2 var Marionette = require('backbone.marionette');
3 var behaviourLookup = require('./lookup');
4 var NeverEndingStory = require('../../utils/never-ending-story');
6 module.exports = (function() {
7 var Behavior = Marionette.Behavior.extend({
9 reverseScrolling: false,
10 scrollElementSelector: null,
11 contentWrapperSelector: null
13 initialize: function() {
15 this.options.scrollElement ||
16 document.querySelector(this.options.scrollElementSelector) ||
20 this.options.contentWrapper || document.querySelector(this.options.contentWrapperSelector);
22 var reverseScrolling = this.options.reverseScrolling;
24 var scroll = new NeverEndingStory(scrollElement, {
25 reverse: reverseScrolling,
26 contentWrapper: contentWrapper
29 this.listenTo(scroll, 'approaching.top', function() {
30 this.view.collection.fetchMoreBefore({});
33 this.listenTo(scroll, 'approaching.bottom', function() {
34 this.view.collection.fetchMoreAfter({});
38 this.view.scroll = scroll;
41 onDestroy: function() {
42 this.scroll.disable();
46 behaviourLookup.register('InfiniteScroll', Behavior);