3
|
1 |
var myDir = new IriSP.Model.Directory(), |
|
2 |
myProject = myDir.remoteSource({ |
|
3 |
url: "data/rigoletto.json", |
|
4 |
serializer: IriSP.serializers.ldt |
|
5 |
}); |
|
6 |
|
|
7 |
myProject.onLoad(function() { |
|
8 |
|
|
9 |
$(".project-title").text(myProject.title); |
|
10 |
|
|
11 |
var myMedia = myProject.getCurrentMedia(); |
|
12 |
|
|
13 |
IriSP.htmlPlayer( |
|
14 |
myMedia, |
|
15 |
$(".video-container"), |
|
16 |
{ |
|
17 |
width: 1000, |
|
18 |
height: 560, |
7
|
19 |
autostart: true, |
|
20 |
url_transform: function(src) { |
|
21 |
return [{ |
|
22 |
type: "video/mp4", |
|
23 |
src: src.replace(/\.[\d\w]+$/,'.mp4') |
|
24 |
}, { |
|
25 |
type: "video/webm", |
|
26 |
src: src.replace(/\.[\d\w]+$/,'.webm') |
|
27 |
}]; |
|
28 |
} |
3
|
29 |
} |
|
30 |
); |
|
31 |
|
|
32 |
myMedia.on("timeupdate", function(t) { |
|
33 |
var progress = $(".progress-indicator"), |
|
34 |
pos = ($(".chapters-bar").width() - 2 * progress.width()) * t / myMedia.duration; |
|
35 |
progress.css("left",pos); |
|
36 |
}); |
|
37 |
myMedia.on("play", function() { |
|
38 |
$(".play-button").addClass("pause"); |
|
39 |
}); |
|
40 |
myMedia.on("pause", function() { |
|
41 |
$(".play-button").removeClass("pause"); |
|
42 |
}); |
|
43 |
|
|
44 |
var tags = myProject.getTags().sortBy(function(t) { |
|
45 |
return - t.getRelated("annotation").length; |
|
46 |
}).slice(0,12), |
|
47 |
tagTemplate = _.template('<li data-tag-id="<%- id %>" class="tag"><%- title %></li>'), |
|
48 |
clickedTag = null, |
|
49 |
lastTag = null; |
|
50 |
|
|
51 |
$(".tags-list").html(tags.map(tagTemplate).join("")); |
|
52 |
|
|
53 |
$("body").click(function() { |
|
54 |
if (clickedTag) { |
6
|
55 |
$(".found").removeClass("found"); |
3
|
56 |
clickedTag = null; |
|
57 |
} |
|
58 |
}); |
|
59 |
|
|
60 |
function showTag(tagId) { |
6
|
61 |
$(".found").removeClass("found"); |
3
|
62 |
var tag = myProject.getElement(tagId); |
|
63 |
if (tag) { |
|
64 |
tag.getRelated("annotation").forEach(function(a) { |
|
65 |
a.trigger("found-tags"); |
|
66 |
}); |
6
|
67 |
$(".tag[data-tag-id="+tagId+"]").addClass("found"); |
3
|
68 |
} |
|
69 |
lastTag = tagId; |
|
70 |
} |
|
71 |
|
|
72 |
$(".tag").hover(function() { |
|
73 |
showTag($(this).attr("data-tag-id")); |
|
74 |
}, function() { |
|
75 |
showTag(clickedTag); |
|
76 |
}).click(function() { |
|
77 |
clickedTag = lastTag; |
|
78 |
return false; |
|
79 |
}); |
|
80 |
|
|
81 |
|
|
82 |
var chapters = myProject.getAnnotationsByTypeTitle("chapitrage"), |
|
83 |
chapterTemplate = _.template( |
|
84 |
'<li class="chapter" style="left: <%- 100*begin/getMedia().duration %>%; width: <%- 100*getDuration()/getMedia().duration %>%;">' |
|
85 |
+ '<div class="chapter-block"></div><div class="chapter-title"><%- title %></div></li>' |
|
86 |
), |
|
87 |
chapterList = $(".chapters-list"), |
|
88 |
hoveredChapter = null, |
|
89 |
currentChapter = null, |
|
90 |
currentChapterI = 0; |
|
91 |
|
|
92 |
function highlightChapter() { |
|
93 |
$(".chapter").removeClass("active"); |
|
94 |
if (hoveredChapter || currentChapter) { |
|
95 |
(hoveredChapter || currentChapter).addClass("active"); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
chapters.forEach(function(chapter, i) { |
|
100 |
var element = $(chapterTemplate(chapter)); |
|
101 |
element.click(function() { |
|
102 |
myMedia.setCurrentTime(chapter.begin); |
|
103 |
}).hover(function() { |
|
104 |
hoveredChapter = element; |
|
105 |
highlightChapter(); |
|
106 |
}, function() { |
|
107 |
hoveredChapter = null; |
|
108 |
highlightChapter(); |
|
109 |
}); |
|
110 |
chapter.on("enter", function() { |
|
111 |
currentChapter = element; |
|
112 |
currentChapterI = i; |
|
113 |
if (i) { |
|
114 |
$(".prev-chapter").removeClass("inactive"); |
|
115 |
} else { |
|
116 |
$(".prev-chapter").addClass("inactive"); |
|
117 |
} |
|
118 |
if (i < chapters.length - 1) { |
|
119 |
$(".next-chapter").removeClass("inactive"); |
|
120 |
} else { |
|
121 |
$(".next-chapter").addClass("inactive"); |
|
122 |
} |
|
123 |
highlightChapter(); |
|
124 |
}); |
|
125 |
chapter.on("leave", function() { |
|
126 |
currentChapter = null; |
|
127 |
highlightChapter(); |
|
128 |
}); |
|
129 |
chapter.on("found-tags", function() { |
6
|
130 |
element.addClass("found"); |
3
|
131 |
}); |
|
132 |
chapterList.append(element); |
|
133 |
}); |
|
134 |
|
|
135 |
$(".prev-chapter").click(function() { |
7
|
136 |
if (currentChapterI) { |
3
|
137 |
myMedia.setCurrentTime(chapters[currentChapterI - 1].begin); |
|
138 |
} |
6
|
139 |
return false; |
3
|
140 |
}); |
|
141 |
$(".next-chapter").click(function() { |
7
|
142 |
if (currentChapterI < chapters.length - 1) { |
3
|
143 |
myMedia.setCurrentTime(chapters[currentChapterI + 1].begin); |
|
144 |
} |
6
|
145 |
return false; |
3
|
146 |
}); |
|
147 |
|
|
148 |
$(".play-button").click(function() { |
|
149 |
if (myMedia.paused) { |
|
150 |
myMedia.play(); |
|
151 |
} else { |
|
152 |
myMedia.pause(); |
|
153 |
} |
6
|
154 |
return false; |
3
|
155 |
}); |
|
156 |
|
2
|
157 |
$(".progress-indicator").draggable({ |
|
158 |
axis: "x", |
3
|
159 |
containment: "parent", |
|
160 |
drag: function(e, ui) { |
|
161 |
var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".chapters-bar").width() - 2 * ui.helper.width() ); |
|
162 |
myMedia.setCurrentTime(t); |
|
163 |
} |
2
|
164 |
}); |
5
|
165 |
|
|
166 |
var pictoTemplate = _.template( |
|
167 |
'<li class="<%- type %>"><span class="picto"><a href="#"></a></span>' |
|
168 |
+ '<span class="picto-title"><%- annotation.title %></span></li>' |
|
169 |
); |
|
170 |
|
|
171 |
var chipTemplate = _.template( |
6
|
172 |
'<li class="chip <%- type %><%- left %>" style="left: <%- pos %>%"><span class="chip-circle">' |
5
|
173 |
+ '</span><span class="chip-title"><%- annotation.title %></span></li>' |
|
174 |
); |
|
175 |
|
|
176 |
var annotations = myProject.getAnnotationsByTypeTitle("annotations"); |
|
177 |
|
6
|
178 |
var annotationinfos = annotations.map(function(annotation) { |
5
|
179 |
var annotationinfo = { |
|
180 |
annotation: annotation, |
|
181 |
open: false, |
|
182 |
pos: 100 * annotation.begin / annotation.getMedia().duration |
|
183 |
}; |
6
|
184 |
annotationinfo.left = (annotationinfo.pos > 80 ? " left": ""); |
5
|
185 |
switch(annotation.content.mimetype) { |
|
186 |
case "application/x-ldt-slideshow": |
|
187 |
annotationinfo.type = "slideshow"; |
|
188 |
break; |
6
|
189 |
case "application/x-ldt-video": |
|
190 |
annotationinfo.type = "video"; |
|
191 |
break; |
|
192 |
case "application/x-ldt-audio": |
|
193 |
annotationinfo.type = "audio"; |
|
194 |
break; |
|
195 |
case "application/x-ldt-links": |
|
196 |
annotationinfo.type = "link"; |
|
197 |
break; |
|
198 |
default: |
|
199 |
annotationinfo.type = "text"; |
2
|
200 |
} |
5
|
201 |
annotationinfo.picto = $(pictoTemplate(annotationinfo)).appendTo(".pictolist"); |
|
202 |
annotationinfo.chip = $(chipTemplate(annotationinfo)).appendTo(".chips-list"); |
|
203 |
annotationinfo.both = annotationinfo.picto.add(annotationinfo.chip); |
|
204 |
annotationinfo.both.click(function() { |
|
205 |
openAnnotation(annotationinfo); |
|
206 |
}) |
|
207 |
.hover(function() { |
|
208 |
annotationinfo.both.addClass("hover"); |
|
209 |
}, function() { |
|
210 |
annotationinfo.both.removeClass("hover"); |
|
211 |
}); |
|
212 |
annotation.on("enter", function() { |
|
213 |
annotationinfo.picto.show(); |
|
214 |
}); |
|
215 |
annotation.on("leave", function() { |
|
216 |
annotationinfo.picto.hide(); |
|
217 |
}); |
6
|
218 |
annotation.on("found-tags", function() { |
|
219 |
annotationinfo.both.addClass("found"); |
|
220 |
}); |
|
221 |
return annotationinfo; |
5
|
222 |
}); |
|
223 |
|
6
|
224 |
currentAnnotation = null; |
|
225 |
|
5
|
226 |
function openAnnotation(annotationinfo) { |
|
227 |
|
6
|
228 |
if (currentAnnotation === annotationinfo) { |
5
|
229 |
closeAnnotation(true); |
|
230 |
return; |
|
231 |
} |
|
232 |
|
|
233 |
if (myMedia.currentTime < annotationinfo.annotation.begin || myMedia.currentTime > annotationinfo.annotation.end) { |
|
234 |
myMedia.setCurrentTime(annotationinfo.annotation.begin); |
|
235 |
} |
|
236 |
|
|
237 |
myMedia.pause(); |
|
238 |
closeAnnotation(false); |
|
239 |
|
6
|
240 |
currentAnnotation = annotationinfo; |
|
241 |
|
5
|
242 |
annotationinfo.both.addClass("current"); |
|
243 |
|
|
244 |
$(".chapters-bar").addClass("annotation-onscreen"); |
|
245 |
|
6
|
246 |
var annotationDiv = $(".annotation-templates ." + annotationinfo.type + "-annotation").clone(); |
|
247 |
|
|
248 |
annotationDiv.appendTo($(".main-video")); |
|
249 |
annotationDiv.find(".close-annotation").click(closeAnnotation); |
|
250 |
annotationDiv.find(".annotation-title").text(annotationinfo.annotation.title); |
|
251 |
|
5
|
252 |
switch (annotationinfo.type) { |
6
|
253 |
|
5
|
254 |
case "slideshow": |
7
|
255 |
|
6
|
256 |
var currentslide = 0, |
|
257 |
slideInterval, |
|
258 |
playing = false, |
|
259 |
loaded = false, |
|
260 |
slides = annotationinfo.annotation.content.images; |
7
|
261 |
|
6
|
262 |
var resizeImage = function() { |
|
263 |
var imgel = annotationDiv.find(".slideshow-image"); |
|
264 |
imgel.css("margin-top",""); |
|
265 |
var w = imgel.width(), |
|
266 |
h = imgel.height(); |
|
267 |
annotationDiv.find(".slideshow-center").css("height",""); |
|
268 |
annotationDiv.find(".slideshow-description").css("margin-left",w); |
|
269 |
var h2 = annotationDiv.find(".slideshow-center").height(); |
|
270 |
if (h < h2) { |
|
271 |
imgel.css("margin-top",Math.floor((h2-h)/2)+"px"); |
|
272 |
} |
|
273 |
} |
7
|
274 |
|
6
|
275 |
var showCurrentImage = function() { |
|
276 |
var slide = slides[currentslide]; |
|
277 |
annotationDiv.find(".slideshow-image").attr({ |
|
278 |
src: slide.image.src, |
|
279 |
title: slide.title, |
|
280 |
alt: slide.title |
|
281 |
}); |
|
282 |
annotationDiv.find(".slideshow-title").text(slide.title); |
|
283 |
annotationDiv.find(".slideshow-description").html( |
|
284 |
slide.description.split(/\n/gm).map(function(l) { |
|
285 |
return '<p>' + _.escape(l) + '</p>'; |
|
286 |
}).join("") |
|
287 |
); |
|
288 |
resizeImage(); |
|
289 |
} |
7
|
290 |
|
6
|
291 |
var nextImage = function() { |
|
292 |
currentslide = (currentslide + 1) % slides.length; |
|
293 |
showCurrentImage(); |
|
294 |
} |
7
|
295 |
|
6
|
296 |
var togglePlay = function() { |
|
297 |
playing = !playing; |
|
298 |
clearInterval(slideInterval); |
|
299 |
if (playing) { |
7
|
300 |
slideInterval = setInterval(nextImage,Math.max(1000,annotationinfo.annotation.content.slideduration || 0)); |
6
|
301 |
annotationDiv.find(".slideshow-play-pause").addClass("pause"); |
|
302 |
} else { |
|
303 |
annotationDiv.find(".slideshow-play-pause").removeClass("pause"); |
|
304 |
} |
|
305 |
} |
7
|
306 |
|
6
|
307 |
var checkloaded = function() { |
|
308 |
if (loaded) { |
|
309 |
return; |
|
310 |
} |
|
311 |
loaded = slides.reduce(function(mem, slide) { |
|
312 |
return (mem && !!slide.image && !!slide.image.width); |
|
313 |
}, true); |
|
314 |
if (loaded) { |
|
315 |
showCurrentImage(); |
7
|
316 |
if (annotationinfo.annotation.autostart && slides.length > 1) { |
6
|
317 |
togglePlay(); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
7
|
321 |
|
6
|
322 |
slides.forEach(function(slide) { |
|
323 |
slide.image = new Image(); |
|
324 |
slide.image.onload = checkloaded; |
|
325 |
slide.image.src = slide.url; |
|
326 |
}); |
7
|
327 |
|
6
|
328 |
checkloaded(); |
7
|
329 |
|
|
330 |
if (slides.length > 1) { |
|
331 |
annotationDiv.find(".slideshow-next").click(nextImage); |
|
332 |
annotationDiv.find(".slideshow-previous").click(function() { |
|
333 |
currentslide = (currentslide ? currentslide : slides.length) - 1; |
|
334 |
showCurrentImage(); |
|
335 |
}); |
|
336 |
annotationDiv.find(".slideshow-play-pause").click(togglePlay); |
|
337 |
} else { |
|
338 |
annotationDiv.find(".slideshow-next, .slideshow-previous, .slideshow-play-pause").hide(); |
|
339 |
} |
6
|
340 |
|
|
341 |
break; |
|
342 |
|
7
|
343 |
case "audio": |
6
|
344 |
case "video": |
|
345 |
|
7
|
346 |
var src = annotationinfo.annotation.content.url; |
|
347 |
|
6
|
348 |
var youtubeTemplate = _.template( |
|
349 |
'<iframe width="<%- width %>" height="<%- height %>" src="http://www.youtube.com/embed/<%- ytid %>?rel=0&autoplay=<%- autoplay %>" frameborder="0"></iframe>' |
|
350 |
); |
|
351 |
|
7
|
352 |
var htmlTemplate = _.template( |
|
353 |
'<<%- type %> width="<%- width %>" controls="true" autoplay="<%- autoplay %>" src="<%- src %>"/>' |
6
|
354 |
); |
|
355 |
|
7
|
356 |
var mediaW = (annotationinfo.type === "audio" ? "100%" : "650"), |
|
357 |
mediaH = (annotationinfo.type === "audio" ? "60" : "420"); |
6
|
358 |
|
7
|
359 |
annotationDiv.find(".media-description").html( |
6
|
360 |
annotationinfo.annotation.description.split(/\n/gm).map(function(l) { |
|
361 |
return '<p>' + _.escape(l) + '</p>'; |
|
362 |
}).join("") |
|
363 |
); |
|
364 |
|
7
|
365 |
if (/^(https?:\/\/)?(www\.)?youtu\.?be/.test(src)) { |
|
366 |
var urlparts = src.split(/[?&]/g), |
6
|
367 |
ytid = "", |
|
368 |
vtest = /^v=/; |
|
369 |
urlparts.slice(1).forEach(function(p) { |
|
370 |
if (/^v=/.test(p)) { |
|
371 |
ytid = p.replace(vtest,""); |
|
372 |
} |
|
373 |
}); |
|
374 |
if (!ytid) { |
|
375 |
ytid = (urlparts[0].match(/[^\/]+$/) || [""])[0]; |
|
376 |
} |
7
|
377 |
annotationDiv.find(".media-frame").html(youtubeTemplate({ |
6
|
378 |
ytid: ytid, |
7
|
379 |
width: mediaW, |
|
380 |
height: mediaH, |
6
|
381 |
autoplay: +annotationinfo.annotation.content.autostart |
|
382 |
})); |
|
383 |
return; |
|
384 |
} |
|
385 |
|
7
|
386 |
if (/^(https?:\/\/)?(www\.)?vimeo/.test(src)) { |
|
387 |
$.ajax({ |
|
388 |
url: "http://vimeo.com/api/oembed.json", |
|
389 |
dataType: "jsonp", |
|
390 |
data: { |
|
391 |
width: mediaW, |
|
392 |
height: mediaH, |
|
393 |
url: src, |
|
394 |
autoplay: +annotationinfo.annotation.content.autostart, |
|
395 |
color: "be4477", |
|
396 |
portrait: false, |
|
397 |
title: false, |
|
398 |
byline: false |
|
399 |
}, |
|
400 |
success: function(data) { |
|
401 |
annotationDiv.find(".media-frame").html(data.html); |
|
402 |
} |
|
403 |
}); |
|
404 |
return; |
|
405 |
} |
6
|
406 |
|
7
|
407 |
if (/^(https?:\/\/)?(www\.)?dailymotion/.test(src)) { |
|
408 |
$.ajax({ |
|
409 |
url: "http://www.dailymotion.com/services/oembed", |
|
410 |
dataType: "jsonp", |
|
411 |
data: { |
|
412 |
format: "json", |
|
413 |
maxwidth: mediaW, |
|
414 |
maxheight: 487, |
|
415 |
url: src |
|
416 |
}, |
|
417 |
success: function(data) { |
|
418 |
annotationDiv.find(".media-frame").html(data.html); |
|
419 |
} |
|
420 |
}); |
|
421 |
return; |
|
422 |
} |
6
|
423 |
|
7
|
424 |
if (/^(https?:\/\/)?(www\.)?soundcloud\.com/.test(src)) { |
6
|
425 |
$.ajax({ |
|
426 |
url: "http://soundcloud.com/oembed", |
|
427 |
dataType: "jsonp", |
|
428 |
data: { |
|
429 |
format: "js", |
|
430 |
show_comments: false, |
|
431 |
auto_play: annotationinfo.annotation.content.autostart, |
|
432 |
show_artwork: false, |
7
|
433 |
url: src, |
6
|
434 |
color: "63be6c" |
|
435 |
}, |
|
436 |
success: function(data) { |
7
|
437 |
annotationDiv.find(".media-frame").html(data.html); |
6
|
438 |
} |
7
|
439 |
}); |
6
|
440 |
return; |
|
441 |
} |
7
|
442 |
|
|
443 |
var extension = (src.match(/\.([\d\w]+)$/) || ["",""])[1], |
|
444 |
mimetype = annotationinfo.type + "/" + extension, |
|
445 |
fallbacks = { "video/webm": "mp4", "video/mp4": "webm" }, |
|
446 |
canPlay = document.createElement("video").canPlayType(mimetype); |
|
447 |
|
|
448 |
if (!canPlay) { |
|
449 |
src = src.replace(/\.[\d\w]+$/,"." + fallbacks[mimetype]); |
|
450 |
} |
|
451 |
|
|
452 |
console.log(mimetype, canPlay, src); |
|
453 |
|
|
454 |
annotationDiv.find(".media-frame").html(htmlTemplate({ |
|
455 |
type: annotationinfo.type, |
|
456 |
src: src, |
|
457 |
width: mediaW, |
|
458 |
height: mediaH, |
|
459 |
autoplay: "" + annotationinfo.annotation.content.autostart |
6
|
460 |
})); |
|
461 |
|
|
462 |
break; |
|
463 |
|
|
464 |
case "text": |
|
465 |
|
|
466 |
var text = annotationinfo.annotation.content.text || annotationinfo.annotation.description; |
|
467 |
|
|
468 |
switch (annotationinfo.annotation.content.markup) { |
|
469 |
case "html": |
|
470 |
annotationDiv.find(".text-contents").html(text); |
|
471 |
break; |
|
472 |
default: |
|
473 |
annotationDiv.find(".text-contents").html( |
|
474 |
text.split(/\n/gm).map(function(l) { |
|
475 |
return '<p>' + _.escape(l) + '</p>'; |
|
476 |
}).join("") |
|
477 |
); |
|
478 |
break; |
|
479 |
} |
|
480 |
annotationDiv.find(".text-contents a").attr("target","_blank"); |
|
481 |
|
|
482 |
break; |
|
483 |
|
|
484 |
case "link": |
|
485 |
|
|
486 |
var linkTemplate = _.template('<p><a href="<%- url %>" target="_blank"><%- title %></a></p>'); |
|
487 |
|
|
488 |
annotationDiv.find(".link-contents").html( |
|
489 |
annotationinfo.annotation.content.links.map(linkTemplate).join("") |
|
490 |
); |
|
491 |
|
5
|
492 |
break; |
|
493 |
} |
|
494 |
} |
7
|
495 |
|
|
496 |
$(".video-container").click(function() { |
|
497 |
if (currentAnnotation) { |
|
498 |
closeAnnotation(true); |
|
499 |
} |
|
500 |
return false; |
|
501 |
}); |
3
|
502 |
|
5
|
503 |
function closeAnnotation(e) { |
6
|
504 |
currentAnnotation = null; |
|
505 |
$(".chip, .pictolist li").removeClass("current"); |
5
|
506 |
$(".chapters-bar").removeClass("annotation-onscreen"); |
7
|
507 |
$(".main-video .annotation").hide().remove(); |
5
|
508 |
if (!!e) { |
|
509 |
myMedia.play(); |
|
510 |
} |
7
|
511 |
return false; |
5
|
512 |
} |
3
|
513 |
|
2
|
514 |
}); |