| author | Raphael Velt <raph.velt@gmail.com> |
| Thu, 18 Apr 2013 18:00:43 +0200 | |
| changeset 866 | f239ebb11236 |
| parent 864 | 4c5f5b62cc89 |
| permissions | -rw-r--r-- |
| 836 | 1 |
var tracking_keywords = [ "#AVPHannaArendt" ]; |
2 |
||
3 |
function rejectUser(username) { |
|
4 |
return (/^[A-Z][a-z]{2,8}[0-9]{4,6}$/.test(username)) |
|
5 |
} |
|
6 |
||
7 |
if (typeof annotations == "undefined" || !annotations) { |
|
8 |
var annotations = { |
|
9 |
"default" : { |
|
10 |
"colors" : { |
|
11 |
"h" : 0, |
|
12 |
"s" : 0 |
|
13 |
} |
|
14 |
}, |
|
15 |
"positive" : { |
|
16 |
"display_name" : "++ | accord", |
|
17 |
"keywords" : [ /\+\+/ ], |
|
18 |
"colors" : { |
|
19 |
"h" : .3, |
|
20 |
"s" : .65 |
|
21 |
} |
|
22 |
}, |
|
23 |
"negative" : { |
|
24 |
"display_name" : "-- | désaccord", |
|
25 |
"keywords" : [ /\-\-/ ], |
|
26 |
"colors" : { |
|
27 |
"h" : 0, |
|
28 |
"s" : .8 |
|
29 |
} |
|
30 |
}, |
|
31 |
"reference" : { |
|
32 |
"display_name" : "== | référence", |
|
33 |
"keywords" : [ /\=\=/ ], |
|
34 |
"colors" : { |
|
35 |
"h" : .16, |
|
36 |
"s" : .8 |
|
37 |
} |
|
38 |
}, |
|
39 |
"question" : { |
|
40 |
"display_name" : "?? | question", |
|
41 |
"keywords" : [ /\?\?/ ], |
|
42 |
"colors" : { |
|
43 |
"h" : .6, |
|
44 |
"s" : .8 |
|
45 |
} |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
if (typeof l10n == "undefined") { |
|
51 |
l10n = { "rechercher" : "Rechercher" } |
|
52 |
} |
|
53 |
||
54 |
if (typeof suggested_keywords == "undefined") { |
|
55 |
suggested_keywords = [ ]; |
|
56 |
} |
|
57 |
||
58 |
if (typeof max_pages == "undefined" || !max_pages) { |
|
| 862 | 59 |
max_pages = 2; |
| 836 | 60 |
} |
61 |
||
62 |
tracking_keywords = _(tracking_keywords).map(function(_w) { |
|
63 |
return _w.toLowerCase(); |
|
64 |
}); |
|
65 |
||
66 |
var twCx = { |
|
67 |
tlPaper : null, |
|
68 |
followLast : true, |
|
69 |
position : "0", |
|
70 |
date_levels : [ |
|
71 |
3600 * 1000, |
|
72 |
15 * 60 * 1000, |
|
73 |
5 * 60 * 1000, |
|
74 |
60 * 1000 |
|
75 |
], |
|
76 |
timeLevel : 1, |
|
77 |
deltaX : 40, |
|
78 |
tlWidth : 150, |
|
79 |
tlHeight : 480, |
|
80 |
globalWords : {}, |
|
81 |
suggestCount : _(suggested_keywords).map(function(_w) { |
|
82 |
return { |
|
83 |
"word" : _w, |
|
84 |
"rgxp" : new RegExp(_w.replace(/(\W)/g, '\\$1'), "im"), |
|
85 |
"freq" : 0, |
|
86 |
"annotations" : {} |
|
87 |
} |
|
88 |
}), |
|
89 |
refMouse : { x : 0, y : 0}, |
|
90 |
refPosTl : { x : 0, y : 0}, |
|
91 |
tlMouseMoved : false, |
|
92 |
tlMouseClicked : false, |
|
93 |
filtre : null, |
|
94 |
tlBuffer : '', |
|
95 |
relHover : [], |
|
96 |
wheelDelta : 0, |
|
97 |
scrollEnabled : false, |
|
98 |
scrollExtent : 8000 - 480, |
|
99 |
lastScrollPos : 0, |
|
100 |
urlRegExp : /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, |
|
101 |
wordRegExp : /[^ \.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, |
|
102 |
stopWords : [ |
|
103 |
'aussi', 'and', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'donc', 'des', 'elle', 'encore', 'est', |
|
104 |
'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre', |
|
105 |
'non', 'nos', 'nous', 'ont', 'oui', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'ses' ,'son', 'sont', 'sur', |
|
106 |
'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' |
|
107 |
] |
|
108 |
} |
|
109 |
||
110 |
function getTweets(options) { |
|
111 |
|
|
112 |
function getTweetUrl(url) { |
|
113 |
$.getJSON(url, function(data) { |
|
114 |
options.tweets = options.tweets.concat(data); |
|
115 |
options.currentPage++; |
|
116 |
if (options.cbData) { |
|
117 |
options.cbData(); |
|
118 |
} |
|
119 |
var _isLast = true; |
|
120 |
if (data.results && data.results.length) { |
|
121 |
var _oldestTweetId = data.results[data.results.length - 1].id_str, |
|
122 |
_maxId = _oldestTweetId; |
|
123 |
if (options.currentPage < options.pages) { |
|
124 |
_isLast = false; |
|
125 |
getTweetUrl(baseurl + firstparams + '&max_id=' + _maxId + lastparams); |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
if (_isLast) { |
|
130 |
options.tweets.sort(function(a,b) { |
|
131 |
return a.id - b.id; |
|
132 |
}); |
|
133 |
if (options.cbEnd) { |
|
134 |
options.cbEnd(); |
|
135 |
} |
|
136 |
} |
|
137 |
}); |
|
138 |
} |
|
139 |
|
|
140 |
options.tweets = []; |
|
141 |
options.pages || (options.pages = 1); |
|
142 |
options.rpp || (options.rpp = 100); |
|
143 |
options.currentPage = 0; |
|
144 |
var baseurl = "search_tweets.php", |
|
145 |
firstparams = "?endpoint=favorites/list" + (typeof favUser === "string" ? ("&screen_name=" + encodeURIComponent(favUser)) : "") |
|
146 |
+ "&count=" + options.rpp + "&include_entities=true", |
|
147 |
lastparams = (options.since_id ? "&since_id=" + options.since_id : '' ) + "&callback=?", |
|
148 |
jsonurl = baseurl + firstparams + lastparams; |
|
149 |
getTweetUrl(jsonurl); |
|
150 |
} |
|
151 |
||
152 |
function getColor(annotation, lum) { |
|
153 |
return Raphael.hsl2rgb(annotations[annotation].colors.h, annotations[annotation].colors.s, lum); |
|
154 |
} |
|
155 |
||
156 |
function tweetPopup(url) { |
|
157 |
var popW = 550, |
|
158 |
popH = 350, |
|
159 |
scrW = screen.width, |
|
160 |
scrH = screen.height, |
|
161 |
posX = Math.round((scrW/2)-(popW/2)), |
|
162 |
posY = (scrH > popH ? Math.round((scrH/2)-(popH/2)) : 0); |
|
163 |
window.open(url, |
|
164 |
'', |
|
165 |
'left=' + posX + ',top=' + posY + ',width=' + popW + ',height=' + popH + ',personalbar=0,toolbar=0,scrollbars=1,resizable=1'); |
|
166 |
} |
|
167 |
||
168 |
function arc(source, target) { |
|
169 |
var x3 = .3 * target.y - .3 * source.y + .8 * source.x + .2 * target.x; |
|
170 |
var y3 = .8 * source.y + .2 * target.y - .3 * target.x + .3 * source.x; |
|
171 |
var x4 = .3 * target.y - .3 * source.y + .2 * source.x + .8 * target.x; |
|
172 |
var y4 = .2 * source.y + .8 * target.y - .3 * target.x + .3 * source.x; |
|
173 |
return "M" + source.x + " " + source.y + "C" + [x3, y3, x4, y4, target.x, target.y].join(" "); |
|
174 |
} |
|
175 |
||
176 |
function addTweet(tweet) { |
|
177 |
if (!tweet) { |
|
178 |
console.log(tweet); |
|
179 |
return; |
|
180 |
} |
|
181 |
|
|
182 |
if (rejectUser(tweet.from_user)) { |
|
183 |
return; |
|
184 |
} |
|
185 |
|
|
186 |
function backRef(source_id, target_id, type) { |
|
187 |
var target = tweetById(target_id); |
|
188 |
if (target) { |
|
189 |
var brobj = { |
|
190 |
"referenced_by_id" : source_id, |
|
191 |
"type" : type |
|
192 |
} |
|
193 |
if (target.backRefs) { |
|
194 |
target.backRefs.push(brobj); |
|
195 |
} else { |
|
196 |
target.backRefs = [ brobj ] |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
_(['id', 'from_user_id', 'in_reply_to_status_id']).each(function(_i) { |
|
202 |
tweet[_i] = tweet[_i + '_str']; |
|
203 |
delete tweet[_i + '_str']; |
|
204 |
}); |
|
205 |
|
|
206 |
if (_(twCx.idIndex).indexOf(tweet.id) != -1) { |
|
207 |
return; |
|
208 |
} |
|
209 |
|
|
210 |
tweet.html_parts = [] |
|
211 |
|
|
212 |
if (tweet.entities && tweet.entities.user_mentions) { |
|
213 |
for (var _i = 0; _i < tweet.entities.user_mentions.length; _i++) { |
|
214 |
var _m = tweet.entities.user_mentions[_i]; |
|
215 |
tweet.html_parts.push({ |
|
216 |
"text" : "@" + _m.screen_name, |
|
217 |
"start" : _m.indices[0], |
|
218 |
"end" : _m.indices[1], |
|
219 |
"link" :'<a href="http://twitter.com/' + _m.screen_name + '" onclick="filtrerTexte(\'' + _m.screen_name + '\'); return false;" target="_blank">' |
|
220 |
}); |
|
221 |
} |
|
222 |
} |
|
223 |
|
|
224 |
if (tweet.entities && tweet.entities.hashtags) { |
|
225 |
for (var _i = 0; _i < tweet.entities.hashtags.length; _i++) { |
|
226 |
var _m = tweet.entities.hashtags[_i], |
|
227 |
_h = "#" + _m.text; |
|
228 |
tweet.html_parts.push({ |
|
229 |
"text" : _h, |
|
230 |
"start" : _m.indices[0], |
|
231 |
"end" : _m.indices[1], |
|
232 |
"link" :'<a href="http://twitter.com/search?q=' + encodeURIComponent(_h) + '" onclick="filtrerTexte(\'' + _.escape(_h) + '\'); return false;" target="_blank">' |
|
233 |
}); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
if (tweet.entities && tweet.entities.urls) { |
|
238 |
for (var _i = 0; _i < tweet.entities.urls.length; _i++) { |
|
239 |
var _m = tweet.entities.urls[_i]; |
|
240 |
tweet.html_parts.push({ |
|
241 |
"text" : _m.display_url || _m.url, |
|
242 |
"start" : _m.indices[0], |
|
243 |
"end" : _m.indices[1], |
|
244 |
"link" :'<a href="' + _m.url + '" target="_blank">' |
|
245 |
}); |
|
246 |
} |
|
247 |
} |
|
248 |
tweet.date_value = Date.parse(tweet.created_at.replace(/(\+|-)/,'UTC$1')); |
|
249 |
|
|
250 |
var ann = []; |
|
251 |
for (var j in annotations) { |
|
252 |
if (j != "default") { |
|
253 |
for (var k in annotations[j].keywords) { |
|
254 |
if (tweet.text.search(annotations[j].keywords[k]) != -1) { |
|
255 |
ann.push(j); |
|
256 |
break; |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
tweet.annotations = ann; |
|
262 |
||
263 |
if (tweet.in_reply_to_status_id) { |
|
264 |
backRef( tweet.id, tweet.in_reply_to_status_id, "reply" ); |
|
265 |
} |
|
266 |
|
|
267 |
if (tweet.retweeted_status && tweet.retweeted_status.id_str) { |
|
268 |
tweet.retweeted_status_id = tweet.retweeted_status.id_str; |
|
269 |
backRef( tweet.id, tweet.retweeted_status_id, "retweet" ); |
|
270 |
} |
|
271 |
|
|
272 |
|
|
273 |
var tab = tweet.text.replace(twCx.urlRegExp,'').match(twCx.wordRegExp); |
|
274 |
_(tab).each(function(w) { |
|
275 |
var word = w.toLowerCase(); |
|
276 |
if (_(twCx.stopWords).indexOf(word) == -1 && _(tracking_keywords).indexOf(word) == -1 && word[0] != '@') { |
|
277 |
if (twCx.globalWords[word]) { |
|
278 |
twCx.globalWords[word].freq++; |
|
279 |
} else { |
|
280 |
twCx.globalWords[word] = { |
|
281 |
"freq" : 1, |
|
282 |
"annotations" : {} |
|
283 |
} |
|
284 |
for (var j in annotations) { |
|
285 |
if (j != 'default') { |
|
286 |
twCx.globalWords[word].annotations[j] = 0; |
|
287 |
} |
|
288 |
} |
|
289 |
} |
|
290 |
for (var j in ann) { |
|
291 |
if (typeof twCx.globalWords[word].annotations != "undefined") { |
|
292 |
twCx.globalWords[word].annotations[ann[j]]++; |
|
293 |
} |
|
294 |
} |
|
295 |
} |
|
296 |
}); |
|
297 |
|
|
298 |
_(twCx.suggestCount).each(function(_k) { |
|
299 |
if (tweet.text.search(_k.rgxp) != -1) { |
|
300 |
_k.freq++; |
|
301 |
_(ann).each(function(_a) { |
|
302 |
_k.annotations[_a] = 1 + ( _k.annotations[_a] || 0 ) |
|
303 |
}) |
|
304 |
} |
|
305 |
}); |
|
306 |
|
|
307 |
|
|
308 |
var p = twCx.idIndex.length; |
|
309 |
while (p && tweet.id < twCx.idIndex[p-1]) { |
|
310 |
p--; |
|
311 |
} |
|
312 |
twCx.tweets.splice(p, 0, tweet); |
|
313 |
twCx.idIndex.splice(p, 0, tweet.id); |
|
314 |
|
|
315 |
if (!twCx.timeline.length) { |
|
316 |
twCx.timeline = [ populateDateStruct(0, twCx.date_levels[0] * parseInt(tweet.date_value / twCx.date_levels[0])) ] |
|
317 |
} |
|
318 |
while (tweet.date_value > twCx.timeline[twCx.timeline.length - 1].end) { |
|
319 |
twCx.timeline.push( populateDateStruct(0, twCx.timeline[twCx.timeline.length - 1].end) ); |
|
320 |
} |
|
321 |
|
|
322 |
insertIntoDateStruct(twCx.timeline, tweet); |
|
323 |
} |
|
324 |
||
325 |
function getSliceContent(slice) { |
|
326 |
if (slice.slices) { |
|
327 |
var result = []; |
|
328 |
for (var i in slice.slices) { |
|
329 |
result = result.concat(getSliceContent(slice.slices[i])); |
|
330 |
} |
|
331 |
} else { |
|
332 |
var result = slice.tweets; |
|
333 |
} |
|
334 |
return result; |
|
335 |
} |
|
336 |
||
337 |
function flattenDateStruct(slices, target_level) { |
|
338 |
var current_level = slices[0].level, |
|
339 |
result = []; |
|
340 |
if (current_level < target_level) { |
|
341 |
if (slices[0].slices) { |
|
342 |
for (var i in slices) { |
|
343 |
result = result.concat(flattenDateStruct(slices[i].slices, target_level)); |
|
344 |
} |
|
345 |
} |
|
346 |
} |
|
347 |
else { |
|
348 |
for (var i in slices) { |
|
349 |
result.push({ |
|
350 |
"start" : slices[i].start, |
|
351 |
"end" : slices[i].end, |
|
352 |
"tweets" : getSliceContent(slices[i]) |
|
353 |
}); |
|
354 |
} |
|
355 |
} |
|
356 |
return result; |
|
357 |
} |
|
358 |
||
359 |
function trimFDS() { |
|
360 |
var slices = flattenDateStruct(twCx.timeline, twCx.timeLevel); |
|
| 849 | 361 |
if (!slices || !slices.length) { |
362 |
return []; |
|
363 |
} |
|
| 836 | 364 |
while (slices[0].tweets.length == 0) { |
365 |
slices.splice(0,1); |
|
366 |
} |
|
367 |
while (slices[slices.length - 1].tweets.length == 0) { |
|
368 |
slices.pop(); |
|
369 |
} |
|
370 |
var centralTweet = ( twCx.centralTweet ? twCx.centralTweet : twCx.tweets[twCx.tweets.length - 1] ), |
|
371 |
delta = 30 * twCx.date_levels[twCx.timeLevel], |
|
372 |
centre = Math.min(slices[slices.length - 1].end - delta , Math.max(slices[0].start + delta, centralTweet.date_value)), |
|
373 |
min = centre - delta, |
|
374 |
max = centre + delta; |
|
375 |
while (slices[0].start < min) { |
|
376 |
slices.splice(0,1); |
|
377 |
} |
|
378 |
while (slices[slices.length - 1].end > max) { |
|
379 |
slices.pop(); |
|
380 |
} |
|
381 |
return slices; |
|
382 |
} |
|
383 |
||
384 |
function populateDateStruct(level, start) { |
|
385 |
var end = start + twCx.date_levels[level], |
|
386 |
struct = { |
|
387 |
"level" : level, |
|
388 |
"start" : start, |
|
389 |
"end" : end |
|
390 |
}; |
|
391 |
if (level < twCx.date_levels.length - 1) { |
|
392 |
struct.slices = []; |
|
393 |
var newstart = start; |
|
394 |
while (newstart < end) { |
|
395 |
struct.slices.push(populateDateStruct(level + 1, newstart)); |
|
396 |
newstart += twCx.date_levels[level + 1]; |
|
397 |
} |
|
398 |
} else { |
|
399 |
struct.tweets = []; |
|
400 |
} |
|
401 |
return struct; |
|
402 |
} |
|
403 |
||
404 |
function insertIntoDateStruct(slices, tweet) { |
|
405 |
var creadate = tweet.date_value; |
|
406 |
for (var i in slices) { |
|
407 |
if (creadate < slices[i].end) { |
|
408 |
if (slices[i].slices) { |
|
409 |
insertIntoDateStruct(slices[i].slices, tweet); |
|
410 |
} else { |
|
411 |
slices[i].tweets.push(tweet.id); |
|
412 |
} |
|
413 |
break; |
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
function placeHolder(className) { |
|
419 |
return '<li class="placeholder ' + className + '"></li>'; |
|
420 |
} |
|
421 |
||
422 |
function tweetById(tweetid) { |
|
423 |
var pos = _(twCx.idIndex).indexOf(tweetid); |
|
424 |
return (pos == -1) ? false : twCx.tweets[pos]; |
|
425 |
} |
|
426 |
||
427 |
function selectTweet(tweetid) { |
|
428 |
twCx.position = tweetid; |
|
429 |
twCx.followLast = (twCx.position == twCx.idIndex[twCx.tweets.length - 1]); |
|
430 |
updateDisplay(); |
|
431 |
} |
|
432 |
||
433 |
function goToPos(nPos) { |
|
434 |
twCx.position = twCx.currentIdIndex[Math.min( twCx.currentIdIndex.length - 1, Math.max(0, nPos ) )]; |
|
435 |
twCx.followLast = (!twCx.filtre && nPos == twCx.tweets.length - 1); |
|
436 |
updateDisplay(); |
|
437 |
} |
|
438 |
||
439 |
function movePos(delta) { |
|
440 |
goToPos( delta + _(twCx.currentIdIndex).indexOf(twCx.position) ); |
|
441 |
} |
|
442 |
||
443 |
function tweetToHtml(tweet, className, elName) { |
|
444 |
|
|
445 |
function highlight(texte) { |
|
446 |
return ( twCx.filtre ? texte.replace(twCx.filtre, '<span class="highlight">$1</span>' ) : texte ); |
|
447 |
} |
|
448 |
|
|
449 |
if (!tweet) { |
|
450 |
return placeHolder(className); |
|
451 |
} |
|
452 |
var el = (elName ? elName : 'li'); |
|
453 |
var html = '<' |
|
454 |
+ el |
|
455 |
+ ' draggable="true" class="tweet ' |
|
456 |
+ className |
|
457 |
+ '" id="tweet_' |
|
458 |
+ tweet.id |
|
459 |
+ '" data-title="Tweet by ' |
|
460 |
+ _(tweet.user.name).escape() |
|
461 |
+ '" data-description="' |
|
462 |
+ _(tweet.text).escape() |
|
463 |
+ '" data-uri="http://twitter.com/' |
|
464 |
+ tweet.user.screen_name |
|
465 |
+ '/status/' |
|
466 |
+ tweet.id |
|
467 |
+ '"'; |
|
468 |
if (className != 'full') { |
|
469 |
html += ' onclick="selectTweet(\'' + tweet.id + '\'); return false;"'; |
|
470 |
} |
|
471 |
html += ' onmouseover="rolloverTweet(\'' + tweet.id + "', " + ( className == 'icons' ) + ');"'; |
|
472 |
if (twCx.followLast && className == 'full' && el == 'li') { |
|
473 |
html += ' style="display: none"'; |
|
474 |
} |
|
475 |
html += '>'; |
|
476 |
if (tweet.annotations.length) { |
|
477 |
html += '<div class="annotations">'; |
|
478 |
for (var i in tweet.annotations) { |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
479 |
html += '<div class="annotation" style="width:' + (100/tweet.annotations.length) + '%; background:' + getColor(tweet.annotations[i], (className == 'icons' ? .4 : .25)).hex + '"></div>'; |
| 836 | 480 |
} |
481 |
html += '</div>'; |
|
482 |
} |
|
483 |
html += '<div class="twmain">'; |
|
484 |
var a_user = '<a href="http://twitter.com/' + tweet.user.screen_name + '" onclick="filtrerTexte(\'@' + tweet.user.screen_name + '\'); return false;" target="_blank">'; |
|
485 |
html += '<div class="around_img"><img class="profile_image" src="' + tweet.user.profile_image_url + '" />'; |
|
486 |
if (className == 'full') { |
|
487 |
html += '<p class="created_at">' + new Date(tweet.date_value).toTimeString().substr(0,8) + '</a></p>'; |
|
488 |
} |
|
489 |
html += '</div>'; |
|
490 |
if (className != 'icons') { |
|
491 |
lastend = 0; |
|
492 |
var txt = ''; |
|
493 |
tweet.html_parts.sort(function(a, b) { return a.start - b.start }); |
|
494 |
_(tweet.html_parts).each(function(_e) { |
|
495 |
txt += highlight( tweet.text.substring(lastend, _e.start) ) + _e.link + highlight( _e.text ) + '</a>'; |
|
496 |
lastend = _e.end; |
|
497 |
}); |
|
498 |
txt += highlight( tweet.text.substring(lastend) ); |
|
499 |
html += '<p class="tweet_text"><b>' + a_user + highlight('@' + tweet.user.screen_name) + '</a>' + ( className == 'full' ? ' (' + tweet.user.name + ')</b><br />' : '</b> : ') + txt + '</p>'; |
|
500 |
if (className == 'full' && el == 'li') { |
|
501 |
html += '<div class="tweet_actions"><a href="http://twitter.com/' + tweet.user.screen_name + '/status/' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">afficher tweet</a> - '; |
|
502 |
html += '<a href="http://twitter.com/intent/tweet?in_reply_to=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">répondre</a> · '; |
|
503 |
html += '<a href="http://twitter.com/intent/retweet?tweet_id=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">retweeter</a> · '; |
|
504 |
html += '<a href="http://twitter.com/intent/favorite?tweet_id=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">favori</a></div>'; |
|
505 |
} |
|
506 |
} |
|
507 |
html += '</div></' + el + '>'; |
|
508 |
return html; |
|
509 |
} |
|
510 |
||
511 |
function tlIdFromPos(x, y, outside) { |
|
| 849 | 512 |
if (!twCx.tlOnDisplay || !twCx.tlOnDisplay.length) { |
| 836 | 513 |
return; |
514 |
} |
|
515 |
var ligne = Math.min( twCx.tlOnDisplay.length - 1, Math.max( 0, Math.floor(( twCx.tlHeight - y ) / twCx.scaleY) ) ), |
|
516 |
colonne = Math.floor(( x - twCx.deltaX ) / twCx.scaleX ), |
|
517 |
l = 0; |
|
518 |
if (colonne >= twCx.tlOnDisplay[ligne].totalTweets || colonne < 0 ) { |
|
519 |
if (outside) { |
|
520 |
colonne = Math.min( twCx.tlOnDisplay[ligne].totalTweets - 1, Math.max( 0, colonne )); |
|
521 |
} else { |
|
522 |
return null; |
|
523 |
} |
|
524 |
} |
|
525 |
for (var i in twCx.tlOnDisplay[ligne].displayData) { |
|
526 |
var nl = l + twCx.tlOnDisplay[ligne].displayData[i].length; |
|
527 |
if (colonne < nl) { |
|
528 |
return { |
|
529 |
"id" : twCx.tlOnDisplay[ligne].displayData[i][colonne - l], |
|
530 |
"annotation" : i |
|
531 |
} |
|
532 |
} |
|
533 |
l = nl; |
|
534 |
} |
|
535 |
} |
|
536 |
||
537 |
function tlPosTweet(tweet, annotation) { |
|
538 |
if (!twCx.tweets) { |
|
539 |
return; |
|
540 |
} |
|
541 |
var x, |
|
542 |
y, |
|
543 |
dt = tweet.date_value, |
|
544 |
ann = ( annotation ? annotation : ( tweet.annotations.length ? tweet.annotations[0] : 'default' ) ); |
|
545 |
for (var i = 0; i < twCx.tlOnDisplay.length; i++) { |
|
546 |
if (twCx.tlOnDisplay[i].end > dt) { |
|
547 |
y = twCx.tlHeight - (i + .5) * twCx.scaleY; |
|
548 |
var l = 0; |
|
549 |
for (var j in twCx.tlOnDisplay[i].displayData) { |
|
550 |
if (j == ann) { |
|
551 |
var p = _(twCx.tlOnDisplay[i].displayData[j]).indexOf(tweet.id); |
|
552 |
if (p != -1) { |
|
553 |
x = twCx.deltaX + twCx.scaleX * ( p + l + .5 ); |
|
554 |
} |
|
555 |
break; |
|
556 |
} |
|
557 |
l += twCx.tlOnDisplay[i].displayData[j].length; |
|
558 |
} |
|
559 |
break; |
|
560 |
} |
|
561 |
} |
|
562 |
return ( x && y ? { "x" : x, "y" : y } : null); |
|
563 |
} |
|
564 |
||
565 |
function rolloverTweet(tweetid, showPopup, annotation) { |
|
566 |
var t = tweetById(tweetid); |
|
567 |
if (!t) { |
|
568 |
return; |
|
569 |
} |
|
570 |
var p = tlPosTweet(t, annotation); |
|
571 |
if (!p) { |
|
572 |
return; |
|
573 |
} |
|
574 |
var ptl = $("#timeline").offset(); |
|
575 |
if (showPopup) { |
|
576 |
$("#hovercontent").html(tweetToHtml(t, 'full', 'div')); |
|
577 |
$("#hovertweet").css({ |
|
578 |
"left" : parseInt(ptl.left + p.x) + "px", |
|
579 |
"top" : parseInt(ptl.top + p.y), |
|
580 |
"display" : "block"}); |
|
581 |
} else { |
|
582 |
$("#hovertweet").hide(); |
|
583 |
} |
|
584 |
for (var i in twCx.relHover) { |
|
585 |
twCx.relHover[i].remove(); |
|
586 |
} |
|
587 |
twCx.relHover = drawTweetArcs(t, p, '#303030'); |
|
588 |
twCx.relHover.push(drawTweetPos(p, '#ffffff')); |
|
589 |
} |
|
590 |
||
591 |
function drawTweetPos(pos, color) { |
|
592 |
var rel = twCx.tlPaper.rect(pos.x - .5 * twCx.scaleX, pos.y - .5 * twCx.scaleY, twCx.scaleX, twCx.scaleY); |
|
593 |
rel.attr({ "stroke" : color, "fill" : color, "fill-opacity" : .25 }); |
|
594 |
return rel; |
|
595 |
} |
|
596 |
||
597 |
function drawTweetArcs(tweet, pos, color) { |
|
598 |
|
|
599 |
var res = []; |
|
600 |
||
601 |
function tweetAndArc(a, b, aorb) { |
|
602 |
if (a && b) { |
|
603 |
res.push(drawTweetPos(aorb ? a : b, color)); |
|
604 |
var aa = twCx.tlPaper.path(arc(a,b)) |
|
605 |
.attr({ "stroke" : color, "stroke-width" : 1.5, "stroke-opacity" : .8 }); |
|
606 |
res.push(aa); |
|
607 |
} |
|
608 |
} |
|
609 |
|
|
610 |
if (tweet.retweeted_status_id) { |
|
611 |
var t = tweetById(tweet.retweeted_status_id); |
|
612 |
if (t) { |
|
613 |
tweetAndArc(pos, tlPosTweet(t)); |
|
614 |
} |
|
615 |
} |
|
616 |
|
|
617 |
if (tweet.in_reply_to_status_id) { |
|
618 |
var t = tweetById(tweet.in_reply_to_status_id); |
|
619 |
if (t) { |
|
620 |
tweetAndArc(pos, tlPosTweet(t)); |
|
621 |
} |
|
622 |
} |
|
623 |
|
|
624 |
if (tweet.backRefs) { |
|
625 |
for (var i in tweet.backRefs) { |
|
626 |
var t = tweetById(tweet.backRefs[i].referenced_by_id); |
|
627 |
if (t) { |
|
628 |
tweetAndArc(tlPosTweet(t), pos, true); |
|
629 |
} |
|
630 |
} |
|
631 |
} |
|
632 |
|
|
633 |
return res; |
|
634 |
} |
|
635 |
||
636 |
function mouseoverkw() { |
|
637 |
var _jel = $(this), |
|
638 |
_off = _jel.offset(); |
|
639 |
_jel.css({ |
|
640 |
color: "#0099ff" |
|
641 |
}); |
|
642 |
$("#hoverkw") |
|
643 |
.css({ |
|
644 |
"left" : _off.left + "px", |
|
645 |
"top" : ( parseInt(_off.top) + ~~ (_jel.height() / 2) ) + "px", |
|
646 |
"display" : "block" |
|
647 |
}) |
|
648 |
.attr("kw", _jel.text()); |
|
649 |
} |
|
650 |
||
651 |
function mouseoutkw() { |
|
652 |
$("#hoverkw").hide(); |
|
653 |
$(this).css({ |
|
654 |
color: "#000000" |
|
655 |
}); |
|
656 |
} |
|
657 |
||
658 |
function makeTagCloud(tab, div) { |
|
659 |
var minfreq = _(tab).min( function(a) { return a.freq} ).freq, |
|
660 |
maxfreq = Math.max(minfreq + .1, _(tab).max( function(a) { return a.freq} ).freq), |
|
661 |
echfreq = 8 / Math.sqrt( maxfreq - minfreq ), |
|
662 |
html = ''; |
|
663 |
_(tab).each(function(_j) { |
|
664 |
var maxann = 0, |
|
665 |
ann = "default"; |
|
666 |
for (var k in _j.annotations) { |
|
667 |
if (_j.annotations[k] == maxann) { |
|
668 |
ann = "default"; |
|
669 |
} |
|
670 |
if (_j.annotations[k] > maxann) { |
|
671 |
ann = k; |
|
672 |
maxann = _j.annotations[k]; |
|
673 |
} |
|
674 |
} |
|
675 |
if (ann == "default") { |
|
676 |
var coul = ''; |
|
677 |
} else { |
|
678 |
var c = getColor(ann, .6), |
|
679 |
coul = "background: rgba(" + [ Math.floor(c.r), Math.floor(c.g), Math.floor(c.b), ( _j.annotations[ann] / _j.freq )].join(',') + ")"; |
|
680 |
} |
|
681 |
var fontsize = Math.floor( ( 12 + Math.sqrt( _j.freq - minfreq ) * echfreq ) ); |
|
682 |
html += '<span style="line-height: ' + (8 + fontsize) + 'px; font-size: ' + fontsize + 'px;' + coul + '">' + _j.word + '</span> '; |
|
683 |
}); |
|
684 |
$(div).html(html); |
|
685 |
$(div + " span") |
|
686 |
.mouseover(mouseoverkw) |
|
687 |
.mouseout(mouseoutkw) |
|
688 |
.click(function() { |
|
689 |
$("#hoverkw").toggle(); |
|
690 |
}); |
|
691 |
} |
|
692 |
||
693 |
function updateDisplay() { |
|
694 |
if (!twCx.tweets) { |
|
695 |
return; |
|
696 |
} |
|
697 |
if (twCx.filtre) { |
|
698 |
var tweets = _(twCx.tweets).filter(function(tweet) { |
|
699 |
var mention = '@' + tweet.user.screen_name; |
|
700 |
return ( tweet.text.search(twCx.filtre) != -1 ) || ( mention.search(twCx.filtre) != -1 ); |
|
701 |
}); |
|
702 |
$("#inp_q").val(twCx.filtreTexte + ' (' + tweets.length + ' tweets)'); |
|
703 |
if (tweets.length) { |
|
704 |
var idIndex = _(tweets).map(function(tweet) { |
|
705 |
return tweet.id; |
|
706 |
}); |
|
707 |
var p = _(idIndex).indexOf(twCx.position); |
|
708 |
if (p == -1) { |
|
709 |
for (p = idIndex.length - 1; p > 0 && idIndex[p] > twCx.position; p--) { |
|
710 |
} |
|
711 |
} |
|
712 |
twCx.position = idIndex[p]; |
|
713 |
twCx.currentIdIndex = idIndex; |
|
714 |
} |
|
715 |
|
|
716 |
} else { |
|
717 |
twCx.currentIdIndex = twCx.idIndex; |
|
718 |
var tweets = twCx.tweets; |
|
719 |
var p = _(twCx.idIndex).indexOf(twCx.position); |
|
720 |
if (p == -1) { |
|
721 |
p = (twCx.followLast ? twCx.idIndex.length - 1 : 0); |
|
722 |
} |
|
723 |
} |
|
724 |
|
|
725 |
|
|
726 |
var l = tweets.length, |
|
727 |
lines = 0, |
|
728 |
ppy = 0, |
|
729 |
html = '', |
|
730 |
tweetsOnDisplay = []; |
|
731 |
|
|
732 |
function pushTweet(tp, className) { |
|
733 |
|
|
734 |
if (tp < l && tp >= 0) { |
|
735 |
|
|
736 |
html += tweetToHtml(tweets[tp], className); |
|
737 |
|
|
738 |
tweetsOnDisplay.push(tp); |
|
739 |
|
|
740 |
} else { |
|
741 |
html += placeHolder(className); |
|
742 |
} |
|
743 |
} |
|
744 |
|
|
745 |
if (l) { |
|
746 |
|
|
747 |
twCx.lastScrollPos = Math.floor( twCx.scrollExtent * ( 1 - ( p / l ) ) ); |
|
748 |
$("#scrollcont").scrollTop(twCx.lastScrollPos); |
|
749 |
|
|
750 |
if (l > p + 18) { |
|
751 |
lines++; |
|
752 |
ppy += 20; |
|
753 |
for (var i = p + 31; i >= p + 18; i--) { |
|
754 |
pushTweet(i, 'icons'); |
|
755 |
} |
|
756 |
} |
|
757 |
if (l > p + 4) { |
|
758 |
lines++; |
|
759 |
ppy += 20; |
|
760 |
for (var i = p + 17; i >= p + 4; i--) { |
|
761 |
pushTweet(i, 'icons'); |
|
762 |
} |
|
763 |
} |
|
764 |
for (var k = 3; k >= 1; k--) { |
|
765 |
if (l > p + k) { |
|
766 |
ppy += 47; |
|
767 |
lines++; |
|
768 |
pushTweet(p + k, 'half'); |
|
769 |
} |
|
770 |
} |
|
771 |
pushTweet(p, 'full'); |
|
772 |
var n = p - 1; |
|
773 |
for (var i = 0; i < Math.min(6, Math.max(3, 6 - lines)); i++) { |
|
774 |
if (n < 0) { |
|
775 |
break; |
|
776 |
} |
|
777 |
pushTweet(n, 'half'); |
|
778 |
n--; |
|
779 |
} |
|
780 |
for (var i = 0; i < 14 * Math.min(4, Math.max(2, 7 - lines)); i++) { |
|
781 |
if (n < 0) { |
|
782 |
break; |
|
783 |
} |
|
784 |
pushTweet(n, 'icons'); |
|
785 |
n--; |
|
786 |
} |
|
787 |
if (html != twCx.tlBuffer) { |
|
788 |
$("#tweetlist").html(html); |
|
789 |
$(".tweet.full").fadeIn(); |
|
790 |
twCx.tlBuffer = html; |
|
791 |
} |
|
792 |
|
|
793 |
if (twCx.suggestCount.length) { |
|
794 |
makeTagCloud(twCx.suggestCount, "#suggkw"); |
|
795 |
} |
|
796 |
|
|
797 |
var tab = _(twCx.globalWords).chain() |
|
798 |
.map(function(v, k) { |
|
799 |
return { |
|
800 |
"word": k, |
|
801 |
"freq" : v.freq, |
|
802 |
"annotations" : v.annotations |
|
803 |
}; |
|
804 |
}).filter(function(v) { |
|
805 |
return v.freq > 3; |
|
806 |
}).value(); |
|
807 |
|
|
808 |
if (tab.length) { |
|
809 |
|
|
810 |
tab = _(tab).sortBy( function(a) { return ( - a.freq ) }).slice(0,40); |
|
811 |
makeTagCloud(tab,"#motscles"); |
|
812 |
} else { |
|
813 |
$("#motscles").html(''); |
|
814 |
} |
|
815 |
twCx.centralTweet = tweets[p]; |
|
816 |
} else { |
|
817 |
$("#tweetlist").html(''); |
|
818 |
twCx.tlBuffer = ''; |
|
819 |
$("#motscles").html(''); |
|
820 |
} |
|
821 |
|
|
822 |
twCx.tlOnDisplay = trimFDS(); |
|
| 849 | 823 |
if (!twCx.tlOnDisplay || !twCx.tlOnDisplay.length) { |
824 |
return; |
|
825 |
} |
|
| 836 | 826 |
twCx.scaleY = twCx.tlHeight / twCx.tlOnDisplay.length; |
827 |
var maxTweets = 0, |
|
828 |
startTl = 0, |
|
829 |
endTl = twCx.tlOnDisplay.length - 1; |
|
830 |
if (l) { |
|
831 |
var startTw = tweets[tweetsOnDisplay[tweetsOnDisplay.length - 1]].date_value, |
|
832 |
endTw = tweets[tweetsOnDisplay[0]].date_value; |
|
833 |
} |
|
834 |
for (var i = 0; i < twCx.tlOnDisplay.length; i++) { |
|
835 |
if (l) { |
|
836 |
if (startTw >= twCx.tlOnDisplay[i].start && startTw < twCx.tlOnDisplay[i].end) { |
|
837 |
startTl = i; |
|
838 |
} |
|
839 |
if (endTw >= twCx.tlOnDisplay[i].start && endTw < twCx.tlOnDisplay[i].end) { |
|
840 |
endTl = i; |
|
841 |
} |
|
842 |
} |
|
843 |
var displayData = {}; |
|
844 |
for (var j in annotations) { |
|
845 |
displayData[j] = []; |
|
846 |
} |
|
847 |
for (var j in twCx.tlOnDisplay[i].tweets) { |
|
848 |
var tweetid = twCx.tlOnDisplay[i].tweets[j], |
|
849 |
tweet = tweetById(tweetid); |
|
850 |
if (tweet) { |
|
851 |
if (tweet.annotations.length) { |
|
852 |
for (var k in tweet.annotations) { |
|
853 |
displayData[tweet.annotations[k]].push(tweetid); |
|
854 |
} |
|
855 |
} else { |
|
856 |
displayData['default'].push(tweetid); |
|
857 |
} |
|
858 |
} |
|
859 |
} |
|
860 |
var nbT = 0; |
|
861 |
for (var j in displayData) { |
|
862 |
nbT += displayData[j].length; |
|
863 |
} |
|
864 |
maxTweets = Math.max(maxTweets, nbT); |
|
865 |
twCx.tlOnDisplay[i].displayData = displayData; |
|
866 |
twCx.tlOnDisplay[i].totalTweets = nbT; |
|
867 |
} |
|
868 |
twCx.scaleX = ( twCx.tlWidth - twCx.deltaX ) / maxTweets; |
|
869 |
twCx.tlPaper.clear(); |
|
870 |
twCx.relHover = null; |
|
871 |
|
|
872 |
// Dessin de la correspondance liste-timeline |
|
873 |
if (l) { |
|
874 |
var startY = twCx.tlHeight - startTl * twCx.scaleY, |
|
875 |
endY = twCx.tlHeight - ( endTl + 1 ) * twCx.scaleY, |
|
876 |
path = "M0 " + twCx.tlHeight + "C" + .7*twCx.deltaX + " " + twCx.tlHeight + " " + .3*twCx.deltaX + " " + startY + " " + twCx.deltaX + " " + startY + "L" + twCx.tlWidth + " " + startY + "L" + twCx.tlWidth + " " + endY + "L" + twCx.deltaX + " " + endY + "C" + .3*twCx.deltaX + " " + endY + " " + .7*twCx.deltaX + " 0 0 0"; |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
877 |
twCx.tlPaper.path( path ).attr({ "stroke" : "none", "fill" : "#8080c0", "opacity" : .2 }); |
| 836 | 878 |
} |
879 |
// dessin de la date de début |
|
880 |
|
|
881 |
twCx.tlPaper.text(twCx.deltaX / 2, twCx.tlHeight - 7, new Date(twCx.tlOnDisplay[0].start).toTimeString().substr(0,5)) |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
882 |
.attr({ "text-anchor" : "middle", "font-size": "9px", "fill": "#cccccc" }); |
| 836 | 883 |
|
884 |
// dessin de la date de fin |
|
885 |
|
|
886 |
twCx.tlPaper.text(twCx.deltaX / 2, 7, new Date(twCx.tlOnDisplay[twCx.tlOnDisplay.length - 1].end).toTimeString().substr(0,5)) |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
887 |
.attr({ "text-anchor" : "middle", "font-size": "9px", "fill": "#cccccc" }); |
| 836 | 888 |
|
889 |
for (var i = 0; i < twCx.tlOnDisplay.length; i++) { |
|
890 |
var n = 0, |
|
891 |
posY = twCx.tlHeight - ( i + 1 ) * twCx.scaleY; |
|
892 |
for (var j in twCx.tlOnDisplay[i].displayData) { |
|
893 |
var ll = twCx.tlOnDisplay[i].displayData[j].length; |
|
894 |
if (ll > 0) { |
|
895 |
twCx.tlPaper.rect( twCx.deltaX + n * twCx.scaleX, posY, ll * twCx.scaleX, twCx.scaleY ) |
|
896 |
.attr({"stroke" : "none", "fill" : getColor(j, .4).hex }); |
|
897 |
n += ll; |
|
898 |
} |
|
899 |
} |
|
900 |
|
|
901 |
// Si on est à une demi-heure, on trace un axe secondaire + heure |
|
902 |
|
|
903 |
if (i < twCx.tlOnDisplay.length - 1 && !(twCx.tlOnDisplay[i].end % 1800000)) { |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
904 |
twCx.tlPaper.path("M0 "+posY+"L" + twCx.tlWidth +" "+posY).attr({"stroke":"#555"}); |
|
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
905 |
twCx.tlPaper.text(twCx.deltaX / 2, posY, new Date(twCx.tlOnDisplay[i].end).toTimeString().substr(0,5)).attr({ "text-anchor" : "middle", "font-size": "9px", "fill": "#cccccc" }); |
| 836 | 906 |
} |
907 |
} |
|
908 |
|
|
909 |
// dessin du tweet courant |
|
910 |
|
|
911 |
if (l) { |
|
912 |
|
|
913 |
if (twCx.filtre) { |
|
914 |
for (var i = 0; i < tweets.length; i++) { |
|
915 |
if (i != p) { |
|
916 |
var pos = tlPosTweet(tweets[i]); |
|
917 |
if (pos) { |
|
918 |
drawTweetPos(pos, "#ffccff"); |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
|
|
923 |
} |
|
924 |
|
|
925 |
var posp = tlPosTweet(tweets[p]); |
|
926 |
if (posp) { |
|
927 |
|
|
928 |
drawTweetPos(posp, "#ffff00"); |
|
929 |
var yy = posp.y - .5 * twCx.scaleY, |
|
930 |
ppy = $(".tweet.full").offset().top - $("#tweetlist").offset().top |
|
931 |
path = "M0 " + ppy + "C" + ( .7 * twCx.deltaX ) + " " + ppy + " " + ( .2 * twCx.deltaX ) + " " + yy + " " + ( twCx.deltaX ) + " " + yy + "L" + ( posp.x - .5 * twCx.scaleX ) + " " + yy; |
|
932 |
yy = posp.y + .5 * twCx.scaleY; |
|
933 |
ppy += $(".tweet.full").height(); |
|
934 |
path += "L" + ( posp.x - .5 * twCx.scaleX ) + " " + yy + "L" + twCx.deltaX + " " + yy + "C" + ( .2 * twCx.deltaX ) + " " + yy + " " + ( .7 * twCx.deltaX ) + " " + ppy + " 0 " + ppy; |
|
935 |
twCx.tlPaper.path( path ).attr({"stroke":"#ffff00", "fill" : "#ffff00", "fill-opacity" : .15}); |
|
936 |
|
|
937 |
drawTweetArcs(tweets[p], posp, '#800080'); |
|
938 |
} |
|
939 |
} |
|
940 |
} |
|
941 |
||
942 |
function filtrerAnnotation(annotation) { |
|
943 |
if (annotations[annotation]) { |
|
944 |
effectuerFiltrage(annotations[annotation].display_name, |
|
945 |
new RegExp( "(" + _(annotations[annotation].keywords).map(function(a) { return a.source }).join("|") + ")", "gim" ) ); |
|
946 |
} else { |
|
947 |
effectuerFiltrage('', null) |
|
948 |
} |
|
949 |
} |
|
950 |
||
951 |
function filtrerTexte(valeur) { |
|
952 |
effectuerFiltrage( valeur, valeur ? new RegExp("(" + valeur.replace(/(\W)/g, '\\$1') + ")" ,'gim') : null ); |
|
953 |
} |
|
954 |
||
955 |
function effectuerFiltrage(filtreTexte, tabRegexp) { |
|
956 |
$("#recherche_annot").slideUp(); |
|
957 |
$("#inp_q").val(filtreTexte).attr("class","rechercheCourante"); |
|
958 |
twCx.filtreTexte = filtreTexte; |
|
959 |
twCx.filtre = tabRegexp; |
|
960 |
twCx.followLast = !tabRegexp && (twCx.position == twCx.idIndex[twCx.idIndex.length - 1]); |
|
961 |
updateDisplay(); |
|
962 |
} |
|
963 |
||
964 |
function clicTl(evt) { |
|
965 |
var o = $("#timeline").offset(); |
|
966 |
if (twCx.tlMouseClicked && twCx.tlMouseMoved) { |
|
967 |
var twid = tlIdFromPos(evt.pageX - o.left + twCx.refPosTl.x - twCx.refMouse.x, evt.pageY - o.top + twCx.refPosTl.y - twCx.refMouse.y, true); |
|
968 |
if (twid) { |
|
969 |
selectTweet(twid.id); |
|
970 |
} |
|
971 |
} else { |
|
972 |
var twid = tlIdFromPos(evt.pageX - o.left, evt.pageY - o.top, twCx.tlMouseClicked); |
|
973 |
if (twCx.tlMouseMoved && !twCx.tlMouseClicked) { |
|
974 |
if (twid) { |
|
975 |
rolloverTweet(twid.id, true, twid.annotation); |
|
976 |
} else { |
|
977 |
$("#hovertweet").hide(); |
|
978 |
} |
|
979 |
} |
|
980 |
if (twCx.tlMouseClicked && !twCx.tlMouseMoved) { |
|
981 |
if (twid) { |
|
982 |
selectTweet(twid.id); |
|
983 |
} |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
||
988 |
function loadTweets(tweets, append) { |
|
989 |
if (!append) { |
|
990 |
twCx.timeline = []; |
|
991 |
twCx.idIndex = []; |
|
992 |
twCx.tweets = []; |
|
993 |
} |
|
994 |
for (var i in tweets) { |
|
995 |
addTweet(tweets[i]); |
|
996 |
} |
|
997 |
if (twCx.followLast) { |
|
998 |
twCx.position = twCx.idIndex[twCx.tweets.length - 1]; |
|
999 |
} |
|
1000 |
updateDisplay(); |
|
1001 |
} |
|
1002 |
||
1003 |
function focusOutRecherche() { |
|
1004 |
$("#recherche_annot").slideUp(); |
|
1005 |
var inpq = $("#inp_q"), |
|
1006 |
val = inpq.val(); |
|
1007 |
if (val == '' || val == twCx.filtreTexte) { |
|
1008 |
if (twCx.filtre) { |
|
1009 |
inpq.attr("class", "rechercheCourante").val(twCx.filtreTexte); |
|
1010 |
} else { |
|
1011 |
inpq.attr("class", "greyed").val(l10n.rechercher); |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
function chaineTimeZoom() { |
|
1017 |
var chaine = "", |
|
1018 |
t = twCx.date_levels[twCx.timeLevel], |
|
1019 |
h = 3600*1000, |
|
1020 |
m = 60*1000, |
|
1021 |
s = 1000, |
|
1022 |
heures = Math.floor(t/h); |
|
1023 |
if (heures) { chaine += heures + ' h. ' }; |
|
1024 |
t -= (heures * h); |
|
1025 |
var minutes = Math.floor(t/m); |
|
1026 |
if (minutes) { chaine += minutes + ' min. ' }; |
|
1027 |
t -= (minutes * m); |
|
1028 |
if (t) { chaine += Math.floor(t/s) + ' sec.' } |
|
1029 |
$("#time_scale").html(chaine); |
|
1030 |
$("#time_zoomout").attr("class",(twCx.timeLevel == 0 ? "inactive" : "")); |
|
1031 |
$("#time_zoomin").attr("class",(twCx.timeLevel == twCx.date_levels.length - 1 ? "inactive" : "")); |
|
1032 |
} |
|
1033 |
||
1034 |
$(document).ready(function() { |
|
1035 |
twCx.tlWidth = $("#timeline").width(); |
|
1036 |
twCx.tlHeight = $("#timeline").height(); |
|
1037 |
twCx.tlPaper = Raphael("timeline", twCx.tlWidth, twCx.tlHeight); |
|
1038 |
|
|
1039 |
connectTweets(); |
|
1040 |
|
|
1041 |
var html = ''; |
|
1042 |
for (var j in annotations) { |
|
1043 |
if (j != "default") { |
|
|
854
4c377df66569
Style adjustments for Hanna Arendt
Raphael Velt <raph.velt@gmail.com>
parents:
849
diff
changeset
|
1044 |
html += '<a href="#" style="background: ' + getColor(j, .6).hex + ';" onclick=filtrerAnnotation(\'' + j + '\'); return false;">' + annotations[j].display_name + '</a> ' |
| 836 | 1045 |
} |
1046 |
} |
|
1047 |
$("#rech_list_annot").html(html); |
|
1048 |
|
|
1049 |
chaineTimeZoom(); |
|
1050 |
|
|
1051 |
$("#tweetlist").mousewheel(function(e, d) { |
|
1052 |
twCx.wheelDelta += d; |
|
1053 |
if (Math.abs(twCx.wheelDelta) >= 1) { |
|
1054 |
movePos( parseInt(twCx.wheelDelta) ); |
|
1055 |
twCx.wheelDelta = 0; |
|
1056 |
} |
|
1057 |
return false; |
|
1058 |
}); |
|
1059 |
$("#tweetlist").delegate(".tweet", "dragstart", function(e) { |
|
1060 |
var div = document.createElement('div'); |
|
1061 |
div.appendChild(this.cloneNode(true)); |
|
1062 |
try { |
|
1063 |
e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
|
1064 |
} |
|
1065 |
catch(err) { |
|
1066 |
e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
|
1067 |
} |
|
1068 |
}); |
|
1069 |
$("#timeline").mousewheel(function(e, d) { |
|
1070 |
twCx.wheelDelta += d; |
|
1071 |
if (Math.abs(twCx.wheelDelta) >= 1) { |
|
1072 |
if (twCx.wheelDelta > 0) { |
|
1073 |
tl = Math.min(twCx.date_levels.length - 1, twCx.timeLevel + 1); |
|
1074 |
} else { |
|
1075 |
tl = Math.max(0, twCx.timeLevel - 1); |
|
1076 |
} |
|
1077 |
if (tl != twCx.timeLevel) { |
|
1078 |
twCx.timeLevel = tl; |
|
1079 |
chaineTimeZoom(); |
|
1080 |
updateDisplay(); |
|
1081 |
} |
|
1082 |
twCx.wheelDelta = 0; |
|
1083 |
} |
|
1084 |
return false; |
|
1085 |
}); |
|
1086 |
$("#time_zoomin").click(function() { |
|
1087 |
if (twCx.timeLevel < twCx.date_levels.length - 1) { |
|
1088 |
twCx.timeLevel++; |
|
1089 |
chaineTimeZoom(); |
|
1090 |
updateDisplay(); |
|
1091 |
} |
|
1092 |
}); |
|
1093 |
$("#time_zoomout").click(function() { |
|
1094 |
if (twCx.timeLevel > 0) { |
|
1095 |
twCx.timeLevel--; |
|
1096 |
chaineTimeZoom(); |
|
1097 |
updateDisplay(); |
|
1098 |
} |
|
1099 |
}); |
|
1100 |
$("#timeline, #tweetlist").mouseout(function() { |
|
1101 |
twCx.tlMouseClicked = false; |
|
1102 |
twCx.tlMouseMoved = false; |
|
1103 |
$("#hovertweet").hide(); |
|
1104 |
}); |
|
1105 |
$("#timeline").mousemove(function(evt) { |
|
1106 |
twCx.tlMouseMoved = true; |
|
1107 |
clicTl(evt); |
|
1108 |
}).mousedown(function(evt) { |
|
1109 |
twCx.tlMouseClicked = true; |
|
1110 |
twCx.tlMouseMoved = false; |
|
1111 |
var o = $(this).offset(); |
|
1112 |
twCx.refMouse = { x : evt.pageX - o.left, y : evt.pageY - o.top }; |
|
1113 |
twCx.refPosTl = tlPosTweet(tweetById(twCx.position)) || twCx.refMouse; |
|
1114 |
}).mouseup(function(evt) { |
|
1115 |
clicTl(evt); |
|
1116 |
twCx.tlMouseClicked = false; |
|
1117 |
twCx.tlMouseMoved = false; |
|
1118 |
}); |
|
1119 |
$("#inp_q").focus(function() { |
|
1120 |
$("#recherche_annot").slideDown(); |
|
1121 |
$(this).val($(this).val().replace(/ \(.+\)$/, '')) |
|
1122 |
if ($(this).hasClass("greyed")) { |
|
1123 |
$(this).val(""); |
|
1124 |
} |
|
1125 |
$(this).attr("class",""); |
|
1126 |
}).focusout(function() { |
|
1127 |
focusOutRecherche(); |
|
1128 |
}); |
|
1129 |
$("#inp_reset").click(function() { |
|
1130 |
$("#inp_q").val(''); |
|
1131 |
if (twCx.filtre) { |
|
1132 |
twCx.filtre = null; |
|
1133 |
updateDisplay(); |
|
1134 |
} |
|
1135 |
twCx.filtreTexte = ''; |
|
1136 |
focusOutRecherche(); |
|
1137 |
return false; |
|
1138 |
}) |
|
1139 |
$("#recherche").submit(function(evt) { |
|
1140 |
evt.preventDefault(); |
|
1141 |
if (!$("#inp_q").hasClass("greyed")) { |
|
1142 |
var valeur = $("#inp_q").val(); |
|
1143 |
filtrerTexte(valeur); |
|
1144 |
} |
|
1145 |
return false; |
|
1146 |
}); |
|
1147 |
$("#hoverkw").mouseover(function() { |
|
1148 |
$(this).dequeue().show(); |
|
1149 |
}).mouseout(function() { |
|
1150 |
$(this).hide(); |
|
1151 |
}); |
|
1152 |
|
|
1153 |
$("#hkwsearch").click(function() { |
|
1154 |
var _hkw = $("#hoverkw"); |
|
1155 |
filtrerTexte(_hkw.attr("kw")); |
|
1156 |
_hkw.hide(); |
|
1157 |
return false; |
|
1158 |
}); |
|
1159 |
$("#hkwtweet").click(function() { |
|
1160 |
var _hkw = $("#hoverkw"); |
|
1161 |
add_grammar(_hkw.attr("kw")); |
|
1162 |
_hkw.hide(); |
|
1163 |
return false; |
|
1164 |
}); |
|
1165 |
$(".acctitre").click(function() { |
|
1166 |
$(this).next().slideToggle(); |
|
1167 |
return false; |
|
1168 |
}) |
|
1169 |
|
|
1170 |
if (!suggested_keywords.length) { |
|
1171 |
$("#suggkw").parent().hide(); |
|
1172 |
} |
|
1173 |
|
|
1174 |
setInterval(function() { |
|
1175 |
var sc = $("#scrollcont"); |
|
1176 |
if (sc.scrollTop() != twCx.lastScrollPos && twCx.tweets && twCx.currentIdIndex) { |
|
1177 |
var p = Math.floor( twCx.currentIdIndex.length * ( 1 - sc.scrollTop() / twCx.scrollExtent ) ); |
|
1178 |
goToPos(p); |
|
1179 |
} |
|
1180 |
}, 100) |
|
1181 |
}); |
|
1182 |
||
1183 |
function connectTweets() { |
|
1184 |
twCx.tlPaper.clear(); |
|
1185 |
var _sq = twCx.tlPaper.rect(0, twCx.tlHeight, twCx.tlWidth, 0) |
|
1186 |
.attr({ |
|
1187 |
"stroke" : "none", |
|
1188 |
"fill" : "#8080cc" |
|
1189 |
}); |
|
1190 |
var _lb = twCx.tlPaper.text(twCx.tlWidth / 2, twCx.tlHeight / 2, "0 tweet") |
|
1191 |
.attr({ |
|
1192 |
"font-size" : "20px", |
|
1193 |
"text-anchor" : "middle" |
|
1194 |
}); |
|
1195 |
|
|
1196 |
getTweets({ |
|
1197 |
"keyword" : tracking_keywords.join(" OR "), |
|
1198 |
"pages" : max_pages, |
|
1199 |
"rpp" : 100, |
|
1200 |
"cbData" : function() { |
|
1201 |
_lb.attr("text", (this.tweets.length - this.currentPage + 1) + " tweets"); |
|
1202 |
var _h = twCx.tlHeight * this.currentPage / this.pages; |
|
1203 |
_sq.animate({ |
|
1204 |
"y" : twCx.tlHeight - _h, |
|
1205 |
"height" : _h |
|
1206 |
}) |
|
1207 |
}, |
|
1208 |
"cbEnd" : function() { |
|
1209 |
loadTweets(this.tweets); |
|
1210 |
setInterval(function() { |
|
1211 |
getTweets({ |
|
1212 |
"keyword" : tracking_keywords.join(" OR "), |
|
1213 |
"pages" : 1, |
|
| 864 | 1214 |
/*"since_id" : twCx.idIndex[twCx.idIndex.length - 1],*/ |
| 836 | 1215 |
"rpp" : 100, |
1216 |
"cbEnd" : function() { |
|
1217 |
loadTweets(this.tweets, true); |
|
1218 |
} |
|
1219 |
}); |
|
1220 |
}, 60000) |
|
1221 |
} |
|
1222 |
}); |
|
1223 |
} |