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:
parent
5e3b63289c
commit
0bc4832995
9
dist/js/select2.amd.full.js
vendored
9
dist/js/select2.amd.full.js
vendored
@ -199,9 +199,11 @@ define('select2/results',[
|
|||||||
var $options = [];
|
var $options = [];
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
if (this.$results.children().length === 0) {
|
||||||
this.trigger('results:message', {
|
this.trigger('results:message', {
|
||||||
message: 'noResults'
|
message: 'noResults'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1591,7 +1593,12 @@ define('select2/dropdown/infiniteScroll',[
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('scroll', function () {
|
this.$results.on('scroll', function () {
|
||||||
if (self.loading) {
|
var loadMoreVisible = $.contains(
|
||||||
|
document.documentElement,
|
||||||
|
self.$loadingMore[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (self.loading || !loadMoreVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
dist/js/select2.amd.js
vendored
9
dist/js/select2.amd.js
vendored
@ -199,9 +199,11 @@ define('select2/results',[
|
|||||||
var $options = [];
|
var $options = [];
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
if (this.$results.children().length === 0) {
|
||||||
this.trigger('results:message', {
|
this.trigger('results:message', {
|
||||||
message: 'noResults'
|
message: 'noResults'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1591,7 +1593,12 @@ define('select2/dropdown/infiniteScroll',[
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('scroll', function () {
|
this.$results.on('scroll', function () {
|
||||||
if (self.loading) {
|
var loadMoreVisible = $.contains(
|
||||||
|
document.documentElement,
|
||||||
|
self.$loadingMore[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (self.loading || !loadMoreVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
dist/js/select2.full.js
vendored
9
dist/js/select2.full.js
vendored
@ -9734,9 +9734,11 @@ define('select2/results',[
|
|||||||
var $options = [];
|
var $options = [];
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
if (this.$results.children().length === 0) {
|
||||||
this.trigger('results:message', {
|
this.trigger('results:message', {
|
||||||
message: 'noResults'
|
message: 'noResults'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -11126,7 +11128,12 @@ define('select2/dropdown/infiniteScroll',[
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('scroll', function () {
|
this.$results.on('scroll', function () {
|
||||||
if (self.loading) {
|
var loadMoreVisible = $.contains(
|
||||||
|
document.documentElement,
|
||||||
|
self.$loadingMore[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (self.loading || !loadMoreVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
9
dist/js/select2.js
vendored
9
dist/js/select2.js
vendored
@ -627,9 +627,11 @@ define('select2/results',[
|
|||||||
var $options = [];
|
var $options = [];
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
if (this.$results.children().length === 0) {
|
||||||
this.trigger('results:message', {
|
this.trigger('results:message', {
|
||||||
message: 'noResults'
|
message: 'noResults'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2019,7 +2021,12 @@ define('select2/dropdown/infiniteScroll',[
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('scroll', function () {
|
this.$results.on('scroll', function () {
|
||||||
if (self.loading) {
|
var loadMoreVisible = $.contains(
|
||||||
|
document.documentElement,
|
||||||
|
self.$loadingMore[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (self.loading || !loadMoreVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
7
src/js/select2/dropdown/infiniteScroll.js
vendored
7
src/js/select2/dropdown/infiniteScroll.js
vendored
@ -38,7 +38,12 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$results.on('scroll', function () {
|
this.$results.on('scroll', function () {
|
||||||
if (self.loading) {
|
var loadMoreVisible = $.contains(
|
||||||
|
document.documentElement,
|
||||||
|
self.$loadingMore[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (self.loading || !loadMoreVisible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
src/js/select2/results.js
vendored
2
src/js/select2/results.js
vendored
@ -45,9 +45,11 @@ define([
|
|||||||
var $options = [];
|
var $options = [];
|
||||||
|
|
||||||
if (data.length === 0) {
|
if (data.length === 0) {
|
||||||
|
if (this.$results.children().length === 0) {
|
||||||
this.trigger('results:message', {
|
this.trigger('results:message', {
|
||||||
message: 'noResults'
|
message: 'noResults'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user