-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
125 lines (94 loc) · 2.24 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* tarun Chaudhary
B tech (EE)
IIT Rajasthan
tarun29061990@github*/
/**************************
* Application
**************************/
App=Em.Application.create({
});
/**************************
* Model
**************************/
App.Tweet=Em.Object.extend({
});
App.Master =Ember.Object.extend({
me_url:null,
facebook_url:null
});
/**************************
* View
**************************/
App.SearchTextField=Em.TextField.extend({
});
var search=App.SearchTextField.create({
insertNewLine:function(){
App.SearchResultsController.refresh();
},
remove:function(){
this.remove();
}
});
App.TweetCountView=Ember.View.extend({
count:null
});
/**************************
* Controller
**************************/
App.searchResultsController=Em.ArrayController.create({
content:[],
query:'',
_idCache: {},
tweet_count:'',
parameter:null,
addTweet: function(tweet) {
// The `id` from Twitter's JSON
var id = tweet.get("id");
this.parameter++;
// If we don't already have an object with this id, add it.
if (typeof this._idCache[id] === "undefined") {
this.pushObject(tweet);
this._idCache[id] = tweet.id;
}
if(this.parameter>2)
{App.TimeInterval.bigInterval();}
else
App.TimeInterval.interval();
},
reverse:function(){
return this.toArray().reverse();
}.property('@each'),
refresh:function(){
var self=this;
var query=self.get("query");
var url="http://search.twitter.com/search.json?q="+query+"&callback=?"
$.getJSON(url,function(data){
for (var i = 0; i < data.results.length; i++)
{
self.addTweet(App.Tweet.create(
data.results[i]));
}
});
}
});
App.TimeInterval=Ember.ArrayController.create({
interval:function(){
setInterval(function() {
App.searchResultsController.refresh();
}, 15000);
},
bigInterval:function(){
setInterval(function() {
App.searchResultsController.refresh();
}, 100000);
}
});
App.masterController=Ember.ArrayController.create({
content:[
App.Master.create({
me_url:"https://graph.facebook.com/tarun29061990/picture/",
facebook_url:"https://www.facebook.com/tarun29061990/",
})
]
});