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