Pārlūkot izejas kodu

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.
Kevin Brown 10 gadi atpakaļ
vecāks
revīzija
0bc4832995

+ 11 - 4
dist/js/select2.amd.full.js

@@ -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;
       }
 

+ 11 - 4
dist/js/select2.amd.js

@@ -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;
       }
 

+ 11 - 4
dist/js/select2.full.js

@@ -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;
       }
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/js/select2.full.min.js


+ 11 - 4
dist/js/select2.js

@@ -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;
       }
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/js/select2.min.js


+ 6 - 1
src/js/select2/dropdown/infiniteScroll.js

@@ -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;
       }
 

+ 5 - 3
src/js/select2/results.js

@@ -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;
     }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels