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