diff -r d7bcf5f39b6c -r eddf4d5db875 player/js/player.js --- a/player/js/player.js Fri May 24 18:49:09 2013 +0200 +++ b/player/js/player.js Mon May 27 18:54:46 2013 +0200 @@ -43,18 +43,19 @@ $("body").click(function() { if (clickedTag) { - $(".chapter").removeClass("found"); + $(".found").removeClass("found"); clickedTag = null; } }); function showTag(tagId) { - $(".chapter").removeClass("found"); + $(".found").removeClass("found"); var tag = myProject.getElement(tagId); if (tag) { tag.getRelated("annotation").forEach(function(a) { a.trigger("found-tags"); }); + $(".tag[data-tag-id="+tagId+"]").addClass("found"); } lastTag = tagId; } @@ -117,7 +118,7 @@ highlightChapter(); }); chapter.on("found-tags", function() { - element.addClass("found"); + element.addClass("found"); }); chapterList.append(element); }); @@ -126,11 +127,13 @@ if (i) { myMedia.setCurrentTime(chapters[currentChapterI - 1].begin); } + return false; }); $(".next-chapter").click(function() { if (i < chapters.length - 1) { myMedia.setCurrentTime(chapters[currentChapterI + 1].begin); } + return false; }); $(".play-button").click(function() { @@ -139,6 +142,7 @@ } else { myMedia.pause(); } + return false; }); $(".progress-indicator").draggable({ @@ -149,9 +153,6 @@ myMedia.setCurrentTime(t); } }); - $(".play-button").click(function() { - $(this).toggleClass("pause"); - }); var pictoTemplate = _.template( '
  • ' @@ -159,22 +160,34 @@ ); var chipTemplate = _.template( - '
  • ' + '
  • ' + '<%- annotation.title %>
  • ' ); var annotations = myProject.getAnnotationsByTypeTitle("annotations"); - annotations.forEach(function(annotation) { + var annotationinfos = annotations.map(function(annotation) { var annotationinfo = { annotation: annotation, open: false, pos: 100 * annotation.begin / annotation.getMedia().duration }; + annotationinfo.left = (annotationinfo.pos > 80 ? " left": ""); switch(annotation.content.mimetype) { case "application/x-ldt-slideshow": annotationinfo.type = "slideshow"; break; + case "application/x-ldt-video": + annotationinfo.type = "video"; + break; + case "application/x-ldt-audio": + annotationinfo.type = "audio"; + break; + case "application/x-ldt-links": + annotationinfo.type = "link"; + break; + default: + annotationinfo.type = "text"; } annotationinfo.picto = $(pictoTemplate(annotationinfo)).appendTo(".pictolist"); annotationinfo.chip = $(chipTemplate(annotationinfo)).appendTo(".chips-list"); @@ -193,12 +206,17 @@ annotation.on("leave", function() { annotationinfo.picto.hide(); }); + annotation.on("found-tags", function() { + annotationinfo.both.addClass("found"); + }); + return annotationinfo; }); + currentAnnotation = null; + function openAnnotation(annotationinfo) { - if (annotationinfo.open) { - annotationinfo.open = false; + if (currentAnnotation === annotationinfo) { closeAnnotation(true); return; } @@ -207,113 +225,231 @@ myMedia.setCurrentTime(annotationinfo.annotation.begin); } - annotationinfo.open = true; - myMedia.pause(); closeAnnotation(false); + currentAnnotation = annotationinfo; + annotationinfo.both.addClass("current"); $(".chapters-bar").addClass("annotation-onscreen"); + var annotationDiv = $(".annotation-templates ." + annotationinfo.type + "-annotation").clone(); + + annotationDiv.appendTo($(".main-video")); + annotationDiv.find(".close-annotation").click(closeAnnotation); + annotationDiv.find(".annotation-title").text(annotationinfo.annotation.title); + switch (annotationinfo.type) { + case "slideshow": - slideshow(annotationinfo.annotation); + + var currentslide = 0, + slideInterval, + playing = false, + loaded = false, + slides = annotationinfo.annotation.content.images; + + var resizeImage = function() { + var imgel = annotationDiv.find(".slideshow-image"); + imgel.css("margin-top",""); + var w = imgel.width(), + h = imgel.height(); + annotationDiv.find(".slideshow-center").css("height",""); + annotationDiv.find(".slideshow-description").css("margin-left",w); + var h2 = annotationDiv.find(".slideshow-center").height(); + if (h < h2) { + imgel.css("margin-top",Math.floor((h2-h)/2)+"px"); + } + } + + var showCurrentImage = function() { + var slide = slides[currentslide]; + annotationDiv.find(".slideshow-image").attr({ + src: slide.image.src, + title: slide.title, + alt: slide.title + }); + annotationDiv.find(".slideshow-title").text(slide.title); + annotationDiv.find(".slideshow-description").html( + slide.description.split(/\n/gm).map(function(l) { + return '

    ' + _.escape(l) + '

    '; + }).join("") + ); + resizeImage(); + } + + var nextImage = function() { + currentslide = (currentslide + 1) % slides.length; + showCurrentImage(); + } + + var togglePlay = function() { + playing = !playing; + clearInterval(slideInterval); + if (playing) { + slideInterval = setInterval(nextImage,annotationinfo.annotation["slide-duration"]); + annotationDiv.find(".slideshow-play-pause").addClass("pause"); + } else { + annotationDiv.find(".slideshow-play-pause").removeClass("pause"); + } + } + + var checkloaded = function() { + if (loaded) { + return; + } + loaded = slides.reduce(function(mem, slide) { + return (mem && !!slide.image && !!slide.image.width); + }, true); + if (loaded) { + showCurrentImage(); + if (annotationinfo.annotation.autostart) { + togglePlay(); + } + } + } + + slides.forEach(function(slide) { + slide.image = new Image(); + slide.image.onload = checkloaded; + slide.image.src = slide.url; + }); + + checkloaded(); + + annotationDiv.find(".slideshow-next").click(nextImage); + annotationDiv.find(".slideshow-previous").click(function() { + currentslide = (currentslide ? currentslide : slides.length) - 1; + showCurrentImage(); + }); + annotationDiv.find(".slideshow-play-pause").click(togglePlay); + + break; + + case "video": + + var youtubeTemplate = _.template( + '' + ); + + var htmlVideoTemplate = _.template( + '' + ); + + var videoW = 650, videoH = 400; + + annotationDiv.find(".video-description").html( + annotationinfo.annotation.description.split(/\n/gm).map(function(l) { + return '

    ' + _.escape(l) + '

    '; + }).join("") + ); + + if (/^(https?:\/\/)?(www\.)?youtu\.?be/.test(annotationinfo.annotation.content.url)) { + var urlparts = annotationinfo.annotation.content.url.split(/[?&]/g), + ytid = "", + vtest = /^v=/; + urlparts.slice(1).forEach(function(p) { + if (/^v=/.test(p)) { + ytid = p.replace(vtest,""); + } + }); + if (!ytid) { + ytid = (urlparts[0].match(/[^\/]+$/) || [""])[0]; + } + annotationDiv.find(".video-frame").html(youtubeTemplate({ + ytid: ytid, + width: videoW, + height: videoH, + autoplay: +annotationinfo.annotation.content.autostart + })); + return; + } + + annotationDiv.find(".video-frame").html(htmlVideoTemplate({ + mp4vid: annotationinfo.annotation.content.url.replace(/\.webm$/,'.mp4'), + webmvid: annotationinfo.annotation.content.url.replace(/\.mp4$/,'.webm'), + width: videoW, + height: videoH, + autoplay: ""+annotationinfo.annotation.content.autostart + })); + + break; + + case "audio": + + var htmlAudioTemplate = _.template( + '