Class: ScrollEndEventEmitter

ScrollEndEventEmitter(eventBus, thresholdopt)

new ScrollEndEventEmitter(eventBus, thresholdopt)

Class to assist a view in implementing infinite scrolling on some DOM element. This module itself is only responsible for emitting an Event when the bottom of an Element is scrolled to.

Parameters:
Name Type Attributes Default Description
eventBus Object

object to listen for scroll:throttled events

threshold number <optional>
100

distance in pixels used to calculate if scroll position is near the end of the $el

Source:
Fires:
Example
<code>
      var ScrollEndEventEmitter =
        require( 'mobile.startup/ScrollEndEventEmitter' ),
        eventBus = require( 'mobile.startup/eventBusSingleton' );
      OO.mfExtend( PhotoList, View, {
        //...
        initialize: function ( options ) {
          this.gateway = new PhotoListGateway( {
            username: options.username
          } );
          // 1. Set up infinite scroll helper and listen to events
          this.scrollEndEventEmitter = new ScrollEndEventEmitter( eventBus, 1000 );
          this.scrollEndEventEmitter.on( ScrollEndEventEmitter.EVENT_SCROLL_END,
            this._loadPhotos.bind( this ) );
          View.prototype.initialize.apply( this, arguments );
        },
        preRender: function () {
          // 2. Disable until we've got the list rendered and set DOM el
          this.scrollEndEventEmitter.setElement( this.$el );
          this.scrollEndEventEmitter.disable();
        },
        _loadPhotos: function () {
          var self = this;
          this.gateway.getPhotos().then( function ( photos ) {
            // load photos into the DOM ...
            // 3. and (re-)enable infinite scrolling
            self.scrollEndEventEmitter.enable();
          } );
        }
      } );
    </code>

Methods

disable()

Disable the ScrollEndEventEmitter so that it doesn't trigger events.

Source:

enable()

Enable the ScrollEndEventEmitter so that it triggers events.

Source:

setElement($el)

Set the element to compare to scroll position to

Parameters:
Name Type Description
$el jQuery.Object

jQuery element where we want to listen for scroll end.

Source:

Events

ScrollEndEventEmitter-scrollEnd

Fired when scroll bottom has been reached.

Source: