|
31
|
1 |
/* |
|
|
2 |
The Timeline Widget fits right under the video |
|
|
3 |
*/ |
|
|
4 |
|
|
|
5 |
IriSP.Widgets.Timeline = function(player, config) { |
|
|
6 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
7 |
this.bindPopcorn("timeupdate","onTimeupdate"); |
|
|
8 |
this.bindPopcorn("loadedmetadata","ready"); |
|
|
9 |
//this.bindPopcorn("IriSP.PlayerWidget.MouseOver","onMouseover"); |
|
|
10 |
//this.bindPopcorn("IriSP.PlayerWidget.MouseOut","onMouseout"); |
|
|
11 |
this.timelineSelected = false; |
|
|
12 |
this.markerShowTime = 200; |
|
|
13 |
this.markerLastTime = 5000; |
|
|
14 |
this.markerBigShown = false; |
|
|
15 |
this.currentMarkerIdx = -1; |
|
|
16 |
this.previousMarkerIdx = -1; |
|
|
17 |
this.hideTimeout; |
|
|
18 |
this.currentMode = "VIDEO"; |
|
|
19 |
this.paused = false |
|
|
20 |
this.top_epsilon = 0; |
|
|
21 |
this.imgDir = "player/img/"; |
|
33
|
22 |
this.markersDir = "pictos/small/"; |
|
|
23 |
this.player = player; |
|
32
|
24 |
|
|
33
|
25 |
this.gestures = ["fall", "jump", "circle", "screw", "bend", "arc", "pendulum", "knee-up", "right-angle", "wave", "slow", "hello", "no-motion", "wheel", "contact", "run"]; |
|
32
|
26 |
|
|
|
27 |
this.annotations = this.annotationsFilter(this.source.getAnnotations(), this.gestures, this.isGesture); |
|
|
28 |
|
|
|
29 |
// for(var a = 0 ; a < this.annotations.length ; a++) |
|
|
30 |
// console.log("A : " + this.annotations[a].annotationType.contents.title); |
|
31
|
31 |
}; |
|
|
32 |
|
|
|
33 |
IriSP.Widgets.Timeline.prototype = new IriSP.Widgets.Widget(); |
|
|
34 |
|
|
32
|
35 |
IriSP.Widgets.Timeline.prototype.isGesture = function(element, index, array) |
|
|
36 |
{ |
|
|
37 |
return ($.inArray(element.annotationType.contents.title, array) > -1); |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
//Fonction de filtrage de tableaux |
|
|
41 |
IriSP.Widgets.Timeline.prototype.annotationsFilter = function(annotations, gestures, fun /*, thisp*/) |
|
|
42 |
{ |
|
|
43 |
var len = annotations.length; |
|
|
44 |
if (typeof fun != "function") |
|
|
45 |
throw new TypeError(); |
|
|
46 |
|
|
|
47 |
var res = new Array(); |
|
|
48 |
var thisp = arguments[1]; |
|
|
49 |
for (var i = 0; i < len; i++) |
|
|
50 |
{ |
|
|
51 |
if (i in annotations) |
|
|
52 |
{ |
|
|
53 |
var val = annotations[i]; // in case fun mutates this |
|
|
54 |
if (fun.call(thisp, val, i, gestures)) |
|
|
55 |
{ |
|
|
56 |
res.push(val); |
|
|
57 |
} |
|
|
58 |
} |
|
|
59 |
} |
|
|
60 |
return res; |
|
|
61 |
}; |
|
|
62 |
|
|
31
|
63 |
IriSP.Widgets.Timeline.prototype.defaults = { |
|
|
64 |
minimized_height : 44, |
|
|
65 |
maximized_height : 44, |
|
|
66 |
middle_height: 4, |
|
|
67 |
timelineBorderLength : 6, |
|
|
68 |
minimize_timeout : 1500 // time before minimizing timeline after mouseout |
|
|
69 |
}; |
|
|
70 |
|
|
|
71 |
IriSP.Widgets.Timeline.prototype.draw = function() { |
|
|
72 |
this.$timeline = IriSP.jQuery('<div>') |
|
|
73 |
.addClass("Ldt-Timeline") |
|
|
74 |
.css(this.calculateTimelineCss(this.minimized_height)); |
|
|
75 |
this.$timelineMiddle = IriSP.jQuery('<div>') |
|
|
76 |
.addClass("Ldt-TimelineMiddle") |
|
|
77 |
.css(this.calculateTimelineMiddleCss(this.minimized_height, this.middle_height)); |
|
|
78 |
|
|
|
79 |
/*this.$timelineContainer = IriSP.jQuery('<div>') |
|
|
80 |
.addClass("Ldt-TimelineContainer"); |
|
|
81 |
this.$timelineContainer.append(this.$timeline); |
|
|
82 |
this.$timelineContainer.append(this.$timelineMiddle);*/ |
|
|
83 |
|
|
|
84 |
|
|
|
85 |
this.$.append(this.$timeline); |
|
|
86 |
this.$.append(this.$timelineMiddle); |
|
|
87 |
|
|
|
88 |
var _this = this; |
|
|
89 |
|
|
|
90 |
this.$timeline.slider({ |
|
|
91 |
range: "min", |
|
|
92 |
value: 0, |
|
|
93 |
min: 0, |
|
|
94 |
max: this.source.getDuration().milliseconds, |
|
|
95 |
slide: function(event, ui) { |
|
|
96 |
_this.player.popcorn.currentTime(Math.floor(ui.value/1000)); |
|
|
97 |
_this.player.popcorn.trigger("IriSP.Mediafragment.setHashToTime"); |
|
|
98 |
|
|
|
99 |
// console.log("manual " + _this.previousMarkerIdx); |
|
|
100 |
//On supprime le marqueur précédemment affiché si c'est le cas. |
|
|
101 |
if(_this.previousMarkerIdx > -1) |
|
|
102 |
{ |
|
|
103 |
var annotations = _this.source.getAnnotations(); |
|
|
104 |
// console.log("EXT hide idx " + _this.previousMarkerIdx); |
|
|
105 |
var previousMarker = IriSP.jQuery("#" + annotations[_this.previousMarkerIdx].id.replace(":", "_")); |
|
|
106 |
_this.hideMarkerBig(previousMarker); |
|
|
107 |
// console.log("EXT hide " + _this.previousMarkerIdx); |
|
|
108 |
} |
|
|
109 |
} |
|
|
110 |
}); |
|
|
111 |
|
|
|
112 |
this.$handle = this.$timeline.find('.ui-slider-handle'); |
|
|
113 |
|
|
|
114 |
this.$handle.css(this.calculateHandleCss(this.minimized_height)); |
|
|
115 |
|
|
|
116 |
this.$ |
|
|
117 |
.mouseover(this.functionWrapper("onMouseover")) |
|
|
118 |
.mouseout(this.functionWrapper("onMouseout")); |
|
|
119 |
IriSP.jQuery('body').keypress(function(evt) {_this.keyPress(evt)}); |
|
|
120 |
|
|
|
121 |
this.maximized = false; |
|
|
122 |
this.timeoutId = false; |
|
|
123 |
}; |
|
|
124 |
|
|
|
125 |
/* |
|
|
126 |
* Starts playing the video when it's ready. |
|
|
127 |
*/ |
|
|
128 |
IriSP.Widgets.Timeline.prototype.ready = function() { |
|
|
129 |
this.player.popcorn.play(); |
|
|
130 |
this.processMarkers(); |
|
|
131 |
} |
|
|
132 |
|
|
|
133 |
/* |
|
|
134 |
* Scale a value from [A, B] to [C, D]. |
|
|
135 |
*/ |
|
|
136 |
IriSP.Widgets.Timeline.prototype.scaleIntervals = function(A, B, C, D, val) { |
|
|
137 |
if(C == D) |
|
|
138 |
{ |
|
|
139 |
return C; |
|
|
140 |
} |
|
|
141 |
if(B != A) |
|
|
142 |
{ |
|
|
143 |
return D / (B - A) * (val - A); |
|
|
144 |
} |
|
|
145 |
else |
|
|
146 |
{ |
|
|
147 |
//If A and B have the same sign. |
|
|
148 |
if(A * B > 0) |
|
|
149 |
{ |
|
|
150 |
//If they are positive. |
|
|
151 |
if(A > 0) |
|
|
152 |
{ |
|
|
153 |
return (D - C)/2; |
|
|
154 |
} |
|
|
155 |
else |
|
|
156 |
{ |
|
|
157 |
return (C - D)/2; |
|
|
158 |
} |
|
|
159 |
} |
|
|
160 |
else |
|
|
161 |
{ |
|
|
162 |
return (C + D)/2; |
|
|
163 |
} |
|
|
164 |
} |
|
|
165 |
} |
|
|
166 |
|
|
|
167 |
/* |
|
|
168 |
* Process the markers. |
|
|
169 |
*/ |
|
|
170 |
IriSP.Widgets.Timeline.prototype.processMarkers = function() { |
|
|
171 |
var _this = this; |
|
|
172 |
var markers = ""; |
|
|
173 |
var timelineMiddleTop = this.$timelineMiddle.position().top; |
|
|
174 |
|
|
32
|
175 |
for(var i = 0 ; i < this.annotations.length ; i++) |
|
31
|
176 |
{ |
|
32
|
177 |
markers += "<div class='Ldt-Marker' id='" + this.annotations[i].id.replace(":", "_") + "'></div>"; |
|
31
|
178 |
// console.log(annotations[i].begin.milliseconds); |
|
|
179 |
} |
|
|
180 |
|
|
|
181 |
this.$.append(markers); |
|
|
182 |
var markerHeight = IriSP.jQuery(".Ldt-Marker").height(); |
|
|
183 |
IriSP.jQuery(".Ldt-Marker").css("z-align", "150"); |
|
|
184 |
|
|
32
|
185 |
for(var i = 0 ; i < this.annotations.length ; i++) |
|
31
|
186 |
{ |
|
32
|
187 |
IriSP.jQuery("#" + this.annotations[i].id.replace(":", "_")).css( |
|
31
|
188 |
{ |
|
|
189 |
top: timelineMiddleTop + "px", |
|
32
|
190 |
left: Math.floor(+this.scaleIntervals(0, this.source.getDuration().getSeconds(), 0, this.$timeline.width(), this.annotations[i].begin/1000) + this.$timeline.position().left) + "px", |
|
31
|
191 |
"margin-top": (-_this.$timeline.height()/2 - markerHeight/2) - this.top_epsilon + "px" |
|
|
192 |
}); |
|
|
193 |
} |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
/* |
|
|
197 |
* Place the cursor on the timeline depending on the keytyped. |
|
|
198 |
*/ |
|
|
199 |
IriSP.Widgets.Timeline.prototype.keyPress = function(e) { |
|
|
200 |
var key = this.whichKey(e.which); |
|
|
201 |
var time = 0; |
|
|
202 |
|
|
35
|
203 |
// console.log($(this)); |
|
33
|
204 |
|
|
31
|
205 |
if(key > -1 && key < 11) |
|
|
206 |
{ |
|
|
207 |
time = this.source.getDuration().getSeconds()/10*key; |
|
|
208 |
this.$timeline.slider("value",time); |
|
|
209 |
this.player.popcorn.currentTime(time); |
|
|
210 |
|
|
|
211 |
//On supprime le marqueur précédemment affiché si c'est le cas. |
|
|
212 |
if(this.previousMarkerIdx > -1) |
|
|
213 |
{ |
|
|
214 |
// console.log("EXT hide idx " + this.previousMarkerIdx); |
|
32
|
215 |
var previousMarker = IriSP.jQuery("#" + this.annotations[this.previousMarkerIdx].id.replace(":", "_")); |
|
31
|
216 |
this.hideMarkerBig(previousMarker); |
|
|
217 |
// console.log("EXT hide " + this.previousMarkerIdx); |
|
|
218 |
} |
|
|
219 |
} |
|
|
220 |
|
|
|
221 |
if(key == 11) |
|
|
222 |
{ |
|
|
223 |
if(!this.timelineSelected) |
|
|
224 |
{ |
|
|
225 |
this.currentMode = "TIMELINE"; |
|
|
226 |
this.selectTimeline(); |
|
|
227 |
} |
|
|
228 |
else |
|
|
229 |
{ |
|
|
230 |
this.currentMode = "VIDEO"; |
|
|
231 |
this.deselectTimeline(); |
|
|
232 |
} |
|
|
233 |
} |
|
|
234 |
|
|
|
235 |
if(key == 12) |
|
|
236 |
{ |
|
|
237 |
this.hideMarkersSearch(); |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
if(key == 13) |
|
|
241 |
{ |
|
33
|
242 |
var gesturesStr = ''; |
|
|
243 |
for(var i = 0 ; i < this.gestures.length ; i++) |
|
|
244 |
{ |
|
|
245 |
gesturesStr += this.gestures[i] + ", "; |
|
|
246 |
} |
|
|
247 |
gesturesStr = gesturesStr.substr(0, gesturesStr.length - 2); |
|
|
248 |
|
|
|
249 |
/*if(IriSP.jQuery('#notify_search_1gesture').length > 0) |
|
|
250 |
{ |
|
|
251 |
this.removeSearch1Gesture(); |
|
|
252 |
}*/ |
|
|
253 |
|
|
|
254 |
var typeName = prompt("Please enter a type name among (" + gesturesStr + ").", ""); |
|
|
255 |
|
|
|
256 |
this.notifySearch1Gesture(typeName, "valid"); |
|
|
257 |
|
|
|
258 |
if(typeName != '' || typeName != undefined) |
|
|
259 |
{ |
|
|
260 |
if(_.include(this.gestures, typeName)) |
|
|
261 |
{ |
|
|
262 |
this.currentMode = "SEARCH"; |
|
|
263 |
this.hideMarkersSearch(typeName); |
|
|
264 |
} |
|
|
265 |
else |
|
|
266 |
{ |
|
35
|
267 |
// alert("Unknown gesture type. Operation aborted."); |
|
|
268 |
this.removeSearch1Gesture(); |
|
|
269 |
this.notifySearch1Gesture(typeName, "none"); |
|
33
|
270 |
} |
|
|
271 |
} |
|
31
|
272 |
} |
|
|
273 |
|
|
|
274 |
if(key == 21) |
|
|
275 |
{ |
|
|
276 |
// console.log(this); |
|
|
277 |
if(!this.paused) |
|
|
278 |
{ |
|
|
279 |
this.paused = true; |
|
|
280 |
this.player.popcorn.pause(); |
|
|
281 |
} |
|
|
282 |
else |
|
|
283 |
{ |
|
|
284 |
this.paused = false; |
|
|
285 |
this.player.popcorn.play(); |
|
|
286 |
} |
|
|
287 |
} |
|
|
288 |
} |
|
|
289 |
|
|
|
290 |
/* |
|
|
291 |
* Find the key corresponding to a given code. |
|
|
292 |
*/ |
|
|
293 |
IriSP.Widgets.Timeline.prototype.whichKey = function(code) { |
|
|
294 |
var key; |
|
|
295 |
|
|
|
296 |
console.log(code); |
|
|
297 |
|
|
|
298 |
if(code > 47 && code < 58) |
|
|
299 |
{ |
|
|
300 |
return (code - 48); |
|
|
301 |
} |
|
|
302 |
|
|
|
303 |
if(code == 115 || code == 83) |
|
|
304 |
{ |
|
|
305 |
return 11; |
|
|
306 |
} |
|
|
307 |
|
|
33
|
308 |
//m ou M pour quitter une recherche. |
|
|
309 |
if(code == 109 || code == 77) |
|
31
|
310 |
{ |
|
|
311 |
return 12; |
|
|
312 |
} |
|
|
313 |
|
|
|
314 |
//p ou P pour mettre la vidéo en pause. |
|
|
315 |
if(code == 112 || code == 80) |
|
|
316 |
{ |
|
|
317 |
return 21; |
|
|
318 |
} |
|
|
319 |
|
|
33
|
320 |
//n ou N pour une recherche par type. |
|
|
321 |
if(code == 110 || code == 78) |
|
31
|
322 |
{ |
|
|
323 |
return 13; |
|
|
324 |
} |
|
|
325 |
|
|
|
326 |
switch(code) |
|
|
327 |
{ |
|
|
328 |
case 224: |
|
|
329 |
key = 0; |
|
|
330 |
break; |
|
|
331 |
case 38: |
|
|
332 |
key = 1; |
|
|
333 |
break; |
|
|
334 |
case 233: |
|
|
335 |
key = 2; |
|
|
336 |
break; |
|
|
337 |
case 34: |
|
|
338 |
key = 3; |
|
|
339 |
break; |
|
|
340 |
case 39: |
|
|
341 |
key = 4; |
|
|
342 |
break; |
|
|
343 |
case 40: |
|
|
344 |
key = 5; |
|
|
345 |
break; |
|
|
346 |
case 45: |
|
|
347 |
key = 6; |
|
|
348 |
break; |
|
|
349 |
case 232: |
|
|
350 |
key = 7; |
|
|
351 |
break; |
|
|
352 |
case 95: |
|
|
353 |
key = 8; |
|
|
354 |
break; |
|
|
355 |
case 231: |
|
|
356 |
key = 9; |
|
|
357 |
break; |
|
|
358 |
default: |
|
|
359 |
key = -1; |
|
|
360 |
} |
|
|
361 |
|
|
|
362 |
return key; |
|
|
363 |
} |
|
|
364 |
|
|
|
365 |
IriSP.Widgets.Timeline.prototype.selectTimeline = function() { |
|
|
366 |
this.timelineSelected = true; |
|
|
367 |
this.$timelineBorderUp = "<div class='TL_Borders' id='TL_BorderUp'></div>"; |
|
|
368 |
this.$timelineBorderDown = "<div class='TL_Borders' id='TL_BorderDown'></div>"; |
|
|
369 |
this.$timelineBorderLeft = "<div class='TL_Borders' id='TL_BorderLeft'></div>"; |
|
|
370 |
this.$timelineBorderRight = "<div class='TL_Borders' id='TL_BorderRight'></div>"; |
|
|
371 |
|
|
|
372 |
this.$arrowUp = "<div class='TL_Arrows' id='TL_ArrowUp'></div>"; |
|
|
373 |
this.$arrowDown = "<div class='TL_Arrows' id='TL_ArrowDown'></div>"; |
|
|
374 |
|
|
|
375 |
this.$.append(this.$timelineBorderUp + this.$timelineBorderDown + this.$timelineBorderLeft + this.$timelineBorderRight + this.$arrowUp + this.$arrowDown); |
|
|
376 |
|
|
|
377 |
var timelineTop = IriSP.jQuery("#LdtPlayer").position().top + IriSP.jQuery("#LdtPlayer").height(); |
|
|
378 |
|
|
|
379 |
IriSP.jQuery("#TL_BorderUp").css( |
|
|
380 |
{ |
|
|
381 |
"margin-top": -this.$timeline.height() - this.top_epsilon, |
|
|
382 |
left: this.$timeline.position().left, |
|
|
383 |
width: this.$timeline.width(), |
|
|
384 |
height: this.timelineBorderLength |
|
|
385 |
}); |
|
|
386 |
IriSP.jQuery("#TL_BorderDown").css( |
|
|
387 |
{ |
|
|
388 |
"margin-top": -this.timelineBorderLength - 2 - this.top_epsilon, |
|
|
389 |
left: this.$timeline.position().left, |
|
|
390 |
width: this.$timeline.width(), |
|
|
391 |
height: this.timelineBorderLength |
|
|
392 |
}); |
|
|
393 |
IriSP.jQuery("#TL_BorderLeft").css( |
|
|
394 |
{ |
|
|
395 |
"margin-top": -this.$timeline.height() - this.top_epsilon, |
|
|
396 |
left: this.$timeline.position().left, |
|
|
397 |
width: this.timelineBorderLength, |
|
|
398 |
height: this.$timeline.height() |
|
|
399 |
}); |
|
|
400 |
IriSP.jQuery("#TL_BorderRight").css( |
|
|
401 |
{ |
|
|
402 |
"margin-top": -this.$timeline.height() - this.top_epsilon, |
|
|
403 |
left: +this.$timeline.position().left + this.$timeline.width() - this.timelineBorderLength - 2, |
|
|
404 |
width: this.timelineBorderLength, |
|
|
405 |
height: this.$timeline.height() |
|
|
406 |
}); |
|
|
407 |
|
|
|
408 |
IriSP.jQuery("#TL_ArrowUp").css( |
|
|
409 |
{ |
|
|
410 |
"background-image": "url(" + this.imgDir + "arrow_up.png)", |
|
|
411 |
"margin-top": -this.$timeline.height() - IriSP.jQuery("#TL_ArrowUp").height() - this.top_epsilon, |
|
|
412 |
left: this.$timeline.position().left - IriSP.jQuery("#TL_ArrowUp").width()/2, |
|
|
413 |
}); |
|
|
414 |
IriSP.jQuery("#TL_ArrowDown").css( |
|
|
415 |
{ |
|
|
416 |
"background-image": "url(" + this.imgDir + "arrow_down.png)", |
|
|
417 |
"margin-top": -this.timelineBorderLength + this.timelineBorderLength - this.top_epsilon, |
|
|
418 |
left: this.$timeline.position().left - IriSP.jQuery("#TL_ArrowUp").width()/2, |
|
|
419 |
}); |
|
|
420 |
|
|
|
421 |
IriSP.jQuery(".Ldt-Timeline .ui-slider-range").css("background-image", "url(" + this.imgDir + "past_timeline.png)"); |
|
|
422 |
} |
|
|
423 |
|
|
|
424 |
IriSP.Widgets.Timeline.prototype.deselectTimeline = function() { |
|
|
425 |
this.timelineSelected = false; |
|
|
426 |
IriSP.jQuery(".TL_Borders").remove(); |
|
|
427 |
IriSP.jQuery(".TL_Arrows").remove(); |
|
|
428 |
IriSP.jQuery(".Ldt-Timeline .ui-slider-range").css("background-image", "url(" + this.imgDir + "selected_timeline.png)"); |
|
|
429 |
} |
|
|
430 |
|
|
|
431 |
IriSP.Widgets.Timeline.prototype.onTimeupdate = function() { |
|
|
432 |
var _time = this.player.popcorn.currentTime(); |
|
|
433 |
var arrowLeft = Math.floor(+this.scaleIntervals(0, this.source.getDuration().getSeconds(), 0, this.$timeline.width(), _time) + this.$timeline.position().left) - IriSP.jQuery("#TL_ArrowUp").width()/2 + "px"; |
|
|
434 |
|
|
|
435 |
this.$timeline.slider("value",_time*1000); |
|
|
436 |
IriSP.jQuery(".TL_Arrows").css("display", "block"); |
|
|
437 |
IriSP.jQuery("#TL_ArrowUp").css("left", arrowLeft); |
|
|
438 |
IriSP.jQuery("#TL_ArrowDown").css("left", arrowLeft); |
|
|
439 |
// this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: 1000 * _time}); |
|
|
440 |
//Si on a une distance de 500 ms à un marqueur, on l'affiche. |
|
|
441 |
var nearestMarkerIdx = 0; |
|
32
|
442 |
for(var i = 0 ; i < this.annotations.length ; i++) |
|
31
|
443 |
{ |
|
|
444 |
//S'il existe des marqueurs dans l'intervalle de temps actuel (ici 500ms). |
|
32
|
445 |
if(Math.abs(_time*1000 - this.annotations[i].begin.milliseconds) <= 250) |
|
31
|
446 |
{ |
|
|
447 |
// console.log("1) i = " + i + " " + Math.abs(_time*1000 - annotations[i].begin.milliseconds)); |
|
|
448 |
|
|
|
449 |
//On sélectionne le plus proche marqueur (dans les cas où il en existe plusieurs dans l'intervalle des 1s) ou bien le premier marqueur. |
|
32
|
450 |
if(Math.abs(_time*1000 - this.annotations[i].begin.milliseconds) < Math.abs(_time*1000 - this.annotations[nearestMarkerIdx].begin.milliseconds) || i == nearestMarkerIdx) |
|
31
|
451 |
{ |
|
|
452 |
// console.log("2) " + Math.abs(_time*1000 - annotations[i].begin.milliseconds) + " < " + Math.abs(_time*1000 - annotations[nearestMarkerIdx].begin.milliseconds)); |
|
|
453 |
//Si le prochain marqueur se situe après le curseur de lecture, on passe donc au marqueur le plus proche. |
|
32
|
454 |
if(_time*1000 < this.annotations[i].begin.milliseconds) |
|
31
|
455 |
{ |
|
|
456 |
// console.log("3) " + _time*1000 + " < " + annotations[i].begin.milliseconds); |
|
|
457 |
// console.log("4) " + "nearest = " + i); |
|
|
458 |
nearestMarkerIdx = i; |
|
|
459 |
// console.log("5a0) before"); |
|
|
460 |
//S'il y a un changement de marqueur (marqueur actuel différent du précédent). |
|
|
461 |
if(nearestMarkerIdx != this.previousMarkerIdx) |
|
|
462 |
{ |
|
32
|
463 |
var currentMarker = IriSP.jQuery("#" + this.annotations[nearestMarkerIdx].id.replace(":", "_")); |
|
31
|
464 |
//S'il existe un marqueur précédent, on le cache. |
|
|
465 |
if(this.previousMarkerIdx > -1) |
|
|
466 |
{ |
|
|
467 |
// console.log("hide idx " + this.previousMarkerIdx); |
|
32
|
468 |
var previousMarker = IriSP.jQuery("#" + this.annotations[this.previousMarkerIdx].id.replace(":", "_")); |
|
31
|
469 |
this.hideMarkerBig(previousMarker); |
|
|
470 |
// console.log("5a) hide " + this.previousMarkerIdx); |
|
|
471 |
} |
|
|
472 |
|
|
|
473 |
// console.log("5b) show " + nearestMarkerIdx); |
|
32
|
474 |
this.showMarkerBig(currentMarker, this.annotations[nearestMarkerIdx].annotationType.contents.title); |
|
31
|
475 |
//Mise à jour du marqueur précédent s'il y a un changement. |
|
|
476 |
this.previousMarkerIdx = nearestMarkerIdx; |
|
|
477 |
// console.log("MAJ : " + this.previousMarkerIdx); |
|
|
478 |
} |
|
|
479 |
} |
|
|
480 |
} |
|
|
481 |
// nearestMarker = (Math.abs(_time*1000 - annotations[i].begin.milliseconds) < Math.abs(_time*1000 - annotations[nearestMarker].begin.milliseconds) && annotations[i].begin.milliseconds >= annotations[nearestMarker].begin.milliseconds && annotations[i].begin.milliseconds >= _time*1000) ? i : nearestMarker; |
|
|
482 |
this.currentMarkerIdx = nearestMarkerIdx; |
|
|
483 |
// this.showMarkerBig(IriSP.jQuery("#" + annotations[i].id.replace(":", "_")), annotations[i].annotationType.contents.title); |
|
|
484 |
} |
|
|
485 |
} |
|
|
486 |
} |
|
|
487 |
|
|
|
488 |
IriSP.Widgets.Timeline.prototype.timeDisplayUpdater = function() { |
|
|
489 |
var _time = this.player.popcorn.currentTime(); |
|
|
490 |
var arrowLeft = Math.floor(+this.scaleIntervals(0, this.source.getDuration().getSeconds(), 0, this.$timeline.width(), _time) + this.$timeline.position().left) - |
|
|
491 |
this.$timeline.slider("value",_time*1000); |
|
|
492 |
|
|
|
493 |
IriSP.jQuery(".TL_Arrows").css("display", "block"); |
|
|
494 |
IriSP.jQuery("#TL_ArrowUp").css("left", arrowLeft); |
|
|
495 |
IriSP.jQuery("#TL_ArrowDown").css("left", arrowLeft); |
|
|
496 |
// this.player.popcorn.trigger("IriSP.Arrow.updatePosition",{widget: this.type, time: 1000 * _time}); |
|
|
497 |
} |
|
|
498 |
|
|
|
499 |
IriSP.Widgets.Timeline.prototype.onMouseover = function() { |
|
|
500 |
/*if (this.timeoutId) { |
|
|
501 |
window.clearTimeout(this.timeoutId); |
|
|
502 |
this.timeoutId = false; |
|
|
503 |
} |
|
|
504 |
if (!this.maximized) { |
|
|
505 |
this.animateToHeight(this.maximized_height); |
|
|
506 |
this.maximized = true; |
|
|
507 |
}*/ |
|
|
508 |
} |
|
|
509 |
|
|
|
510 |
IriSP.Widgets.Timeline.prototype.onMouseout = function() { |
|
|
511 |
/*if (this.timeoutId) { |
|
|
512 |
window.clearTimeout(this.timeoutId); |
|
|
513 |
this.timeoutId = false; |
|
|
514 |
} |
|
|
515 |
var _this = this; |
|
|
516 |
this.timeoutId = window.setTimeout(function() { |
|
|
517 |
if (_this.maximized) { |
|
|
518 |
_this.animateToHeight(_this.minimized_height); |
|
|
519 |
_this.maximized = false; |
|
|
520 |
} |
|
|
521 |
_this.timeoutId = false; |
|
|
522 |
}, this.minimize_timeout);*/ |
|
|
523 |
|
|
|
524 |
} |
|
|
525 |
|
|
|
526 |
IriSP.Widgets.Timeline.prototype.animateToHeight = function(_height) { |
|
|
527 |
/*this.$timeline.stop().animate( |
|
|
528 |
this.calculateTimelineCss(_height), |
|
|
529 |
500, |
|
|
530 |
function() { |
|
|
531 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
532 |
}); |
|
|
533 |
this.$handle.stop().animate( |
|
|
534 |
this.calculateHandleCss(_height), |
|
|
535 |
500, |
|
|
536 |
function() { |
|
|
537 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
538 |
});*/ |
|
|
539 |
} |
|
|
540 |
|
|
|
541 |
IriSP.Widgets.Timeline.prototype.calculateTimelineCss = function(_size) { |
|
|
542 |
var middleWidth = this.player.config.gui.width; |
|
|
543 |
return { |
|
|
544 |
position: "absolute", |
|
|
545 |
top: "0px", |
|
|
546 |
left: "0px", |
|
|
547 |
width: middleWidth + "px", |
|
|
548 |
height: _size + "px", |
|
|
549 |
"margin-top": (-this.minimized_height - this.top_epsilon) + "px", |
|
|
550 |
"z-align": "50" |
|
|
551 |
}; |
|
|
552 |
} |
|
|
553 |
|
|
|
554 |
IriSP.Widgets.Timeline.prototype.calculateTimelineMiddleCss = function(_size, _middleSize) { |
|
|
555 |
var middleWidth = this.player.config.gui.width; |
|
|
556 |
return { |
|
|
557 |
position: "absolute", |
|
|
558 |
top: "0px", |
|
|
559 |
left: "0px", |
|
|
560 |
width: middleWidth + "px", |
|
|
561 |
height: _middleSize + "px", |
|
|
562 |
"margin-top": (-this.minimized_height/2 - _middleSize/2 - this.top_epsilon) + "px", |
|
|
563 |
"z-align": "100" |
|
|
564 |
}; |
|
|
565 |
} |
|
|
566 |
|
|
|
567 |
IriSP.Widgets.Timeline.prototype.calculateHandleCss = function(_size) { |
|
|
568 |
return { |
|
|
569 |
position: "absolute", |
|
|
570 |
top: "0px", |
|
|
571 |
left: "0px", |
|
|
572 |
height: (2 + _size) + "px", |
|
|
573 |
width: (2 + _size) + "px", |
|
|
574 |
"margin-left": -Math.ceil(2 + _size / 2) + "px", |
|
|
575 |
"z-align": "60" |
|
|
576 |
} |
|
|
577 |
} |
|
|
578 |
|
|
|
579 |
IriSP.Widgets.Timeline.prototype.showMarkerBig = function(marker, type) { |
|
|
580 |
// console.log("avant"); |
|
|
581 |
if(this.markerBigShown) |
|
|
582 |
{ |
|
|
583 |
return; |
|
|
584 |
} |
|
|
585 |
// console.log("apres"); |
|
|
586 |
|
|
|
587 |
clearTimeout(this.hideTimeout); |
|
|
588 |
|
|
|
589 |
var _this = this; |
|
|
590 |
|
|
32
|
591 |
var markerTop, markerLeft; |
|
|
592 |
|
|
|
593 |
if(marker.position() == null) |
|
|
594 |
{ |
|
|
595 |
markerTop = 0; |
|
|
596 |
markerLeft = 0; |
|
|
597 |
} |
|
|
598 |
else |
|
|
599 |
{ |
|
|
600 |
markerTop = marker.position().top; |
|
|
601 |
markerLeft = marker.position().left; |
|
|
602 |
} |
|
|
603 |
|
|
|
604 |
var markerWidth = marker.width(), markerHeight = marker.height(); |
|
31
|
605 |
|
|
|
606 |
this.markerBigShown = true; |
|
|
607 |
var markerBig = "<div class='TL_MarkersBig' id='MB_Text'>" + type + "<div class='TL_MarkersBig' id='MB_Spike'></div></div><div class='TL_MarkersBig' id='MB_Pic'></div>"; |
|
|
608 |
this.$.append(markerBig); |
|
|
609 |
|
|
|
610 |
var markerBigText = IriSP.jQuery("#MB_Text"); |
|
|
611 |
var markerBigSpike = IriSP.jQuery("#MB_Spike"); |
|
|
612 |
var markerBigPic = IriSP.jQuery("#MB_Pic"); |
|
|
613 |
|
|
|
614 |
var markerBigTextWidth = markerBigText.outerWidth(), markerBigTextHeight = markerBigText.outerHeight(); |
|
|
615 |
var markerBigSpikeWidth = markerBigSpike.width(), markerBigSpikeHeight = markerBigSpike.height(); |
|
|
616 |
var markerBigPicWidth = markerBigPic.width(), markerBigPicHeight = markerBigPic.height(); |
|
|
617 |
var markerBigPicTop = +parseFloat(marker.css("margin-top")) + markerHeight, markerBigPicLeft = (markerLeft - markerBigPicWidth/2 + markerWidth/2); |
|
|
618 |
var markerBigTextTop = (parseFloat(marker.css("margin-top")) - markerBigTextHeight - markerBigSpikeHeight), markerBigTextLeft = (markerLeft - (markerBigTextWidth - markerBigSpikeWidth)/2); |
|
|
619 |
var markerBigSpikeLeft = ((markerBigTextWidth - markerBigSpikeWidth)/2); |
|
|
620 |
|
|
|
621 |
marker.css("background-image", "url(" + this.imgDir + "selected_marker.png)"); |
|
|
622 |
IriSP.jQuery("#MB_Text").css( |
|
|
623 |
{ |
|
|
624 |
top: markerBigTextTop, |
|
|
625 |
left: markerBigTextLeft |
|
|
626 |
}); |
|
|
627 |
IriSP.jQuery("#MB_Spike").css( |
|
|
628 |
{ |
|
|
629 |
left: markerBigSpikeLeft |
|
|
630 |
}); |
|
|
631 |
IriSP.jQuery("#MB_Pic").css( |
|
|
632 |
{ |
|
|
633 |
"background-image": "url(" + this.markersDir + type + ".png)", |
|
|
634 |
top: markerBigPicTop, |
|
|
635 |
left: markerBigPicLeft |
|
|
636 |
}); |
|
|
637 |
|
|
|
638 |
IriSP.jQuery(".TL_MarkersBig").fadeTo(this.markerShowTime, "1"); |
|
|
639 |
|
|
|
640 |
//On rajoute un timeout pour supprimer le marqueur après un certain temps. |
|
|
641 |
this.hideTimeout = setTimeout(function() |
|
|
642 |
{ |
|
|
643 |
_this.hideMarkerBig(marker); |
|
|
644 |
}, this.markerLastTime); |
|
|
645 |
} |
|
|
646 |
|
|
|
647 |
IriSP.Widgets.Timeline.prototype.hideMarkerBig = function(marker) { |
|
|
648 |
if(!this.markerBigShown) |
|
|
649 |
{ |
|
|
650 |
return; |
|
|
651 |
} |
|
|
652 |
|
|
|
653 |
this.currentMarker = -1; |
|
|
654 |
this.markerBigShown = false; |
|
|
655 |
marker.css("background-image", "url(" + this.imgDir + "marker.png)"); |
|
|
656 |
|
|
|
657 |
IriSP.jQuery(".TL_MarkersBig").fadeOut(this.markerShowTime).remove(); |
|
|
658 |
} |
|
|
659 |
|
|
|
660 |
/* |
|
|
661 |
* Affiche le bas des marqueurs correspondants à la recherche. |
|
|
662 |
*/ |
|
|
663 |
IriSP.Widgets.Timeline.prototype.showMarkersSearchByType = function(type) { |
|
|
664 |
//Si on est en mode SEARCH. |
|
|
665 |
if(this.currentMode != "SEARCH") |
|
|
666 |
{ |
|
|
667 |
return; |
|
|
668 |
} |
|
|
669 |
|
|
|
670 |
var _this = this; |
|
|
671 |
|
|
|
672 |
//On récupère les annotations. |
|
|
673 |
var markersSearch = "", markersPicSearch = ""; |
|
|
674 |
//Pour chaque annotation, on ajoute un double. |
|
32
|
675 |
for(var i = 0 ; i < this.annotations.length ; i++) |
|
31
|
676 |
{ |
|
|
677 |
//Si elle correspond à la recherche. |
|
32
|
678 |
if(this.annotations[i].annotationType.contents.title == type) |
|
31
|
679 |
{ |
|
|
680 |
//On récupère le marqueur associé à l'annotation. |
|
32
|
681 |
var markerId = this.annotations[i].id.replace(":", "_"); |
|
31
|
682 |
|
|
|
683 |
markersSearch += "<div class='search_Marker' id='search_Marker_" + markerId + "'></div>"; |
|
|
684 |
markersPicSearch += "<div class='search_MBPic' id='search_Pic_" + markerId + "'></div>"; |
|
|
685 |
} |
|
|
686 |
} |
|
|
687 |
|
|
|
688 |
this.$.append(markersSearch + markersPicSearch); |
|
|
689 |
|
|
|
690 |
//On place chaque double. |
|
32
|
691 |
for(var i = 0 ; i < this.annotations.length ; i++) |
|
31
|
692 |
{ |
|
|
693 |
//Si elle correspond à la recherche. |
|
32
|
694 |
if(this.annotations[i].annotationType.contents.title == type) |
|
31
|
695 |
{ |
|
32
|
696 |
var markerId = this.annotations[i].id.replace(":", "_"), marker = IriSP.jQuery("#" + markerId); |
|
31
|
697 |
var markerTop = marker.position().top, markerLeft = marker.position().left, markerWidth = marker.width(), markerHeight = marker.height(); |
|
|
698 |
var markerBigPicWidth = parseFloat(IriSP.jQuery(".search_MBPic").css("width")), markerBigPicHeight = parseFloat(IriSP.jQuery(".search_MBPic").css("height")), markerBigPicTop = +parseFloat(marker.css("margin-top")) + markerHeight, markerBigPicLeft = (markerLeft - markerBigPicWidth/2 + markerWidth/2); |
|
|
699 |
|
|
|
700 |
// console.log(markerLeft + " - " + IriSP.jQuery(".search_MBPic").css("width") + " " + markerBigPicWidth + "/2 " + markerWidth + "/2"); |
|
|
701 |
|
|
|
702 |
IriSP.jQuery("#search_Pic_" + markerId).css( |
|
|
703 |
{ |
|
|
704 |
position: "absolute", |
|
|
705 |
"background-image": "url(" + this.markersDir + type + ".png)", |
|
|
706 |
top: markerBigPicTop, |
|
|
707 |
left: markerBigPicLeft, |
|
|
708 |
"z-index": "300" |
|
|
709 |
}).fadeTo(this.markerShowTime, "1"); |
|
|
710 |
|
|
|
711 |
IriSP.jQuery("#search_Marker_" + markerId).css( |
|
|
712 |
{ |
|
|
713 |
position: "absolute", |
|
|
714 |
top: _this.$timelineMiddle.position().top - _this.top_epsilon, |
|
|
715 |
"margin-top": (-_this.$timeline.height()/2 - markerHeight/2), |
|
|
716 |
"background-image": "url(" + this.imgDir + "selected_marker.png)", |
|
|
717 |
//top: markerTop, |
|
|
718 |
left: markerLeft, |
|
|
719 |
"z-index": "300" |
|
|
720 |
}).fadeTo(this.markerShowTime, "1"); |
|
|
721 |
} |
|
|
722 |
} |
|
|
723 |
} |
|
|
724 |
|
|
|
725 |
/* |
|
|
726 |
* Enlever une recherche faite précédemment. |
|
|
727 |
*/ |
|
|
728 |
IriSP.Widgets.Timeline.prototype.hideMarkersSearch = function(type) { |
|
|
729 |
//Si on est en mode SEARCH. |
|
|
730 |
if(this.currentMode != "SEARCH") |
|
|
731 |
{ |
|
|
732 |
return; |
|
|
733 |
} |
|
|
734 |
|
|
35
|
735 |
console.log('(0)'); |
|
|
736 |
|
|
31
|
737 |
var _this = this; |
|
|
738 |
|
|
|
739 |
IriSP.jQuery(".search_MBPic").fadeOut(this.markerShowTime, function() |
|
|
740 |
{ |
|
|
741 |
IriSP.jQuery("div").remove(".search_MBPic"); |
|
|
742 |
}); |
|
|
743 |
IriSP.jQuery(".search_Marker").fadeOut(this.markerShowTime, function() |
|
|
744 |
{ |
|
|
745 |
IriSP.jQuery("div").remove(".search_Marker"); |
|
33
|
746 |
_this.removeSearch1Gesture(); |
|
31
|
747 |
|
|
|
748 |
if(type == undefined) |
|
|
749 |
{ |
|
|
750 |
_this.currentMode = "VIDEO"; |
|
|
751 |
} |
|
|
752 |
else |
|
|
753 |
{ |
|
35
|
754 |
console.log('(1)'); |
|
31
|
755 |
// console.log(_this.currentMode); |
|
|
756 |
_this.showMarkersSearchByType(type); |
|
33
|
757 |
_this.notifySearch1Gesture(type, "valid"); |
|
31
|
758 |
return; |
|
|
759 |
} |
|
|
760 |
}); |
|
|
761 |
|
|
|
762 |
if(IriSP.jQuery(".search_Marker").length == 0 && type != undefined) |
|
|
763 |
{ |
|
35
|
764 |
console.log('(2)'); |
|
|
765 |
this.showMarkersSearchByType(type); |
|
|
766 |
_this.removeSearch1Gesture(); |
|
|
767 |
|
|
|
768 |
if(!_.include(this.gestures, type)) |
|
33
|
769 |
{ |
|
|
770 |
this.notifySearch1Gesture(type, "none"); |
|
|
771 |
} |
|
35
|
772 |
else |
|
|
773 |
{ |
|
|
774 |
_this.notifySearch1Gesture(type, "valid"); |
|
|
775 |
} |
|
31
|
776 |
// console.log(this.currentMode); |
|
|
777 |
} |
|
33
|
778 |
} |
|
|
779 |
|
|
|
780 |
IriSP.Widgets.Timeline.prototype.freePlayer = function() |
|
|
781 |
{ |
|
35
|
782 |
IriSP.jQuery('body').unbind('keypress'); |
|
33
|
783 |
IriSP.jQuery('.notifications').remove(); |
|
|
784 |
} |
|
|
785 |
|
|
|
786 |
/* |
|
|
787 |
* Affiche la notification de validation/survol de gesture de recherche. |
|
|
788 |
* Mode prend pour valeurs : "valid" ou "hover". |
|
|
789 |
*/ |
|
|
790 |
IriSP.Widgets.Timeline.prototype.notifySearch1Gesture = function(gestureName, mode) |
|
|
791 |
{ |
|
35
|
792 |
// console.log('C'); |
|
33
|
793 |
if(IriSP.jQuery('#notify_search_1gesture').length > 0) |
|
|
794 |
{ |
|
|
795 |
return; |
|
|
796 |
} |
|
|
797 |
|
|
|
798 |
var _this = this; |
|
|
799 |
|
|
|
800 |
//On spécifie les notifications en div. |
|
|
801 |
var notification_search_1gesture = "<div id='notify_search_1gesture' class='notifications'></div>"; |
|
|
802 |
|
|
|
803 |
//On les ajoute à la mosaïque. |
|
|
804 |
$('#mainPanel').append(notification_search_1gesture); |
|
|
805 |
|
|
35
|
806 |
// console.log(this.player.config.gui.zoomTop + " " + this.player.config.gui.zoomLeft); |
|
33
|
807 |
|
|
|
808 |
//On calcule leurs coordonnées et dimensions. |
|
|
809 |
var notify_width = $('.notifications').width(), notify_height = $('.notifications').height(); |
|
|
810 |
var notify_margin = parseInt($('.notifications').css('margin')); |
|
|
811 |
var point_left = $(window).width() / 2 - (notify_width) / 2 - notify_margin; |
|
|
812 |
|
|
|
813 |
if(_.include(this.gestures, gestureName)) |
|
|
814 |
{ |
|
35
|
815 |
IriSP.jQuery('#notify_search_1gesture').css('background-image', 'url("./pictos/big/' + mode + '/' + gestureName + '.png")'); |
|
33
|
816 |
} |
|
|
817 |
else if(mode == 'none') |
|
|
818 |
{ |
|
|
819 |
IriSP.jQuery('#notify_search_1gesture').css('background-image', 'url("./pictos/big/normal/inconnu.png")'); |
|
|
820 |
} |
|
|
821 |
|
|
|
822 |
if(mode != 'none') |
|
|
823 |
{ |
|
|
824 |
IriSP.jQuery('#notify_search_1gesture').mouseover(function() |
|
|
825 |
{ |
|
|
826 |
IriSP.jQuery(this).css('background-image', 'url("./pictos/big/hover/' + gestureName + '.png")'); |
|
|
827 |
}).mouseout(function() |
|
|
828 |
{ |
|
|
829 |
IriSP.jQuery(this).css('background-image', 'url("./pictos/big/valid/' + gestureName + '.png")'); |
|
|
830 |
}).click(function() |
|
|
831 |
{ |
|
|
832 |
_this.removeSearch1Gesture(); |
|
|
833 |
_this.hideMarkersSearch(); |
|
|
834 |
}); |
|
|
835 |
} |
|
|
836 |
|
|
|
837 |
var notifyTop = this.player.config.gui.zoomTop, notifyLeft = this.player.config.gui.zoomLeft; |
|
|
838 |
|
|
|
839 |
//On les positionne. |
|
|
840 |
$('#notify_search_1gesture').css( |
|
|
841 |
{ |
|
|
842 |
top: -notifyTop, |
|
|
843 |
left: -notifyLeft + (IriSP.jQuery(window).width() - notify_width) / 2 |
|
|
844 |
}); |
|
|
845 |
|
|
|
846 |
//On les fait apparaître. |
|
|
847 |
$('.notifications').css( |
|
|
848 |
{ |
|
|
849 |
opacity: "0.9" |
|
|
850 |
}); |
|
|
851 |
} |
|
|
852 |
|
|
|
853 |
/* |
|
|
854 |
* Supprime la notification de recherche de gesture. |
|
|
855 |
*/ |
|
|
856 |
IriSP.Widgets.Timeline.prototype.removeSearch1Gesture = function() |
|
|
857 |
{ |
|
35
|
858 |
// console.log('R'); |
|
|
859 |
// console.trace(); |
|
33
|
860 |
IriSP.jQuery('#notify_search_1gesture').remove(); |
|
31
|
861 |
} |