forked from chieffancypants/angular-loading-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (37 loc) · 1.33 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);
});