|
1 var tweetQueue = []; |
|
2 var isAnimating = false; |
|
3 var countTweets = 0; |
|
4 var isPlayingTweets = false; // auto start |
|
5 var SPEED_TWEETS = 10; |
|
6 var MAX_VOTES = 25; |
|
7 var DUMP_TWEETS = 10; |
|
8 var toDel = []; |
|
9 |
|
10 var current_tweet = null; |
|
11 var current_past_tweet = 0; |
|
12 |
|
13 var ts = []; |
|
14 |
|
15 var b = 0; |
|
16 |
|
17 var defaultTweet = { |
|
18 created_at: "Sun, 19 Feb 2012 19:12:15 +0000", |
|
19 date_value: 1329678735000, |
|
20 from_user: "chateaudeau", |
|
21 from_user_id: 164810536, |
|
22 from_user_id_str: "164810536", |
|
23 from_user_name: "Olivia Duchâteau", |
|
24 geo: null, |
|
25 id: 171311150900854800, |
|
26 id_str: "171311150900854784", |
|
27 iso_language_code: "fr", |
|
28 profile_image_url: "http://a2.twimg.com/profile_images/1481618117/clip_image00212_normal.jpg", |
|
29 profile_image_url_https: "https://si0.twimg.com/profile_images/1481618117/clip_image00212_normal.jpg", |
|
30 source: "<a href="http://phnxapp.com" rel="nofollow">phnx</a>", |
|
31 text: "RT @LeProf_Higgins: Le carton rouge à Sarkozy, on a eu l'idée avant MLP mais le mien sera rouge, puis rose, mais pas brun !", |
|
32 to_user: null, |
|
33 to_user_id: null, |
|
34 to_user_id_str: null, |
|
35 to_user_name: null, |
|
36 }; |
|
37 |
|
38 var TweetAnim = { |
|
39 |
|
40 init: function() { |
|
41 |
|
42 var html = getDefaultTweet(); |
|
43 $('#tweet-container').fadeOut(0).html(html).fadeIn(2000, function() { |
|
44 $(this).fadeOut(500, function() { |
|
45 isPlayingTweets=true; |
|
46 $(this).html("").fadeIn(); |
|
47 }); |
|
48 }); |
|
49 |
|
50 |
|
51 |
|
52 }, |
|
53 queueTweet: function(t) { |
|
54 console.log("Queued " + t.text); |
|
55 tweetQueue.push({t: t, anim: true}); |
|
56 $('#nbr-mesure-new').html(tweetQueue.length); |
|
57 /* |
|
58 if(tweetQueue.length>0) |
|
59 document.getElementById('btn-tweet-next').style.visibility="visible"; |
|
60 */ |
|
61 }, |
|
62 |
|
63 shiftQueue: function() { |
|
64 if(tweetQueue.length==0) { |
|
65 $('#tweet-container').html(getDefaultTweet()); |
|
66 } |
|
67 if((tweetQueue.length>0) && (!isAnimating)) { |
|
68 countTweets++; |
|
69 isAnimating = true; |
|
70 var q = tweetQueue.shift(); |
|
71 this.showTweet(q.t, q.anim); |
|
72 |
|
73 } |
|
74 |
|
75 }, |
|
76 |
|
77 skipQueue: function() { |
|
78 |
|
79 if((tweetQueue.length>0) && (current_tweet!=null)) { |
|
80 countTweets++; |
|
81 isAnimating = true; |
|
82 $('#tweet_anim_'+ current_tweet.id_str).dequeue(); |
|
83 TweetAnim.animate(current_tweet, true); |
|
84 var q = tweetQueue.shift(); |
|
85 this.showTweet(q.t, true); |
|
86 } |
|
87 }, |
|
88 |
|
89 showTweet: function(t, anim) { |
|
90 |
|
91 var tweetId = "tweet_anim_" + t.id_str; |
|
92 var imgId = "img_" + t.id_str; |
|
93 |
|
94 if(anim) |
|
95 current_tweet = t; |
|
96 |
|
97 var htmlStr = "<div id='"+tweetId+"'><div class='tweet-bulle-avatar'>"; |
|
98 htmlStr += " <img class='tweet-img-avatar' src='"+t.profile_image_url+"' id='"+imgId+"'/>"; |
|
99 htmlStr += "</div>"; |
|
100 htmlStr += "<div class='tweet-preview-container'>"; |
|
101 htmlStr += " <span class='tweet-screen-name'><a target='_blank' href='http://twitter.com/intent/user?screen_name="+t.from_user+"'>"+t.from_user+"</a></span>"; |
|
102 htmlStr += " <span class='tweet-full-name'>"+t.from_user_name+"</span>"; |
|
103 htmlStr += " <div class='tweet-text'>"+t.text+"</div>"; |
|
104 htmlStr += " <div class='tweet-time'><a target='_blank' href='http://twitter.com/#!/" + t.from_user + "/status/" +t.id_str+"'>"+t.created_at+"</div>"; |
|
105 htmlStr += "</div>"; |
|
106 |
|
107 $('#tweet-container').html(htmlStr); |
|
108 $('#nbr-mesure-show').html(countTweets); |
|
109 $('#nbr-mesure-new').html(tweetQueue.length); |
|
110 /* |
|
111 if(tweetQueue.length>0) |
|
112 document.getElementById('btn-tweet-next').style.visibility="visible"; |
|
113 else |
|
114 document.getElementById('btn-tweet-next').style.visibility="hidden"; |
|
115 */ |
|
116 |
|
117 if(anim) { |
|
118 TweetAnim.animate(t, true); |
|
119 |
|
120 $('#'+tweetId).hover(function() { |
|
121 $(this).stop(true, true).fadeIn(); |
|
122 }, function() { |
|
123 TweetAnim.animate(t, true); |
|
124 }); |
|
125 } |
|
126 }, |
|
127 |
|
128 animate: function(t, doSshift) { |
|
129 var tweetId = "tweet_anim_" + t.id_str; |
|
130 |
|
131 t.cat = t.from_user_id%4; |
|
132 createBallTweetForce(t); |
|
133 |
|
134 |
|
135 // Pour expérimenter le balayage de tout le podium |
|
136 //setInterval(function() {defaultTweet.cat = b%4; createBallTweetForce(defaultTweet); b++;}, 500); |
|
137 |
|
138 |
|
139 |
|
140 isAnimating = false; |
|
141 if(doSshift) |
|
142 TweetAnim.shiftQueue(); |
|
143 |
|
144 /* |
|
145 toDel.push(t); |
|
146 current_past_tweet = toDel.length; |
|
147 ts[t.candidats[0]]++; |
|
148 checkSilos(); |
|
149 */ |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 function getDefaultTweet() { |
|
155 |
|
156 var htmlStr = "<div class='tweet-bulle-avatar'>"; |
|
157 htmlStr += " <img class='tweet-img-avatar' src='img/avatar-icon.png' />"; |
|
158 htmlStr += " </div>"; |
|
159 htmlStr += " <div class='tweet-preview-container'>"; |
|
160 htmlStr += " <span class='tweet-screen-name'><a target='_blank' href='http://twitter.com/intent/user?screen_name=bubbleT2012'>Bubble T</a></span>"; |
|
161 htmlStr += " <span class='tweet-full-name'>tea or tweet ?</span>"; |
|
162 htmlStr += " <div class='tweet-text'>"; |
|
163 htmlStr += " <a href='http://www.twitter.com' target='blank'>"; |
|
164 htmlStr += " Pendant que les prochains tweets se chargent.</br>"; |
|
165 htmlStr += " Exprimez, vous aussi, vos opinions sur vos candidats favoris !</a>"; |
|
166 htmlStr += " </div>"; |
|
167 htmlStr += " <div class='tweet-time'>maintenant</div>"; |
|
168 |
|
169 return htmlStr; |
|
170 |
|
171 } |
|
172 |
|
173 function checkSilos() { |
|
174 |
|
175 for(var j=0; j<ts.length; j++) { |
|
176 if(ts[j]>MAX_VOTES) { |
|
177 j=ts.length+1; |
|
178 emptySilos(); |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 |
|
184 function emptySilos() { |
|
185 |
|
186 var toDel2 = []; |
|
187 var m =0; |
|
188 |
|
189 for(var k=0; k<DUMP_TWEETS; k++) { |
|
190 world.DestroyBody(b2bod[toDel[k].id_str]); |
|
191 $('#'+toDel[k].id_str).delay(10).hide("slow").queue(function() { |
|
192 $(this).remove(); |
|
193 }); |
|
194 } |
|
195 |
|
196 for(var h= 0; h < candidats.length; h++) { |
|
197 ts[h] = 0; |
|
198 } |
|
199 |
|
200 for(var l=DUMP_TWEETS; l<toDel.length; l++) { |
|
201 toDel2[l-DUMP_TWEETS] = toDel[l]; |
|
202 ts[toDel2[l-DUMP_TWEETS].candidats[0]]++; |
|
203 } |
|
204 |
|
205 toDel = toDel2; |
|
206 current_past_tweet=toDel.length; |
|
207 } |
|
208 |
|
209 TweetAnim.init(); |