diff --git a/biomed-frontend/bower.json b/biomed-frontend/bower.json index 93847ca..e43c830 100644 --- a/biomed-frontend/bower.json +++ b/biomed-frontend/bower.json @@ -14,6 +14,7 @@ "imagesloaded": "~3.1.8", "jquery-colorbox": "~1.5.14", "angular-foundation": "~0.4.0", - "font-awesome": "~4.3.0" + "font-awesome": "~4.3.0", + "ngInfiniteScroll": "~1.2.0" } } diff --git a/biomed-frontend/gulpfile.js b/biomed-frontend/gulpfile.js index c0311db..0a39d3a 100644 --- a/biomed-frontend/gulpfile.js +++ b/biomed-frontend/gulpfile.js @@ -36,7 +36,8 @@ gulp.task('vendor', function() { 'vendor/masonry/dist/masonry.pkgd.js', 'vendor/angular-masonry/angular-masonry.js', 'vendor/imagesloaded/imagesloaded.pkgd.js', - 'vendor/jquery-colorbox/jquery.colorbox.js' + 'vendor/jquery-colorbox/jquery.colorbox.js', + 'vendor/ngInfiniteScroll/build/ng-infinite-scroll.js' ]) .pipe(sourcemaps.init({loadMaps: true})) .pipe(concat('vendor.js')) diff --git a/biomed-frontend/src/app/index.js b/biomed-frontend/src/app/index.js index fb07af3..7c9cb8f 100644 --- a/biomed-frontend/src/app/index.js +++ b/biomed-frontend/src/app/index.js @@ -4,7 +4,8 @@ angular.module('biomed-frontend', [ 'ngResource', 'angular-loading-bar', 'wu.masonry', - 'mm.foundation' + 'mm.foundation', + 'infinite-scroll' ]) .factory('Posts', function($resource) { return $resource('/api/v1/posts/:_id', @@ -23,28 +24,42 @@ angular.module('biomed-frontend', [ .state('site.list', { url: '/', templateUrl: 'app/list.html', - resolve: { - posts: function(Posts) { - return Posts.query({ - 'status': 'posted', - 'sort': '-postedOn', - }).$promise; - } - }, - controller: function($scope, posts, $timeout, $sce, $location, $anchorScroll) { + controller: function($scope, $timeout, $sce, $location, $anchorScroll, Posts) { $scope.posts = []; - angular.forEach(posts, function(post) { - if (post.previewHtml) { - post.previewHtml = $sce.trustAsHtml(post.previewHtml); - } + var deferred = false; + var more = true; - $scope.posts.push(post); - }); + var loadNextPage = function() { + if (more && (!deferred || deferred.$resolved)) { + var query = { + 'status': 'posted', + 'sort': '-postedOn', + 'limit': 10, + 'skip': $scope.posts.length + }; + + deferred = Posts.query(query, function(posts) { + more = posts.length > 0; + + angular.forEach(posts, function(post) { + if (post.previewHtml) { + post.previewHtml = $sce.trustAsHtml(post.previewHtml); + } + + $scope.posts.push(post); + }); + }); + } + } $scope.showMore = function(post) { return post.details || post.gallery.length > 0; } + + $scope.addMoreItems = function() { + loadNextPage(); + } } }) .state('site.details', { diff --git a/biomed-frontend/src/app/list.html b/biomed-frontend/src/app/list.html index d66f0a4..2b5a8a3 100644 --- a/biomed-frontend/src/app/list.html +++ b/biomed-frontend/src/app/list.html @@ -1,4 +1,4 @@ -
+