ember-infinity
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -15,4 +15,6 @@ import Ember from 'ember'; | ||
developmentMode: false, | ||
scrollable: null, | ||
didInsertElement: function() { | ||
this._setupScrollable(); | ||
this.set('guid', Ember.guidFor(this)); | ||
@@ -29,3 +31,3 @@ this._bindScroll(); | ||
var _this = this; | ||
Ember.$(window).on("scroll."+this.get('guid'), function() { | ||
this.get("scrollable").on("scroll."+this.get('guid'), function() { | ||
Ember.run.debounce(_this, _this._checkIfInView, _this.get('scrollDebounce')); | ||
@@ -36,10 +38,11 @@ }); | ||
_unbindScroll: function() { | ||
Ember.$(window).off("scroll."+this.get('guid')); | ||
this.get("scrollable").off("scroll."+this.get('guid')); | ||
}, | ||
_checkIfInView: function() { | ||
var selfOffset = this.$().offset().top; | ||
var windowBottom = Ember.$(window).height() + Ember.$(window).scrollTop(); | ||
var selfOffset = this.$().offset().top; | ||
var scrollable = this.get("scrollable"); | ||
var scrollableBottom = scrollable.height() + scrollable.scrollTop(); | ||
var inView = selfOffset < windowBottom ? true : false; | ||
var inView = selfOffset < scrollableBottom ? true : false; | ||
@@ -51,2 +54,18 @@ if (inView && !this.get('developmentMode')) { | ||
_setupScrollable: function() { | ||
var scrollable = this.get('scrollable'); | ||
if (Ember.$.type(scrollable) === 'string') { | ||
var items = Ember.$(scrollable); | ||
if (items.length === 1) { | ||
this.set('scrollable', items.eq(0)); | ||
} else if (items.length > 1) { | ||
throw new Error("Multiple scrollable elements found for: " + scrollable); | ||
} else { | ||
throw new Error("No scrollable element found for: " + scrollable); | ||
} | ||
} else { | ||
this.set('scrollable', Ember.$(window)); | ||
} | ||
}, | ||
loadedStatusDidChange: Ember.observer('infinityModel.reachedInfinity', 'destroyOnInfinity', function() { | ||
@@ -53,0 +72,0 @@ if (this.get('infinityModel.reachedInfinity') && this.get('destroyOnInfinity')) { this.destroy(); } |
{ | ||
"name": "ember-infinity", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Simple, flexible infinite scroll for Ember CLI Apps.", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -95,2 +95,11 @@ # Ember Infinity | ||
Will install the default `infinity-loader` template into your host app, at | ||
`app/templates/components/infinity-loader`. | ||
`app/templates/components/infinity-loader`. | ||
* **scrollable** | ||
```html | ||
{{infinity-loader scrollable="#content"}} | ||
``` | ||
You can optionally pass in a jQuery style selector string. If it's not a string, | ||
scrollable will default to using the window for the scroll binding. |
15965384
144847
105