Permalink
Browse files

Merge pull request #17 from saiwong/element_scrolling

Added support for in element scrolling
  • Loading branch information...
reissbaker committed Oct 11, 2012
2 parents 6e38cc7 + 8a0d551 commit adac94ad2dfda1b143480c0ab572f9cb0aabc20c
Showing with 19 additions and 5 deletions.
  1. +19 −5 infinity.js
View
@@ -80,6 +80,8 @@
this.lazy = !!options.lazy;
this.lazyFn = options.lazy || null;
+ this.useElementScroll = options.useElementScroll === true;
+
initBuffer(this);
this.top = this.$el.offset().top;
@@ -89,6 +91,8 @@
this.pages = [];
this.startIndex = 0;
+ this.$scrollParent = this.useElementScroll ? $el : $window;
+
DOMEvent.attach(this);
}
@@ -226,8 +230,9 @@
function updateStartIndex(listView) {
var index, length, pages, lastIndex, nextLastIndex,
startIndex = listView.startIndex,
- viewTop = $window.scrollTop() - listView.top,
- viewHeight = $window.height(),
+ viewRef = listView.$scrollParent,
+ viewTop = viewRef.scrollTop() - listView.top,
+ viewHeight = viewRef.height(),
viewBottom = viewTop + viewHeight,
nextIndex = startIndexWithinRange(listView, viewTop, viewBottom);
@@ -558,8 +563,12 @@
// event.
attach: function(listView) {
+ if(!listView.eventIsBound) {
+ listView.$scrollParent.on('scroll', scrollHandler);
+ listView.eventIsBound = true;
+ }
+
if(!eventIsBound) {
- $window.on('scroll', scrollHandler);
$window.on('resize', resizeHandler);
eventIsBound = true;
}
@@ -582,11 +591,15 @@
detach: function(listView) {
var index, length;
+ if(listView.eventIsBound) {
+ listView.$scrollParent.on('scroll', scrollHandler);
+ listView.eventIsBound = false;
+ }
+
for(index = 0, length = boundViews.length; index < length; index++) {
if(boundViews[index] === listView) {
boundViews.splice(index, 1);
if(boundViews.length === 0) {
- $window.off('scroll', scrollHandler);
$window.off('resize', resizeHandler);
eventIsBound = false;
}
@@ -680,7 +693,8 @@
// Returns false if the Page is at max capacity; false otherwise.
Page.prototype.hasVacancy = function() {
- return this.height < $window.height() * config.PAGE_TO_SCREEN_RATIO;
+ var viewRef = this.parent.$scrollParent;
+ return this.height < viewRef.height() * config.PAGE_TO_SCREEN_RATIO;
};

0 comments on commit adac94a

Please sign in to comment.