front_idill/src/player/metadataplayer/Polemic.js
author bastiena
Mon, 24 Sep 2012 15:19:49 +0200
changeset 123 57a65edde708
parent 31 2c7fc855eba8
permissions -rw-r--r--
Front IDILL: non tmpl config files removed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     1
IriSP.Widgets.Polemic = function(player, config) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     2
    IriSP.Widgets.Widget.call(this, player, config);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     3
};
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     4
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     5
IriSP.Widgets.Polemic.prototype = new IriSP.Widgets.Widget();
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     6
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     7
IriSP.Widgets.Polemic.prototype.messages = {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     8
    fr: {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
     9
        from_: "de ",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    10
        _to_: " à ",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    11
        _annotations: " annotation(s)"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    12
    },
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    13
    en: {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    14
        from_: "from ",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    15
        _to_: " to ",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    16
        _annotations: " annotation(s)"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    17
    }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    18
}
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    19
IriSP.Widgets.Polemic.prototype.defaults = {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    20
    element_width : 5,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    21
    element_height : 5,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    22
    max_elements : 15,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    23
    annotation_type : "tweet",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    24
    defaultcolor : "#585858",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    25
    foundcolor : "#fc00ff",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    26
    polemics : [
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    27
        {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    28
            "keywords" : [ "++" ],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    29
            "description" : "positif",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    30
            "color" : "#1D973D"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    31
        },
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    32
        {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    33
            "keywords" : [ "--" ],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    34
            "description" : "negatif",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    35
            "color" : "#CE0A15"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    36
        },
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    37
        {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    38
            "keywords" : [ "==" ],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    39
            "description" : "reference",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    40
            "color" : "#C5A62D"  
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    41
        },
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    42
        {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    43
            "keywords" : [ "??" ],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    44
            "description" : "question",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    45
            "color" : "#036AAE"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    46
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    47
    ],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    48
    requires : [
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    49
        {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    50
            type: "Tooltip"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    51
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    52
    ]
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    53
};
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    54
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    55
IriSP.Widgets.Polemic.prototype.onSearch = function(searchString) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    56
    this.searchString = typeof searchString !== "undefined" ? searchString : '';
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    57
    var _found = 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    58
        _re = IriSP.Model.regexpFromTextOrArray(searchString),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    59
        _this = this;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    60
    this.$tweets.each(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    61
        var _el = IriSP.jQuery(this);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    62
        if (_this.searchString) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    63
            if (_re.test(_el.attr("tweet-title"))) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    64
                _el.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    65
                    "background" : _this.foundcolor,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    66
                    "opacity" : 1
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    67
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    68
                _found++;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    69
            } else {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    70
                _el.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    71
                    "background" : _el.attr("polemic-color"),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    72
                    "opacity" : .5
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    73
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    74
            }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    75
        } else {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    76
            _el.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    77
                "background" : _el.attr("polemic-color"),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    78
                "opacity" : 1
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    79
            });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    80
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    81
    });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    82
    if (this.searchString) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    83
        if (_found) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    84
            this.player.popcorn.trigger("IriSP.search.matchFound");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    85
        } else {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    86
            this.player.popcorn.trigger("IriSP.search.noMatchFound");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    87
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    88
    }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    89
}
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    90
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    91
IriSP.Widgets.Polemic.prototype.draw = function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    92
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    93
    this.bindPopcorn("timeupdate", "onTimeupdate");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    94
    this.$zone = IriSP.jQuery('<div>');
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    95
    this.$zone.addClass("Ldt-Polemic");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    96
    this.$.append(this.$zone);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    97
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    98
    this.$elapsed = IriSP.jQuery('<div>')
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
    99
        .css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   100
            background: '#cccccc',
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   101
            position: "absolute",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   102
            top: 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   103
            left: 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   104
            width: 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   105
            height: "100%"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   106
        });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   107
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   108
    this.$zone.append(this.$elapsed);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   109
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   110
    var _slices = [],
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   111
        _slice_count = Math.floor( this.width / this.element_width ),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   112
        _duration = this.source.getDuration(),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   113
        _max = 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   114
        _list = this.getWidgetAnnotations(),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   115
        _this = this;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   116
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   117
    for (var _i = 0; _i < _slice_count; _i++) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   118
        var _begin = new IriSP.Model.Time( _i * _duration / _slice_count ),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   119
            _end = new IriSP.Model.Time( ( _i + 1 ) * _duration / _slice_count ),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   120
            _count = 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   121
            _res = {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   122
                begin : _begin.toString(),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   123
                end : _end.toString(),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   124
                annotations : _list.filter(function(_annotation) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   125
                    return _annotation.begin >= _begin && _annotation.end < _end;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   126
                }),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   127
                polemicStacks : []
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   128
            }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   129
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   130
        for (var _j = 0; _j < this.polemics.length; _j++) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   131
            var _polemic = _res.annotations.searchByDescription(this.polemics[_j].keywords);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   132
            _count += _polemic.length;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   133
            _res.polemicStacks.push(_polemic);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   134
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   135
        for (var _j = 0; _j < this.polemics.length; _j++) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   136
            _res.annotations.removeElements(_res.polemicStacks[_j]);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   137
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   138
        _count += _res.annotations.length;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   139
        _max = Math.max(_max, _count);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   140
        _slices.push(_res);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   141
    }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   142
    if (_max < this.max_elements) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   143
        this.is_stackgraph = false;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   144
        if (_max) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   145
                    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   146
            this.height = (2 + _max) * this.element_height;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   147
            this.$zone.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   148
                width: this.width + "px",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   149
                height: this.height + "px",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   150
                position: "relative"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   151
            });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   152
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   153
            var _x = 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   154
                _html = '';
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   155
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   156
            function displayElement(_x, _y, _color, _id, _title) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   157
                _html += Mustache.to_html(
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   158
                    '<div class="Ldt-Polemic-TweetDiv" annotation-id="{{id}}" tweet-title="{{title}}" pos-x="{{posx}}" pos-y="{{top}}" polemic-color="{{color}}"'
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   159
                    + ' style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>',
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   160
                {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   161
                    id: _id,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   162
                    title: _title,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   163
                    posx: Math.floor(_x + (_this.element_width - 1) / 2),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   164
                    left: _x,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   165
                    top: _y,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   166
                    color: _color,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   167
                    width: (_this.element_width-1),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   168
                    height: _this.element_height
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   169
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   170
            }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   171
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   172
            IriSP._(_slices).forEach(function(_slice) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   173
                var _y = _this.height;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   174
                _slice.annotations.forEach(function(_annotation) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   175
                    _y -= _this.element_height;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   176
                    displayElement(_x, _y, _this.defaultcolor, _annotation.id, _annotation.title);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   177
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   178
                IriSP._(_slice.polemicStacks).forEach(function(_annotations, _j) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   179
                    var _color = _this.polemics[_j].color;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   180
                    _annotations.forEach(function(_annotation) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   181
                        _y -= _this.element_height;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   182
                        displayElement(_x, _y, _color, _annotation.id, _annotation.title);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   183
                    });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   184
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   185
                _x += _this.element_width;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   186
            });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   187
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   188
            this.$zone.append(_html);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   189
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   190
            this.$tweets = this.$.find(".Ldt-Polemic-TweetDiv");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   191
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   192
            this.$tweets
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   193
                .mouseover(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   194
                    var _el = IriSP.jQuery(this);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   195
                    _this.tooltip.show(_el.attr("pos-x"), _el.attr("pos-y"), _el.attr("tweet-title"), _el.attr("polemic-color"));
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   196
                })
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   197
                .mouseout(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   198
                    _this.tooltip.hide();
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   199
                })
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   200
                .click(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   201
                    var _id = IriSP.jQuery(this).attr("annotation-id");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   202
                    _this.player.popcorn.trigger("IriSP.Mediafragment.setHashToAnnotation", _id);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   203
                    _this.player.popcorn.trigger("IriSP.Tweet.show", _id);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   204
                });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   205
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   206
            this.bindPopcorn("IriSP.search", "onSearch");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   207
            this.bindPopcorn("IriSP.search.closed", "onSearch");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   208
            this.bindPopcorn("IriSP.search.cleared", "onSearch");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   209
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   210
        } else {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   211
            this.$zone.hide();
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   212
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   213
    } else {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   214
        this.is_stackgraph = true;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   215
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   216
        this.height = (2 + this.max_elements) * this.element_height;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   217
        this.$zone.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   218
            width: this.width + "px",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   219
            height: this.height + "px",
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   220
            position: "relative"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   221
        });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   222
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   223
        var _x = 0,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   224
            _html = '',
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   225
            _scale = this.max_elements * this.element_height / _max;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   226
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   227
        function displayStackElement(_x, _y, _h, _color, _nums, _begin, _end) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   228
            _html += Mustache.to_html(
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   229
                '<div class="Ldt-Polemic-TweetDiv" pos-x="{{posx}}" pos-y="{{top}}" annotation-counts="{{nums}}" begin-time="{{begin}}" end-time="{{end}}"'
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   230
                + ' style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>',
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   231
            {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   232
                nums: _nums,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   233
                posx: Math.floor(_x + (_this.element_width - 1) / 2),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   234
                left: _x,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   235
                top: _y,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   236
                color: _color,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   237
                width: (_this.element_width-1),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   238
                height: _h,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   239
                begin: _begin,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   240
                end: _end
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   241
            });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   242
        }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   243
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   244
        IriSP._(_slices).forEach(function(_slice) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   245
            var _y = _this.height,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   246
                _nums = _slice.annotations.length + "," + IriSP._(_slice.polemicStacks).map(function(_annotations) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   247
                    return _annotations.length
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   248
                }).join(",");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   249
            if (_slice.annotations.length) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   250
                var _h = Math.ceil(_scale * _slice.annotations.length);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   251
                _y -= _h;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   252
                displayStackElement(_x, _y, _h, _this.defaultcolor, _nums, _slice.begin, _slice.end);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   253
            }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   254
            IriSP._(_slice.polemicStacks).forEach(function(_annotations, _j) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   255
                if (_annotations.length) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   256
                    var _color = _this.polemics[_j].color,
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   257
                        _h = Math.ceil(_scale * _annotations.length);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   258
                    _y -= _h;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   259
                    displayStackElement(_x, _y, _h, _color, _nums, _slice.begin, _slice.end);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   260
                }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   261
            });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   262
            _x += _this.element_width;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   263
        });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   264
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   265
        this.$zone.append(_html);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   266
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   267
        this.$tweets = this.$.find(".Ldt-Polemic-TweetDiv");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   268
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   269
        this.$tweets
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   270
            .mouseover(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   271
                var _el = IriSP.jQuery(this),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   272
                    _nums = _el.attr("annotation-counts").split(","),
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   273
                    _html = '<p>' + _this.l10n.from_ + _el.attr("begin-time") + _this.l10n._to_ + _el.attr("end-time") + '</p>';
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   274
                for (var _i = 0; _i <= _this.polemics.length; _i++) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   275
                    var _color = _i ? _this.polemics[_i - 1].color : _this.defaultcolor;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   276
                    _html += '<div class="Ldt-Tooltip-Color" style="background: ' + _color + '"></div><p>' + _nums[_i] + _this.l10n._annotations + '</p>'
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   277
                }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   278
                _this.tooltip.show(_el.attr("pos-x"), _el.attr("pos-y"), _html);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   279
            })
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   280
            .mouseout(function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   281
                _this.tooltip.hide();
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   282
            })
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   283
            
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   284
    }
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   285
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   286
    this.$position = IriSP.jQuery('<div>').addClass("Ldt-Polemic-Position");
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   287
        
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   288
    this.$zone.append(this.$position);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   289
    
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   290
    this.$zone.click(function(_e) {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   291
        var _x = _e.pageX - _this.$zone.offset().left;
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   292
        _this.player.popcorn.currentTime(_this.source.getDuration().getSeconds() * _x / _this.width);
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   293
    });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   294
}
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   295
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   296
IriSP.Widgets.Polemic.prototype.onTimeupdate = function() {
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   297
    var _x = Math.floor( this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds());
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   298
    this.$elapsed.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   299
        width:  _x + "px"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   300
    });
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   301
    this.$position.css({
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   302
        left: _x + "px"
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   303
    })
2c7fc855eba8 FRONT IDILL :
bastiena
parents:
diff changeset
   304
}