|
22
|
1 |
IriSP.Hashcut = function() { |
|
|
2 |
|
|
|
3 |
/* Load Media List */ |
|
|
4 |
|
|
|
5 |
var directory = new IriSP.Model.Directory(), |
|
|
6 |
project = directory.remoteSource({ |
|
|
7 |
url: "data/bpidata.json", |
|
|
8 |
serializer: IriSP.serializers.medialist |
|
|
9 |
}), |
|
|
10 |
mediatemplate = '<li class="item-video" data-media-id="{{id}}"><img src="{{thumbnail}}" alt="{{title}}" />' |
|
|
11 |
+ '<span class="video-info"><span class="title-video">{{title}}</span><span class="author">{{description}}</span>' |
|
|
12 |
+ '<span class="time-length">Durée : <span>{{duration}}</span></span></span></li>'; |
|
|
13 |
|
|
|
14 |
/* Fill left column with Media List */ |
|
|
15 |
|
|
|
16 |
project.onLoad(function() { |
|
|
17 |
var html = ''; |
|
|
18 |
project.getMedias().forEach(function(_m) { |
|
|
19 |
html += Mustache.to_html(mediatemplate, _m); |
|
13
|
20 |
}); |
|
22
|
21 |
$(".col-left .list-video").html(html); |
|
|
22 |
}); |
|
|
23 |
|
|
|
24 |
/* Search Media with left column form */ |
|
|
25 |
|
|
|
26 |
$(".col-left input").on("keyup change input paste", function() { |
|
|
27 |
var val = $(this).val(); |
|
|
28 |
if (val) { |
|
|
29 |
var find = IriSP.Model.regexpFromTextOrArray(val, true), |
|
|
30 |
replace = IriSP.Model.regexpFromTextOrArray(val, false); |
|
|
31 |
} |
|
|
32 |
$(".col-left .item-video").each(function() { |
|
|
33 |
var li = $(this), |
|
|
34 |
title = $(this).find(".title-video"), |
|
|
35 |
titletext = title.text(); |
|
|
36 |
if (val && find.test(titletext)) { |
|
|
37 |
title.html(titletext.replace(replace, '<span style="background: yellow;">$1</span>')); |
|
|
38 |
li.show(); |
|
|
39 |
} else { |
|
|
40 |
title.text(titletext); |
|
|
41 |
if (val) { |
|
|
42 |
li.hide(); |
|
13
|
43 |
} else { |
|
22
|
44 |
li.show(); |
|
13
|
45 |
} |
|
22
|
46 |
} |
|
|
47 |
}) |
|
|
48 |
}); |
|
|
49 |
|
|
|
50 |
/* Slider */ |
|
|
51 |
|
|
23
|
52 |
var timeSlider = $(".Ldt-Slider"), |
|
|
53 |
slidersRange = 920; |
|
22
|
54 |
timeSlider.slider({ |
|
|
55 |
range: "min", |
|
|
56 |
value: 0, |
|
|
57 |
min: 0, |
|
23
|
58 |
max: slidersRange, |
|
22
|
59 |
slide: function(event, ui) { |
|
23
|
60 |
if (currentMedia) { |
|
|
61 |
var t = currentMedia.duration * ui.value / slidersRange; |
|
|
62 |
currentMedia.setCurrentTime(t); |
|
|
63 |
} |
|
22
|
64 |
} |
|
|
65 |
}); |
|
|
66 |
|
|
|
67 |
var timeSliderHandle = timeSlider.find('.ui-slider-handle'), |
|
|
68 |
timeSliderMaximized = false, |
|
|
69 |
timeSliderTimeoutId = false, |
|
|
70 |
timeSliderMinimizedHeight = 4, |
|
|
71 |
timeSliderMaximizedHeight = 10, |
|
|
72 |
timeSliderTimeoutDuration = 1500, |
|
|
73 |
timeTooltip = $(".Ldt-Slider-Time"); |
|
|
74 |
|
|
|
75 |
timeSlider.css(calculateSliderCss(timeSliderMinimizedHeight)); |
|
|
76 |
timeSliderHandle.css(calculateHandleCss(timeSliderMinimizedHeight)); |
|
|
77 |
|
|
|
78 |
function timeSliderMouseOver() { |
|
|
79 |
if (timeSliderTimeoutId) { |
|
|
80 |
window.clearTimeout(timeSliderTimeoutId); |
|
|
81 |
timeSliderTimeoutId = false; |
|
|
82 |
} |
|
|
83 |
if (!timeSliderMaximized) { |
|
|
84 |
timeSliderAnimateToHeight(timeSliderMaximizedHeight); |
|
|
85 |
timeSliderMaximized = true; |
|
|
86 |
} |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
function timeSliderMouseOut() { |
|
|
90 |
timeTooltip.hide(); |
|
|
91 |
if (timeSliderTimeoutId) { |
|
|
92 |
clearTimeout(timeSliderTimeoutId); |
|
|
93 |
timeSliderTimeoutId = false; |
|
|
94 |
} |
|
|
95 |
timeSliderTimeoutId = setTimeout(function() { |
|
|
96 |
if (timeSliderMaximized) { |
|
|
97 |
timeSliderAnimateToHeight(timeSliderMinimizedHeight); |
|
|
98 |
timeSliderMaximized = false; |
|
|
99 |
} |
|
|
100 |
timeSliderTimeoutId = false; |
|
|
101 |
}, timeSliderTimeoutDuration); |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
timeSlider |
|
|
105 |
.mouseover(function() { |
|
|
106 |
timeTooltip.show(); |
|
|
107 |
timeSliderMouseOver(); |
|
|
108 |
}) |
|
|
109 |
.mouseout(timeSliderMouseOut) |
|
|
110 |
.mousemove(function(_e) { |
|
|
111 |
var _x = _e.pageX - timeSlider.offset().left, |
|
23
|
112 |
_t = new IriSP.Model.Time( |
|
|
113 |
currentMedia ? currentMedia.duration * _x / timeSlider.width() : 0 |
|
|
114 |
); |
|
22
|
115 |
timeTooltip.text(_t.toString()).css("left",_x); |
|
15
|
116 |
}); |
|
22
|
117 |
|
|
|
118 |
$(".Ldt-Ctrl").mouseover(timeSliderMouseOver).mouseout(timeSliderMouseOut); |
|
|
119 |
|
|
|
120 |
function timeSliderAnimateToHeight(_height) { |
|
|
121 |
timeSlider.stop().animate( |
|
|
122 |
calculateSliderCss(_height), |
|
|
123 |
500, |
|
|
124 |
function() { |
|
|
125 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
126 |
}); |
|
|
127 |
timeSliderHandle.stop().animate( |
|
|
128 |
calculateHandleCss(_height), |
|
|
129 |
500, |
|
|
130 |
function() { |
|
|
131 |
IriSP.jQuery(this).css("overflow","visible"); |
|
|
132 |
}); |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
function calculateSliderCss(_size) { |
|
|
136 |
return { |
|
|
137 |
height: _size + "px", |
|
|
138 |
"margin-top": (timeSliderMinimizedHeight - _size) + "px" |
|
|
139 |
}; |
|
|
140 |
} |
|
|
141 |
|
|
|
142 |
function calculateHandleCss(_size) { |
|
|
143 |
return { |
|
|
144 |
height: (2 + _size) + "px", |
|
|
145 |
width: (2 + _size) + "px", |
|
|
146 |
"margin-left": -Math.ceil(2 + _size / 2) + "px" |
|
18
|
147 |
} |
|
22
|
148 |
} |
|
|
149 |
|
|
|
150 |
/* Controller Widget */ |
|
|
151 |
|
|
|
152 |
var volBlock = $(".Ldt-Ctrl-Volume-Control"); |
|
|
153 |
$('.Ldt-Ctrl-Sound') |
|
23
|
154 |
.click(function(){}) //TODO: Add Mute and Volume Handlers |
|
22
|
155 |
.mouseover(function() { |
|
|
156 |
volBlock.show(); |
|
|
157 |
}) |
|
|
158 |
.mouseout(function() { |
|
|
159 |
volBlock.hide(); |
|
18
|
160 |
}); |
|
22
|
161 |
volBlock.mouseover(function() { |
|
|
162 |
volBlock.show(); |
|
|
163 |
}).mouseout(function() { |
|
|
164 |
volBlock.hide(); |
|
|
165 |
}); |
|
|
166 |
|
|
|
167 |
var volBar = $(".Ldt-Ctrl-Volume-Bar"); |
|
|
168 |
volBar.slider({ |
|
|
169 |
slide: function(event, ui) { |
|
|
170 |
volBar.attr("title",'Volume : ' + ui.value + '%'); |
|
|
171 |
//_this.media.setVolume(ui.value / 100); |
|
|
172 |
}, |
|
|
173 |
stop: function() { |
|
|
174 |
// IriSP.Widgets.Controller.prototype.volumeUpdater |
|
|
175 |
} |
|
|
176 |
}); |
|
|
177 |
|
|
23
|
178 |
$(".Ldt-Ctrl-Play").click(function() { |
|
|
179 |
if (currentMedia) { |
|
|
180 |
if (currentMedia.getPaused()) { |
|
|
181 |
currentMedia.play(); |
|
|
182 |
} else { |
|
|
183 |
currentMedia.pause(); |
|
|
184 |
} |
|
|
185 |
} |
|
|
186 |
}); |
|
|
187 |
|
|
|
188 |
/* Slice Widget */ |
|
|
189 |
var sliceSlider = $(".Ldt-Slice"), |
|
|
190 |
sliceStartTime; |
|
|
191 |
|
|
|
192 |
function setTangles(sliderValues) { |
|
|
193 |
//TODO: Move to Annotation.on("changebounds") |
|
|
194 |
if (currentMedia) { |
|
|
195 |
startTime = new IriSP.Model.Time(currentMedia.duration * sliderValues[0] / slidersRange), |
|
|
196 |
endTime = new IriSP.Model.Time(currentMedia.duration * sliderValues[1] / slidersRange), |
|
|
197 |
duration = new IriSP.Model.Time(endTime - startTime); |
|
|
198 |
$(".tangle-start").text(startTime.toString()).attr("data-milliseconds",startTime.milliseconds); |
|
|
199 |
$(".tangle-end").text(endTime.toString()).attr("data-milliseconds",endTime.milliseconds); |
|
|
200 |
$(".tangle-duration").text(duration.toString()).attr("data-milliseconds",duration.milliseconds); |
|
|
201 |
} |
|
|
202 |
} |
|
|
203 |
|
|
|
204 |
sliceSlider.slider({ |
|
|
205 |
range: true, |
|
|
206 |
values: [0, slidersRange], |
|
|
207 |
min: 0, |
|
|
208 |
max: slidersRange, |
|
|
209 |
change: function(event, ui) { |
|
|
210 |
setTangles(ui.values); // Not the right place to put it |
|
|
211 |
}, |
|
|
212 |
start: function() { |
|
|
213 |
if (currentMedia) { |
|
|
214 |
if (!currentMedia.getPaused()) { |
|
|
215 |
currentMedia.pause(); |
|
|
216 |
} |
|
|
217 |
// sliceStartTime = currentMedia.getCurrentTime(); |
|
|
218 |
} |
|
|
219 |
}, |
|
|
220 |
slide: function(event, ui) { |
|
|
221 |
if (currentMedia) { |
|
|
222 |
var t = currentMedia.duration * ui.value / slidersRange; |
|
|
223 |
currentMedia.setCurrentTime(t); |
|
|
224 |
} |
|
|
225 |
setTangles(ui.values); |
|
|
226 |
}, |
|
|
227 |
stop: function() { |
|
|
228 |
if (currentMedia && sliceStartTime) { |
|
|
229 |
// currentMedia.setCurrentTime(sliceStartTime); |
|
|
230 |
} |
|
|
231 |
} |
|
|
232 |
}); |
|
|
233 |
|
|
|
234 |
sliceSlider.find(".ui-slider-handle:first").addClass("Ldt-Slice-left-handle"); |
|
|
235 |
sliceSlider.find(".ui-slider-handle:last").addClass("Ldt-Slice-right-handle"); |
|
|
236 |
|
|
|
237 |
/* UI Events */ |
|
|
238 |
|
|
|
239 |
function onCurrentMediaPlay() { |
|
|
240 |
$(".Ldt-Ctrl-Play") |
|
|
241 |
.attr("title", "Pause") |
|
|
242 |
.removeClass("Ldt-Ctrl-Play-PlayState") |
|
|
243 |
.addClass("Ldt-Ctrl-Play-PauseState") |
|
|
244 |
} |
|
|
245 |
|
|
|
246 |
function onCurrentMediaPause() { |
|
|
247 |
$(".Ldt-Ctrl-Play") |
|
|
248 |
.attr("title", "Lecture") |
|
|
249 |
.removeClass("Ldt-Ctrl-Play-PauseState") |
|
|
250 |
.addClass("Ldt-Ctrl-Play-PlayState") |
|
|
251 |
} |
|
|
252 |
|
|
|
253 |
function onCurrentMediaTimeupdate(_time) { |
|
|
254 |
$(".Ldt-Ctrl-Time-Elapsed").text(_time.toString()); |
|
|
255 |
timeSlider.slider("value",slidersRange * _time / currentMedia.duration); |
|
|
256 |
} |
|
|
257 |
|
|
22
|
258 |
/* Set current Media */ |
|
|
259 |
var currentMedia; |
|
|
260 |
|
|
|
261 |
function setMedia(mediaid) { |
|
23
|
262 |
$(".col-left .item-video").removeClass("active"); |
|
|
263 |
$(".tutorial").hide(); |
|
|
264 |
$("video").hide(); |
|
|
265 |
if (currentMedia) { |
|
|
266 |
currentMedia.pause(); |
|
|
267 |
} |
|
22
|
268 |
currentMedia = project.getElement(mediaid); |
|
|
269 |
if (currentMedia.elementType == "media") { |
|
23
|
270 |
$(".col-left .item-video[data-media-id='" + mediaid + "']").addClass("active"); |
|
|
271 |
showSegmentation(); |
|
|
272 |
var currentvideo = $('#video_' + mediaid); |
|
|
273 |
if (!currentvideo.length) { |
|
|
274 |
addMediaPlayer(currentMedia); |
|
|
275 |
currentvideo = $('#video_' + mediaid); |
|
|
276 |
} |
|
|
277 |
$(".tab-media-title").text(currentMedia.title); |
|
|
278 |
sliceSlider.slider("values",[0, slidersRange]); |
|
22
|
279 |
} |
|
23
|
280 |
currentvideo.show(); |
|
|
281 |
$(".Ldt-Ctrl-Time-Total").text(currentMedia.duration.toString()); |
|
|
282 |
onCurrentMediaTimeupdate(currentMedia.getCurrentTime()); |
|
|
283 |
onCurrentMediaPause(); |
|
22
|
284 |
} |
|
|
285 |
|
|
|
286 |
function addMediaPlayer(media) { |
|
23
|
287 |
var videoid = "video_" + media.id, |
|
|
288 |
videoEl = $('<video>'), |
|
|
289 |
width = $(".video").width(), |
|
|
290 |
height = $(".video").height(), |
|
|
291 |
mp4_file = media.video.replace(/\.webm$/i,'.mp4'), |
|
|
292 |
webm_file = media.video.replace(/\.mp4$/i,'.webm'), |
|
|
293 |
mp4_src = $('<source>'), |
|
|
294 |
webm_src = $('<source>'); |
|
|
295 |
mp4_src.attr({ |
|
|
296 |
src: mp4_file, |
|
|
297 |
type: "video/mp4" |
|
|
298 |
}); |
|
|
299 |
webm_src.attr({ |
|
|
300 |
src: webm_file, |
|
|
301 |
type: "video/webm" |
|
|
302 |
}); |
|
|
303 |
videoEl.attr({ |
|
|
304 |
id : videoid, |
|
|
305 |
width : width, |
|
|
306 |
height : height |
|
|
307 |
}).css({ |
|
|
308 |
position : "absolute", |
|
|
309 |
left: 0, |
|
|
310 |
top: 0, |
|
|
311 |
width : width, |
|
|
312 |
height : height |
|
|
313 |
}); |
|
|
314 |
videoEl.append(mp4_src).append(webm_src); |
|
|
315 |
$(".video").append(videoEl); |
|
|
316 |
|
|
|
317 |
var popcorn = Popcorn("#" + videoid); |
|
|
318 |
|
|
|
319 |
// Binding functions to Popcorn |
|
|
320 |
|
|
|
321 |
media.on("setcurrenttime", function(_milliseconds) { |
|
|
322 |
popcorn.currentTime(_milliseconds / 1000); |
|
|
323 |
}); |
|
|
324 |
|
|
|
325 |
media.on("setvolume", function(_vol) { |
|
|
326 |
popcorn.volume(_vol); |
|
|
327 |
media.volume = _vol; |
|
|
328 |
}); |
|
|
329 |
|
|
|
330 |
media.on("setmuted", function(_muted) { |
|
|
331 |
popcorn.muted(_muted); |
|
|
332 |
media.muted = _muted; |
|
|
333 |
}); |
|
|
334 |
|
|
|
335 |
media.on("setplay", function() { |
|
|
336 |
popcorn.play(); |
|
|
337 |
}); |
|
|
338 |
|
|
|
339 |
media.on("setpause", function() { |
|
|
340 |
popcorn.pause(); |
|
|
341 |
}); |
|
|
342 |
|
|
|
343 |
// Binding Popcorn events to media |
|
|
344 |
|
|
|
345 |
function getVolume() { |
|
|
346 |
media.muted = popcorn.muted(); |
|
|
347 |
media.volume = popcorn.volume(); |
|
|
348 |
} |
|
|
349 |
|
|
|
350 |
popcorn.on("loadedmetadata", function() { |
|
|
351 |
getVolume(); |
|
|
352 |
media.trigger("loadedmetadata"); |
|
|
353 |
media.trigger("volumechange"); |
|
|
354 |
}) |
|
|
355 |
|
|
|
356 |
popcorn.on("timeupdate", function() { |
|
|
357 |
media.trigger("timeupdate", new IriSP.Model.Time(1000*popcorn.currentTime())); |
|
|
358 |
}); |
|
|
359 |
|
|
|
360 |
popcorn.on("volumechange", function() { |
|
|
361 |
getVolume(); |
|
|
362 |
media.trigger("volumechange"); |
|
|
363 |
}) |
|
|
364 |
|
|
|
365 |
popcorn.on("play", function() { |
|
|
366 |
media.trigger("play"); |
|
|
367 |
}); |
|
|
368 |
|
|
|
369 |
popcorn.on("pause", function() { |
|
|
370 |
media.trigger("pause"); |
|
|
371 |
}); |
|
|
372 |
|
|
|
373 |
popcorn.on("seeked", function() { |
|
|
374 |
media.trigger("seeked"); |
|
|
375 |
}); |
|
|
376 |
|
|
|
377 |
// Binding UI Events to Media |
|
|
378 |
|
|
|
379 |
media.on("play", function() { |
|
|
380 |
if (media === currentMedia) { |
|
|
381 |
onCurrentMediaPlay(); |
|
|
382 |
} |
|
|
383 |
}); |
|
|
384 |
|
|
|
385 |
media.on("pause", function() { |
|
|
386 |
if (media === currentMedia) { |
|
|
387 |
onCurrentMediaPause(); |
|
|
388 |
} |
|
|
389 |
}); |
|
|
390 |
|
|
|
391 |
media.on("timeupdate", function(_time) { |
|
|
392 |
if (media === currentMedia) { |
|
|
393 |
onCurrentMediaTimeupdate(_time); |
|
|
394 |
} |
|
|
395 |
}) |
|
18
|
396 |
|
|
13
|
397 |
} |
|
22
|
398 |
/* Click on media items */ |
|
|
399 |
|
|
|
400 |
$(".col-left").on("click", ".item-video", function() { |
|
|
401 |
setMedia($(this).attr("data-media-id")); |
|
|
402 |
}); |
|
12
|
403 |
|
|
22
|
404 |
/* Click on Tabs */ |
|
|
405 |
|
|
|
406 |
function showSegmentation() { |
|
|
407 |
$(".col-middle").removeClass("empty-mode pvw-mode").addClass("segment-mode"); |
|
|
408 |
return false; |
|
|
409 |
} |
|
|
410 |
function showPreview() { |
|
|
411 |
$(".col-middle").removeClass("empty-mode segment-mode").addClass("pvw-mode"); |
|
|
412 |
return false; |
|
|
413 |
} |
|
|
414 |
|
|
|
415 |
$(".tab-pvw").click(showPreview); |
|
|
416 |
|
|
|
417 |
function disableMoveItemVideo() { |
|
|
418 |
$(".organize-segments .top, .organize-segments .bottom").removeClass("disable"); |
|
|
419 |
$(".organize-segments .item-video:last-child .bottom, .organize-segments .item-video:first-child .top").addClass("disable"); |
|
|
420 |
} |
|
|
421 |
|
|
|
422 |
$(".organize-segments").sortable({ |
|
|
423 |
stop : function(){ |
|
|
424 |
disableMoveItemVideo(); |
|
|
425 |
} |
|
|
426 |
}); |
|
|
427 |
|
|
|
428 |
$(".organize-segments .top").click(function(e){ |
|
|
429 |
var currentItem = $(this).parents(".item-video"); |
|
|
430 |
currentItem.insertBefore(currentItem.prev()); |
|
|
431 |
disableMoveItemVideo(); |
|
|
432 |
}); |
|
|
433 |
|
|
|
434 |
$(".organize-segments .bottom").click(function(e){ |
|
|
435 |
var currentItem = $(this).parents(".item-video"); |
|
|
436 |
currentItem.insertAfter(currentItem.next()); |
|
|
437 |
disableMoveItemVideo(); |
|
|
438 |
}); |
|
|
439 |
|
|
23
|
440 |
/* Tangle */ |
|
|
441 |
var activeTangle, |
|
|
442 |
tangleStartX, |
|
|
443 |
tangleStartVal; |
|
|
444 |
$(".time-tangle").mousedown(function(evt) { |
|
|
445 |
activeTangle = $(this); |
|
|
446 |
activeTangle.addClass("active"); |
|
|
447 |
tangleStartVal = +activeTangle.attr("data-milliseconds"); |
|
|
448 |
tangleStartX = evt.pageX; |
|
|
449 |
return false; |
|
|
450 |
}); |
|
|
451 |
$(document) |
|
|
452 |
.mousemove(function(evt) { |
|
|
453 |
if (activeTangle) { |
|
|
454 |
var newval = new IriSP.Model.Time(100 * (evt.pageX - tangleStartX) + tangleStartVal); |
|
|
455 |
activeTangle.text(newval.toString()); |
|
|
456 |
activeTangle.attr("data-milliseconds",newval.milliseconds); |
|
|
457 |
activeTangle.trigger("valuechange", newval); |
|
|
458 |
return false; |
|
|
459 |
} |
|
|
460 |
}) |
|
|
461 |
.mouseup(function() { |
|
|
462 |
if (activeTangle) { |
|
|
463 |
activeTangle.removeClass("active"); |
|
|
464 |
activeTangle = undefined; |
|
|
465 |
} |
|
|
466 |
}) |
|
|
467 |
|
|
13
|
468 |
} |
|
|
469 |
|
|
|
470 |
$(function() { |
|
|
471 |
var hashcut = new IriSP.Hashcut(); |
|
12
|
472 |
}); |