|
1 | 1 | angular.module('App.Controllers', [])
|
2 | 2 |
|
3 |
| - .controller('HomeCtrl', function($scope) { |
4 |
| - $scope.status = 'ready'; |
5 |
| - }) |
| 3 | + .run(['$rootScope', '$appScope', function($rootScope, $appScope) { |
| 4 | + $rootScope.$on("$routeChangeStart", function(event, next, current) { |
| 5 | + $appScope.topScope().onLoading(); |
| 6 | + }); |
6 | 7 |
|
7 |
| - .controller('OtherCtrl', function($scope) { |
| 8 | + $rootScope.onLoading = function() { |
| 9 | + var $scope = $appScope.topScope(); |
| 10 | + $appScope.safeApply(function() { |
| 11 | + $scope.loading = true; |
| 12 | + $scope.status = 'loading'; |
| 13 | + },this); |
| 14 | + }; |
8 | 15 |
|
9 |
| - }); |
| 16 | + $rootScope.onReady = function() { |
| 17 | + var $scope = $appScope.topScope(); |
| 18 | + $appScope.safeApply(function() { |
| 19 | + $scope.loading = false; |
| 20 | + $scope.status = 'ready'; |
| 21 | + },this); |
| 22 | + }; |
| 23 | + }]) |
| 24 | + |
| 25 | + .controller('AppCtrl', ['$appTimer', '$appStorage', '$location', '$scope', function($timer, $storage, $location, $scope) { |
| 26 | + $scope.search = function(q, skip) { |
| 27 | + var S = function() { |
| 28 | + var indexPath = ROUTER.routePath('videos_path'); |
| 29 | + var current = $location.path(); |
| 30 | + if(indexPath != current) { |
| 31 | + $location.path(indexPath); |
| 32 | + } |
| 33 | + $location.search('q',q); |
| 34 | + if(!$scope.$$phase) $scope.$apply(); |
| 35 | + } |
| 36 | + if(skip) { |
| 37 | + S(); |
| 38 | + } |
| 39 | + else { |
| 40 | + $timer(function() { |
| 41 | + S(); |
| 42 | + }); |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + $scope.onReady(); |
| 47 | + }]) |
| 48 | + |
| 49 | + .controller('VideosCtrl', ['$appYoutubeSearcher', '$scope', '$routeParams', function($youtube, $scope, $params) { |
| 50 | + $scope.q = $params.q || 'latest'; |
| 51 | + $youtube.query($scope.q, true, function(q, videos) { |
| 52 | + $scope.videos = videos; |
| 53 | + $scope.onReady(); |
| 54 | + }); |
| 55 | + }]) |
| 56 | + |
| 57 | + .controller('OtherCtrl', ['$scope', function($scope) { |
| 58 | + $scope.other_status = 'success' |
| 59 | + }]) |
| 60 | + |
| 61 | + .controller('WatchedVideosCtrl', ['$appYoutubeSearcher','$appStorage', '$scope', '$routeParams', function($youtube, $storage, $scope, $params) { |
| 62 | + $scope.videos = $youtube.getWatchedVideos(); |
| 63 | + $scope.sortFn = function(entry) { |
| 64 | + return entry.timestamp; |
| 65 | + }; |
| 66 | + $scope.onReady(); |
| 67 | + }]) |
| 68 | + |
| 69 | + .controller('VideoCtrl', ['$appYoutubeSearcher','$compile', '$rootScope', '$routeParams', '$scope',function($youtube, $compile, $rootScope, $params, $scope) { |
| 70 | + var id = $params.id; |
| 71 | + $youtube.findVideo(id, true, function(id, video) { |
| 72 | + $scope.video_id = id; |
| 73 | + $scope.video = video; |
| 74 | + $scope.stars = 5; |
| 75 | + |
| 76 | + $youtube.addToWatchedVideos(video); |
| 77 | + $scope.onReady(); |
| 78 | + |
| 79 | + $youtube.query(video.title, true, function(q, videos) { |
| 80 | + $scope.related = videos; |
| 81 | + if(!$scope.$$phase) $scope.$apply(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }]); |
0 commit comments