ie8 compatibility
authorRaphael Velt <raph.velt@gmail.com>
Wed, 20 Mar 2013 16:21:32 +0100
changeset 801 9638278530e0
parent 800 71209c25aea1
child 802 a9fa8dbfb8f0
ie8 compatibility
web/res/js/live-polemic.js
--- a/web/res/js/live-polemic.js	Tue Mar 12 15:27:04 2013 +0100
+++ b/web/res/js/live-polemic.js	Wed Mar 20 16:21:32 2013 +0100
@@ -76,7 +76,7 @@
         tlWidth : 150,
         tlHeight : 480,
         globalWords : {},
-        suggestCount : suggested_keywords.map(function(_w) {
+        suggestCount : _(suggested_keywords).map(function(_w) {
             return {
                 "word" : _w,
                 "rgxp" : new RegExp(_w.replace(/(\W)/g, '\\$1'), "im"),
@@ -201,7 +201,7 @@
        delete tweet[_i + '_str']; 
     });
     
-    if (twCx.idIndex.indexOf(tweet.id) != -1) {
+    if (_(twCx.idIndex).indexOf(tweet.id) != -1) {
         return;
     }
     
@@ -288,9 +288,9 @@
     
     
     var tab = tweet.text.replace(twCx.urlRegExp,'').match(twCx.wordRegExp);
-    for (var i in tab) {
-        var word = tab[i].toLowerCase();
-        if (twCx.stopWords.indexOf(word) == -1 && tracking_keywords.indexOf(word) == -1 && word[0] != '@') {
+    _(tab).each(function(w) {
+        var word = w.toLowerCase();
+        if (_(twCx.stopWords).indexOf(word) == -1 && _(tracking_keywords).indexOf(word) == -1 && word[0] != '@') {
             if (twCx.globalWords[word]) {
                 twCx.globalWords[word].freq++;
             } else {
@@ -310,7 +310,7 @@
                 }
             }
         }
-    }
+    });
     
     _(twCx.suggestCount).each(function(_k) {
         if (tweet.text.search(_k.rgxp) != -1) {
@@ -434,7 +434,7 @@
 }
 
 function tweetById(tweetid) {
-    var pos = twCx.idIndex.indexOf(tweetid);
+    var pos = _(twCx.idIndex).indexOf(tweetid);
     return (pos == -1) ? false : twCx.tweets[pos];
 }
 
@@ -451,7 +451,7 @@
 }
 
 function movePos(delta) {
-    goToPos( delta + twCx.currentIdIndex.indexOf(twCx.position) );
+    goToPos( delta + _(twCx.currentIdIndex).indexOf(twCx.position) );
 }
 
 function tweetToHtml(tweet, className, elName) {
@@ -548,7 +548,7 @@
             var l = 0;
             for (var j in twCx.tlOnDisplay[i].displayData) {
                 if (j == ann) {
-                    var p = twCx.tlOnDisplay[i].displayData[j].indexOf(tweet.id);
+                    var p = _(twCx.tlOnDisplay[i].displayData[j]).indexOf(tweet.id);
                     if (p != -1) {
                         x = twCx.deltaX + twCx.scaleX * ( p + l + .5 );
                     }
@@ -695,16 +695,16 @@
         return;
     }
     if (twCx.filtre) {
-        var tweets = twCx.tweets.filter(function(tweet) {
+        var tweets = _(twCx.tweets).filter(function(tweet) {
             var mention = '@' + tweet.from_user;
             return ( tweet.text.search(twCx.filtre) != -1 ) || ( mention.search(twCx.filtre) != -1 );
         });
         $("#inp_q").val(twCx.filtreTexte + ' (' + tweets.length + ' tweets)');
         if (tweets.length) {
-            var idIndex = tweets.map(function(tweet) {
+            var idIndex = _(tweets).map(function(tweet) {
                 return tweet.id;
             });
-            var p = idIndex.indexOf(twCx.position);
+            var p = _(idIndex).indexOf(twCx.position);
             if (p == -1) {
                 for (p = idIndex.length - 1; p > 0 && idIndex[p] > twCx.position; p--) {
                 }
@@ -716,7 +716,7 @@
     } else {
         twCx.currentIdIndex = twCx.idIndex;
         var tweets = twCx.tweets;
-        var p = twCx.idIndex.indexOf(twCx.position);
+        var p = _(twCx.idIndex).indexOf(twCx.position);
         if (p == -1) {
             p = (twCx.followLast ? twCx.idIndex.length - 1 : 0);
         }
@@ -794,7 +794,8 @@
             makeTagCloud(twCx.suggestCount, "#suggkw");
         }
         
-        var tab = _(twCx.globalWords).map(function(v, k) {
+        var tab = _(twCx.globalWords).chain()
+        .map(function(v, k) {
             return {
                 "word": k,
                 "freq" : v.freq,
@@ -802,7 +803,7 @@
             };
         }).filter(function(v) {
             return v.freq > 1;
-        });
+        }).value();
         
         if (tab.length) {
             
@@ -937,7 +938,7 @@
 function filtrerAnnotation(annotation) {
     if (annotations[annotation]) {
         effectuerFiltrage(annotations[annotation].display_name,
-            new RegExp( "(" + annotations[annotation].keywords.map(function(a) { return a.source }).join("|") + ")", "gim" ) );
+            new RegExp( "(" + _(annotations[annotation].keywords).map(function(a) { return a.source }).join("|") + ")", "gim" ) );
     } else {
         effectuerFiltrage('', null)
     }
@@ -1046,13 +1047,13 @@
 
 function saveCSV() {
     function csvEncode(tableau) {
-      return tableau.map(function(el) {
+      return _(tableau).map(function(el) {
           return '"' + unescape(encodeURIComponent(el)).replace(/"/gm, '""') + '"';
       }).join(",")
     };
     var _csvfields = [ "id", "from_user", "from_user_name", "created_at", "text" ],
-        _csvtxt = csvEncode(_csvfields) + "\n" + twCx.tweets.map(function(tw) {
-            return csvEncode(_csvfields.map(function(field) {
+        _csvtxt = csvEncode(_csvfields) + "\n" + _(twCx.tweets).map(function(tw) {
+            return csvEncode(_(_csvfields).map(function(field) {
                 return tw[field];
             }));
         }).join("\n");