-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedify.js
104 lines (85 loc) · 2.62 KB
/
feedify.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//IIFE
'use strict';
/** Main app Module **/
(function(){
angular
.module('Feedify',['ngDialog'])
.controller('FeedCtrl',['$scope','FeedService','FeedResource','ngDialog',FeedCtrl]);
//our feed ctrl
function FeedCtrl($scope,FeedService,FeedResource,ngDialog){
$scope.resource = FeedResource.getResource();
$scope.loadText = "Select Feed Resource From here";
$scope.init = function(){
var resource = $scope.resource[0];
$scope.loadText = resource.title;
FeedService.parseFeed(resource.url).then(function(res){
$scope.feeds=res.data.responseData.feed.entries;
console.log($scope.feeds);
});
}
$scope.addResource = function() {
ngDialog.open({
template: 'addFeedForm',
controller : ['$scope','FeedResource', addFeedController],
scope : $scope,
});
};
$scope.loadFeed = function(resource){
$scope.loadText = resource.title;
FeedService.parseFeed(resource.url).then(function(res){
$scope.feeds=res.data.responseData.feed.entries;
console.log($scope.feeds);
});
}
$scope.removeResource = function(resource){
FeedResource.deleteResource(resource);
}
};
function addFeedController($scope,FeedResource){
console.log($scope);
$scope.resource = {};
$scope.submitNewResource = function(){
FeedResource.addResource($scope.resource.title,$scope.resource.url);
$scope.closeThisDialog();
}
}
})();
/** Services **/
(function(){
angular
.module('Feedify')
.factory('FeedService',['$http',function($http){
return {
parseFeed : function(url){
return $http.jsonp('//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q=' + encodeURIComponent(url));
}
}
}])
.factory('FeedResource',function(){
var resource = [{
title:'McAfee Blogs',
url: 'https://community.mcafee.com/blogs/feeds/blogs',
},{
title:'Google news',
url: 'https://news.google.com/?output=rss',
},{
title:'Hacker Earth',
url:'http://blog.hackerearth.com/feed',
},{
title:'YCombinator',
url:'https://news.ycombinator.com/rss',
}];
return {
addResource : function(title,url){
resource.push({title:title,url:url});
},
getResource : function(){
return resource;
},
deleteResource : function(res){
var i = resource.indexOf(res);
resource.splice(i, 1);
}
}
})
})();