|
902
|
1 |
IriSP.Widgets.MediaList = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
this.lastMedia = false; |
|
|
4 |
}; |
|
|
5 |
|
|
|
6 |
IriSP.Widgets.MediaList.prototype = new IriSP.Widgets.Widget(); |
|
|
7 |
|
|
|
8 |
IriSP.Widgets.MediaList.prototype.messages = { |
|
|
9 |
"fr": { |
|
|
10 |
now_playing: "Média en cours", |
|
|
11 |
all_media: "Tous les medias", |
|
|
12 |
other_media: "Autres médias" |
|
|
13 |
}, |
|
|
14 |
"en": { |
|
|
15 |
now_playing: "Now playing", |
|
|
16 |
all_media: "All media", |
|
|
17 |
other_media: "Other media" |
|
|
18 |
} |
|
|
19 |
} |
|
|
20 |
|
|
|
21 |
IriSP.Widgets.MediaList.prototype.defaults = { |
|
|
22 |
default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png", |
|
917
|
23 |
media_url_template : "http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/front/player/{{media}}/", |
|
|
24 |
default_color : "#000080" |
|
902
|
25 |
}; |
|
|
26 |
|
|
|
27 |
IriSP.Widgets.MediaList.prototype.template = |
|
|
28 |
'<div class="Ldt-MediaList-NowPlaying"><h2>{{l10n.now_playing}}</h2><hr />' |
|
|
29 |
+ '<div class="Ldt-MediaList-NowContainer">' |
|
|
30 |
+ '<div class="Ldt-MediaList-Now-ThumbContainer"><a href="" target="_blank">' |
|
|
31 |
+ '<img class="Ldt-MediaList-Now-Thumbnail" src="" /></a></div>' |
|
|
32 |
+ '<h3 class="Ldt-MediaList-Now-Title"><a href="" target="_blank"></a></h3>' |
|
917
|
33 |
+ '<p class="Ldt-MediaList-Now-Description"></p><div class="Ldt-MediaList-Now-MediaView"></div></div></div>' |
|
903
|
34 |
+ '<div class="Ldt-MediaList-Other"><h2></h2><hr /><ul class="Ldt-MediaList-OtherList"></ul></div>'; |
|
902
|
35 |
|
|
917
|
36 |
IriSP.Widgets.MediaList.prototype.mediaViewTemplate = |
|
|
37 |
'<div class="Ldt-MediaList-MediaView-Background"></div>{{#segments}}<div class="Ldt-MediaList-Segment" style="background: {{color}}; left: {{left}}px; width: {{width}}px;"></div>{{/segments}}'; |
|
|
38 |
|
|
902
|
39 |
IriSP.Widgets.MediaList.prototype.mediaTemplate = |
|
|
40 |
'<li class="Ldt-MediaList-OtherList-li"><div class="Ldt-MediaList-Other-ThumbContainer"><a href="{{url}}" target="_blank">' |
|
|
41 |
+ '<img class="Ldt-MediaList-Other-Thumbnail" src="{{thumbnail}}" /></a></div>' |
|
|
42 |
+ '<h3 class="Ldt-MediaList-Other-Title"><a href="{{url}}" target="_blank">{{title}}</a></h3>' |
|
917
|
43 |
+ '<p class="Ldt-MediaList-Other-Description">{{description}}</p><div class="Ldt-MediaList-Other-MediaView">' |
|
|
44 |
+ IriSP.Widgets.MediaList.prototype.mediaViewTemplate + '</div></li>'; |
|
|
45 |
|
|
902
|
46 |
|
|
|
47 |
IriSP.Widgets.MediaList.prototype.onSearch = function(searchString) { |
|
|
48 |
this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
|
49 |
var _n = this.refresh(true); |
|
|
50 |
if (this.searchString) { |
|
|
51 |
if (_n) { |
|
|
52 |
this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
|
53 |
} else { |
|
|
54 |
this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
|
55 |
} |
|
|
56 |
} |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
IriSP.Widgets.MediaList.prototype.draw = function() { |
|
|
60 |
this.bindPopcorn("timeupdate","onTimeupdate"); |
|
|
61 |
this.$.addClass("Ldt-MediaListWidget") |
|
|
62 |
this.renderTemplate(); |
|
|
63 |
this.redraw(); |
|
|
64 |
}; |
|
|
65 |
|
|
917
|
66 |
IriSP.Widgets.MediaList.prototype.getSegments = function(_media) { |
|
|
67 |
var _this = this, |
|
|
68 |
_scale = this.$.width()/_media.duration.milliseconds; |
|
|
69 |
return this.getWidgetAnnotations() |
|
|
70 |
.filter(function(_annotation) { |
|
|
71 |
return _annotation.getMedia().id == _media.id; |
|
|
72 |
}) |
|
|
73 |
.map(function(_a) { |
|
|
74 |
var _annotation = ( _a.type = "mashedAnnotation" ? _a.annotation : _a ); |
|
|
75 |
return { |
|
|
76 |
left: _scale * _annotation.begin, |
|
|
77 |
width: _scale * (_annotation.end - _annotation.begin), |
|
|
78 |
color: ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.default_color ) |
|
|
79 |
} |
|
|
80 |
}) |
|
|
81 |
} |
|
|
82 |
|
|
903
|
83 |
IriSP.Widgets.MediaList.prototype.redraw = function(_media) { |
|
902
|
84 |
if (typeof _media !== "undefined") { |
|
|
85 |
this.$.find('.Ldt-MediaList-Other h2').html(this.l10n.other_media); |
|
|
86 |
this.$.find('.Ldt-MediaList-NowPlaying').show(); |
|
|
87 |
this.$.find('.Ldt-MediaList-Now-Thumbnail').attr("src", _media.thumbnail || this.default_thumbnail); |
|
|
88 |
this.$.find('.Ldt-MediaList-Now-Title a').html(_media.title); |
|
|
89 |
this.$.find('.Ldt-MediaList-Now-Description').html(_media.description); |
|
|
90 |
var _url = _media.url || Mustache.to_html( |
|
|
91 |
this.media_url_template, { |
|
916
|
92 |
media: _media.id |
|
902
|
93 |
}); |
|
|
94 |
this.$.find('.Ldt-MediaList-NowContainer a').attr("href", _url); |
|
917
|
95 |
var _mediaView = Mustache.to_html( this.mediaViewTemplate, { |
|
|
96 |
segments: this.getSegments(_media) |
|
|
97 |
}); |
|
|
98 |
this.$.find('.Ldt-MediaList-Now-MediaView').html(_mediaView); |
|
902
|
99 |
} else { |
|
|
100 |
this.$.find('.Ldt-MediaList-Other h2').html(this.l10n.all_media); |
|
|
101 |
this.$.find('.Ldt-MediaList-NowPlaying').hide(); |
|
|
102 |
} |
|
|
103 |
var _this = this, |
|
903
|
104 |
_otherlist = this.source.getMedias().filter(function(_m) { |
|
|
105 |
return (_m.id !== _this.lastMedia) |
|
902
|
106 |
}); |
|
|
107 |
if (_otherlist.length) { |
|
|
108 |
this.$.find('.Ldt-MediaList-Other').show(); |
|
|
109 |
var _html = _otherlist.map(function(_media) { |
|
|
110 |
return Mustache.to_html(_this.mediaTemplate, { |
|
|
111 |
thumbnail: _media.thumbnail || _this.default_thumbnail, |
|
|
112 |
url: _media.url || Mustache.to_html( |
|
|
113 |
_this.media_url_template, { |
|
916
|
114 |
media: _media.id |
|
902
|
115 |
}), |
|
|
116 |
title: _media.title, |
|
917
|
117 |
description: _media.description, |
|
|
118 |
segments: _this.getSegments(_media) |
|
902
|
119 |
}) |
|
|
120 |
}).join(""); |
|
|
121 |
this.$.find('.Ldt-MediaList-OtherList').html(_html); |
|
|
122 |
} else { |
|
|
123 |
this.$.find('.Ldt-MediaList-Other').hide(); |
|
|
124 |
} |
|
|
125 |
}; |
|
|
126 |
|
|
|
127 |
IriSP.Widgets.MediaList.prototype.onTimeupdate = function() { |
|
903
|
128 |
var _media = this.source.currentMedia; |
|
|
129 |
if (_media.elementType === "mashup") { |
|
|
130 |
_media = _media.getMediaAtTime(this.player.popcorn.currentTime() * 1000); |
|
|
131 |
} |
|
|
132 |
if (typeof _media !== "undefined" && _media.id !== this.lastMedia) { |
|
|
133 |
this.lastMedia = _media.id; |
|
|
134 |
this.redraw(_media); |
|
902
|
135 |
} |
|
|
136 |
} |