10 currentMedia, |
10 currentMedia, |
11 globalTags = {}, |
11 globalTags = {}, |
12 seqCount; |
12 seqCount; |
13 |
13 |
14 var ratio = 2.37; |
14 var ratio = 2.37; |
|
15 |
|
16 if (typeof window.localStorage !== "undefined" && window.localStorage.getItem !== "undefined") { |
|
17 var resolution = window.localStorage.getItem("resolution") || "SD"; |
|
18 } else { |
|
19 var resolution = "SD"; |
|
20 } |
|
21 var video_url_transform = function(url) { |
|
22 return url.replace(/[SH]D(\.[a-z0-9]+)$/,resolution + "$1"); |
|
23 } |
15 |
24 |
16 function resizeVideo() { |
25 function resizeVideo() { |
17 var currentwidth = $(window).width(), |
26 var currentwidth = $(window).width(), |
18 maxheight = $(window).height() - 220, |
27 maxheight = $(window).height() - 220, |
19 height = Math.min(maxheight, currentwidth / ratio), |
28 height = Math.min(maxheight, currentwidth / ratio), |
60 segmentdragin = segmentdragout.find("ul") |
69 segmentdragin = segmentdragout.find("ul") |
61 segmentdragging = false; |
70 segmentdragging = false; |
62 |
71 |
63 function resizeSegmentDrag() { |
72 function resizeSegmentDrag() { |
64 var segmentdelta = segmentdragout.width() - segmentdragin.width(); |
73 var segmentdelta = segmentdragout.width() - segmentdragin.width(); |
65 segmentdragin.draggable("option","containment",segmentdelta < 0 ? [ segmentdelta - 20, 0, 20, 0 ] : "parent") |
74 segmentdragin.draggable("option","containment",segmentdelta < 0 ? [ segmentdelta - 20, 0, 20, 0 ] : "parent"); |
|
75 if (segmentdelta < 0 && currentSegment && $("#title_sequence li").length) { |
|
76 var x = $("#title_sequence li[data-segment-id='" + currentSegment.id + "']").offset().left - segmentdragin.offset().left; |
|
77 segmentdragin.css("left", Math.max(segmentdelta - 20, Math.min( 20, 36 - x))) |
|
78 } |
66 } |
79 } |
67 |
80 |
68 segmentdragin.draggable({ |
81 segmentdragin.draggable({ |
69 axis: "x", |
82 axis: "x", |
70 start: function() { |
83 start: function() { |
91 |
104 |
92 var tagsdragout = $("#tag_sequence"), |
105 var tagsdragout = $("#tag_sequence"), |
93 tagsdragin = tagsdragout.find("ul") |
106 tagsdragin = tagsdragout.find("ul") |
94 tagsdragging = false; |
107 tagsdragging = false; |
95 |
108 |
96 function resizeTagsDrag() { |
109 function resizeTagsDrag(toRight) { |
97 var tagsdelta = tagsdragout.width() - tagsdragin.width(); |
110 var tagsdelta = tagsdragout.width() - tagsdragin.width(); |
98 tagsdragin.draggable("option","containment",tagsdelta < 0 ? [ tagsdelta - 20, 0, 20, 0 ] : "parent"); |
111 tagsdragin.draggable("option","containment",tagsdelta < 0 ? [ tagsdelta - 20, 0, 20, 0 ] : "parent"); |
99 tagsdragin.css("left",Math.floor(tagsdelta/2)); |
112 tagsdragin.css("left",(toRight && tagsdelta < 0) ? tagsdelta - 20 : Math.floor(tagsdelta/2)); |
100 } |
113 } |
101 |
114 |
102 tagsdragin.draggable({ |
115 tagsdragin.draggable({ |
103 axis: "x", |
116 axis: "x", |
104 start: function() { |
117 start: function() { |
194 contentType: 'application/json', |
207 contentType: 'application/json', |
195 data: _export.serialize(), /* L'objet Source est sérialisé */ |
208 data: _export.serialize(), /* L'objet Source est sérialisé */ |
196 success: function(_data) { |
209 success: function(_data) { |
197 var n = 1 + (segmentAtPost.__tags[_tagvalue] || 0) |
210 var n = 1 + (segmentAtPost.__tags[_tagvalue] || 0) |
198 segmentAtPost.__tags[_tagvalue] = n; |
211 segmentAtPost.__tags[_tagvalue] = n; |
199 showCurrentTags(); |
212 showCurrentTags(_tagvalue); |
200 }, |
213 }, |
201 error: function(_xhr, _error, _thrown) { |
214 error: function(_xhr, _error, _thrown) { |
202 console.log("Error when sending annotation", _thrown); |
215 console.log("Error when sending annotation", _thrown); |
203 } |
216 } |
204 }); |
217 }); |
246 s.on("enter", function() { |
259 s.on("enter", function() { |
247 currentSegment = s; |
260 currentSegment = s; |
248 showCurrentTags(); |
261 showCurrentTags(); |
249 $("#title_sequence li").removeClass("here"); |
262 $("#title_sequence li").removeClass("here"); |
250 $("#title_sequence li[data-segment-id='" + s.id + "']").addClass("here"); |
263 $("#title_sequence li[data-segment-id='" + s.id + "']").addClass("here"); |
|
264 resizeSegmentDrag(); |
251 }); |
265 }); |
252 }); |
266 }); |
253 |
267 |
254 segmentdragin.html(segmentsHtml); |
268 segmentdragin.html(segmentsHtml); |
255 resizeSegmentDrag(); |
269 resizeSegmentDrag(); |
256 |
270 |
257 currentMedia.play(); |
271 currentMedia.play(); |
258 }); |
272 }); |
259 |
273 |
260 function showCurrentTags() { |
274 function showCurrentTags(tagToShow) { |
261 var vals = _(currentSegment.__tags).values(), |
275 var vals = _(currentSegment.__tags).values(), |
262 max = Math.max.apply(Math, vals), |
276 max = Math.max.apply(Math, vals), |
263 min = Math.min(max - 1, Math.min.apply(Math, vals)), |
277 min = Math.min(max - 1, Math.min.apply(Math, vals)), |
264 b = 160 / (max - min); |
278 b = 160 / (max - min), |
265 var html = _(currentSegment.__tags) |
279 tagList = _(currentSegment.__tags).map(function(v, k) { |
266 .chain() |
280 return { |
267 .map(function(v, k) { |
281 label: k, |
268 var c = Math.floor( 95 + (v - min) * b ); |
282 weight: v |
269 return '<li><a href="' |
283 } |
270 + IriSP.endpoints.tag_page.replace("__TAG__",encodeURIComponent(k)) |
284 }); |
|
285 tagList = _(tagList).shuffle(); |
|
286 if (tagToShow && currentSegment.__tags[tagToShow]) { |
|
287 tagList = tagList.filter(function(t) { |
|
288 return (t.label !== tagToShow); |
|
289 }); |
|
290 tagList.push({ |
|
291 label: tagToShow, |
|
292 weight: currentSegment.__tags[tagToShow] |
|
293 }); |
|
294 } |
|
295 var html = tagList.reduce( |
|
296 function(memo, tag) { |
|
297 var c = Math.floor( 95 + (tag.weight - min) * b ); |
|
298 return memo + '<li><a href="' |
|
299 + IriSP.endpoints.tag_page.replace("__TAG__",encodeURIComponent(tag.label)) |
271 + '" style="color: rgb(' |
300 + '" style="color: rgb(' |
272 + [c,c,c].join(",") |
301 + [c,c,c].join(",") |
273 + ')">' |
302 + ')">' |
274 + k |
303 + tag.label |
275 + ' </a> </li>' |
304 + ' </a> </li>'; |
276 }) |
305 }, |
277 .shuffle() |
306 ""); |
278 .value() |
|
279 .join(""); |
|
280 tagsdragin.html(html); |
307 tagsdragin.html(html); |
281 resizeTagsDrag(); |
308 resizeTagsDrag(!!tagToShow); |
282 } |
309 } |
283 |
310 |
284 function addMedia(media) { |
311 function addMedia(media) { |
285 if (media.has_player) { |
312 if (media.has_player) { |
286 return; |
313 return; |
287 } |
314 } |
288 media.has_player = true; |
315 media.has_player = true; |
289 media.loaded = false; |
316 media.loaded = false; |
290 media.paused = true; |
317 media.paused = true; |
291 var videourl = media.video; |
318 var videourl = video_url_transform(media.video), |
292 if (typeof IriSP.video_url_transform === "function") { |
319 videoid = "video_" + media.id, |
293 videourl = IriSP.video_url_transform(media.video); |
|
294 } |
|
295 var videoid = "video_" + media.id, |
|
296 videoEl = $('<video>'), |
320 videoEl = $('<video>'), |
297 mp4_file = videourl.replace(/\.webm$/i,'.mp4'), |
321 mp4_file = videourl.replace(/\.webm$/i,'.mp4'), |
298 webm_file = videourl.replace(/\.mp4$/i,'.webm'), |
322 webm_file = videourl.replace(/\.mp4$/i,'.webm'), |
299 mediaEl = videoEl[0], |
323 mediaEl = videoEl[0], |
300 can_play_mp4 = !!mediaEl.canPlayType('video/mp4'), |
324 can_play_mp4 = !!mediaEl.canPlayType('video/mp4'), |