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( '
' + _.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( + '' + ); + + annotationDiv.find(".audio-description").html( + annotationinfo.annotation.description.split(/\n/gm).map(function(l) { + return '' + _.escape(l) + '
'; + }).join("") + ); + + if (/^(https?:\/\/)?(www\.)?soundcloud\.com/.test(annotationinfo.annotation.content.url)) { + $.ajax({ + url: "http://soundcloud.com/oembed", + dataType: "jsonp", + data: { + format: "js", + show_comments: false, + auto_play: annotationinfo.annotation.content.autostart, + show_artwork: false, + url: annotationinfo.annotation.content.url, + color: "63be6c" + }, + success: function(data) { + annotationDiv.find(".audio-frame").html(data.html); + } + } + ); + return; + } + + annotationDiv.find(".audio-frame").html(htmlAudioTemplate({ + src: annotationinfo.annotation.content.url, + autoplay: ""+annotationinfo.annotation.content.autostart + })); + + break; + + case "text": + + var text = annotationinfo.annotation.content.text || annotationinfo.annotation.description; + + switch (annotationinfo.annotation.content.markup) { + case "html": + annotationDiv.find(".text-contents").html(text); + break; + default: + annotationDiv.find(".text-contents").html( + text.split(/\n/gm).map(function(l) { + return '' + _.escape(l) + '
'; + }).join("") + ); + break; + } + annotationDiv.find(".text-contents a").attr("target","_blank"); + + break; + + case "link": + + var linkTemplate = _.template(''); + + annotationDiv.find(".link-contents").html( + annotationinfo.annotation.content.links.map(linkTemplate).join("") + ); + break; } } - - function slideshow(data) { - - var currentslide = 0, - slideInterval, - playing = false, - loaded = false, - slides = data.content.images - slideShowElement = $(".annotation-templates .slideshow-annotation").clone(); - - slideShowElement.appendTo($(".main-video")); - - function checkloaded() { - if (loaded) { - return; - } - loaded = slides.reduce(function(mem, slide) { - return (mem && !!slide.image && !!slide.image.width); - }, true); - if (loaded) { - showCurrentImage(); - if (data.autostart) { - togglePlay(); - } - } - } - - slides.forEach(function(slide) { - slide.image = new Image(); - slide.image.onload = checkloaded; - slide.image.src = slide.url; - }); - - checkloaded(); - - function resizeImage() { - var imgel = slideShowElement.find(".slideshow-image"); - imgel.css("margin-top",""); - var w = imgel.width(), - h = imgel.height(); - slideShowElement.find(".slideshow-center").css("height",""); - slideShowElement.find(".slideshow-description").css("margin-left",w); - var h2 = slideShowElement.find(".slideshow-center").height(); - if (h < h2) { - imgel.css("margin-top",Math.floor((h2-h)/2)+"px"); - } - } - - function showCurrentImage() { - var slide = slides[currentslide]; - slideShowElement.find(".slideshow-image").attr({ - src: slide.image.src, - title: slide.title, - alt: slide.title - }); - slideShowElement.find(".slideshow-title").text(slide.title); - slideShowElement.find(".slideshow-description").html( - slide.description.split(/\n/gm).map(function(l) { - return '' + _.escape(l) + '
'; - }).join("") - ); - resizeImage(); - } - - function nextImage() { - currentslide = (currentslide + 1) % slides.length; - showCurrentImage(); - } - - function togglePlay() { - playing = !playing; - clearInterval(slideInterval); - if (playing) { - slideInterval = setInterval(nextImage,data["slide-duration"]); - slideShowElement.find(".slideshow-play-pause").addClass("pause"); - } else { - slideShowElement.find(".slideshow-play-pause").removeClass("pause"); - } - } - - slideShowElement.find(".slideshow-next").click(nextImage); - slideShowElement.find(".slideshow-previous").click(function() { - currentslide = (currentslide ? currentslide : slides.length) - 1; - showCurrentImage(); - }); - slideShowElement.find(".slideshow-play-pause").click(togglePlay); - slideShowElement.find(".close-annotation").click(closeAnnotation); - slideShowElement.find(".annotation-title").text(data.title); - } function closeAnnotation(e) { - $(".chip").removeClass("current"); + currentAnnotation = null; + $(".chip, .pictolist li").removeClass("current"); $(".chapters-bar").removeClass("annotation-onscreen"); $(".main-video .annotation").remove(); if (!!e) {