|
10
|
1 |
var myPodium, |
|
|
2 |
myTweetSource, |
|
|
3 |
myQueueManager; |
|
|
4 |
|
|
23
|
5 |
var columnCounts, |
|
|
6 |
onlineTweets = [], |
|
|
7 |
dumpIsPaused = false; |
|
|
8 |
|
|
25
|
9 |
var MAX_TWEETS_BEFORE_DUMP = 20, |
|
|
10 |
TWEETS_TO_DUMP_AT_ONCE = 10; |
|
23
|
11 |
|
|
10
|
12 |
function updateLastTweetList() { |
|
|
13 |
var _filtered = myTweetSource.afterDate(startHour), |
|
|
14 |
_txtFilter = $("#btv-cp-champ-filtre").val(), |
|
|
15 |
_reFilter = null; |
|
|
16 |
if (_txtFilter.length > 1) { |
|
|
17 |
_filtered = _filtered.search(_txtFilter); |
|
|
18 |
_reFilter = regexpFromText(_txtFilter); |
|
25
|
19 |
for (var _i = 0; _i < onlineTweets.length; _i++) { |
|
|
20 |
if (onlineTweets[_i].text.search(_reFilter) == -1) { |
|
|
21 |
$('#'+onlineTweets[_i].id_str).fadeTo(250, 0.1); |
|
|
22 |
} else { |
|
|
23 |
$('#'+onlineTweets[_i].id_str).fadeTo(250, 1); |
|
|
24 |
} |
|
|
25 |
} |
|
|
26 |
} else { |
|
|
27 |
for (var _i = 0; _i < onlineTweets.length; _i++) { |
|
|
28 |
$('#'+onlineTweets[_i].id_str).fadeTo(250, 1); |
|
|
29 |
} |
|
10
|
30 |
} |
|
|
31 |
$('#btv-cp-liste-tweets-tout').html( |
|
|
32 |
_filtered.reverse().slice(0,20).map(function(_t) { |
|
|
33 |
return '<li onclick="addTweetToSelection(\'' |
|
|
34 |
+ _t.id_str |
|
|
35 |
+ '\'); return false;"><a title="Ajouter à la sélection" href="#"><span class="btv-cp-tweet-date">' |
|
|
36 |
+ _t.created_at.match(/\d+:\d+:\d+/)[0] |
|
|
37 |
+ '</span> <span class="btv-cp-tweet-from">' |
|
|
38 |
+ ( _reFilter ? ('@' + _t.from_user).replace(_reFilter, '<span class="btv-cp-highlight">$1</span>') : ('@' + _t.from_user) ) |
|
|
39 |
+ '</span> <span class="btv-cp-tweet-text">' |
|
|
40 |
+ ( _reFilter ? _t.text.replace(_reFilter, '<span class="btv-cp-highlight">$1</span>') : _t.text ) |
|
|
41 |
+ '</span><div class="btv-cp-tweet-button btv-cp-tweet-add"></div></a></li>' |
|
|
42 |
}).join('') |
|
|
43 |
); |
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
function addTweetToSelection(tweetId) { |
|
|
47 |
var _t = myTweetSource.tweetById(tweetId); |
|
|
48 |
if (_t) { |
|
|
49 |
$("#btv-cp-liste-tweets-selection").prepend( |
|
13
|
50 |
'<li><a title="Afficher sur l\'écran" href="#" onclick="showTweetOnScreen(\'' |
|
|
51 |
+ _t.id_str |
|
|
52 |
+ '\'); return false;"><span class="btv-cp-tweet-date">' |
|
|
53 |
+ _t.created_at.match(/\d+:\d+:\d+/)[0] |
|
|
54 |
+ '</span> <span class="btv-cp-tweet-from">@' |
|
|
55 |
+ _t.from_user |
|
|
56 |
+ '</span> <span class="btv-cp-tweet-text">' |
|
|
57 |
+ _t.text |
|
14
|
58 |
+ '</span><div class="btv-cp-tweet-button btv-cp-tweet-show"></div></a>' |
|
|
59 |
+ '<a title="Supprimer de cette liste" href="#" onclick="$(this).parent().detach(); return false;"><div class="btv-cp-tweet-button btv-cp-tweet-remove"></div></a></li>' |
|
10
|
60 |
); |
|
|
61 |
} |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
function showTweetOnScreen(tweetId) { |
|
|
65 |
var _t = myTweetSource.tweetById(tweetId); |
|
|
66 |
console.log(_t); |
|
|
67 |
if (_t) { |
|
|
68 |
$("#btv-bigtweet").html('<img class="btv-bigtweet-image" src="' |
|
|
69 |
+ _t.profile_image_url |
|
|
70 |
+ '" /><p class="btv-bigtweet-screen-name">' |
|
|
71 |
+ _t.from_user |
|
|
72 |
+ '</p><p class="btv-bigtweet-name">' |
|
|
73 |
+ _t.from_user_name |
|
|
74 |
+'</p><p class="btv-bigtweet-text">' |
|
|
75 |
+ _t.text |
|
|
76 |
+'</p>').show(); |
|
|
77 |
$(".btv-cp-hide-tweets").show(); |
|
|
78 |
} |
|
|
79 |
} |
|
|
80 |
|
|
26
|
81 |
function showTooltip(_t, _x, _y) { |
|
|
82 |
$("#btv-tooltip").html('<img class="btv-tooltip-image" src="' |
|
|
83 |
+ _t.profile_image_url |
|
|
84 |
+ '" /><p class="btv-tooltip-name"><span>' |
|
|
85 |
+ _t.from_user |
|
|
86 |
+ '</span> (<span>' |
|
|
87 |
+ _t.from_user_name |
|
|
88 |
+'</span>)</p><p>' |
|
|
89 |
+ _t.text |
|
|
90 |
+'</p><div class="btv-tooltip-arrow"></div>').show().css({ |
|
|
91 |
"left": _x + "px", |
|
|
92 |
"top": _y + "px", |
|
|
93 |
}) |
|
|
94 |
} |
|
|
95 |
|
|
|
96 |
function hideTooltip() { |
|
|
97 |
$("#btv-tooltip").hide(); |
|
|
98 |
} |
|
|
99 |
|
|
|
100 |
function showControlPanel() { |
|
|
101 |
$("#btv-cp-container").dequeue().animate({ |
|
|
102 |
"left": 0 |
|
|
103 |
}); |
|
|
104 |
} |
|
|
105 |
|
|
|
106 |
function hideControlPanel() { |
|
|
107 |
$("#btv-cp-container").dequeue().animate({ |
|
|
108 |
"left": "-315px" |
|
|
109 |
}); |
|
|
110 |
} |
|
|
111 |
|
|
10
|
112 |
$(function() { |
|
23
|
113 |
columnCounts = columnKeywords.map(function() { |
|
|
114 |
return 0; |
|
|
115 |
}) |
|
10
|
116 |
setInterval(function() { |
|
|
117 |
var _t = Math.floor((new Date() - startHour)/1000), |
|
|
118 |
_s = _t % 60, |
|
|
119 |
_m = Math.floor(_t/60) % 60, |
|
|
120 |
_h = Math.floor(_t/3600); |
|
|
121 |
$("#btv-cp-temps").html( |
|
|
122 |
_h + ':' + (_m < 10 ? '0' : '') + _m + ':' + (_s < 10 ? '0' : '') + _s |
|
|
123 |
) |
|
|
124 |
}, 500); |
|
|
125 |
myPodium = new Btv_Podium([0,0,0,0], { minHeight: 50 }); |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
$("#podium-labels").html(columnKeywords.map(function(_w) { |
|
|
129 |
return '<li>' + _w + '</li>' |
|
|
130 |
}).join("")); |
|
|
131 |
|
|
|
132 |
myTweetSource = new Btv_TweetSource({ |
|
|
133 |
keywords: searchKeywords |
|
|
134 |
}); |
|
|
135 |
|
|
|
136 |
myTweetSource.setOnNewTweets(function() { |
|
|
137 |
var _filtered = this.afterDate(startHour); |
|
|
138 |
$("#btv-cp-nb-tweets").html(_filtered.count()); |
|
|
139 |
var _counts = []; |
|
|
140 |
for (var _i = 0; _i < columnKeywords.length; _i++) { |
|
|
141 |
_counts.push(_filtered.search(columnKeywords[_i]).count()); |
|
|
142 |
} |
|
|
143 |
updateLastTweetList(); |
|
|
144 |
myPodium.update(_counts); |
|
|
145 |
$("#podium-chiffres").html(_counts.map(function(_c) { |
|
|
146 |
return '<li>' + _c + '</li>' |
|
|
147 |
}).join("")); |
|
|
148 |
}); |
|
|
149 |
myQueueManager = new Btv_TweetQueueManager(myTweetSource, function(_t) { |
|
|
150 |
var _cat = -1; |
|
|
151 |
for (var i = 0; i < columnKeywords.length; i++) { |
|
|
152 |
if (_t.text.search(regexpFromText(columnKeywords[i])) != -1) { |
|
|
153 |
_cat = i; |
|
|
154 |
break; |
|
|
155 |
} |
|
|
156 |
} |
|
|
157 |
if (_cat != -1) { |
|
23
|
158 |
_t.cat = _cat; |
|
|
159 |
columnCounts[_cat]++; |
|
|
160 |
onlineTweets.push(_t); |
|
|
161 |
createBallTweetForce(_t); |
|
|
162 |
if (!dumpIsPaused) { |
|
|
163 |
for (var _i = 0; _i < columnCounts.length; _i++) { |
|
|
164 |
if (columnCounts[_cat] > MAX_TWEETS_BEFORE_DUMP) { |
|
|
165 |
var toDel = onlineTweets.splice(0,TWEETS_TO_DUMP_AT_ONCE); |
|
|
166 |
|
|
|
167 |
for (var _j = 0; _j < toDel.length; _j++) { |
|
|
168 |
var _id = toDel[_j].id_str; |
|
|
169 |
world.DestroyBody(b2bod[_id]); |
|
|
170 |
|
|
26
|
171 |
$('#'+_id).fadeTo(500, 0, function() { |
|
23
|
172 |
$(this).remove(); |
|
|
173 |
}); |
|
|
174 |
} |
|
|
175 |
|
|
|
176 |
// Regenerate column counts |
|
|
177 |
columnCounts = columnKeywords.map(function() { |
|
|
178 |
return 0; |
|
|
179 |
}); |
|
|
180 |
for (var _k = 0; _k < onlineTweets.length; _k++) { |
|
|
181 |
columnCounts[onlineTweets[_k].cat]++; |
|
|
182 |
} |
|
|
183 |
break; |
|
|
184 |
} |
|
|
185 |
} |
|
10
|
186 |
} |
|
|
187 |
} |
|
23
|
188 |
}); |
|
10
|
189 |
|
|
26
|
190 |
$("#btv-cp-container").mouseover(showControlPanel).mouseout(hideControlPanel); |
|
|
191 |
|
|
10
|
192 |
$("#btv-cp-champ-filtre").keyup(function() { |
|
|
193 |
updateLastTweetList(); |
|
|
194 |
}); |
|
|
195 |
$("#btv-cp-clear-filtre").click(function() { |
|
|
196 |
$("#btv-cp-champ-filtre").val(""); |
|
|
197 |
updateLastTweetList(); |
|
|
198 |
return false; |
|
|
199 |
}); |
|
|
200 |
$("#btv-bigtweet, .btv-cp-hide-tweets").click(function() { |
|
|
201 |
$("#btv-bigtweet, .btv-cp-hide-tweets").hide(); |
|
|
202 |
}); |
|
|
203 |
$("#btv-cp-cont-pause-amont").click(function() { |
|
|
204 |
if (myQueueManager.playPause()) { |
|
|
205 |
$(this).removeClass("btv-cp-status-pause"); |
|
|
206 |
$(this).addClass("btv-cp-status-play"); |
|
|
207 |
} else { |
|
|
208 |
$(this).addClass("btv-cp-status-pause"); |
|
|
209 |
$(this).removeClass("btv-cp-status-play"); |
|
|
210 |
} |
|
|
211 |
}); |
|
23
|
212 |
$("#btv-cp-cont-pause-aval").click(function() { |
|
|
213 |
dumpIsPaused = !dumpIsPaused |
|
|
214 |
if (dumpIsPaused) { |
|
|
215 |
$(this).removeClass("btv-cp-status-pause"); |
|
|
216 |
$(this).addClass("btv-cp-status-play"); |
|
|
217 |
} else { |
|
|
218 |
$(this).addClass("btv-cp-status-pause"); |
|
|
219 |
$(this).removeClass("btv-cp-status-play"); |
|
|
220 |
} |
|
|
221 |
}); |
|
10
|
222 |
}); |