Skip to content

Commit db98526

Browse files
committed
updated the code
1 parent c71c4ff commit db98526

File tree

89 files changed

+11210
-26523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+11210
-26523
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
npm-debug.log
22
node_modules/
3+
vendor/
34
.DS_Store

app/app.css

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
h1 {
2+
font-size:40px;
3+
}
4+
5+
h2 {
6+
font-size:20px;
7+
margin-bottom:10px;
8+
}
9+
10+
#wrapper {
11+
padding-top:60px;
12+
}
13+
14+
.app-youtube-listing {
15+
padding:25px;
16+
border-bottom:1px solid #ddd;
17+
background:#eee;
18+
overflow:auto;
19+
}
20+
21+
.app-youtube-listing + .app-youtube-listing {
22+
margin-top:20px;
23+
}
24+
25+
.app-youtube-listing:hover {
26+
background:white;
27+
cursor:pointer;
28+
box-shadow:0 0 10px silver;
29+
}
30+
31+
.app-youtube-listing-image {
32+
float:left;
33+
margin-right:20px;
34+
}
35+
36+
.app-youtube-listing-thumbnails > .app-youtube-listing-thumbnail {
37+
margin:5px;
38+
}
39+
40+
.app-youtube-listing-thumbnail {
41+
border:2px solid #aaa;
42+
}
43+
44+
.app-youtube-searcher {
45+
float:right;
46+
}
47+
48+
.app-loading-container {
49+
float:left;
50+
margin-right:20px;
51+
width:25px;
52+
height:25px;
53+
}
54+
55+
.app-loading-animation {
56+
-webkit-transition:all 0.25s linear;
57+
background:url(./lib/spinner.gif) center center no-repeat;
58+
width:25px;
59+
height:25px;
60+
display:block;
61+
}
62+
63+
.app-loading-animation.ready {
64+
opacity:0;
65+
}
66+
67+
.app-loading-animation,
68+
.app-loading-animation.loading {
69+
opacity:1;
70+
}
71+
72+
.app-youtube-profile {
73+
text-align:center;
74+
padding:20px;
75+
}
76+
77+
.app-youtube-listing-imagery {
78+
overflow:auto;
79+
margin-bottom:20px;
80+
}

app/app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var App = window.App = angular.module('App',
44
'App.Filters',
55
'App.Services',
66
'App.Directives',
7-
'App.Resources',
8-
'App.Config'
7+
'App.Routes'
98
]
109
);

app/config/config.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1-
angular.module('App.Config', [])
1+
var CONFIG;
22

3-
.config(['$routeProvider', function($routes) {
4-
$routes.when('/home', {
5-
redirectTo : '/'
6-
});
3+
(function() {
74

8-
$routes.when('/', {
9-
controller : 'HomeCtrl',
10-
templateUrl : 'application/templates/home.html'
11-
});
5+
var appPrefix = 'app/';
6+
var templateUrlPrefix = 'templates/';
127

13-
}]);
8+
CONFIG = {
9+
10+
baseDirectory : appPrefix,
11+
templateDirectory : templateUrlPrefix,
12+
13+
routing : {
14+
15+
prefix : '!',
16+
html5Mode : false
17+
18+
},
19+
20+
viewUrlPrefix : templateUrlPrefix + 'views/',
21+
partialUrlPrefix : templateUrlPrefix + 'partials/',
22+
23+
templateFileSuffix : '_tpl.html',
24+
25+
prepareViewTemplateUrl : function(url) {
26+
return this.viewUrlPrefix + url + this.templateFileSuffix;
27+
}
28+
29+
};
30+
31+
})();

app/config/routes.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
angular.module('App.Routes', [])
2+
3+
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
4+
5+
if(CONFIG.routing.html5Mode) {
6+
$locationProvider.html5Mode(true);
7+
}
8+
else {
9+
var routingPrefix = CONFIG.routing.prefix;
10+
if(routingPrefix && routingPrefix.length > 0) {
11+
$locationProvider.hashPrefix(routingPrefix);
12+
}
13+
}
14+
15+
ROUTER.when('videos_path', '/videos', {
16+
controller : 'VideosCtrl',
17+
templateUrl : CONFIG.prepareViewTemplateUrl('videos/index')
18+
});
19+
20+
ROUTER.when('video_path', '/videos/:id', {
21+
controller : 'VideoCtrl',
22+
templateUrl : CONFIG.prepareViewTemplateUrl('videos/show')
23+
});
24+
25+
ROUTER.when('watched_videos_path', '/watched-videos', {
26+
controller : 'WatchedVideosCtrl',
27+
templateUrl : CONFIG.prepareViewTemplateUrl('videos/watched_videos')
28+
});
29+
30+
ROUTER.when('other_path', '/other', {
31+
controller : 'OtherCtrl',
32+
templateUrl : CONFIG.prepareViewTemplateUrl('other/index')
33+
});
34+
35+
ROUTER.alias('home_path', 'videos_path');
36+
37+
ROUTER.otherwise({
38+
redirectTo : '/videos'
39+
});
40+
41+
ROUTER.install($routeProvider);
42+
}]).
43+
44+
run(['$rootScope', '$location', function($rootScope, $location) {
45+
var prefix = '';
46+
if(!CONFIG.routing.html5Mode) {
47+
prefix = '#' + CONFIG.routing.prefix;
48+
}
49+
$rootScope.route = function(url, args) {
50+
return prefix + ROUTER.routePath(url, args);
51+
};
52+
53+
$rootScope.r = $rootScope.route;
54+
55+
$rootScope.c = function(route, value) {
56+
var url = ROUTER.routePath(route);
57+
if(url == $location.path()) {
58+
return value;
59+
}
60+
};
61+
}]);

