| author | Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> |
| Fri, 12 Sep 2014 14:55:06 +0200 | |
| changeset 1144 | 38f13bb5c082 |
| parent 955 | 5171f8825985 |
| child 1198 | ff4b567d51f2 |
| permissions | -rw-r--r-- |
| 598 | 1 |
IriSP.Widgets.Polemic = function(player, config) { |
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
3 |
}; |
|
4 |
||
5 |
IriSP.Widgets.Polemic.prototype = new IriSP.Widgets.Widget(); |
|
6 |
||
7 |
IriSP.Widgets.Polemic.prototype.messages = { |
|
8 |
fr: { |
|
9 |
from_: "de ", |
|
10 |
_to_: " à ", |
|
11 |
_annotations: " annotation(s)" |
|
12 |
}, |
|
13 |
en: { |
|
14 |
from_: "from ", |
|
15 |
_to_: " to ", |
|
16 |
_annotations: " annotation(s)" |
|
17 |
} |
|
| 955 | 18 |
}; |
19 |
||
| 598 | 20 |
IriSP.Widgets.Polemic.prototype.defaults = { |
21 |
element_width : 5, |
|
22 |
element_height : 5, |
|
| 765 | 23 |
max_elements: 20, |
| 598 | 24 |
annotation_type : "tweet", |
25 |
defaultcolor : "#585858", |
|
26 |
foundcolor : "#fc00ff", |
|
27 |
polemics : [ |
|
28 |
{ |
|
| 668 | 29 |
"name" : "OK", |
| 598 | 30 |
"keywords" : [ "++" ], |
31 |
"color" : "#1D973D" |
|
32 |
}, |
|
33 |
{ |
|
| 668 | 34 |
"name" : "KO", |
| 598 | 35 |
"keywords" : [ "--" ], |
36 |
"color" : "#CE0A15" |
|
37 |
}, |
|
38 |
{ |
|
| 668 | 39 |
"name" : "REF", |
| 638 | 40 |
"keywords" : [ "==", "http://" ], |
| 598 | 41 |
"color" : "#C5A62D" |
42 |
}, |
|
43 |
{ |
|
| 668 | 44 |
"name" : "Q", |
| 638 | 45 |
"keywords" : [ "?" ], |
| 598 | 46 |
"color" : "#036AAE" |
47 |
} |
|
48 |
] |
|
49 |
}; |
|
50 |
||
51 |
IriSP.Widgets.Polemic.prototype.draw = function() { |
|
52 |
|
|
| 694 | 53 |
this.onMediaEvent("timeupdate", "onTimeupdate"); |
| 598 | 54 |
this.$zone = IriSP.jQuery('<div>'); |
55 |
this.$zone.addClass("Ldt-Polemic"); |
|
56 |
this.$.append(this.$zone); |
|
57 |
|
|
58 |
this.$elapsed = IriSP.jQuery('<div>') |
|
59 |
.css({ |
|
60 |
background: '#cccccc', |
|
61 |
position: "absolute", |
|
62 |
top: 0, |
|
63 |
left: 0, |
|
64 |
width: 0, |
|
65 |
height: "100%" |
|
66 |
}); |
|
67 |
|
|
68 |
this.$zone.append(this.$elapsed); |
|
69 |
|
|
70 |
var _slices = [], |
|
71 |
_slice_count = Math.floor( this.width / this.element_width ), |
|
72 |
_duration = this.source.getDuration(), |
|
73 |
_max = 0, |
|
| 955 | 74 |
_list = this.getWidgetAnnotations().filter(function(_a) { |
75 |
return !_a.getDuration().milliseconds; |
|
76 |
}), |
|
| 598 | 77 |
_this = this; |
78 |
|
|
79 |
for (var _i = 0; _i < _slice_count; _i++) { |
|
80 |
var _begin = new IriSP.Model.Time( _i * _duration / _slice_count ), |
|
81 |
_end = new IriSP.Model.Time( ( _i + 1 ) * _duration / _slice_count ), |
|
82 |
_count = 0, |
|
83 |
_res = { |
|
84 |
begin : _begin.toString(), |
|
85 |
end : _end.toString(), |
|
86 |
annotations : _list.filter(function(_annotation) { |
|
| 940 | 87 |
return _annotation.begin >= _begin && _annotation.begin < _end; |
| 598 | 88 |
}), |
89 |
polemicStacks : [] |
|
| 955 | 90 |
}; |
| 598 | 91 |
|
92 |
for (var _j = 0; _j < this.polemics.length; _j++) { |
|
93 |
var _polemic = _res.annotations.searchByDescription(this.polemics[_j].keywords); |
|
94 |
_count += _polemic.length; |
|
95 |
_res.polemicStacks.push(_polemic); |
|
96 |
} |
|
97 |
for (var _j = 0; _j < this.polemics.length; _j++) { |
|
98 |
_res.annotations.removeElements(_res.polemicStacks[_j]); |
|
99 |
} |
|
100 |
_count += _res.annotations.length; |
|
101 |
_max = Math.max(_max, _count); |
|
102 |
_slices.push(_res); |
|
103 |
} |
|
104 |
if (_max < this.max_elements) { |
|
105 |
this.is_stackgraph = false; |
|
106 |
if (_max) { |
|
107 |
|
|
108 |
this.height = (2 + _max) * this.element_height; |
|
109 |
this.$zone.css({ |
|
110 |
width: this.width + "px", |
|
111 |
height: this.height + "px", |
|
112 |
position: "relative" |
|
113 |
}); |
|
114 |
|
|
| 694 | 115 |
var _x = 0; |
| 598 | 116 |
|
| 694 | 117 |
function displayAnnotation(_elx, _ely, _pol, _col, _annotation) { |
118 |
var _html = Mustache.to_html( |
|
| 828 | 119 |
'<div class="Ldt-Polemic-TweetDiv Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}, polemic:{{polemic}}, time:{{time}}" polemic-color="{{color}}"' |
| 694 | 120 |
+ ' tweet-title="{{title}}" annotation-id="{{id}}" style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>', |
| 598 | 121 |
{ |
| 694 | 122 |
id: _annotation.id, |
| 668 | 123 |
media_id: _this.source.currentMedia.id, |
| 694 | 124 |
polemic: _pol, |
125 |
left: _elx, |
|
126 |
top: _ely, |
|
127 |
color: _col, |
|
| 598 | 128 |
width: (_this.element_width-1), |
| 694 | 129 |
height: _this.element_height, |
| 779 | 130 |
title: _annotation.title, |
131 |
time: _annotation.begin.toString() |
|
| 694 | 132 |
}); |
133 |
var _el = IriSP.jQuery(_html); |
|
134 |
_el.mouseover(function() { |
|
135 |
_annotation.trigger("select"); |
|
136 |
}).mouseout(function() { |
|
137 |
_annotation.trigger("unselect"); |
|
138 |
}).click(function() { |
|
139 |
_annotation.trigger("click"); |
|
| 940 | 140 |
return false; |
| 828 | 141 |
}); |
142 |
IriSP.attachDndData(_el, { |
|
143 |
title: _annotation.title, |
|
144 |
description: _annotation.description, |
|
145 |
image: _annotation.thumbnail, |
|
146 |
uri: (typeof _annotation.url !== "undefined" |
|
147 |
? _annotation.url |
|
148 |
: (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)) |
|
149 |
}); |
|
| 694 | 150 |
_annotation.on("select", function() { |
| 755 | 151 |
if (_this.tooltip) { |
152 |
_this.tooltip.show( |
|
| 765 | 153 |
+ Math.floor(_elx + (_this.element_width - 1) / 2), |
154 |
+ _ely, |
|
| 755 | 155 |
_annotation.title, |
156 |
_col |
|
157 |
); |
|
158 |
} |
|
| 694 | 159 |
_this.$tweets.each(function() { |
160 |
var _e = IriSP.jQuery(this); |
|
161 |
_e.css( |
|
162 |
"opacity", |
|
163 |
( _e.attr("annotation-id") == _annotation.id ? 1 : .3 ) |
|
164 |
); |
|
165 |
}); |
|
166 |
}); |
|
167 |
_annotation.on("unselect", function() { |
|
| 755 | 168 |
if (_this.tooltip) { |
169 |
_this.tooltip.hide(); |
|
170 |
} |
|
| 694 | 171 |
_this.$tweets.css("opacity",1); |
172 |
}); |
|
| 719 | 173 |
_annotation.on("found", function() { |
174 |
_el.css({ |
|
175 |
"background" : _this.foundcolor, |
|
176 |
"opacity" : 1 |
|
177 |
}); |
|
178 |
}); |
|
179 |
_annotation.on("not-found", function() { |
|
180 |
_el.css({ |
|
181 |
"background" : _col, |
|
182 |
"opacity" : .3 |
|
183 |
}); |
|
184 |
}); |
|
| 694 | 185 |
_this.$zone.append(_el); |
| 598 | 186 |
} |
187 |
|
|
188 |
IriSP._(_slices).forEach(function(_slice) { |
|
189 |
var _y = _this.height; |
|
190 |
_slice.annotations.forEach(function(_annotation) { |
|
191 |
_y -= _this.element_height; |
|
| 694 | 192 |
displayAnnotation(_x, _y, "none", _this.defaultcolor, _annotation); |
| 598 | 193 |
}); |
194 |
IriSP._(_slice.polemicStacks).forEach(function(_annotations, _j) { |
|
| 668 | 195 |
var _color = _this.polemics[_j].color, |
196 |
_polemic = _this.polemics[_j].name; |
|
| 598 | 197 |
_annotations.forEach(function(_annotation) { |
198 |
_y -= _this.element_height; |
|
| 694 | 199 |
displayAnnotation(_x, _y, _polemic, _color, _annotation); |
| 598 | 200 |
}); |
201 |
}); |
|
202 |
_x += _this.element_width; |
|
203 |
}); |
|
204 |
|
|
205 |
this.$zone.append(_html); |
|
206 |
|
|
207 |
this.$tweets = this.$.find(".Ldt-Polemic-TweetDiv"); |
|
208 |
|
|
| 719 | 209 |
this.source.getAnnotations().on("search-cleared", function() { |
210 |
_this.$tweets.each(function() { |
|
211 |
var _el = IriSP.jQuery(this); |
|
212 |
_el.css({ |
|
213 |
"background" : _el.attr("polemic-color"), |
|
214 |
"opacity" : 1 |
|
215 |
}); |
|
216 |
}); |
|
217 |
}); |
|
| 598 | 218 |
|
219 |
} else { |
|
220 |
this.$zone.hide(); |
|
221 |
} |
|
222 |
} else { |
|
223 |
this.is_stackgraph = true; |
|
224 |
|
|
225 |
this.height = (2 + this.max_elements) * this.element_height; |
|
226 |
this.$zone.css({ |
|
227 |
width: this.width + "px", |
|
228 |
height: this.height + "px", |
|
229 |
position: "relative" |
|
230 |
}); |
|
231 |
|
|
232 |
var _x = 0, |
|
233 |
_html = '', |
|
234 |
_scale = this.max_elements * this.element_height / _max; |
|
235 |
|
|
| 668 | 236 |
function displayStackElement(_x, _y, _h, _color, _nums, _begin, _end, _polemic) { |
| 598 | 237 |
_html += Mustache.to_html( |
| 668 | 238 |
'<div class="Ldt-Polemic-TweetDiv Ldt-TraceMe" trace-info="annotation-block, media-id={{media_id}}, polemic={{polemic}}, time:{{begin}}" pos-x="{{posx}}" pos-y="{{top}}" annotation-counts="{{nums}}" begin-time="{{begin}}" end-time="{{end}}"' |
| 598 | 239 |
+ ' style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>', |
240 |
{ |
|
241 |
nums: _nums, |
|
242 |
posx: Math.floor(_x + (_this.element_width - 1) / 2), |
|
| 668 | 243 |
media_id: _this.source.currentMedia.id, |
244 |
polemic: _polemic, |
|
| 598 | 245 |
left: _x, |
246 |
top: _y, |
|
247 |
color: _color, |
|
248 |
width: (_this.element_width-1), |
|
249 |
height: _h, |
|
250 |
begin: _begin, |
|
251 |
end: _end |
|
252 |
}); |
|
253 |
} |
|
254 |
|
|
255 |
IriSP._(_slices).forEach(function(_slice) { |
|
256 |
var _y = _this.height, |
|
257 |
_nums = _slice.annotations.length + "," + IriSP._(_slice.polemicStacks).map(function(_annotations) { |
|
| 955 | 258 |
return _annotations.length; |
| 598 | 259 |
}).join(","); |
260 |
if (_slice.annotations.length) { |
|
261 |
var _h = Math.ceil(_scale * _slice.annotations.length); |
|
262 |
_y -= _h; |
|
| 668 | 263 |
displayStackElement(_x, _y, _h, _this.defaultcolor, _nums, _slice.begin, _slice.end, "none"); |
| 598 | 264 |
} |
265 |
IriSP._(_slice.polemicStacks).forEach(function(_annotations, _j) { |
|
266 |
if (_annotations.length) { |
|
267 |
var _color = _this.polemics[_j].color, |
|
| 668 | 268 |
_polemic = _this.polemics[_j].name, |
| 598 | 269 |
_h = Math.ceil(_scale * _annotations.length); |
270 |
_y -= _h; |
|
| 668 | 271 |
displayStackElement(_x, _y, _h, _color, _nums, _slice.begin, _slice.end, _polemic); |
| 598 | 272 |
} |
273 |
}); |
|
274 |
_x += _this.element_width; |
|
275 |
}); |
|
276 |
|
|
277 |
this.$zone.append(_html); |
|
278 |
|
|
279 |
this.$tweets = this.$.find(".Ldt-Polemic-TweetDiv"); |
|
280 |
|
|
281 |
this.$tweets |
|
282 |
.mouseover(function() { |
|
283 |
var _el = IriSP.jQuery(this), |
|
284 |
_nums = _el.attr("annotation-counts").split(","), |
|
285 |
_html = '<p>' + _this.l10n.from_ + _el.attr("begin-time") + _this.l10n._to_ + _el.attr("end-time") + '</p>'; |
|
286 |
for (var _i = 0; _i <= _this.polemics.length; _i++) { |
|
287 |
var _color = _i ? _this.polemics[_i - 1].color : _this.defaultcolor; |
|
| 955 | 288 |
_html += '<div class="Ldt-Tooltip-AltColor" style="background: ' + _color + '"></div><p>' + _nums[_i] + _this.l10n._annotations + '</p>'; |
| 598 | 289 |
} |
| 755 | 290 |
if (_this.tooltip) { |
| 765 | 291 |
_this.tooltip.show(+ _el.attr("pos-x"), + _el.attr("pos-y"), _html); |
| 755 | 292 |
} |
| 598 | 293 |
}) |
294 |
.mouseout(function() { |
|
| 755 | 295 |
if (_this.tooltip) { |
296 |
_this.tooltip.hide(); |
|
297 |
} |
|
| 955 | 298 |
}); |
| 598 | 299 |
|
| 955 | 300 |
}; |
| 598 | 301 |
|
302 |
this.$position = IriSP.jQuery('<div>').addClass("Ldt-Polemic-Position"); |
|
303 |
|
|
304 |
this.$zone.append(this.$position); |
|
305 |
|
|
306 |
this.$zone.click(function(_e) { |
|
307 |
var _x = _e.pageX - _this.$zone.offset().left; |
|
| 694 | 308 |
_this.media.setCurrentTime(_this.media.duration * _x / _this.width); |
| 598 | 309 |
}); |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
310 |
|
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
311 |
this.$.append('<div class="Ldt-Polemic-Tooltip"></div>'); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
312 |
|
| 755 | 313 |
this.insertSubwidget( |
314 |
this.$.find(".Ldt-Polemic-Tooltip"), |
|
315 |
{ |
|
316 |
type: "Tooltip", |
|
317 |
min_x: 0, |
|
318 |
max_x: this.width |
|
319 |
}, |
|
320 |
"tooltip" |
|
321 |
); |
|
| 955 | 322 |
}; |
| 598 | 323 |
|
| 694 | 324 |
IriSP.Widgets.Polemic.prototype.onTimeupdate = function(_time) { |
325 |
var _x = Math.floor( this.width * _time / this.media.duration); |
|
| 598 | 326 |
this.$elapsed.css({ |
327 |
width: _x + "px" |
|
328 |
}); |
|
329 |
this.$position.css({ |
|
330 |
left: _x + "px" |
|
| 955 | 331 |
}); |
332 |
}; |