| author | veltr |
| Wed, 05 Dec 2012 11:17:58 +0100 | |
| changeset 109 | 3034776c1f35 |
| parent 86 | 4857ac3892e3 |
| child 141 | f1b68efb360a |
| permissions | -rw-r--r-- |
| 49 | 1 |
IriSP.mashupplayer = function(options) { |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
2 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
3 |
var directory = new IriSP.Model.Directory(), |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
4 |
project = directory.remoteSource({ |
| 109 | 5 |
url: IriSP.endpoints.ldt.replace('__PROJECT_ID__', options.id), |
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
6 |
serializer: IriSP.serializers.ldt |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
7 |
}), |
| 49 | 8 |
apidirectory = new IriSP.Model.Directory(), |
| 43 | 9 |
mashup, |
10 |
mediatemplate = _.template('<li class="item-video media" data-media-id="<%= media.id %>">' |
|
| 109 | 11 |
+ '<a href="<%= IriSP.endpoints.media_page.replace("__CONTENT_ID__", media.id) %>"><img class="thumbnail" alt="<%= media.title %>" src="<%= media.thumbnail %>"></a><div class="video-info">' |
12 |
+ '<h3 class="title-video"><a href="<%= IriSP.endpoints.media_page.replace("__CONTENT_ID__", media.id) %>"><%= media.title %></a></h3><p class="description"><%= media.description %></p>' |
|
| 43 | 13 |
+ '<p class="time-length">Durée : <span><%= media.duration.toString() %></span></p><div class="frise">' |
14 |
+ '<div class="frise-overflow"><div class="frise-segments"><%= segments %></div></div></div></div></li>'); |
|
15 |
segmenttemplate = _.template('<div style="background-color:<%= annotation.color %>; left:<%= left %>%; width: <%= width %>%;"' |
|
16 |
+ ' class="frise-segment annotation" data-segment-id="<%= annotation.id %>" title="<%= annotation.title %>"></div>') |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
17 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
18 |
project.onLoad(function() { |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
19 |
mashup = project.getMashups()[0]; |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
20 |
IriSP.mashupcore(project, mashup); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
21 |
project.trigger("set-current",mashup); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
22 |
|
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
23 |
$(".info-duration td").text(mashup.duration.toString()); |
| 86 | 24 |
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
25 |
$(".info-description td").text(mashup.description); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
26 |
|
| 43 | 27 |
mashup.getMedias().forEach(function(media) { |
| 49 | 28 |
apidirectory.remoteSource({ |
29 |
url: IriSP.endpoints.content + media.id, |
|
30 |
serializer: IriSP.serializers.content |
|
31 |
}).onLoad(function() { |
|
32 |
var m = apidirectory.getElement(media.id); |
|
33 |
if (m) { |
|
34 |
media.thumbnail = m.thumbnail; |
|
35 |
} |
|
36 |
var segments = mashup.segments.filter(function(segment) { |
|
37 |
return segment.getMedia() === media; |
|
38 |
}); |
|
39 |
var segmentshtml = '', k = media.duration ? (100 / media.duration) : 0; |
|
40 |
segments.forEach(function(segment) { |
|
41 |
var vizdata = { |
|
42 |
annotation: segment.annotation, |
|
43 |
left: k * segment.annotation.begin, |
|
44 |
width: k * segment.annotation.getDuration() |
|
45 |
} |
|
46 |
segmentshtml += segmenttemplate(vizdata); |
|
47 |
}); |
|
48 |
var mediadata = { |
|
49 |
media: media, |
|
50 |
segments: segmentshtml |
|
51 |
} |
|
52 |
|
|
53 |
$(".list-video").append(mediatemplate(mediadata)); |
|
| 43 | 54 |
}); |
55 |
}); |
|
56 |
|
|
57 |
|
|
58 |
project.on("mouseover-annotation", function(annotation) { |
|
59 |
var mediaid = annotation.getMedia().id; |
|
60 |
$(".media").removeClass("active"); |
|
61 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
62 |
}); |
|
63 |
|
|
64 |
project.on("mouseout-annotation", function(annotation) { |
|
65 |
$(".media").removeClass("active"); |
|
66 |
var mediaid = mashup.currentMedia.id; |
|
67 |
$(".media[data-media-id='" + mediaid + "']").addClass("active"); |
|
68 |
}); |
|
69 |
|
|
| 49 | 70 |
$(".list-video") |
71 |
.on("mouseover", ".frise-segment", function() { |
|
| 43 | 72 |
project.trigger("mouseover-annotation", project.getElement($(this).attr("data-segment-id"))); |
73 |
}) |
|
| 49 | 74 |
.on("click", ".frise-segment", function() { |
| 43 | 75 |
project.trigger("click-annotation", project.getElement($(this).attr("data-segment-id"))); |
| 49 | 76 |
}) |
77 |
.on("mouseover", ".item-video", function() { |
|
| 43 | 78 |
$(".media").removeClass("active"); |
79 |
}) |
|
| 49 | 80 |
.on("mouseout", ".item-video", function() { |
| 43 | 81 |
project.trigger("mouseout-annotation"); |
| 73 | 82 |
}); |
83 |
|
|
84 |
$(".mashup-frise") |
|
85 |
.click(function(evt) { |
|
86 |
if (!mashup.duration.milliseconds) { |
|
87 |
return; |
|
88 |
} |
|
89 |
var el = $(this), t = ( evt.pageX - el.offset().left ) * mashup.duration / el.width(), segment = mashup.getAnnotationAtTime(t); |
|
90 |
if (segment) { |
|
91 |
project.trigger("click-annotation", segment.annotation); |
|
92 |
} |
|
93 |
}); |
|
| 43 | 94 |
|
95 |
|
|
|
41
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
96 |
}); |
|
3ec2343f2b85
Refactoring to have common code between editor and player
veltr
parents:
diff
changeset
|
97 |
} |
| 50 | 98 |
|
99 |
/* END mashupplayer.js */ |