Files
website/biomed-frontend/src/app/index.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2014-09-29 22:42:21 -07:00
angular.module('biomed-frontend', [
'templates',
'ui.router',
'ngResource',
2014-10-07 01:40:02 -04:00
'angular-loading-bar',
2014-10-26 02:29:04 -07:00
'wu.masonry',
2015-02-01 22:19:57 -08:00
'mm.foundation',
'infinite-scroll'
2014-09-29 22:42:21 -07:00
])
.factory('Posts', function($resource) {
2014-10-07 03:25:36 -07:00
return $resource('/api/v1/posts/:_id',
{ '_id': '@_id' }
2014-09-29 22:42:21 -07:00
);
})
.config(function($urlRouterProvider, $locationProvider) {
$locationProvider.html5Mode(true);
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('site', {
abstract: true,
templateUrl: 'app/layout.html'
})
.state('site.list', {
url: '/',
templateUrl: 'app/list.html',
2015-02-01 22:19:57 -08:00
controller: function($scope, $timeout, $sce, $location, $anchorScroll, Posts) {
$scope.posts = [];
2015-02-01 22:19:57 -08:00
var deferred = false;
var more = true;
var loadNextPage = function() {
if (more && (!deferred || deferred.$resolved)) {
var query = {
'status': 'posted',
'sort': '-postedOn',
'limit': 10,
'skip': $scope.posts.length
};
2015-02-01 22:19:57 -08:00
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);
});
});
}
}
2014-10-07 03:25:36 -07:00
$scope.showMore = function(post) {
return post.details || post.gallery.length > 0;
}
2015-02-01 22:19:57 -08:00
$scope.addMoreItems = function() {
loadNextPage();
}
2014-09-29 22:42:21 -07:00
}
})
.state('site.details', {
2014-10-07 03:25:36 -07:00
url: '/posts/:_id',
2014-09-29 22:42:21 -07:00
templateUrl: 'app/details.html',
resolve: {
post: function(Posts, $stateParams) {
2014-10-07 03:25:36 -07:00
return Posts.get({
'_id': $stateParams._id
}).$promise;
2014-09-29 22:42:21 -07:00
}
},
controller: function($scope, post, $sce) {
if (post.detailsHtml) {
post.detailsHtml = $sce.trustAsHtml(post.detailsHtml);
}
$scope.post = post;
$scope.gallery = post.gallery;
2014-09-29 22:42:21 -07:00
}
});
2014-10-26 02:29:04 -07:00
})
$(window).scroll(function() {
if ($(this).scrollTop() >= 50) {
$('#return-to-top').fadeIn(200);
} else {
$('#return-to-top').fadeOut(200);
}
});
$('#return-to-top').click(function() {
$('body,html').animate({
scrollTop : 0
}, 500);
});