14
|
1 |
IriSP.player = function(url) { |
|
2 |
|
3
|
3 |
var myDir = new IriSP.Model.Directory(), |
|
4 |
myProject = myDir.remoteSource({ |
14
|
5 |
url: url, |
3
|
6 |
serializer: IriSP.serializers.ldt |
|
7 |
}); |
|
8 |
|
|
9 |
myProject.onLoad(function() { |
|
10 |
|
|
11 |
$(".project-title").text(myProject.title); |
|
12 |
|
|
13 |
var myMedia = myProject.getCurrentMedia(); |
|
14 |
|
|
15 |
IriSP.htmlPlayer( |
|
16 |
myMedia, |
|
17 |
$(".video-container"), |
|
18 |
{ |
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 |
|
64
|
32 |
function preventRightClick(selector) { |
|
33 |
selector.on("contextmenu", function() { |
|
34 |
return false; |
|
35 |
}); |
|
36 |
} |
|
37 |
|
|
38 |
preventRightClick($(".video-container video")); |
|
39 |
|
55
|
40 |
$(".media-duration").text(myMedia.duration); |
|
41 |
|
3
|
42 |
myMedia.on("timeupdate", function(t) { |
21
|
43 |
var pos = (100 * t / myMedia.duration) + "%"; |
55
|
44 |
$(".media-position").text(t); |
18
|
45 |
$(".progress-indicator").css("left",pos); |
|
46 |
$(".elapsed").css("width", pos); |
3
|
47 |
}); |
|
48 |
myMedia.on("play", function() { |
|
49 |
$(".play-button").addClass("pause"); |
|
50 |
}); |
|
51 |
myMedia.on("pause", function() { |
|
52 |
$(".play-button").removeClass("pause"); |
|
53 |
}); |
|
54 |
|
18
|
55 |
function showAtMousePos(evt) { |
|
56 |
var pos = evt.pageX - $(".timeline").offset().left; |
|
57 |
$(".mouse-progress-indicator").css("left", pos); |
55
|
58 |
var t = new IriSP.Model.Time(pos * myMedia.duration / $(".timeline").width()); |
|
59 |
$(".time-at-mouse").text(t); |
|
60 |
return t; |
18
|
61 |
} |
|
62 |
|
|
63 |
$(".timeline").mouseenter(function(e) { |
|
64 |
$(".mouse-progress-indicator").show(); |
|
65 |
showAtMousePos(e); |
|
66 |
}).mouseleave(function(e) { |
|
67 |
$(".mouse-progress-indicator").hide(); |
|
68 |
}).mousemove(showAtMousePos) |
|
69 |
.click(function(e) { |
55
|
70 |
myMedia.setCurrentTime( showAtMousePos(e) ); |
18
|
71 |
}); |
|
72 |
|
3
|
73 |
var tags = myProject.getTags().sortBy(function(t) { |
|
74 |
return - t.getRelated("annotation").length; |
18
|
75 |
}).slice(0,20).sortBy(function(t) { |
|
76 |
return t.title; |
|
77 |
}), |
3
|
78 |
tagTemplate = _.template('<li data-tag-id="<%- id %>" class="tag"><%- title %></li>'), |
|
79 |
clickedTag = null, |
|
80 |
lastTag = null; |
|
81 |
|
|
82 |
$(".tags-list").html(tags.map(tagTemplate).join("")); |
|
83 |
|
8
|
84 |
$(".tags-title").mouseenter(function() { |
16
|
85 |
$(".tags-list").stop().slideDown(); |
18
|
86 |
}).click(function() { |
3
|
87 |
if (clickedTag) { |
|
88 |
clickedTag = null; |
74
|
89 |
showTag(null); |
3
|
90 |
} |
8
|
91 |
return false; |
3
|
92 |
}); |
18
|
93 |
$(".tags").mouseleave(function() { |
|
94 |
$(".tags-list").stop().slideUp(); |
|
95 |
}); |
3
|
96 |
|
|
97 |
function showTag(tagId) { |
6
|
98 |
$(".found").removeClass("found"); |
3
|
99 |
var tag = myProject.getElement(tagId); |
|
100 |
if (tag) { |
74
|
101 |
$("body").addClass("searching"); |
|
102 |
$(".tags-title").text(tag.title); |
3
|
103 |
tag.getRelated("annotation").forEach(function(a) { |
|
104 |
a.trigger("found-tags"); |
|
105 |
}); |
6
|
106 |
$(".tag[data-tag-id="+tagId+"]").addClass("found"); |
71
|
107 |
} else { |
74
|
108 |
$("body").removeClass("searching"); |
|
109 |
$(".tags-title").text("Mots-clés"); |
3
|
110 |
} |
|
111 |
lastTag = tagId; |
|
112 |
} |
|
113 |
|
|
114 |
$(".tag").hover(function() { |
|
115 |
showTag($(this).attr("data-tag-id")); |
|
116 |
}, function() { |
|
117 |
showTag(clickedTag); |
|
118 |
}).click(function() { |
74
|
119 |
var tag = $(this).attr("data-tag-id"); |
|
120 |
if (clickedTag === tag) { |
|
121 |
clickedTag = null; |
18
|
122 |
} else { |
74
|
123 |
clickedTag = tag; |
18
|
124 |
} |
74
|
125 |
showTag(clickedTag); |
3
|
126 |
return false; |
|
127 |
}); |
|
128 |
|
|
129 |
|
|
130 |
var chapters = myProject.getAnnotationsByTypeTitle("chapitrage"), |
|
131 |
chapterTemplate = _.template( |
|
132 |
'<li class="chapter" style="left: <%- 100*begin/getMedia().duration %>%; width: <%- 100*getDuration()/getMedia().duration %>%;">' |
|
133 |
+ '<div class="chapter-block"></div><div class="chapter-title"><%- title %></div></li>' |
|
134 |
), |
|
135 |
chapterList = $(".chapters-list"), |
|
136 |
hoveredChapter = null, |
|
137 |
currentChapter = null, |
74
|
138 |
currentChapterI = 0, |
|
139 |
slideInterval; |
3
|
140 |
|
|
141 |
function highlightChapter() { |
|
142 |
$(".chapter").removeClass("active"); |
|
143 |
if (hoveredChapter || currentChapter) { |
|
144 |
(hoveredChapter || currentChapter).addClass("active"); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
chapters.forEach(function(chapter, i) { |
|
149 |
var element = $(chapterTemplate(chapter)); |
|
150 |
element.click(function() { |
|
151 |
myMedia.setCurrentTime(chapter.begin); |
8
|
152 |
return false; |
3
|
153 |
}).hover(function() { |
|
154 |
hoveredChapter = element; |
|
155 |
highlightChapter(); |
|
156 |
}, function() { |
|
157 |
hoveredChapter = null; |
|
158 |
highlightChapter(); |
|
159 |
}); |
|
160 |
chapter.on("enter", function() { |
|
161 |
currentChapter = element; |
|
162 |
currentChapterI = i; |
|
163 |
if (i) { |
|
164 |
$(".prev-chapter").removeClass("inactive"); |
|
165 |
} else { |
|
166 |
$(".prev-chapter").addClass("inactive"); |
|
167 |
} |
|
168 |
if (i < chapters.length - 1) { |
|
169 |
$(".next-chapter").removeClass("inactive"); |
|
170 |
} else { |
|
171 |
$(".next-chapter").addClass("inactive"); |
|
172 |
} |
|
173 |
highlightChapter(); |
|
174 |
}); |
|
175 |
chapter.on("leave", function() { |
|
176 |
currentChapter = null; |
|
177 |
highlightChapter(); |
|
178 |
}); |
|
179 |
chapter.on("found-tags", function() { |
6
|
180 |
element.addClass("found"); |
3
|
181 |
}); |
|
182 |
chapterList.append(element); |
|
183 |
}); |
|
184 |
|
|
185 |
$(".prev-chapter").click(function() { |
7
|
186 |
if (currentChapterI) { |
3
|
187 |
myMedia.setCurrentTime(chapters[currentChapterI - 1].begin); |
|
188 |
} |
6
|
189 |
return false; |
3
|
190 |
}); |
|
191 |
$(".next-chapter").click(function() { |
7
|
192 |
if (currentChapterI < chapters.length - 1) { |
3
|
193 |
myMedia.setCurrentTime(chapters[currentChapterI + 1].begin); |
|
194 |
} |
6
|
195 |
return false; |
3
|
196 |
}); |
|
197 |
|
|
198 |
$(".play-button").click(function() { |
|
199 |
if (myMedia.paused) { |
|
200 |
myMedia.play(); |
|
201 |
} else { |
|
202 |
myMedia.pause(); |
|
203 |
} |
6
|
204 |
return false; |
3
|
205 |
}); |
18
|
206 |
|
5
|
207 |
var pictoTemplate = _.template( |
|
208 |
'<li class="<%- type %>"><span class="picto"><a href="#"></a></span>' |
|
209 |
+ '<span class="picto-title"><%- annotation.title %></span></li>' |
|
210 |
); |
|
211 |
|
|
212 |
var chipTemplate = _.template( |
8
|
213 |
'<li class="chip <%- type %><%- left %>" style="left: <%- pos %>%"><div class="chip-circle">' |
|
214 |
+ '</div><div class="chip-pole"></div><div class="chip-title"><%- annotation.title %></div></li>' |
5
|
215 |
); |
|
216 |
|
8
|
217 |
var annotations = myProject.getAnnotationsByTypeTitle("annotations").sortBy(function(a) { |
|
218 |
return a.begin; |
|
219 |
}); |
5
|
220 |
|
6
|
221 |
var annotationinfos = annotations.map(function(annotation) { |
5
|
222 |
var annotationinfo = { |
|
223 |
annotation: annotation, |
|
224 |
open: false, |
|
225 |
pos: 100 * annotation.begin / annotation.getMedia().duration |
|
226 |
}; |
6
|
227 |
annotationinfo.left = (annotationinfo.pos > 80 ? " left": ""); |
5
|
228 |
switch(annotation.content.mimetype) { |
|
229 |
case "application/x-ldt-slideshow": |
|
230 |
annotationinfo.type = "slideshow"; |
|
231 |
break; |
6
|
232 |
case "application/x-ldt-video": |
|
233 |
annotationinfo.type = "video"; |
|
234 |
break; |
|
235 |
case "application/x-ldt-audio": |
|
236 |
annotationinfo.type = "audio"; |
|
237 |
break; |
|
238 |
case "application/x-ldt-links": |
|
239 |
annotationinfo.type = "link"; |
|
240 |
break; |
|
241 |
default: |
|
242 |
annotationinfo.type = "text"; |
2
|
243 |
} |
5
|
244 |
annotationinfo.picto = $(pictoTemplate(annotationinfo)).appendTo(".pictolist"); |
|
245 |
annotationinfo.chip = $(chipTemplate(annotationinfo)).appendTo(".chips-list"); |
|
246 |
annotationinfo.both = annotationinfo.picto.add(annotationinfo.chip); |
|
247 |
annotationinfo.both.click(function() { |
|
248 |
openAnnotation(annotationinfo); |
8
|
249 |
return false; |
5
|
250 |
}) |
|
251 |
.hover(function() { |
|
252 |
annotationinfo.both.addClass("hover"); |
|
253 |
}, function() { |
|
254 |
annotationinfo.both.removeClass("hover"); |
|
255 |
}); |
|
256 |
annotation.on("enter", function() { |
8
|
257 |
annotationinfo.picto.show().animate({ |
|
258 |
height: "38px", |
|
259 |
opacity: 1 |
9
|
260 |
}, 800); |
5
|
261 |
}); |
|
262 |
annotation.on("leave", function() { |
8
|
263 |
annotationinfo.picto.animate({ |
|
264 |
height: 0, |
|
265 |
opacity: 0 |
9
|
266 |
}, 800, function() { |
8
|
267 |
annotationinfo.picto.hide(); |
|
268 |
}); |
5
|
269 |
}); |
6
|
270 |
annotation.on("found-tags", function() { |
|
271 |
annotationinfo.both.addClass("found"); |
|
272 |
}); |
|
273 |
return annotationinfo; |
5
|
274 |
}); |
|
275 |
|
6
|
276 |
currentAnnotation = null; |
|
277 |
|
5
|
278 |
function openAnnotation(annotationinfo) { |
|
279 |
|
6
|
280 |
if (currentAnnotation === annotationinfo) { |
5
|
281 |
closeAnnotation(true); |
|
282 |
return; |
|
283 |
} |
|
284 |
|
|
285 |
if (myMedia.currentTime < annotationinfo.annotation.begin || myMedia.currentTime > annotationinfo.annotation.end) { |
|
286 |
myMedia.setCurrentTime(annotationinfo.annotation.begin); |
|
287 |
} |
|
288 |
|
|
289 |
myMedia.pause(); |
|
290 |
closeAnnotation(false); |
|
291 |
|
6
|
292 |
currentAnnotation = annotationinfo; |
|
293 |
|
5
|
294 |
annotationinfo.both.addClass("current"); |
|
295 |
|
18
|
296 |
$(".timelines").addClass("annotation-onscreen"); |
5
|
297 |
|
6
|
298 |
var annotationDiv = $(".annotation-templates ." + annotationinfo.type + "-annotation").clone(); |
|
299 |
|
|
300 |
annotationDiv.appendTo($(".main-video")); |
|
301 |
annotationDiv.find(".close-annotation").click(closeAnnotation); |
|
302 |
annotationDiv.find(".annotation-title").text(annotationinfo.annotation.title); |
|
303 |
|
71
|
304 |
annotationinfo.positionDiv = function() { |
|
305 |
var mainH = $(".main-video").height() |
|
306 |
switch (annotationinfo.type) { |
|
307 |
case "video": |
|
308 |
var mediaW = annotationDiv.find(".media-frame").width(), |
|
309 |
mediaH = Math.floor(Math.min(mainH - 70, mediaW * 9 / 16)); |
|
310 |
annotationDiv.find("iframe, video").attr({ |
|
311 |
width: mediaW, |
|
312 |
height: mediaH |
|
313 |
}); |
|
314 |
annotationDiv.find(".media-description").css({ |
|
315 |
height: mediaH |
|
316 |
}); |
|
317 |
break; |
|
318 |
case "text": |
|
319 |
annotationDiv.find(".text-contents").css({ |
|
320 |
"max-height": mainH - 140 |
|
321 |
}); |
|
322 |
break; |
|
323 |
} |
15
|
324 |
annotationDiv.css({ |
71
|
325 |
top: Math.floor((mainH - annotationDiv.height())/2)+"px" |
15
|
326 |
}); |
9
|
327 |
} |
|
328 |
|
5
|
329 |
switch (annotationinfo.type) { |
6
|
330 |
|
5
|
331 |
case "slideshow": |
7
|
332 |
|
6
|
333 |
var currentslide = 0, |
|
334 |
playing = false, |
|
335 |
loaded = false, |
32
|
336 |
currentSlideLoaded = false, |
6
|
337 |
slides = annotationinfo.annotation.content.images; |
7
|
338 |
|
6
|
339 |
var showCurrentImage = function() { |
16
|
340 |
$(".slideshow-image").remove(); |
|
341 |
var slide = slides[currentslide], |
|
342 |
srcimg = slide.image, |
|
343 |
imgel = $("<img>"); |
|
344 |
imgel.addClass("slideshow-image"); |
20
|
345 |
var wcont = 650, hcont = 452, wsrc = srcimg.width, hsrc = srcimg.height, scale = Math.min(1, Math.min(wcont/wsrc, hcont/hsrc)), h = hsrc * scale; |
16
|
346 |
imgel.attr({ |
|
347 |
src: srcimg.src, |
6
|
348 |
title: slide.title, |
20
|
349 |
alt: slide.title, |
|
350 |
width: wsrc * scale, |
|
351 |
height: h |
6
|
352 |
}); |
16
|
353 |
imgel.css({ |
|
354 |
opacity: 0, |
|
355 |
"margin-top": (h < hcont ? Math.floor((hcont-h)/2)+"px": 0) |
|
356 |
}); |
|
357 |
annotationDiv.find(".slideshow-frame").prepend(imgel); |
6
|
358 |
annotationDiv.find(".slideshow-title").text(slide.title); |
|
359 |
annotationDiv.find(".slideshow-description").html( |
|
360 |
slide.description.split(/\n/gm).map(function(l) { |
|
361 |
return '<p>' + _.escape(l) + '</p>'; |
|
362 |
}).join("") |
|
363 |
); |
16
|
364 |
imgel.fadeTo(400, 1); |
64
|
365 |
preventRightClick(imgel); |
6
|
366 |
} |
7
|
367 |
|
6
|
368 |
var nextImage = function() { |
|
369 |
currentslide = (currentslide + 1) % slides.length; |
8
|
370 |
annotationDiv.find(".slideshow-image").fadeTo(400, 0, showCurrentImage); |
|
371 |
return false; |
6
|
372 |
} |
7
|
373 |
|
6
|
374 |
var togglePlay = function() { |
|
375 |
playing = !playing; |
|
376 |
clearInterval(slideInterval); |
|
377 |
if (playing) { |
7
|
378 |
slideInterval = setInterval(nextImage,Math.max(1000,annotationinfo.annotation.content.slideduration || 0)); |
6
|
379 |
annotationDiv.find(".slideshow-play-pause").addClass("pause"); |
|
380 |
} else { |
|
381 |
annotationDiv.find(".slideshow-play-pause").removeClass("pause"); |
|
382 |
} |
8
|
383 |
return false; |
6
|
384 |
} |
7
|
385 |
|
6
|
386 |
var checkloaded = function() { |
|
387 |
if (loaded) { |
|
388 |
return; |
|
389 |
} |
32
|
390 |
if (!currentSlideLoaded) { |
|
391 |
if (!!slides[currentslide].image && !!slides[currentslide].image.height) { |
|
392 |
currentSlideLoaded = true; |
|
393 |
showCurrentImage(); |
|
394 |
} |
|
395 |
} |
6
|
396 |
loaded = slides.reduce(function(mem, slide) { |
16
|
397 |
return (mem && !!slide.image && !!slide.image.height); |
6
|
398 |
}, true); |
|
399 |
if (loaded) { |
74
|
400 |
if (annotationinfo.annotation.content.autostart && slides.length > 1) { |
6
|
401 |
togglePlay(); |
|
402 |
} |
|
403 |
} |
|
404 |
} |
7
|
405 |
|
6
|
406 |
slides.forEach(function(slide) { |
|
407 |
slide.image = new Image(); |
|
408 |
slide.image.onload = checkloaded; |
17
|
409 |
slide.image.src = slide.url + "?maxwidth=650&maxheight=452"; |
6
|
410 |
}); |
7
|
411 |
|
6
|
412 |
checkloaded(); |
7
|
413 |
|
|
414 |
if (slides.length > 1) { |
74
|
415 |
annotationDiv.find(".slideshow-next").click(function() { |
|
416 |
if (playing) { |
|
417 |
playing = false; |
|
418 |
togglePlay(); |
|
419 |
} |
|
420 |
nextImage(); |
|
421 |
}); |
7
|
422 |
annotationDiv.find(".slideshow-previous").click(function() { |
74
|
423 |
if (playing) { |
|
424 |
playing = false; |
|
425 |
togglePlay(); |
|
426 |
} |
7
|
427 |
currentslide = (currentslide ? currentslide : slides.length) - 1; |
8
|
428 |
annotationDiv.find(".slideshow-image").fadeTo(400, 0, showCurrentImage); |
7
|
429 |
}); |
|
430 |
annotationDiv.find(".slideshow-play-pause").click(togglePlay); |
|
431 |
} else { |
|
432 |
annotationDiv.find(".slideshow-next, .slideshow-previous, .slideshow-play-pause").hide(); |
|
433 |
} |
6
|
434 |
|
|
435 |
break; |
|
436 |
|
7
|
437 |
case "audio": |
6
|
438 |
case "video": |
|
439 |
|
7
|
440 |
var src = annotationinfo.annotation.content.url; |
|
441 |
|
6
|
442 |
var youtubeTemplate = _.template( |
|
443 |
'<iframe width="<%- width %>" height="<%- height %>" src="http://www.youtube.com/embed/<%- ytid %>?rel=0&autoplay=<%- autoplay %>" frameborder="0"></iframe>' |
|
444 |
); |
|
445 |
|
7
|
446 |
var htmlTemplate = _.template( |
71
|
447 |
'<<%- type %> width="<%- width %>" height="<%- height %>" controls="true" autoplay="<%- autoplay %>" src="<%- src %>"/>' |
6
|
448 |
); |
|
449 |
|
71
|
450 |
var mediaW = (annotationinfo.type === "audio" ? "100%" : annotationDiv.find(".media-frame").width()), |
|
451 |
mediaH = (annotationinfo.type === "audio" ? "60" : Math.floor(Math.min($(".main-video").height() - 70, mediaW * 9 / 16))); |
6
|
452 |
|
7
|
453 |
annotationDiv.find(".media-description").html( |
6
|
454 |
annotationinfo.annotation.description.split(/\n/gm).map(function(l) { |
|
455 |
return '<p>' + _.escape(l) + '</p>'; |
|
456 |
}).join("") |
|
457 |
); |
|
458 |
|
7
|
459 |
if (/^(https?:\/\/)?(www\.)?youtu\.?be/.test(src)) { |
|
460 |
var urlparts = src.split(/[?&]/g), |
6
|
461 |
ytid = "", |
|
462 |
vtest = /^v=/; |
|
463 |
urlparts.slice(1).forEach(function(p) { |
|
464 |
if (/^v=/.test(p)) { |
|
465 |
ytid = p.replace(vtest,""); |
|
466 |
} |
|
467 |
}); |
|
468 |
if (!ytid) { |
|
469 |
ytid = (urlparts[0].match(/[^\/]+$/) || [""])[0]; |
|
470 |
} |
7
|
471 |
annotationDiv.find(".media-frame").html(youtubeTemplate({ |
6
|
472 |
ytid: ytid, |
7
|
473 |
width: mediaW, |
|
474 |
height: mediaH, |
6
|
475 |
autoplay: +annotationinfo.annotation.content.autostart |
|
476 |
})); |
9
|
477 |
break; |
6
|
478 |
} |
|
479 |
|
7
|
480 |
if (/^(https?:\/\/)?(www\.)?vimeo/.test(src)) { |
|
481 |
$.ajax({ |
|
482 |
url: "http://vimeo.com/api/oembed.json", |
|
483 |
dataType: "jsonp", |
|
484 |
data: { |
|
485 |
width: mediaW, |
|
486 |
height: mediaH, |
|
487 |
url: src, |
8
|
488 |
autoplay: annotationinfo.annotation.content.autostart, |
|
489 |
color: "B8155F", |
7
|
490 |
portrait: false, |
|
491 |
title: false, |
|
492 |
byline: false |
|
493 |
}, |
|
494 |
success: function(data) { |
|
495 |
annotationDiv.find(".media-frame").html(data.html); |
71
|
496 |
annotationinfo.positionDiv(); |
7
|
497 |
} |
|
498 |
}); |
64
|
499 |
break; |
7
|
500 |
} |
6
|
501 |
|
7
|
502 |
if (/^(https?:\/\/)?(www\.)?dailymotion/.test(src)) { |
|
503 |
$.ajax({ |
|
504 |
url: "http://www.dailymotion.com/services/oembed", |
|
505 |
dataType: "jsonp", |
|
506 |
data: { |
|
507 |
format: "json", |
|
508 |
maxwidth: mediaW, |
71
|
509 |
maxheight: mediaH, |
7
|
510 |
url: src |
|
511 |
}, |
|
512 |
success: function(data) { |
|
513 |
annotationDiv.find(".media-frame").html(data.html); |
71
|
514 |
annotationinfo.positionDiv(); |
7
|
515 |
} |
|
516 |
}); |
64
|
517 |
break; |
7
|
518 |
} |
6
|
519 |
|
7
|
520 |
if (/^(https?:\/\/)?(www\.)?soundcloud\.com/.test(src)) { |
6
|
521 |
$.ajax({ |
|
522 |
url: "http://soundcloud.com/oembed", |
|
523 |
dataType: "jsonp", |
|
524 |
data: { |
|
525 |
format: "js", |
|
526 |
show_comments: false, |
|
527 |
auto_play: annotationinfo.annotation.content.autostart, |
|
528 |
show_artwork: false, |
7
|
529 |
url: src, |
8
|
530 |
color: "B8155F" |
6
|
531 |
}, |
|
532 |
success: function(data) { |
7
|
533 |
annotationDiv.find(".media-frame").html(data.html); |
71
|
534 |
annotationinfo.positionDiv(); |
6
|
535 |
} |
7
|
536 |
}); |
64
|
537 |
break; |
6
|
538 |
} |
7
|
539 |
|
|
540 |
var extension = (src.match(/\.([\d\w]+)$/) || ["",""])[1], |
|
541 |
mimetype = annotationinfo.type + "/" + extension, |
41
|
542 |
fallbacks = { "video/webm": "mp4", "video/mp4": "webm", "audio/ogg": "mp3", "audio/mp3": "ogg" }, |
7
|
543 |
canPlay = document.createElement("video").canPlayType(mimetype); |
|
544 |
|
|
545 |
if (!canPlay) { |
|
546 |
src = src.replace(/\.[\d\w]+$/,"." + fallbacks[mimetype]); |
|
547 |
} |
|
548 |
|
9
|
549 |
var media = $(htmlTemplate({ |
7
|
550 |
type: annotationinfo.type, |
|
551 |
src: src, |
|
552 |
width: mediaW, |
|
553 |
height: mediaH, |
|
554 |
autoplay: "" + annotationinfo.annotation.content.autostart |
6
|
555 |
})); |
|
556 |
|
9
|
557 |
media.on("loadedmetadata", function() { |
71
|
558 |
annotationinfo.positionDiv(); |
9
|
559 |
}); |
|
560 |
|
64
|
561 |
preventRightClick(media); |
|
562 |
|
9
|
563 |
annotationDiv.find(".media-frame").html(media); |
|
564 |
|
6
|
565 |
break; |
|
566 |
|
|
567 |
case "text": |
|
568 |
|
|
569 |
var text = annotationinfo.annotation.content.text || annotationinfo.annotation.description; |
|
570 |
|
|
571 |
switch (annotationinfo.annotation.content.markup) { |
|
572 |
case "html": |
|
573 |
annotationDiv.find(".text-contents").html(text); |
|
574 |
break; |
|
575 |
default: |
|
576 |
annotationDiv.find(".text-contents").html( |
|
577 |
text.split(/\n/gm).map(function(l) { |
|
578 |
return '<p>' + _.escape(l) + '</p>'; |
|
579 |
}).join("") |
|
580 |
); |
|
581 |
break; |
|
582 |
} |
|
583 |
annotationDiv.find(".text-contents a").attr("target","_blank"); |
|
584 |
|
|
585 |
break; |
|
586 |
|
|
587 |
case "link": |
|
588 |
|
|
589 |
var linkTemplate = _.template('<p><a href="<%- url %>" target="_blank"><%- title %></a></p>'); |
|
590 |
|
|
591 |
annotationDiv.find(".link-contents").html( |
|
592 |
annotationinfo.annotation.content.links.map(linkTemplate).join("") |
71
|
593 |
); |
6
|
594 |
|
5
|
595 |
break; |
|
596 |
} |
9
|
597 |
|
71
|
598 |
annotationinfo.positionDiv(); |
9
|
599 |
|
5
|
600 |
} |
7
|
601 |
|
|
602 |
$(".video-container").click(function() { |
|
603 |
if (currentAnnotation) { |
|
604 |
closeAnnotation(true); |
|
605 |
} |
|
606 |
return false; |
|
607 |
}); |
18
|
608 |
|
|
609 |
function fullScreen() { |
74
|
610 |
var isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen || false, |
18
|
611 |
el = document.querySelector("body"), |
|
612 |
requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
613 |
cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
614 |
if (isFull) { |
|
615 |
for (var i = 0; i < cancelMethods.length; i++) { |
|
616 |
if (typeof document[cancelMethods[i]] === "function") { |
|
617 |
document[cancelMethods[i]](); |
|
618 |
break; |
|
619 |
} |
|
620 |
} |
|
621 |
} else { |
|
622 |
for (var i = 0; i < requestMethods.length; i++) { |
|
623 |
if (typeof el[requestMethods[i]] === "function") { |
|
624 |
el[requestMethods[i]](); |
|
625 |
break; |
|
626 |
} |
|
627 |
} |
|
628 |
} |
|
629 |
return false; |
|
630 |
} |
|
631 |
|
|
632 |
$(".full-screen").click(fullScreen); |
71
|
633 |
$(".top-bar").dblclick(fullScreen); |
74
|
634 |
|
|
635 |
if ( typeof document.fullScreen === "undefined" |
|
636 |
&& typeof document.mozFullScreen === "undefined" |
|
637 |
&& typeof document.webkitIsFullScreen === "undefined") { |
71
|
638 |
$(".full-screen").remove(); |
|
639 |
} |
|
640 |
|
18
|
641 |
$(".about").click(function() { |
80
|
642 |
myMedia.pause(); |
18
|
643 |
closeAnnotation(); |
|
644 |
var aboutBox = $(".annotation-templates .about-box").clone().appendTo($(".main-video")); |
|
645 |
aboutBox.find(".close-annotation").click(closeAnnotation); |
80
|
646 |
var mainH = $(".main-video").height(); |
|
647 |
aboutBox.find(".about-contents").css("max-height", mainH - 100); |
|
648 |
aboutBox.css("top", Math.floor((mainH - aboutBox.height())/2)+"px"); |
18
|
649 |
}); |
3
|
650 |
|
5
|
651 |
function closeAnnotation(e) { |
74
|
652 |
clearInterval(slideInterval); |
6
|
653 |
currentAnnotation = null; |
|
654 |
$(".chip, .pictolist li").removeClass("current"); |
18
|
655 |
$(".timelines").removeClass("annotation-onscreen"); |
9
|
656 |
$(".annotation audio, .annotation video").each(function() { |
|
657 |
try { |
|
658 |
this.pause(); |
18
|
659 |
} catch(err) { } |
9
|
660 |
}); |
7
|
661 |
$(".main-video .annotation").hide().remove(); |
5
|
662 |
if (!!e) { |
|
663 |
myMedia.play(); |
|
664 |
} |
7
|
665 |
return false; |
18
|
666 |
} |
|
667 |
|
|
668 |
var videoRatio = null; |
|
669 |
|
|
670 |
function repositionElements() { |
|
671 |
var videoel = $(".video-container video"); |
|
672 |
if (!videoRatio) { |
|
673 |
videoRatio = videoel.width() / videoel.height(); |
|
674 |
} |
|
675 |
if (!videoRatio) { |
|
676 |
return; |
|
677 |
} |
|
678 |
var container = $(".main-video"), |
|
679 |
ch = container.height(), |
|
680 |
cw = container.width(), |
|
681 |
vw = Math.min(cw, ch * videoRatio), |
|
682 |
vh = vw / videoRatio, |
|
683 |
dw = (cw - vw) / 2, |
|
684 |
dh = (ch - vh) / 2; |
|
685 |
videoel.css({ |
|
686 |
width: vw, |
|
687 |
height: vh, |
|
688 |
"margin-top": dh |
|
689 |
}); |
|
690 |
$(".pictolist").css({ |
|
691 |
left: dw, |
|
692 |
bottom: dh |
|
693 |
}); |
71
|
694 |
if (currentAnnotation) { |
|
695 |
currentAnnotation.positionDiv(); |
|
696 |
} |
18
|
697 |
} |
|
698 |
|
|
699 |
$(".video-container video").on("loadedmetadata",repositionElements); |
|
700 |
|
|
701 |
$(window).resize(repositionElements); |
|
702 |
|
|
703 |
$(document).keydown(function(e) { |
55
|
704 |
if (e.keyCode === 122) { // F11 |
18
|
705 |
fullScreen(); |
|
706 |
return false; |
|
707 |
} |
55
|
708 |
if (e.keyCode === 32) { // Space |
|
709 |
myMedia[myMedia.paused ? "play" : "pause"](); |
|
710 |
return false; |
|
711 |
} |
18
|
712 |
}); |
|
713 |
|
2
|
714 |
}); |
14
|
715 |
|
|
716 |
}; |