/
infiniteScrollView.js
52 lines (40 loc) · 1.51 KB
/
infiniteScrollView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
define(function(require, exports, module) {
var ScrollView = require('famous/views/Scrollview');
function InfiniteScrollView(options) {
ScrollView.apply(this, arguments);
if (this.options.offset)
this.setOffset(this.options.offset);
_monitor.call(this);
}
InfiniteScrollView.prototype = Object.create(ScrollView.prototype);
InfiniteScrollView.prototype.constructor = InfiniteScrollView;
InfiniteScrollView.DEFAULT_OPTIONS = {};
InfiniteScrollView.prototype.setOffset = function(o) {
this.offset = o;
}
InfiniteScrollView.prototype._setContentSize = function() {
var node = this._node;
this.contentSize = 0;
for(var i in node._.array) {
this.contentSize += node._.array[i].getSize()[1];
}
}
InfiniteScrollView.prototype.disable = function() {
this.infiniteScrollDisabled = true;
}
InfiniteScrollView.prototype.enable = function() {
this._setContentSize();
this.infiniteScrollDisabled = false;
}
function _monitor() {
this.sync.on('start',function(data) {
this._setContentSize();
}.bind(this));
this.sync.on('update',function(data) {
if (!this.infiniteScrollDisabled && this.getAbsolutePosition() + this._scroller._contextSize[1] >= this.contentSize - this.offset) {
this._eventOutput.emit('infiniteScroll');
}
}.bind(this));
}
module.exports = InfiniteScrollView;
});