1
0
mirror of synced 2024-11-22 13:06:08 +03:00

Better infinite scroll

Only show the "No results found" message when there are no results
visible in the list. This avoid issues when loading more data, and
it returns no results.

Only try to see if the load more button is visible if it is present
in the DOM. This prevents making continuous requests when there are
no more results.
This commit is contained in:
Kevin Brown 2014-11-03 19:24:29 -05:00
parent 5e3b63289c
commit 0bc4832995
8 changed files with 58 additions and 23 deletions

View File

@ -199,9 +199,11 @@ define('select2/results',[
var $options = [];
if (data.length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
if (this.$results.children().length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
}
return;
}
@ -1591,7 +1593,12 @@ define('select2/dropdown/infiniteScroll',[
});
this.$results.on('scroll', function () {
if (self.loading) {
var loadMoreVisible = $.contains(
document.documentElement,
self.$loadingMore[0]
);
if (self.loading || !loadMoreVisible) {
return;
}

View File

@ -199,9 +199,11 @@ define('select2/results',[
var $options = [];
if (data.length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
if (this.$results.children().length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
}
return;
}
@ -1591,7 +1593,12 @@ define('select2/dropdown/infiniteScroll',[
});
this.$results.on('scroll', function () {
if (self.loading) {
var loadMoreVisible = $.contains(
document.documentElement,
self.$loadingMore[0]
);
if (self.loading || !loadMoreVisible) {
return;
}

View File

@ -9734,9 +9734,11 @@ define('select2/results',[
var $options = [];
if (data.length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
if (this.$results.children().length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
}
return;
}
@ -11126,7 +11128,12 @@ define('select2/dropdown/infiniteScroll',[
});
this.$results.on('scroll', function () {
if (self.loading) {
var loadMoreVisible = $.contains(
document.documentElement,
self.$loadingMore[0]
);
if (self.loading || !loadMoreVisible) {
return;
}

File diff suppressed because one or more lines are too long

15
dist/js/select2.js vendored
View File

@ -627,9 +627,11 @@ define('select2/results',[
var $options = [];
if (data.length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
if (this.$results.children().length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
}
return;
}
@ -2019,7 +2021,12 @@ define('select2/dropdown/infiniteScroll',[
});
this.$results.on('scroll', function () {
if (self.loading) {
var loadMoreVisible = $.contains(
document.documentElement,
self.$loadingMore[0]
);
if (self.loading || !loadMoreVisible) {
return;
}

File diff suppressed because one or more lines are too long

View File

@ -38,7 +38,12 @@ define([
});
this.$results.on('scroll', function () {
if (self.loading) {
var loadMoreVisible = $.contains(
document.documentElement,
self.$loadingMore[0]
);
if (self.loading || !loadMoreVisible) {
return;
}

View File

@ -45,9 +45,11 @@ define([
var $options = [];
if (data.length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
if (this.$results.children().length === 0) {
this.trigger('results:message', {
message: 'noResults'
});
}
return;
}