r1020 - branches/dev/grid/ui
Author: paul.bakaus
Date: Fri Nov 28 01:25:55 2008
New Revision: 1020
Modified:
branches/dev/grid/ui/ui.infiniteScrolling.js
Log:
infiniteScrolling: implemented 'delay' option, causes the update event to
be delayed, so if you scroll fast, or directly to a block, only the
immediate blocks are shown/preloaded (default to 100ms)
Modified: branches/dev/grid/ui/ui.infiniteScrolling.js
==============================================================================
--- branches/dev/grid/ui/ui.infiniteScrolling.js (original)
+++ branches/dev/grid/ui/ui.infiniteScrolling.js Fri Nov 28 01:25:55 2008
@@ -74,6 +74,7 @@
_update: function(event) {
var self = this;
+ var timeoutFunctions = [];
var start = this.element[0].scrollTop;
var stop = start + this.height;
@@ -86,15 +87,29 @@
for (var i=firstBlock - this.options.preload; i <= lastBlock +
this.options.preload; i++) {
if(i < 0 || i >= this.cache.length) continue;
- if(this.cache[i]) continue;
-
- this.cache[i] = (new Date()).getTime(); //TODO: Revalidation option
- this._trigger('scroll', event, { total: this.options.total, block: i,
start: i * this.options.block, fill: function() { return
self.fill.apply(self, arguments); } });
+ timeoutFunctions.push(function(i2) {
+ return function() {
+ if(self.cache[i2]) return;
+ self.cache[i2] = (new Date()).getTime(); //TODO: Revalidation option
+ self._trigger('scroll', event, { total: self.options.total, block:
i2, start: i2 * self.options.block, fill: function() { return
self.fill.apply(self, arguments); } });
+ };
+ }(i));
};
- this._trigger('update', event, { firstBlock: firstBlock, lastBlock:
lastBlock, firstItem: firstItem, lastItem: lastItem, total:
this.options.total });
+ if(this.timeout) window.clearTimeout(this.timeout);
+ this.timeout = window.setTimeout(function() {
+
+ $(timeoutFunctions).each(function() {
+ this();
+ });
+
+ self._trigger('update', event, { firstBlock: firstBlock, lastBlock:
lastBlock, firstItem: firstItem, lastItem: lastItem, total:
self.options.total });
+
+ }, this.options.delay);
+
+
},
fill: function(o) {
@@ -127,7 +142,8 @@
defaults: {
total: 1000,
block: 20,
- preload: 1
+ preload: 1,
+ delay: 100
}
});