client/js/main.js
changeset 31 7b76d97e3051
parent 26 83cf3d8be396
child 32 1e47b1f9f42d
--- a/client/js/main.js	Tue Feb 21 22:46:45 2012 +0100
+++ b/client/js/main.js	Tue Feb 21 22:47:19 2012 +0100
@@ -2,6 +2,13 @@
     myTweetSource,
     myQueueManager;
 
+var columnCounts,
+    onlineTweets = [],
+    dumpIsPaused = false;
+
+var MAX_TWEETS_BEFORE_DUMP = 20,
+    TWEETS_TO_DUMP_AT_ONCE = 10;
+
 function updateLastTweetList() {
     var _filtered = myTweetSource.afterDate(startHour),
         _txtFilter = $("#btv-cp-champ-filtre").val(),
@@ -9,6 +16,17 @@
     if (_txtFilter.length > 1) {
         _filtered = _filtered.search(_txtFilter);
         _reFilter = regexpFromText(_txtFilter);
+        for (var _i = 0; _i < onlineTweets.length; _i++) {
+            if (onlineTweets[_i].text.search(_reFilter) == -1) {
+                $('#'+onlineTweets[_i].id_str).fadeTo(250, 0.1);
+            } else {
+                $('#'+onlineTweets[_i].id_str).fadeTo(250, 1);
+            }
+        }
+    } else {
+        for (var _i = 0; _i < onlineTweets.length; _i++) {
+            $('#'+onlineTweets[_i].id_str).fadeTo(250, 1);
+        }
     }
     $('#btv-cp-liste-tweets-tout').html(
         _filtered.reverse().slice(0,20).map(function(_t) {
@@ -29,15 +47,16 @@
     var _t = myTweetSource.tweetById(tweetId);
     if (_t) {
         $("#btv-cp-liste-tweets-selection").prepend(
-            '<li onclick="showTweetOnScreen(\''
-                + _t.id_str
-                + '\'); return false;"><a title="Afficher sur l\'écran" href="#"><span class="btv-cp-tweet-date">'
-                + _t.created_at.match(/\d+:\d+:\d+/)[0]
-                + '</span> <span class="btv-cp-tweet-from">@'
-                + _t.from_user
-                + '</span> <span class="btv-cp-tweet-text">'
-                + _t.text
-                + '</span><div class="btv-cp-tweet-button btv-cp-tweet-show"></div></a></li>'
+            '<li><a title="Afficher sur l\'écran" href="#" onclick="showTweetOnScreen(\''
+            + _t.id_str
+            + '\'); return false;"><span class="btv-cp-tweet-date">'
+            + _t.created_at.match(/\d+:\d+:\d+/)[0]
+            + '</span> <span class="btv-cp-tweet-from">@'
+            + _t.from_user
+            + '</span> <span class="btv-cp-tweet-text">'
+            + _t.text
+            + '</span><div class="btv-cp-tweet-button btv-cp-tweet-show"></div></a>'
+            + '<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>'
         );
     }
 }
@@ -59,7 +78,41 @@
     }
 }
 
+function showTooltip(_t, _x, _y) {
+    $("#btv-tooltip").html('<img class="btv-tooltip-image" src="'
+        + _t.profile_image_url
+        + '" /><p class="btv-tooltip-name"><span>'
+        + _t.from_user
+        + '</span> (<span>'
+        + _t.from_user_name
+        +'</span>)</p><p>'
+        + _t.text
+        +'</p><div class="btv-tooltip-arrow"></div>').show().css({
+            "left": _x + "px",
+            "top": _y + "px",
+        })
+}
+
+function hideTooltip() {
+    $("#btv-tooltip").hide();
+}
+
+function showControlPanel() {
+    $("#btv-cp-container").dequeue().animate({
+            "left": 0
+        });
+}
+
+function hideControlPanel() {
+    $("#btv-cp-container").dequeue().animate({
+            "left": "-315px"
+        });
+}
+
 $(function() {
+    columnCounts = columnKeywords.map(function() {
+        return 0;
+    })
     setInterval(function() {
         var _t = Math.floor((new Date() - startHour)/1000),
             _s = _t % 60,
@@ -102,13 +155,39 @@
             }
         }
         if (_cat != -1) {
-            if (_cat == 2) {
-                console.log(_t.text);
+            _t.cat = _cat;
+            columnCounts[_cat]++;
+            onlineTweets.push(_t);
+            createBallTweetForce(_t);
+            if (!dumpIsPaused) {
+                for (var _i = 0; _i < columnCounts.length; _i++) {
+                    if (columnCounts[_cat] > MAX_TWEETS_BEFORE_DUMP) {
+                        var toDel = onlineTweets.splice(0,TWEETS_TO_DUMP_AT_ONCE);
+                        
+                        for (var _j = 0; _j < toDel.length; _j++) {
+                            var _id = toDel[_j].id_str;
+                            world.DestroyBody(b2bod[_id]);
+                            
+                            $('#'+_id).fadeTo(500, 0, function() {
+                                $(this).remove(); 
+                            });
+                        }
+                        
+                        // Regenerate column counts
+                        columnCounts = columnKeywords.map(function() {
+                            return 0;
+                        });
+                        for (var _k = 0; _k < onlineTweets.length; _k++) {
+                            columnCounts[onlineTweets[_k].cat]++;
+                        }
+                        break;
+                    }
+                }
             }
-            _t.cat = _cat;
-            createBallTweetForce(_t);
         }
-});
+    });
+    
+    $("#btv-cp-container").mouseover(showControlPanel).mouseout(hideControlPanel);
     
     $("#btv-cp-champ-filtre").keyup(function() {
         updateLastTweetList();
@@ -130,4 +209,14 @@
            $(this).removeClass("btv-cp-status-play");
        }
     });
+    $("#btv-cp-cont-pause-aval").click(function() {
+        dumpIsPaused = !dumpIsPaused
+        if (dumpIsPaused) {
+            $(this).removeClass("btv-cp-status-pause");
+            $(this).addClass("btv-cp-status-play");
+        } else {
+            $(this).addClass("btv-cp-status-pause");
+            $(this).removeClass("btv-cp-status-play");
+        }
+    });
 });
\ No newline at end of file