app/controllers/controllers.js

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,84 @@
11
angular.module('App.Controllers', [])
22

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+
});
67

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+
};
815

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+
}]);

app/directives/directives.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
angular.module('App.directives', [])
1+
angular.module('App.Directives', [])
22

3-
.directive('appWelcomeText', function($scope) {
3+
.directive('appWelcome', function() {
4+
return function($scope, element, attrs) {
5+
var html = element.html();
6+
element.html('Welcome: <strong>' + html + '</strong>');
7+
};
8+
})
49

5-
});
10+
.directive('appYoutubeListing', ['$appLocation', function($appLocation) {
11+
return function($scope, element, attrs) {
12+
element.bind('click', function() {
13+
var elm = $(this);
14+
var id = elm.attr('data-app-youtube-listing-id');
15+
var url = ROUTER.routePath('video_path', {
16+
id : id
17+
});
18+
$appLocation.change(url, $scope);
19+
});
20+
};
21+
}])
22+
23+
.directive('appYoutubeListings', ['$appLocation', function($appLocation) {
24+
var listingSelector = '.app-youtube-listing';
25+
var className = 'app-youtube-listings';
26+
27+
return function($scope, element, attrs) {
28+
element.addClass(className);
29+
};
30+
}]);

app/filters/filters.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
angular.module('App.Filters', [])
2-
3-
.filter('censor', function() {
4-
return function() {
5-
1+
angular.module('App.Filters', []).
2+
filter('range', function() {
3+
return function(input, total) {
4+
if(!input) return null;
5+
total = parseInt(total);
6+
for (var i=0; i<total; i++)
7+
input.push(i);
8+
return input;
69
};
710
});

app/index.html

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
11
<!DOCTYPE html>
2-
<html data-ng-app="App">
2+
<html data-ng-app="App" data-ng-controller="AppCtrl">
33
<head>
44
<title>AngularJS Testing Demo</title>
5+
<link rel="stylesheet" type="text/css" href="./lib/reset.css" />
6+
<link rel="stylesheet" type="text/css" href="./lib/bootstrap/css/bootstrap.css" />
7+
<link rel="stylesheet" type="text/css" href="./app.css" />
58
</head>
9+
610
<body data-status="{{ status }}" class="ng-cloak">
7-
<div data-ng-view></div>
11+
<div id="wrapper">
12+
<nav class="app-navigation">
13+
<div class="navbar navbar-inverse navbar-fixed-top">
14+
<div class="navbar-inner">
15+
<div class="container">
16+
<a class="brand" href="#">
17+
<span class="app-loading-container">
18+
<span class="app-loading-animation" data-ng-class="status"></span>
19+
</span>
20+
Angular Youtube Library
21+
</a>
22+
23+
<form data-app-youtube-searcher data-ng-submit="search(q, true)" class="app-youtube-searcher navbar-search pull-left">
24+
<input type="search" data-ng-model="q" data-ng-change="search(q)" class="search-query" placeholder="Search for youtube videos..." />
25+
</form>
26+
27+
<ol class="nav">
28+
<li data-ng-class="c('videos_path','active')">
29+
<a data-ng-href="{{ r('videos_path') }}">Videos</a>
30+
</li>
31+
<li data-ng-class="c('watched_videos_path','active')">
32+
<a data-ng-href="{{ r('watched_videos') }}">Watched Videos</a>
33+
</li>
34+
</ol>
35+
</div>
36+
</div>
37+
</div>
38+
</nav>
39+
<div class="container">
40+
<div data-ng-view id="ng-view"></div>
41+
</div>
42+
</div>
43+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
844
<script src="./lib/angular.min.js"></script>
9-
<script src="./resources/resources.js"></script>
45+
<script src="./lib/bootstrap/js/bootstrap.js"></script>
46+
<script src="./lib/app.router.js"></script>
47+
<script src="./config/config.js"></script>
1048
<script src="./services/services.js"></script>
1149
<script src="./directives/directives.js"></script>
1250
<script src="./controllers/controllers.js"></script>
1351
<script src="./filters/filters.js"></script>
14-
<script src="./config/config.js"></script>
52+
<script src="./config/routes.js"></script>
1553
<script src="./app.js"></script>
54+
1655
<body>
1756
</html>

0 commit comments

Comments
 (0)