1
0
mirror of synced 2024-11-25 14:26:03 +03:00

change paging of remote data to be 1-based instead of 0-based

This commit is contained in:
Igor Vaynberg 2012-03-25 22:10:10 -07:00
parent b5c4817149
commit f6eb1edbce

View File

@ -273,7 +273,7 @@
query.callback(data); query.callback(data);
}); });
} else { } else {
if (!opts.query && opts.ajax) { if (!("query" in opts) && opts.ajax) {
opts.query = (function () { opts.query = (function () {
var timeout, // current scheduled but not yet executed request var timeout, // current scheduled but not yet executed request
requestSequence = 0, // sequence used to drop out-of-order responses requestSequence = 0, // sequence used to drop out-of-order responses
@ -438,7 +438,8 @@
var results = this.results, var results = this.results,
more = results.find("li.select2-more-results"), more = results.find("li.select2-more-results"),
below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
offset = -1; // index of first element without data offset = -1, // index of first element without data
page = this.resultsPage+1;
if (more.length === 0) return; if (more.length === 0) return;
@ -446,7 +447,7 @@
if (below <= 0) { if (below <= 0) {
more.addClass("select2-active"); more.addClass("select2-active");
this.opts.query({term: this.search.val(), page: (this.resultsPage + 1), callback: this.bind(function (data) { this.opts.query({term: this.search.val(), page: page, callback: this.bind(function (data) {
var parts = [], self = this; var parts = [], self = this;
$(data.results).each(function () { $(data.results).each(function () {
parts.push("<li class='select2-result'>"); parts.push("<li class='select2-result'>");
@ -467,7 +468,7 @@
} else { } else {
more.remove(); more.remove();
} }
this.resultsPage = data.page; this.resultsPage = page;
})}); })});
} }
}; };
@ -488,7 +489,7 @@
return; return;
} }
this.resultsPage = 0; this.resultsPage = 1;
opts.query({term: search.val(), page: this.resultsPage, callback: this.bind(function (data) { opts.query({term: search.val(), page: this.resultsPage, callback: this.bind(function (data) {
var parts = []; // html parts var parts = []; // html parts