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) { |
|
46 |
$(".chapter").removeClass("found"); |
|
47 |
clickedTag = null; |
|
48 |
} |
|
49 |
}); |
|
50 |
|
|
51 |
function showTag(tagId) { |
|
52 |
$(".chapter").removeClass("found"); |
|
53 |
var tag = myProject.getElement(tagId); |
|
54 |
if (tag) { |
|
55 |
tag.getRelated("annotation").forEach(function(a) { |
|
56 |
a.trigger("found-tags"); |
|
57 |
}); |
|
58 |
} |
|
59 |
lastTag = tagId; |
|
60 |
} |
|
61 |
|
|
62 |
$(".tag").hover(function() { |
|
63 |
showTag($(this).attr("data-tag-id")); |
|
64 |
}, function() { |
|
65 |
showTag(clickedTag); |
|
66 |
}).click(function() { |
|
67 |
clickedTag = lastTag; |
|
68 |
return false; |
|
69 |
}); |
|
70 |
|
|
71 |
|
|
72 |
var chapters = myProject.getAnnotationsByTypeTitle("chapitrage"), |
|
73 |
chapterTemplate = _.template( |
|
74 |
'<li class="chapter" style="left: <%- 100*begin/getMedia().duration %>%; width: <%- 100*getDuration()/getMedia().duration %>%;">' |
|
75 |
+ '<div class="chapter-block"></div><div class="chapter-title"><%- title %></div></li>' |
|
76 |
), |
|
77 |
chapterList = $(".chapters-list"), |
|
78 |
hoveredChapter = null, |
|
79 |
currentChapter = null, |
|
80 |
currentChapterI = 0; |
|
81 |
|
|
82 |
function highlightChapter() { |
|
83 |
$(".chapter").removeClass("active"); |
|
84 |
if (hoveredChapter || currentChapter) { |
|
85 |
(hoveredChapter || currentChapter).addClass("active"); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
chapters.forEach(function(chapter, i) { |
|
90 |
var element = $(chapterTemplate(chapter)); |
|
91 |
element.click(function() { |
|
92 |
myMedia.setCurrentTime(chapter.begin); |
|
93 |
}).hover(function() { |
|
94 |
hoveredChapter = element; |
|
95 |
highlightChapter(); |
|
96 |
}, function() { |
|
97 |
hoveredChapter = null; |
|
98 |
highlightChapter(); |
|
99 |
}); |
|
100 |
chapter.on("enter", function() { |
|
101 |
currentChapter = element; |
|
102 |
currentChapterI = i; |
|
103 |
if (i) { |
|
104 |
$(".prev-chapter").removeClass("inactive"); |
|
105 |
} else { |
|
106 |
$(".prev-chapter").addClass("inactive"); |
|
107 |
} |
|
108 |
if (i < chapters.length - 1) { |
|
109 |
$(".next-chapter").removeClass("inactive"); |
|
110 |
} else { |
|
111 |
$(".next-chapter").addClass("inactive"); |
|
112 |
} |
|
113 |
highlightChapter(); |
|
114 |
}); |
|
115 |
chapter.on("leave", function() { |
|
116 |
currentChapter = null; |
|
117 |
highlightChapter(); |
|
118 |
}); |
|
119 |
chapter.on("found-tags", function() { |
|
120 |
element.addClass("found"); |
|
121 |
}); |
|
122 |
chapterList.append(element); |
|
123 |
}); |
|
124 |
|
|
125 |
$(".prev-chapter").click(function() { |
|
126 |
if (i) { |
|
127 |
myMedia.setCurrentTime(chapters[currentChapterI - 1].begin); |
|
128 |
} |
|
129 |
}); |
|
130 |
$(".next-chapter").click(function() { |
|
131 |
if (i < chapters.length - 1) { |
|
132 |
myMedia.setCurrentTime(chapters[currentChapterI + 1].begin); |
|
133 |
} |
|
134 |
}); |
|
135 |
|
|
136 |
$(".play-button").click(function() { |
|
137 |
if (myMedia.paused) { |
|
138 |
myMedia.play(); |
|
139 |
} else { |
|
140 |
myMedia.pause(); |
|
141 |
} |
|
142 |
}); |
|
143 |
|
2
|
144 |
$(".progress-indicator").draggable({ |
|
145 |
axis: "x", |
3
|
146 |
containment: "parent", |
|
147 |
drag: function(e, ui) { |
|
148 |
var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".chapters-bar").width() - 2 * ui.helper.width() ); |
|
149 |
myMedia.setCurrentTime(t); |
|
150 |
} |
2
|
151 |
}); |
|
152 |
$(".play-button").click(function() { |
|
153 |
$(this).toggleClass("pause"); |
|
154 |
}); |
5
|
155 |
|
|
156 |
var pictoTemplate = _.template( |
|
157 |
'<li class="<%- type %>"><span class="picto"><a href="#"></a></span>' |
|
158 |
+ '<span class="picto-title"><%- annotation.title %></span></li>' |
|
159 |
); |
|
160 |
|
|
161 |
var chipTemplate = _.template( |
|
162 |
'<li class="chip <%- type %>" style="left: <%- pos %>%"><span class="chip-circle">' |
|
163 |
+ '</span><span class="chip-title"><%- annotation.title %></span></li>' |
|
164 |
); |
|
165 |
|
|
166 |
var annotations = myProject.getAnnotationsByTypeTitle("annotations"); |
|
167 |
|
|
168 |
annotations.forEach(function(annotation) { |
|
169 |
var annotationinfo = { |
|
170 |
annotation: annotation, |
|
171 |
open: false, |
|
172 |
pos: 100 * annotation.begin / annotation.getMedia().duration |
|
173 |
}; |
|
174 |
switch(annotation.content.mimetype) { |
|
175 |
case "application/x-ldt-slideshow": |
|
176 |
annotationinfo.type = "slideshow"; |
|
177 |
break; |
2
|
178 |
} |
5
|
179 |
annotationinfo.picto = $(pictoTemplate(annotationinfo)).appendTo(".pictolist"); |
|
180 |
annotationinfo.chip = $(chipTemplate(annotationinfo)).appendTo(".chips-list"); |
|
181 |
annotationinfo.both = annotationinfo.picto.add(annotationinfo.chip); |
|
182 |
annotationinfo.both.click(function() { |
|
183 |
openAnnotation(annotationinfo); |
|
184 |
}) |
|
185 |
.hover(function() { |
|
186 |
annotationinfo.both.addClass("hover"); |
|
187 |
}, function() { |
|
188 |
annotationinfo.both.removeClass("hover"); |
|
189 |
}); |
|
190 |
annotation.on("enter", function() { |
|
191 |
annotationinfo.picto.show(); |
|
192 |
}); |
|
193 |
annotation.on("leave", function() { |
|
194 |
annotationinfo.picto.hide(); |
|
195 |
}); |
|
196 |
}); |
|
197 |
|
|
198 |
function openAnnotation(annotationinfo) { |
|
199 |
|
|
200 |
if (annotationinfo.open) { |
|
201 |
annotationinfo.open = false; |
|
202 |
closeAnnotation(true); |
|
203 |
return; |
|
204 |
} |
|
205 |
|
|
206 |
if (myMedia.currentTime < annotationinfo.annotation.begin || myMedia.currentTime > annotationinfo.annotation.end) { |
|
207 |
myMedia.setCurrentTime(annotationinfo.annotation.begin); |
|
208 |
} |
|
209 |
|
|
210 |
annotationinfo.open = true; |
|
211 |
|
|
212 |
myMedia.pause(); |
|
213 |
closeAnnotation(false); |
|
214 |
|
|
215 |
annotationinfo.both.addClass("current"); |
|
216 |
|
|
217 |
$(".chapters-bar").addClass("annotation-onscreen"); |
|
218 |
|
|
219 |
switch (annotationinfo.type) { |
|
220 |
case "slideshow": |
|
221 |
slideshow(annotationinfo.annotation); |
|
222 |
break; |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 |
function slideshow(data) { |
3
|
227 |
|
5
|
228 |
var currentslide = 0, |
|
229 |
slideInterval, |
|
230 |
playing = false, |
|
231 |
loaded = false, |
|
232 |
slides = data.content.images |
|
233 |
slideShowElement = $(".annotation-templates .slideshow-annotation").clone(); |
2
|
234 |
|
5
|
235 |
slideShowElement.appendTo($(".main-video")); |
3
|
236 |
|
5
|
237 |
function checkloaded() { |
|
238 |
if (loaded) { |
|
239 |
return; |
|
240 |
} |
|
241 |
loaded = slides.reduce(function(mem, slide) { |
|
242 |
return (mem && !!slide.image && !!slide.image.width); |
|
243 |
}, true); |
|
244 |
if (loaded) { |
|
245 |
showCurrentImage(); |
|
246 |
if (data.autostart) { |
|
247 |
togglePlay(); |
|
248 |
} |
|
249 |
} |
|
250 |
} |
2
|
251 |
|
5
|
252 |
slides.forEach(function(slide) { |
|
253 |
slide.image = new Image(); |
|
254 |
slide.image.onload = checkloaded; |
|
255 |
slide.image.src = slide.url; |
|
256 |
}); |
2
|
257 |
|
5
|
258 |
checkloaded(); |
|
259 |
|
|
260 |
function resizeImage() { |
|
261 |
var imgel = slideShowElement.find(".slideshow-image"); |
|
262 |
imgel.css("margin-top",""); |
|
263 |
var w = imgel.width(), |
|
264 |
h = imgel.height(); |
|
265 |
slideShowElement.find(".slideshow-center").css("height",""); |
|
266 |
slideShowElement.find(".slideshow-description").css("margin-left",w); |
|
267 |
var h2 = slideShowElement.find(".slideshow-center").height(); |
|
268 |
if (h < h2) { |
|
269 |
imgel.css("margin-top",Math.floor((h2-h)/2)+"px"); |
|
270 |
} |
|
271 |
} |
2
|
272 |
|
5
|
273 |
function showCurrentImage() { |
|
274 |
var slide = slides[currentslide]; |
|
275 |
slideShowElement.find(".slideshow-image").attr({ |
|
276 |
src: slide.image.src, |
|
277 |
title: slide.title, |
|
278 |
alt: slide.title |
|
279 |
}); |
|
280 |
slideShowElement.find(".slideshow-title").text(slide.title); |
|
281 |
slideShowElement.find(".slideshow-description").html( |
|
282 |
slide.description.split(/\n/gm).map(function(l) { |
|
283 |
return '<p>' + _.escape(l) + '</p>'; |
|
284 |
}).join("") |
|
285 |
); |
|
286 |
resizeImage(); |
|
287 |
} |
2
|
288 |
|
5
|
289 |
function nextImage() { |
|
290 |
currentslide = (currentslide + 1) % slides.length; |
|
291 |
showCurrentImage(); |
|
292 |
} |
2
|
293 |
|
5
|
294 |
function togglePlay() { |
|
295 |
playing = !playing; |
|
296 |
clearInterval(slideInterval); |
|
297 |
if (playing) { |
|
298 |
slideInterval = setInterval(nextImage,data["slide-duration"]); |
|
299 |
slideShowElement.find(".slideshow-play-pause").addClass("pause"); |
|
300 |
} else { |
|
301 |
slideShowElement.find(".slideshow-play-pause").removeClass("pause"); |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
slideShowElement.find(".slideshow-next").click(nextImage); |
|
306 |
slideShowElement.find(".slideshow-previous").click(function() { |
|
307 |
currentslide = (currentslide ? currentslide : slides.length) - 1; |
|
308 |
showCurrentImage(); |
|
309 |
}); |
|
310 |
slideShowElement.find(".slideshow-play-pause").click(togglePlay); |
|
311 |
slideShowElement.find(".close-annotation").click(closeAnnotation); |
|
312 |
slideShowElement.find(".annotation-title").text(data.title); |
|
313 |
} |
3
|
314 |
|
5
|
315 |
function closeAnnotation(e) { |
|
316 |
$(".chip").removeClass("current"); |
|
317 |
$(".chapters-bar").removeClass("annotation-onscreen"); |
|
318 |
$(".main-video .annotation").remove(); |
|
319 |
if (!!e) { |
|
320 |
myMedia.play(); |
|
321 |
} |
|
322 |
} |
3
|
323 |
|
2
|
324 |
}); |