diff -r e7f9898e6f99 -r 99d105834315 web/res/js-tweetcast/semanticboard.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/res/js-tweetcast/semanticboard.js Mon Jan 09 12:51:19 2012 +0100
@@ -0,0 +1,241 @@
+var THRESHOLD = 10,
+ DROPCOUNT = 12;
+
+var swTw = {
+ "tweets" : [],
+ "tweetsIndex" : [],
+ "twInCol" : [],
+ "firstDisplayedTweet" : 0,
+ "cursor" : -1,
+ "annotations" : {
+ "positive" : {
+ "keyword" : "++",
+ "colors" : {
+ "tweet" : "#c5e7cd",
+ "timeline" : "#1D973D"
+ }
+ },
+ "negative" : {
+ "keyword" : "--",
+ "colors" : {
+ "tweet" : "#f6ced0",
+ "timeline" : "#CE0A15"
+ }
+ },
+ "reference" : {
+ "keyword" : "==",
+ "colors" : {
+ "tweet" : "#efefa1",
+ "timeline" : "#C5A62D"
+ }
+ },
+ "question" : {
+ "keyword" : "??",
+ "colors" : {
+ "tweet" : "#bfdbec",
+ "timeline" : "#036AAE"
+ }
+ }
+ }
+}
+
+function highlightKeyword(stra, strb, color) {
+ var rgxp = RegExp( '(' + strb.replace(/(\W)/gm, '\\$1') + ')', "gim");
+ return stra.replace(rgxp, '$1');
+}
+
+function highlightText(txt) {
+ res = suggested_keywords.reduce(function(a, b) {
+ return highlightKeyword(a,b, '#333333');
+ }, txt);
+ res = _(swTw.annotations).reduce(function(a, b) {
+ return (b.keyword ? highlightKeyword(a,b.keyword,b.colors.timeline) : a);
+ }, res);
+ return res;
+}
+
+function nextTweet() {
+ if (!swTw.tweets.length) {
+ return;
+ }
+ if (swTw.cursor < swTw.tweets.length - 1) {
+ swTw.cursor = Math.max(swTw.cursor + 1, swTw.tweets.length - 120);
+ var tweet = swTw.tweets[swTw.cursor],
+ html = '
@' + + tweet.from_user + + ' (' + + tweet.from_user_name + + ')' + + '
' + + highlightText(tweet.text) + + '
'; + $("#tweetcont").html(html) + } else { + $("#tweetcont").html("") + } +} + +function dropOldTweets() { + var _newPos = swTw.firstDisplayedTweet + DROPCOUNT; + _(swTw.tweets.slice(swTw.firstDisplayedTweet,_newPos)).each(function(tweet) { + swTw.twInCol = _(swTw.twInCol).map(function(col) { + return _(col).without(tweet.id_str); + }); + _(tweet.elements).each(function(elid) { + $("#" + elid).animate({ + "width": "0px" + }, + 2000, + function() { + $(this).detach(); + }) + }); + }); + swTw.firstDisplayedTweet = _newPos; +} + +function callbackTweets(tweets) { + _(tweets).each(function(tweet) { + var tl = tweet.text.toLowerCase(); + tweet.columns = suggested_keywords.filter(function(word) { + return tl.search(word) != -1 + }); + tweet.elements = []; + _(tweet.columns).each(function(word) { + var iword = suggested_keywords.indexOf(word), + icol = ( swTw.twInCol[iword*2+1].length < swTw.twInCol[iword*2].length ? iword*2+1 : iword*2 ), + elid = 'avatar_' + tweet.id_str + '_' + iword, + colA = swTw.colAnnot[iword], + ttl = 0; + _(swTw.annotations).each(function(v,k) { + if (tweet.text.indexOf(v.keyword) != -1) { + colA[k]++; + ttl++; + } + }); + colA.total += Math.max(1,ttl); + $('#tube_' + icol).append( + '