r1024 - in branches/dev/grid: tests/visual ui
Author: paul.bakaus
Date: Fri Nov 28 08:40:12 2008
New Revision: 1024
Modified:
branches/dev/grid/tests/visual/infiniteScrolling.html
branches/dev/grid/ui/ui.infiniteScrolling.js
Log:
infiniteScrolling: now supports true infinite scrolling: if you don't set
the 'total' option, empty rows are not allocated and it simply appends new
rows when it comes to the end of the scrollbar
Modified: branches/dev/grid/tests/visual/infiniteScrolling.html
==============================================================================
--- branches/dev/grid/tests/visual/infiniteScrolling.html (original)
+++ branches/dev/grid/tests/visual/infiniteScrolling.html Fri Nov 28
08:40:12 2008
@@ -31,7 +31,6 @@
$(document).ready(function() {
$('.scrollme').infiniteScrolling({
- total: 1000,
template: '<tr class="{$1}"><td>{$2}</td><td>{$3}</td></tr>',
scroll: function(e, ui) {
@@ -47,7 +46,7 @@
data: data
});
- }, 1000);
+ }, 0);
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 08:40:12 2008
@@ -27,7 +27,8 @@
this._prepareCache();
//Alocate all rows in this.options.total to change the scrollbar size
- this._allocateRows();
+ if(this.options.total)
+ this._allocateRows();
//Call update the first time to retrieve the first set of rows
this._update();
@@ -44,7 +45,7 @@
_prepareCache: function() {
- this.cache = new Array(Math.ceil(this.options.total /
this.options.chunk));
+ this.cache = new Array(this.options.total ? Math.ceil(this.options.total
/ this.options.chunk) : undefined);
var alreadyCached = Math.floor($('tr', this.tbody).length /
this.options.chunk);
for (var i=0; i < alreadyCached; i++) {
this.cache[i] = (new Date()).getTime();
@@ -84,9 +85,9 @@
var firstChunk = Math.round(firstItem / this.options.chunk);
var lastChunk = Math.round(lastItem / this.options.chunk);
- for (var i=firstChunk - this.options.preload; i <= lastChunk +
this.options.preload; i++) {
+ for (var i=firstChunk - (this.options.total ? this.options.preload : 0);
i <= lastChunk + this.options.preload; i++) {
- if(i < 0 || i >= this.cache.length) continue;
+ if(i < 0 || (this.options.total && i >= this.cache.length)) continue;
timeoutFunctions.push(function(i2) {
return function() {
if(self.cache[i2]) return;
@@ -129,7 +130,7 @@
//I'm sure there is a better way to do this..
- this.tbody[0].replaceChild($(template)[0], rows[(o.chunk *
this.options.chunk)+i]);
+
this.tbody[0][(this.options.total ? 'replace' : 'append')+'Child']($(template)[0],
rows[(o.chunk * this.options.chunk)+i]);
};
@@ -140,7 +141,7 @@
$.extend($.ui.infiniteScrolling, {
version: "@VERSION",
defaults: {
- total: 1000,
+ total: null, //If set to false, rows are not allocated
chunk: 20,
preload: 1,
delay: 100