|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -var app = angular.module('demo', ['ngSanitize', 'ui.select']); |
| 3 | +var app = angular.module('demo', ['ngSanitize', 'ui.select', 'ui.scrollpoint']); |
4 | 4 |
|
5 | 5 | /**
|
6 | 6 | * AngularJS default filter with the following expression:
|
@@ -212,6 +212,32 @@ app.controller('DemoCtrl', function ($scope, $http, $timeout, $interval) {
|
212 | 212 | }
|
213 | 213 | }
|
214 | 214 |
|
| 215 | + vm.infinity = { |
| 216 | + cursor: 0, // start from (limitTo begin parameter requires angular >= 1.4.0) |
| 217 | + count: 10, // starting count |
| 218 | + limit: 10, // how many to show per load |
| 219 | + loading: false, // loading state |
| 220 | + more: function(distance, element, edge) { |
| 221 | + if (distance < 0 && (edge || element[0].offsetTop) && !$scope.infinity.loading) { |
| 222 | + // make sure we won't exceed the bounds |
| 223 | + if (($scope.infinity.cursor + $scope.infinity.count) < $scope.countries.length) { |
| 224 | + $scope.infinity.loading = true; |
| 225 | + $scope.$apply(); // infinity.more is triggered by non-angular window scroll event |
| 226 | + |
| 227 | + // using a $timeout for demo purposes (this would typically be some async call to load more resources) |
| 228 | + $timeout(function(){ |
| 229 | + $scope.infinity.loading = false; |
| 230 | + $scope.infinity.count += $scope.infinity.limit; |
| 231 | + var overflow = ($scope.infinity.cursor + $scope.infinity.count) - $scope.countries.length; |
| 232 | + if(overflow > 0){ |
| 233 | + $scope.infinity.count -= overflow; |
| 234 | + } |
| 235 | + }, 500); |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + }; |
| 240 | + |
215 | 241 | vm.country = {};
|
216 | 242 | vm.countries = [ // Taken from https://gist.github.com/unceus/6501985
|
217 | 243 | {name: 'Afghanistan', code: 'AF'},
|
|
0 commit comments