mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-01-29 08:34:30 +01:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
|
|
|
|
angular.module('LoadingBarExample', ['chieffancypants.loadingBar', 'ngAnimate'])
|
|
.config(function(cfpLoadingBarProvider) {
|
|
cfpLoadingBarProvider.includeSpinner = true;
|
|
})
|
|
|
|
.controller('ExampleCtrl', function ($scope, $http, $timeout, cfpLoadingBar) {
|
|
$scope.posts = [];
|
|
$scope.section = null;
|
|
$scope.subreddit = null;
|
|
$scope.subreddits = ['cats', 'pics', 'funny', 'gaming', 'AdviceAnimals', 'aww'];
|
|
|
|
var getRandomSubreddit = function() {
|
|
var sub = $scope.subreddits[Math.floor(Math.random() * $scope.subreddits.length)];
|
|
|
|
// ensure we get a new subreddit each time.
|
|
if (sub == $scope.subreddit) {
|
|
return getRandomSubreddit();
|
|
}
|
|
|
|
return sub;
|
|
};
|
|
|
|
$scope.fetch = function() {
|
|
$scope.subreddit = getRandomSubreddit();
|
|
$http.jsonp('http://www.reddit.com/r/' + $scope.subreddit + '.json?limit=50&jsonp=JSON_CALLBACK').success(function(data) {
|
|
$scope.posts = data.data.children;
|
|
});
|
|
};
|
|
|
|
$scope.start = function() {
|
|
cfpLoadingBar.start();
|
|
};
|
|
|
|
$scope.complete = function () {
|
|
cfpLoadingBar.complete();
|
|
}
|
|
|
|
|
|
// fake the initial load so first time users can see it right away:
|
|
$scope.start();
|
|
$scope.fakeIntro = true;
|
|
$timeout(function() {
|
|
$scope.complete();
|
|
$scope.fakeIntro = false;
|
|
}, 750);
|
|
|
|
});
|