web/res/js-tweetcast/live-polemic.js
changeset 407 5ab44abc46df
parent 406 86b62b98fea7
child 408 4141c5821c98
--- a/web/res/js-tweetcast/live-polemic.js	Tue Dec 13 19:01:59 2011 +0100
+++ b/web/res/js-tweetcast/live-polemic.js	Wed Dec 14 16:58:57 2011 +0100
@@ -467,10 +467,93 @@
     return res;
 }
 
+function mouseoverkw() {
+    var _jel = $(this),
+        _off = _jel.offset();
+    _jel.css({
+        color: "#0099ff"
+    });
+    $("#hoverkw")
+        .css({
+            "left" : _off.left + "px",
+            "top" : ( parseInt(_off.top) + ~~ (_jel.height() / 2) )  + "px",
+            "display" : "block"
+        })
+        .attr("kw", _jel.text());
+}
+
+function mouseoutkw() {
+    $("#hoverkw").hide();
+    $(this).css({
+        color: "#000000"
+    });
+}
+
+function makeTagCloud(tab, div) {
+    var minfreq = _(tab).min( function(a) { return a.freq} ).freq,
+        maxfreq = Math.max(minfreq + .1, _(tab).max( function(a) { return a.freq} ).freq),
+        echfreq = 8 / Math.sqrt( maxfreq - minfreq ),
+        html = '';
+    _(tab).each(function(_j) {
+        var maxann = 0,
+            ann = "default";
+        for (var k in _j.annotations) {
+            if (_j.annotations[k] == maxann) {
+                ann = "default";
+            }
+            if (_j.annotations[k] > maxann) {
+                ann = k;
+                maxann = _j.annotations[k];
+            }
+        }
+        if (ann == "default") {
+            var coul = '';
+        } else {
+            var c = getColor(ann, .6),
+                coul = "background: rgba(" + [ Math.floor(c.r), Math.floor(c.g), Math.floor(c.b), ( _j.annotations[ann] / _j.freq )].join(',') + ")";
+        }
+        var fontsize = Math.floor( ( 12 + Math.sqrt( _j.freq - minfreq ) * echfreq ) );
+        html += '<span style="line-height: ' + (8 + fontsize) + 'px; font-size: ' + fontsize + 'px;' + coul + '">' + _j.word + '</span> ';
+    });
+    $(div).html(html);
+    $(div + " span")
+        .mouseover(mouseoverkw)
+        .mouseout(mouseoutkw)
+        .click(function() {
+            $("#hoverkw").toggle();
+        });
+}
+
+function updateSuggested() {
+    if (!suggested_keywords || !suggested_keywords.length) {
+        return;
+    }
+    var _skw = suggested_keywords.map(function(_e) {
+        return {
+            "word" : _e,
+            "rgxp" : new RegExp(_e, "im"),
+            "freq" : 0,
+            "annotations" : {}
+        }
+    })
+    _(twCx.tweets).each(function(_t) {
+        _(_skw).each(function(_k) {
+            if (_t.text.search(_k.rgxp) != -1) {
+                _k.freq++;
+                _(_t.annotations).each(function(_a) {
+                    _k.annotations[_a] = 1 + ( _k.annotations[_a] || 0 )
+                })
+            }
+        });
+    });
+    makeTagCloud(_skw, "#suggkw");
+}
+
 function updateDisplay() {
     if (!twCx.tweets) {
         return;
     }
+    updateSuggested();
     if (twCx.filtre) {
         var tweets = twCx.tweets.filter(function(tweet) {
             var mention = '@' + tweet.user.screen_name;
@@ -598,32 +681,7 @@
         if (tab.length) {
             
             tab = _(tab).sortBy( function(a) { return ( - a.score ) }).slice(0,20);
-            var minfreq = _(tab).min( function(a) { return a.freq} ).freq,
-                maxfreq = Math.max(minfreq + .1, _(tab).max( function(a) { return a.freq} ).freq),
-                echfreq = 8 / Math.sqrt( maxfreq - minfreq ),
-                html = '';
-            for (var j in tab) {
-                var maxann = 0,
-                    ann = "default";
-                for (var k in tab[j].annotations) {
-                    if (tab[j].annotations[k] == maxann) {
-                        ann = "default";
-                    }
-                    if (tab[j].annotations[k] > maxann) {
-                        ann = k;
-                        maxann = tab[j].annotations[k];
-                    }
-                }
-                if (ann == "default") {
-                    var coul = '';
-                } else {
-                    var c = getColor(ann, .6),
-                        coul = "background: rgba(" + [ Math.floor(c.r), Math.floor(c.g), Math.floor(c.b), ( tab[j].annotations[ann] / tab[j].freq )].join(',') + ")";
-                }
-                var fontsize = Math.floor( ( 12 + Math.sqrt( tab[j].freq - minfreq ) * echfreq ) );
-                html += '<span style="line-height: ' + (8 + fontsize) + 'px; font-size: ' + fontsize + 'px;' + coul + '" onclick="filtrerTexte(\'' + tab[j].word.replace(/('|")/g, '\\$1') + '\')">' + tab[j].word + '</span> ';
-            }
-            $("#motscles").html(html);
+            makeTagCloud(tab,"#motscles");
         } else {
             $("#motscles").html('');
         }
@@ -753,14 +811,14 @@
 function filtrerAnnotation(annotation) {
     if (annotations[annotation]) {
         effectuerFiltrage(annotations[annotation].display_name,
-            new RegExp( "(" + annotations[annotation].keywords.map(function(a) { return a.source }).join("|") + ")", "gi" ) );
+            new RegExp( "(" + annotations[annotation].keywords.map(function(a) { return a.source }).join("|") + ")", "gim" ) );
     } else {
         effectuerFiltrage('', null)
     }
 }
 
 function filtrerTexte(valeur) {
-    effectuerFiltrage( valeur, valeur ? new RegExp("(" + valeur.replace(/(\W)/g, '\\$1') + ")" ,'gi') : null );
+    effectuerFiltrage( valeur, valeur ? new RegExp("(" + valeur.replace(/(\W)/g, '\\$1') + ")" ,'gim') : null );
 }
 
 function effectuerFiltrage(filtreTexte, tabRegexp) {
@@ -904,15 +962,13 @@
     $("#timeline").mousemove(function(evt) {
         twCx.tlMouseMoved = true;
         clicTl(evt);
-    });
-    $("#timeline").mousedown(function(evt) {
+    }).mousedown(function(evt) {
         twCx.tlMouseClicked = true;
         twCx.tlMouseMoved = false;
         var o = $(this).offset();
         twCx.refMouse = { x : evt.pageX - o.left, y : evt.pageY - o.top };
         twCx.refPosTl = tlPosTweet(tweetById(twCx.position)) || twCx.refMouse;
-    });
-    $("#timeline").mouseup(function(evt) {
+    }).mouseup(function(evt) {
         clicTl(evt);
         twCx.tlMouseClicked = false;
         twCx.tlMouseMoved = false;
@@ -924,8 +980,7 @@
             $(this).val("");
         }
         $(this).attr("class","");
-    });
-    $("#inp_q").focusout(function() {
+    }).focusout(function() {
         focusOutRecherche();
     });
     $("#inp_reset").click(function() {
@@ -946,6 +1001,24 @@
         }
         return false;
     });
+    $("#hoverkw").mouseover(function() {
+        $(this).dequeue().show();
+    }).mouseout(function() {
+        $(this).hide();
+    });
+    
+    $("#hkwsearch").click(function() {
+        var _hkw = $("#hoverkw");
+        filtrerTexte(_hkw.attr("kw"));
+        _hkw.hide();
+        return false;
+    });
+    $("#hkwtweet").click(function() {
+        var _hkw = $("#hoverkw");
+        add_grammar(_hkw.attr("kw"));
+        _hkw.hide();
+        return false;
+    });
     
     setInterval(function() {
         var sc = $("#scrollcont");