-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitterRecursion.html
103 lines (78 loc) · 2.31 KB
/
twitterRecursion.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html" charset="utf-8">
<title>The Recursion Experiment</title>
<style>
.tweet-image { width: 48px; height: 48px;}
</style>
</head>
<body>
<h2>Latest Tweets</h2>
<ul id="tweets"></ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
(function() {
var UpdatePanel = {
init : function(options) {
this.options = $.extend({
interval : 50000,
number : 3
},options);
this.options.url += '&callback=?';
this.updater();
},
updater : function(){
(function updateBox(){
setTimeout(function(){
updateIt();
updateBox();
}, UpdatePanel.options.interval)
})();
// get the ball rolling
updateIt();
function updateIt() {
$.ajax({
type: 'GET',
url: UpdatePanel.options.url,
dataType: 'json',
error : function() {},
success : function(results) {
console.log(results);
var theTweets = '',
elem = UpdatePanel.options.elem
elem.empty();
$.each(results.results, function(index, tweet){
if ( index === UpdatePanel.options.number) {
return false;
} else {
UpdatePanel.createTweetDisplay(tweet)
.prependTo(elem)
.wrap($('<li>', {'class':'tweet'}));
}
});
// elem.append(theTweets);
}
});
}
},
createTweetDisplay : function(tweet) {
var theTweet = $('<div>', {'class':'tweet-wrap'});
theTweet
.prepend($('<img>', {'src':tweet.profile_image_url, 'class':'tweet-image'}))
.append($('<p>', {'text': tweet.text, 'class':'tweet-text'}))
.append($('<a>', {'class':'user-link', 'href': 'http://twitter.com/'+tweet.from_user, 'text':'@'+tweet.from_user}));
return theTweet;
}
};
window.UpdatePanel = UpdatePanel;
})();
UpdatePanel.init({
interval : 10000,
number : 10,
url : "http://search.twitter.com/search.json?q=DearMrHicks",
elem : $('#tweets')
});
</script>
</body>
</html>