소스 검색

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 년 전
부모
커밋
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;
       }
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 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;
       }
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 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;
     }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.