tweetcast/client/js/live-polemic.js
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Mon, 19 Dec 2011 01:41:39 +0100
changeset 431 0218f9d62a63
parent 410 bf5cf5a9e737
permissions -rw-r--r--
Added tag V01.08 for changeset 6e512b2896b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
403
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     1
var socket,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     2
    tlPaper,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     3
    twCx = {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     4
        followLast : true,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     5
        position : "0",
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     6
        date_levels : [
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     7
            3600 * 1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     8
            15 * 60 * 1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
     9
            5 * 60 * 1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    10
            60 * 1000
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    11
        ],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    12
        timeLevel : 1,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    13
        deltaX : 40,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    14
        tlWidth : 150,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    15
        tlHeight : 480,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    16
        globalWords : {},
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    17
        refMouse : { x : 0, y : 0},
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    18
        refPosTl : { x : 0, y : 0},
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    19
        tlMouseMoved : false,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    20
        tlMouseClicked : false,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    21
        filtre : null
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    22
        },
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    23
    tlBuffer = '',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    24
    relHover = [],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    25
    wheelDelta = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    26
    scrollEnabled = false,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    27
    scrollExtent = 8000 - 480,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    28
    lastScrollPos = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    29
    rx_url = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    30
    rx_word = /[^ \.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    31
    stop_list = [ 'and', 'avec', 'aux', 'car', 'comme', 'dans', 'donc', 'des', 'elle', 'est', 'être', 'eux', 'ils', 'les', 'leur', 'leurs', 'mes', 'mon', 'tes', 'ton', 'notre', 'nos', 'nous', 'ont', 'pas', 'que', 'qui', 'sont', 'the', 'une', 'votre', 'vos', 'vous' ];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    32
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    33
function getColor(annotation, lum) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    34
    return Raphael.hsl2rgb(annotations[annotation].colors.h, annotations[annotation].colors.s, lum);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    35
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    36
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    37
function tweetPopup(url) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    38
    var popW = 550,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    39
        popH = 350,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    40
        scrW = screen.width,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    41
        scrH = screen.height,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    42
        posX = Math.round((scrW/2)-(popW/2)),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    43
        posY = (scrH > popH ? Math.round((scrH/2)-(popH/2)) : 0);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    44
    window.open(url,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    45
        '',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    46
        'left=' + posX + ',top=' + posY + ',width=' + popW + ',height=' + popH + ',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    47
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    48
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    49
function arc(source, target) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    50
    var x3 = .3 * target.y - .3 * source.y + .8 * source.x + .2 * target.x;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    51
    var y3 = .8 * source.y + .2 * target.y - .3 * target.x + .3 * source.x;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    52
    var x4 = .3 * target.y - .3 * source.y + .2 * source.x + .8 * target.x;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    53
    var y4 = .2 * source.y + .8 * target.y - .3 * target.x + .3 * source.x;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    54
    return "M" + source.x + " " + source.y + "C" + [x3, y3, x4, y4, target.x, target.y].join(" ");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    55
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    56
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    57
function addTweet(tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    58
    function backRef(source_id, target_id, type) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    59
        var target = tweetById(target_id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    60
        if (target) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    61
            var brobj = {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    62
                "referenced_by_id" : source_id,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    63
                "type" : type
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    64
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    65
            if (target.backRefs) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    66
                target.backRefs.push(brobj);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    67
            } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    68
                target.backRefs = [ brobj ]
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    69
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    70
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    71
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    72
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    73
    if (twCx.idIndex.indexOf(tweet.id) != -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    74
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    75
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    76
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    77
    var txt_date = tweet.created_at;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    78
    if (navigator.userAgent.search(/MSIE/) != -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    79
        txt_date = txt_date.replace(/( \+)/, ' UTC$1');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    80
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    81
    tweet.date_value = Date.parse(txt_date);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    82
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    83
    var tab = tweet.text.match(/\&\#[0-9]+\;/g);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    84
    for (var i in tab) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    85
        var n = parseInt(tab[i].substr(2));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    86
        if (n != NaN) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    87
            tweet.text = tweet.text.replace(tab[i], String.fromCharCode(n));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    88
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    89
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    90
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    91
    var ann = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    92
    for (var j in annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    93
        if (j != "default") {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    94
            for (var k in annotations[j].keywords) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    95
                if (tweet.text.search(annotations[j].keywords[k]) != -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    96
                    ann.push(j);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    97
                    break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    98
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
    99
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   100
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   101
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   102
    tweet.annotations = ann;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   103
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   104
    if (tweet.in_reply_to_status_id) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   105
        backRef( tweet.id, tweet.in_reply_to_status_id, "reply" );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   106
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   107
    if (tweet.retweeted_status) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   108
        backRef( tweet.id,  tweet.retweeted_status.id, "retweet" );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   109
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   110
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   111
    var localWords = []
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   112
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   113
    var tab = tweet.text.replace(rx_url,'').match(rx_word);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   114
    for (var i in tab) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   115
        var word = tab[i].toLowerCase();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   116
        if (stop_list.indexOf(word) == -1 && tracking_keywords.indexOf(word) == -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   117
            if (twCx.globalWords[word]) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   118
                twCx.globalWords[word]++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   119
            } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   120
                twCx.globalWords[word] = 1;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   121
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   122
            localWords.push(word);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   123
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   124
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   125
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   126
    tweet.words = localWords;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   127
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   128
    var p = twCx.idIndex.length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   129
    while (p && tweet.id < twCx.idIndex[p-1]) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   130
        p--;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   131
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   132
    twCx.tweets.splice(p, 0, tweet);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   133
    twCx.idIndex.splice(p, 0, tweet.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   134
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   135
    if (!twCx.timeline.length) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   136
        twCx.timeline = [ populateDateStruct(0, twCx.date_levels[0] * parseInt(tweet.date_value / twCx.date_levels[0])) ]
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   137
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   138
    while (tweet.date_value > twCx.timeline[twCx.timeline.length - 1].end) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   139
        twCx.timeline.push( populateDateStruct(0, twCx.timeline[twCx.timeline.length - 1].end) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   140
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   141
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   142
    insertIntoDateStruct(twCx.timeline, tweet);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   143
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   144
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   145
function getSliceContent(slice) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   146
    if (slice.slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   147
        var result = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   148
        for (var i in slice.slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   149
            result = result.concat(getSliceContent(slice.slices[i]));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   150
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   151
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   152
        var result = slice.tweets;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   153
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   154
    return result;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   155
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   156
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   157
function flattenDateStruct(slices, target_level) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   158
    var current_level = slices[0].level,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   159
        result = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   160
    if (current_level < target_level) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   161
        if (slices[0].slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   162
            for (var i in slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   163
                result = result.concat(flattenDateStruct(slices[i].slices, target_level));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   164
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   165
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   166
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   167
    else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   168
        for (var i in slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   169
            result.push({
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   170
                "start" : slices[i].start,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   171
                "end" : slices[i].end,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   172
                "tweets" : getSliceContent(slices[i])
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   173
            });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   174
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   175
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   176
    return result;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   177
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   178
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   179
function trimFDS() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   180
    var slices = flattenDateStruct(twCx.timeline, twCx.timeLevel);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   181
    while (slices[0].tweets.length == 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   182
        slices.splice(0,1);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   183
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   184
    while (slices[slices.length - 1].tweets.length == 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   185
        slices.pop();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   186
    }    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   187
    var centralTweet = ( twCx.centralTweet ? twCx.centralTweet : twCx.tweets[twCx.tweets.length - 1] ),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   188
        delta = 30 * twCx.date_levels[twCx.timeLevel],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   189
        centre = Math.min(slices[slices.length - 1].end - delta , Math.max(slices[0].start + delta, centralTweet.date_value)),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   190
        min = centre - delta,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   191
        max = centre + delta;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   192
    while (slices[0].start < min) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   193
        slices.splice(0,1);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   194
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   195
    while (slices[slices.length - 1].end > max) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   196
        slices.pop();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   197
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   198
    return slices;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   199
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   200
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   201
function populateDateStruct(level, start) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   202
    var end = start + twCx.date_levels[level],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   203
        struct = {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   204
            "level" : level,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   205
            "start" : start,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   206
            "end" : end
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   207
        };
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   208
    if (level < twCx.date_levels.length - 1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   209
        struct.slices = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   210
        var newstart = start;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   211
        while (newstart < end) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   212
            struct.slices.push(populateDateStruct(level + 1, newstart));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   213
            newstart += twCx.date_levels[level + 1];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   214
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   215
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   216
        struct.tweets = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   217
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   218
    return struct;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   219
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   220
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   221
function insertIntoDateStruct(slices, tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   222
    var creadate = tweet.date_value;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   223
    for (var i in slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   224
        if (creadate < slices[i].end) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   225
            if (slices[i].slices) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   226
                insertIntoDateStruct(slices[i].slices, tweet);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   227
            } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   228
                slices[i].tweets.push(tweet.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   229
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   230
            break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   231
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   232
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   233
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   234
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   235
function placeHolder(className) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   236
    return '<li class="placeholder ' + className + '"></li>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   237
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   238
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   239
function tweetById(tweetid) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   240
    var pos = twCx.idIndex.indexOf(tweetid);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   241
    return (pos == -1) ? false : twCx.tweets[pos];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   242
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   243
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   244
function selectTweet(tweetid) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   245
    twCx.position = tweetid;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   246
    twCx.followLast = (twCx.position == twCx.idIndex[twCx.tweets.length - 1]);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   247
    updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   248
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   249
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   250
function goToPos(nPos) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   251
    twCx.position = twCx.currentIdIndex[Math.min( twCx.currentIdIndex.length - 1, Math.max(0, nPos ) )];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   252
    twCx.followLast = (!twCx.filtre && nPos == twCx.tweets.length - 1);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   253
    updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   254
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   255
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   256
function movePos(delta) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   257
    goToPos( delta + twCx.currentIdIndex.indexOf(twCx.position) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   258
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   259
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   260
function tweetToHtml(tweet, className, elName) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   261
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   262
    function highlight(texte) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   263
        return ( twCx.filtre ? texte.replace(twCx.filtre, '<span class="highlight">$1</span>' ) : texte );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   264
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   265
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   266
    if (!tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   267
        return placeHolder(className);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   268
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   269
    var el = (elName ? elName : 'li');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   270
    var html = '<' + el + ' class="tweet ' + className + '" id="tweet_' + tweet.id + '"';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   271
    if (className != 'full') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   272
        html += ' onclick="selectTweet(\'' + tweet.id + '\'); return false;"';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   273
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   274
    html += ' onmouseover="rolloverTweet(\'' + tweet.id + "', " + ( className == 'icons' ) + ');"';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   275
    if (twCx.followLast && className == 'full' && el == 'li') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   276
        html += ' style="display: none"';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   277
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   278
    html += '>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   279
    if (tweet.annotations.length) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   280
        html += '<div class="annotations">';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   281
        for (var i in tweet.annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   282
            html += '<div class="annotation" style="width:' + (100/tweet.annotations.length) + '%; background:' + getColor(tweet.annotations[i], (className == 'icons' ? .4 : .85)).hex + '"></div>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   283
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   284
        html += '</div>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   285
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   286
    html += '<div class="twmain">';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   287
    var a_user = '<a href="http://twitter.com/' + tweet.user.screen_name + '"  onclick="filtrerTexte(\'@' + tweet.user.screen_name + '\'); return false;" target="_blank">';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   288
    html += '<div class="around_img">' + a_user + '<img class="profile_image" src="' + tweet.user.profile_image_url + '" /></a>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   289
    if (className == 'full') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   290
        html += '<p class="created_at">' + new Date(tweet.date_value).toTimeString().substr(0,8) + '</a></p>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   291
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   292
    html += '</div>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   293
    if (className != 'icons') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   294
        lastend = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   295
        var txt = '',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   296
            entities = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   297
        for (var i in tweet.entities.hashtags) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   298
            entities.push({
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   299
                "start" : tweet.entities.hashtags[i].indices[0],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   300
                "end" : tweet.entities.hashtags[i].indices[1],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   301
                "link" : '<a href="http://twitter.com/search?q=%23' + tweet.entities.hashtags[i].text + '" onclick="filtrerTexte(\'#' + tweet.entities.hashtags[i].text + '\'); return false;" target="_blank">',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   302
                "text" : '#' + tweet.entities.hashtags[i].text
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   303
            });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   304
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   305
        for (var i in tweet.entities.urls) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   306
            var linkurl = ( tweet.entities.urls[i].expanded_url ? tweet.entities.urls[i].expanded_url : tweet.entities.urls[i].url ),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   307
                dispurl = linkurl.replace(/https?:\/\//,'');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   308
            if (linkurl.search(/https?:\/\//) == -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   309
                linkurl = 'http://' + linkurl;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   310
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   311
            entities.push({
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   312
                "start" : tweet.entities.urls[i].indices[0],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   313
                "end" : tweet.entities.urls[i].indices[1],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   314
                "link" : '<a href="' + linkurl  + '" target="_blank">',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   315
                "text" : dispurl
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   316
            });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   317
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   318
        for (var i in tweet.entities.user_mentions) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   319
            entities.push({
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   320
                "start" : tweet.entities.user_mentions[i].indices[0],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   321
                "end" : tweet.entities.user_mentions[i].indices[1],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   322
                "link" : '<a href="http://twitter.com/' + tweet.entities.user_mentions[i].screen_name + '" onclick="filtrerTexte(\'@' + tweet.entities.user_mentions[i].screen_name + '\'); return false;" target="_blank">',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   323
                "text" : '@' + tweet.entities.user_mentions[i].screen_name
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   324
            });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   325
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   326
        entities.sort(function(a, b) { return a.start - b.start });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   327
        for (var i in entities) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   328
            txt += highlight( tweet.text.substring(lastend, entities[i].start) ) + entities[i].link + highlight( entities[i].text ) + '</a>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   329
            lastend = entities[i].end;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   330
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   331
        txt += highlight( tweet.text.substring(lastend) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   332
        html += '<p class="tweet_text"><b>' + a_user + highlight('@' + tweet.user.screen_name) + '</a>' + ( className == 'full' ? ' (' + tweet.user.name + ')</b><br />' : '</b> : ') + txt + '</p>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   333
        if (className == 'full' && el == 'li') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   334
            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> - ';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   335
            html += '<a href="http://twitter.com/intent/tweet?in_reply_to=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">répondre</a> · ';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   336
            html += '<a href="http://twitter.com/intent/retweet?tweet_id=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">retweeter</a> · ';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   337
            html += '<a href="http://twitter.com/intent/favorite?tweet_id=' + tweet.id + '" onclick="tweetPopup(this.href); return false;" target="_blank">favori</a></div>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   338
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   339
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   340
    html += '</div></' + el + '>';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   341
    return html;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   342
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   343
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   344
function tlIdFromPos(x, y, outside) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   345
    if (!twCx.tlOnDisplay) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   346
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   347
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   348
    var ligne = Math.min( twCx.tlOnDisplay.length - 1, Math.max( 0, Math.floor(( twCx.tlHeight - y ) / twCx.scaleY) ) ),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   349
        colonne = Math.floor(( x - twCx.deltaX ) / twCx.scaleX ),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   350
        l = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   351
    if (colonne >= twCx.tlOnDisplay[ligne].totalTweets || colonne < 0 ) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   352
        if (outside) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   353
            colonne = Math.min( twCx.tlOnDisplay[ligne].totalTweets - 1, Math.max( 0, colonne ));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   354
        } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   355
            return null;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   356
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   357
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   358
    for (var i in twCx.tlOnDisplay[ligne].displayData) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   359
        var nl = l + twCx.tlOnDisplay[ligne].displayData[i].length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   360
        if (colonne < nl) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   361
            return {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   362
                "id" : twCx.tlOnDisplay[ligne].displayData[i][colonne - l],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   363
                "annotation" : i
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   364
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   365
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   366
        l = nl;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   367
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   368
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   369
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   370
function tlPosTweet(tweet, annotation) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   371
    if (!twCx.tweets) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   372
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   373
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   374
    var x,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   375
        y,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   376
        dt = tweet.date_value,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   377
        ann = ( annotation ? annotation : ( tweet.annotations.length ? tweet.annotations[0] : 'default' ) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   378
    for (var i = 0; i < twCx.tlOnDisplay.length; i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   379
        if (twCx.tlOnDisplay[i].end > dt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   380
            y = twCx.tlHeight - (i + .5) * twCx.scaleY;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   381
            var l = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   382
            for (var j in twCx.tlOnDisplay[i].displayData) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   383
                if (j == ann) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   384
                    var p = twCx.tlOnDisplay[i].displayData[j].indexOf(tweet.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   385
                    if (p != -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   386
                        x = twCx.deltaX + twCx.scaleX * ( p + l + .5 );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   387
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   388
                    break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   389
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   390
                l += twCx.tlOnDisplay[i].displayData[j].length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   391
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   392
            break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   393
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   394
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   395
    return ( x && y ? { "x" : x, "y" : y } : null);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   396
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   397
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   398
function rolloverTweet(tweetid, showPopup, annotation) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   399
    var t = tweetById(tweetid);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   400
    if (!t) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   401
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   402
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   403
    var p = tlPosTweet(t, annotation);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   404
    if (!p) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   405
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   406
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   407
    var ptl = $("#timeline").offset();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   408
    if (showPopup) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   409
        $("#hovercontent").html(tweetToHtml(t, 'full', 'div'));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   410
        $("#hovertweet").css({
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   411
            "left" : parseInt(ptl.left + p.x) + "px",
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   412
            "top" : parseInt(ptl.top + p.y),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   413
            "display" : "block"});
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   414
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   415
        $("#hovertweet").hide();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   416
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   417
    for (var i in relHover) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   418
        relHover[i].remove();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   419
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   420
    relHover = drawTweetArcs(t, p, '#303030');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   421
    relHover.push(drawTweetPos(p, '#ffffff'));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   422
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   423
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   424
function drawTweetPos(pos, color) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   425
    var rel = tlPaper.rect(pos.x - .5 * twCx.scaleX, pos.y - .5 * twCx.scaleY, twCx.scaleX, twCx.scaleY);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   426
    rel.attr({ "stroke" : color, "fill" : color, "fill-opacity" : .25 });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   427
    return rel;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   428
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   429
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   430
function drawTweetArcs(tweet, pos, color) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   431
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   432
    var res = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   433
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   434
    function tweetAndArc(a, b, aorb) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   435
        if (a && b) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   436
            res.push(drawTweetPos(aorb ? a : b, color));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   437
            var aa = tlPaper.path(arc(a,b))
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   438
                .attr({ "stroke" : color, "stroke-width" : 1.5, "stroke-opacity" : .8 });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   439
            res.push(aa);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   440
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   441
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   442
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   443
    if (tweet.retweeted_status) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   444
        var t = tweetById(tweet.retweeted_status.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   445
        if (t) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   446
            tweetAndArc(pos, tlPosTweet(t));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   447
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   448
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   449
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   450
    if (tweet.in_reply_to_status_id) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   451
        var t = tweetById(tweet.in_reply_to_status_id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   452
        if (t) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   453
            tweetAndArc(pos, tlPosTweet(t));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   454
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   455
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   456
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   457
    if (tweet.backRefs) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   458
        for (var i in tweet.backRefs) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   459
            var t = tweetById(tweet.backRefs[i].referenced_by_id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   460
            if (t) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   461
            tweetAndArc(tlPosTweet(t), pos, true);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   462
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   463
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   464
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   465
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   466
    return res;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   467
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   468
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   469
function updateDisplay() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   470
    if (!twCx.tweets) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   471
        return;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   472
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   473
    if (twCx.filtre) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   474
        var tweets = twCx.tweets.filter(function(tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   475
            var mention = '@' + tweet.user.screen_name;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   476
            return ( tweet.text.search(twCx.filtre) != -1 ) || ( mention.search(twCx.filtre) != -1 );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   477
        });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   478
        $("#inp_q").val(twCx.filtreTexte + ' (' + tweets.length + ' tweets)');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   479
        if (tweets.length) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   480
            var idIndex = tweets.map(function(tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   481
                return tweet.id;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   482
            });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   483
            var p = idIndex.indexOf(twCx.position);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   484
            if (p == -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   485
                for (p = idIndex.length - 1; p > 0 && idIndex[p] > twCx.position; p--) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   486
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   487
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   488
            twCx.position = idIndex[p];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   489
            twCx.currentIdIndex = idIndex;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   490
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   491
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   492
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   493
        twCx.currentIdIndex = twCx.idIndex;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   494
        var tweets = twCx.tweets;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   495
        var p = twCx.idIndex.indexOf(twCx.position);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   496
        if (p == -1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   497
            p = (twCx.followLast ? twCx.idIndex.length - 1 : 0);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   498
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   499
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   500
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   501
    var l = tweets.length,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   502
        lines = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   503
        ppy = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   504
        html = '',
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   505
        tweetsOnDisplay = [],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   506
        localWords = {};
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   507
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   508
    function pushTweet(tp, className) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   509
        if (tp < l && tp >= 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   510
            html += tweetToHtml(tweets[tp], className)
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   511
            tweetsOnDisplay.push(tp);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   512
            for (var i in tweets[tp].words) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   513
                var w = tweets[tp].words[i];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   514
                if (localWords[w]) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   515
                    localWords[w].freq++
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   516
                } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   517
                    localWords[w] = {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   518
                        "freq" : 1,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   519
                        "annotations" : {}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   520
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   521
                    for (var j in annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   522
                        if (j != 'default') {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   523
                            localWords[w].annotations[j] = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   524
                        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   525
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   526
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   527
                for (var j in tweets[tp].annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   528
                    localWords[w].annotations[tweets[tp].annotations[j]]++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   529
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   530
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   531
        } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   532
            html += placeHolder(className);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   533
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   534
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   535
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   536
    if (l) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   537
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   538
        lastScrollPos = Math.floor( scrollExtent * ( 1 - ( p / l ) ) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   539
        $("#scrollcont").scrollTop(lastScrollPos);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   540
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   541
        if (l > p + 18) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   542
            lines++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   543
            ppy += 20;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   544
            for (var i = p + 31; i >= p + 18; i--) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   545
                pushTweet(i, 'icons');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   546
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   547
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   548
        if (l > p + 4) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   549
            lines++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   550
            ppy += 20;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   551
            for (var i = p + 17; i >= p + 4; i--) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   552
                pushTweet(i, 'icons');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   553
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   554
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   555
        for (var k = 3; k >= 1; k--) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   556
            if (l > p + k) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   557
                ppy += 47;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   558
                lines++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   559
                pushTweet(p + k, 'half');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   560
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   561
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   562
        pushTweet(p, 'full');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   563
        var n = p - 1;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   564
        for (var i = 0; i < Math.min(6, Math.max(3, 6 - lines)); i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   565
            if (n < 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   566
                break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   567
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   568
            pushTweet(n, 'half');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   569
            n--;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   570
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   571
        for (var i = 0; i < 14 * Math.min(4, Math.max(2, 7 - lines)); i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   572
            if (n < 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   573
                break;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   574
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   575
            pushTweet(n, 'icons');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   576
            n--;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   577
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   578
        if (html != tlBuffer) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   579
            $("#tweetlist").html(html);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   580
            $(".tweet.full").fadeIn();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   581
            tlBuffer = html;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   582
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   583
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   584
        /* Recherche des mots pertinents correspondant à la sélection */
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   585
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   586
        var tab = _(localWords).map(function(v, k) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   587
            return {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   588
                "word": k,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   589
                "freq" : v.freq,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   590
                "annotations" : v.annotations,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   591
                "score" : v.freq / Math.log( 2 + twCx.globalWords[j] )
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   592
            };
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   593
        }).filter(function(v) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   594
            return v.freq > 1;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   595
        });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   596
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   597
        if (tab.length) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   598
            
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   599
            tab = _(tab).sortBy( function(a) { return ( - a.score ) }).slice(0,20);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   600
            var minfreq = _(tab).min( function(a) { return a.freq} ).freq,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   601
                maxfreq = Math.max(minfreq + .1, _(tab).max( function(a) { return a.freq} ).freq),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   602
                echfreq = 8 / Math.sqrt( maxfreq - minfreq ),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   603
                html = '';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   604
            for (var j in tab) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   605
                var maxann = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   606
                    ann = "default";
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   607
                for (var k in tab[j].annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   608
                    if (tab[j].annotations[k] == maxann) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   609
                        ann = "default";
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   610
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   611
                    if (tab[j].annotations[k] > maxann) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   612
                        ann = k;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   613
                        maxann = tab[j].annotations[k];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   614
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   615
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   616
                if (ann == "default") {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   617
                    var coul = '';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   618
                } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   619
                    var c = getColor(ann, .6),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   620
                        coul = "background: rgba(" + [ Math.floor(c.r), Math.floor(c.g), Math.floor(c.b), ( tab[j].annotations[ann] / tab[j].freq )].join(',') + ")";
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   621
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   622
                var fontsize = Math.floor( ( 12 + Math.sqrt( tab[j].freq - minfreq ) * echfreq ) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   623
                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> ';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   624
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   625
            $("#motscles").html(html);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   626
        } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   627
            $("#motscles").html('');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   628
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   629
        twCx.centralTweet = tweets[p];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   630
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   631
        $("#tweetlist").html('');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   632
        tlBuffer = '';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   633
        $("#motscles").html('');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   634
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   635
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   636
    twCx.tlOnDisplay = trimFDS();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   637
    twCx.scaleY = twCx.tlHeight / twCx.tlOnDisplay.length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   638
    var maxTweets = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   639
        startTl = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   640
        endTl = twCx.tlOnDisplay.length - 1;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   641
    if (l) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   642
        var startTw = tweets[tweetsOnDisplay[tweetsOnDisplay.length - 1]].date_value,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   643
            endTw = tweets[tweetsOnDisplay[0]].date_value;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   644
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   645
    for (var i = 0; i < twCx.tlOnDisplay.length; i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   646
        if (l) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   647
            if (startTw >= twCx.tlOnDisplay[i].start && startTw < twCx.tlOnDisplay[i].end) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   648
                startTl = i;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   649
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   650
            if (endTw >= twCx.tlOnDisplay[i].start && endTw < twCx.tlOnDisplay[i].end) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   651
                endTl = i;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   652
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   653
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   654
        var displayData = {};
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   655
        for (var j in annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   656
            displayData[j] = [];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   657
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   658
        for (var j in twCx.tlOnDisplay[i].tweets) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   659
            var tweetid = twCx.tlOnDisplay[i].tweets[j],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   660
                tweet = tweetById(tweetid);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   661
            if (tweet) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   662
                if (tweet.annotations.length) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   663
                    for (var k in tweet.annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   664
                        displayData[tweet.annotations[k]].push(tweetid);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   665
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   666
                } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   667
                    displayData['default'].push(tweetid);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   668
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   669
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   670
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   671
        var nbT = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   672
        for (var j in displayData) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   673
            nbT += displayData[j].length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   674
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   675
        maxTweets = Math.max(maxTweets, nbT);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   676
        twCx.tlOnDisplay[i].displayData = displayData;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   677
        twCx.tlOnDisplay[i].totalTweets = nbT;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   678
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   679
    twCx.scaleX = ( twCx.tlWidth - twCx.deltaX ) / maxTweets;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   680
    tlPaper.clear();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   681
    relHover = null;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   682
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   683
    // Dessin de la correspondance liste-timeline
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   684
    if (l) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   685
        var startY = twCx.tlHeight - startTl * twCx.scaleY,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   686
            endY = twCx.tlHeight - ( endTl + 1 ) * twCx.scaleY,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   687
            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";
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   688
        tlPaper.path( path ).attr({ "stroke" : "none", "fill" : "#000080", "opacity" : .2 });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   689
    }   
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   690
    // dessin de la date de début
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   691
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   692
    tlPaper.text(twCx.deltaX / 2, twCx.tlHeight - 7, new Date(twCx.tlOnDisplay[0].start).toTimeString().substr(0,5))
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   693
        .attr({ "text-anchor" : "middle", "font-size": "9px" });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   694
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   695
    // dessin de la date de fin
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   696
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   697
    tlPaper.text(twCx.deltaX / 2, 7, new Date(twCx.tlOnDisplay[twCx.tlOnDisplay.length - 1].end).toTimeString().substr(0,5))
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   698
        .attr({ "text-anchor" : "middle", "font-size": "9px" });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   699
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   700
    for (var i = 0; i < twCx.tlOnDisplay.length; i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   701
        var n = 0,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   702
            posY = twCx.tlHeight - ( i + 1 ) * twCx.scaleY;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   703
        for (var j in twCx.tlOnDisplay[i].displayData) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   704
            var ll = twCx.tlOnDisplay[i].displayData[j].length;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   705
            if (ll > 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   706
                tlPaper.rect( twCx.deltaX + n * twCx.scaleX, posY, ll * twCx.scaleX, twCx.scaleY )
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   707
                    .attr({"stroke" : "none", "fill" : getColor(j, .4).hex });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   708
                n += ll;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   709
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   710
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   711
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   712
        // Si on est à une demi-heure, on trace un axe secondaire + heure
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   713
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   714
        if (i < twCx.tlOnDisplay.length - 1 && !(twCx.tlOnDisplay[i].end % 1800000)) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   715
            tlPaper.path("M0 "+posY+"L" + twCx.tlWidth +" "+posY).attr({"stroke":"#ccc"});
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   716
            tlPaper.text(twCx.deltaX / 2, posY, new Date(twCx.tlOnDisplay[i].end).toTimeString().substr(0,5)).attr({ "text-anchor" : "middle", "font-size": "9px" });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   717
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   718
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   719
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   720
    // dessin du tweet courant
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   721
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   722
    if (l) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   723
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   724
        if (twCx.filtre) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   725
            for (var i = 0; i < tweets.length; i++) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   726
                if (i != p) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   727
                    var pos = tlPosTweet(tweets[i]);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   728
                    if (pos) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   729
                        drawTweetPos(pos, "#ffccff");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   730
                    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   731
                }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   732
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   733
            
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   734
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   735
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   736
        var posp = tlPosTweet(tweets[p]);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   737
        if (posp) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   738
            
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   739
            drawTweetPos(posp, "#ffff00");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   740
            var yy = posp.y - .5 * twCx.scaleY,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   741
                path = "M0 " + ppy + "C" + ( .7 * twCx.deltaX ) + " " + ppy + " " + ( .2 * twCx.deltaX ) + " " + yy + " " + ( twCx.deltaX ) + " " + yy + "L" + ( posp.x - .5 * twCx.scaleX ) + " " + yy;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   742
            yy = posp.y + .5 * twCx.scaleY;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   743
            ppy += 117;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   744
            path += "L" + ( posp.x - .5 * twCx.scaleX ) + " " + yy + "L" + twCx.deltaX + " " + yy + "C"  + ( .2 * twCx.deltaX ) + " " + yy + " " + ( .7 * twCx.deltaX ) + " " + ppy + " 0 " + ppy;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   745
            tlPaper.path( path ).attr({"stroke":"#ffff00", "fill" : "#ffff00", "fill-opacity" : .15});
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   746
            
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   747
            drawTweetArcs(tweets[p], posp, '#800080');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   748
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   749
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   750
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   751
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   752
function filtrerAnnotation(annotation) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   753
    if (annotations[annotation]) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   754
        effectuerFiltrage(annotations[annotation].display_name,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   755
            new RegExp( "(" + annotations[annotation].keywords.map(function(a) { return a.source }).join("|") + ")", "gi" ) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   756
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   757
        effectuerFiltrage('', null)
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   758
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   759
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   760
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   761
function filtrerTexte(valeur) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   762
    effectuerFiltrage( valeur, valeur ? new RegExp("(" + valeur.replace(/(\W)/g, '\\$1') + ")" ,'gi') : null );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   763
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   764
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   765
function effectuerFiltrage(filtreTexte, tabRegexp) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   766
    $("#recherche_annot").slideUp();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   767
    $("#inp_q").val(filtreTexte).attr("class","rechercheCourante");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   768
    twCx.filtreTexte = filtreTexte;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   769
    twCx.filtre = tabRegexp;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   770
    twCx.followLast = !tabRegexp && (twCx.position == twCx.idIndex[twCx.idIndex.length - 1]);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   771
    updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   772
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   773
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   774
function clicTl(evt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   775
    var o = $("#timeline").offset();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   776
    if (twCx.tlMouseClicked && twCx.tlMouseMoved) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   777
        var twid = tlIdFromPos(evt.pageX - o.left + twCx.refPosTl.x - twCx.refMouse.x, evt.pageY - o.top + twCx.refPosTl.y - twCx.refMouse.y, true);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   778
        if (twid) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   779
            selectTweet(twid.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   780
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   781
    } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   782
        var twid = tlIdFromPos(evt.pageX - o.left, evt.pageY - o.top, twCx.tlMouseClicked);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   783
        if (twCx.tlMouseMoved && !twCx.tlMouseClicked) { 
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   784
            if (twid) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   785
                rolloverTweet(twid.id, true, twid.annotation);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   786
            } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   787
                $("#hovertweet").hide();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   788
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   789
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   790
        if (twCx.tlMouseClicked && !twCx.tlMouseMoved) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   791
            if (twid) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   792
                selectTweet(twid.id);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   793
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   794
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   795
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   796
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   797
404
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   798
function loadTweets(tweets, append) {
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   799
    if (!append) {
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   800
        twCx.timeline = [];
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   801
        twCx.idIndex = [];
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   802
        twCx.tweets = [];
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   803
    }
403
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   804
    for (var i in tweets) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   805
        addTweet(tweets[i]);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   806
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   807
    if (twCx.followLast) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   808
        twCx.position = twCx.idIndex[twCx.tweets.length - 1];
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   809
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   810
    updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   811
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   812
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   813
function focusOutRecherche() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   814
    $("#recherche_annot").slideUp();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   815
    var inpq = $("#inp_q"),
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   816
        val = inpq.val();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   817
    if (val == '' || val == twCx.filtreTexte) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   818
        if (twCx.filtre) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   819
            inpq.attr("class", "rechercheCourante").val(twCx.filtreTexte);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   820
        } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   821
            inpq.attr("class", "greyed").val("Rechercher");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   822
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   823
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   824
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   825
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   826
function chaineTimeZoom() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   827
    var chaine = "",
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   828
        t = twCx.date_levels[twCx.timeLevel],
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   829
        h = 3600*1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   830
        m = 60*1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   831
        s = 1000,
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   832
        heures = Math.floor(t/h);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   833
    if (heures) { chaine += heures + ' h. ' };
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   834
    t -= (heures * h);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   835
    var minutes = Math.floor(t/m);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   836
    if (minutes) { chaine += minutes + ' min. ' };
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   837
    t -= (minutes * m);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   838
    if (t) { chaine += Math.floor(t/s) + ' sec.' }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   839
    $("#time_scale").html(chaine);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   840
    $("#time_zoomout").attr("class",(twCx.timeLevel == 0 ? "inactive" : ""));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   841
    $("#time_zoomin").attr("class",(twCx.timeLevel == twCx.date_levels.length - 1 ? "inactive" : ""));
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   842
}
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   843
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   844
$(document).ready(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   845
    tlPaper = Raphael("timeline", twCx.tlWidth, twCx.tlHeight);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   846
    
404
89968844eb7d Tweetcast: heavy refactoring !
Raphael Velt <raph.velt@gmail.com>
parents: 403
diff changeset
   847
    connectTweets();
403
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   848
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   849
    var html = '';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   850
    for (var j in annotations) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   851
        if (j != "default") {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   852
            html += '<a href="#" style="background: ' + getColor(j, .7).hex + ';" onclick=filtrerAnnotation(\'' + j + '\'); return false;">' + annotations[j].display_name + '</a> '
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   853
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   854
    }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   855
    $("#rech_list_annot").html(html);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   856
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   857
    chaineTimeZoom();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   858
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   859
    $("#tweetlist").mousewheel(function(e, d) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   860
        wheelDelta += d;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   861
        if (Math.abs(wheelDelta) >= 1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   862
            movePos( parseInt(wheelDelta) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   863
            wheelDelta = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   864
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   865
        return false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   866
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   867
    $("#timeline").mousewheel(function(e, d) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   868
        wheelDelta += d;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   869
        if (Math.abs(wheelDelta) >= 1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   870
            if (wheelDelta > 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   871
                tl = Math.min(twCx.date_levels.length - 1, twCx.timeLevel + 1);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   872
            } else {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   873
                tl = Math.max(0, twCx.timeLevel - 1);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   874
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   875
            if (tl != twCx.timeLevel) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   876
                twCx.timeLevel = tl;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   877
                chaineTimeZoom();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   878
                updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   879
            }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   880
            wheelDelta = 0;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   881
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   882
        return false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   883
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   884
    $("#time_zoomin").click(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   885
        if (twCx.timeLevel < twCx.date_levels.length - 1) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   886
            twCx.timeLevel++;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   887
            chaineTimeZoom();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   888
            updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   889
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   890
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   891
    $("#time_zoomout").click(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   892
        if (twCx.timeLevel > 0) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   893
            twCx.timeLevel--;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   894
            chaineTimeZoom();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   895
            updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   896
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   897
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   898
    $("#timeline, #tweetlist").mouseout(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   899
        twCx.tlMouseClicked = false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   900
        twCx.tlMouseMoved = false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   901
        $("#hovertweet").hide();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   902
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   903
    $("#timeline").mousemove(function(evt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   904
        twCx.tlMouseMoved = true;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   905
        clicTl(evt);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   906
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   907
    $("#timeline").mousedown(function(evt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   908
        twCx.tlMouseClicked = true;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   909
        twCx.tlMouseMoved = false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   910
        var o = $(this).offset();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   911
        twCx.refMouse = { x : evt.pageX - o.left, y : evt.pageY - o.top };
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   912
        twCx.refPosTl = tlPosTweet(tweetById(twCx.position)) || twCx.refMouse;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   913
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   914
    $("#timeline").mouseup(function(evt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   915
        clicTl(evt);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   916
        twCx.tlMouseClicked = false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   917
        twCx.tlMouseMoved = false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   918
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   919
    $("#inp_q").focus(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   920
        $("#recherche_annot").slideDown();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   921
        $(this).val($(this).val().replace(/ \(.+\)$/, ''))
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   922
        if ($(this).hasClass("greyed")) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   923
            $(this).val("");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   924
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   925
        $(this).attr("class","");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   926
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   927
    $("#inp_q").focusout(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   928
        focusOutRecherche();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   929
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   930
    $("#inp_reset").click(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   931
        $("#inp_q").val('');
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   932
        if (twCx.filtre) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   933
            twCx.filtre = null;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   934
            updateDisplay();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   935
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   936
        twCx.filtreTexte = '';
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   937
        focusOutRecherche();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   938
        return false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   939
    })
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   940
    $("#recherche").submit(function(evt) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   941
        evt.preventDefault();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   942
        if (!$("#inp_q").hasClass("greyed")) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   943
            var valeur = $("#inp_q").val();
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   944
            filtrerTexte(valeur);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   945
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   946
        return false;
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   947
    });
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   948
    
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   949
    setInterval(function() {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   950
        var sc = $("#scrollcont");
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   951
        if (sc.scrollTop() != lastScrollPos && twCx.tweets) {
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   952
            var p = Math.floor( twCx.currentIdIndex.length * ( 1 - sc.scrollTop() / scrollExtent ) );
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   953
            goToPos(p);
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   954
        }
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   955
        
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   956
    }, 100)
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   957
});
dd1686ae5506 minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 391
diff changeset
   958