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