import Ember from 'ember';

export default Ember.Component.extend({
  /**
  Selector for the container to watch for scroll events. Defaults to `window`.
  
  @property
  @type String
  */
  containerSelector: null,
  
  didInsertElement: function() {
    var container = $(this.get('containerSelector') || window);

    container.on('scroll', () => {
      Ember.run.debounce(this, this.checkScroll, container, 20);
    });
  },
  
  checkScroll: function(container) {
    var content = this.$();
    
    if (content.height() < (container.height() * 2) + container.scrollTop()) {
      this.get('contents').nextPage();
    }
  }
});
import Ember from 'ember';

export default Ember.Component.extend({
  /**
  Selector for the container to watch for scroll events. Defaults to the component's element.
  
  @property
  @type String
  */
  containerSelector: null,
  
  /**
  The paginated array containing the elements to scroll
  
  @property
  @type PaginatedArray
  */
  contents:null,
  
  didInsertElement: function() {
    var container = Ember.$(this.get('containerSelector') || this.$());

    container.on('scroll', () => {
      Ember.run.debounce(this, this.checkScroll, container, 20);
    });
    
    this.checkScroll(container);
  },
  
  checkScroll: function(container) {
    var content = this.$();
    var contentHeight = content.height();
    if (content[0].scrollHeight) {
      //  if the content element is scrollable, use the scrollHeight to calculate the content height
      // this allows us to use the same element for content and container.
      contentHeight = content[0].scrollHeight;
    }
    if ("scroll", contentHeight < (container.height() * 2) + container.scrollTop()) {
      if (!this.get('contents.isUpdating')) {
        this.get('contents').nextPage();
      }
    }
  }
});
Use the component's element as the scroll container, by default
Use the component's element as the scroll container, by default

We also have to allow the same container to be both the scroll container
and the content container, which we've done here.
