|
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) { |
|
957
|
52 |
this.player.trigger("search.matchFound"); |
|
902
|
53 |
} else { |
|
957
|
54 |
this.player.trigger("search.noMatchFound"); |
|
902
|
55 |
} |
|
|
56 |
} |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
IriSP.Widgets.MediaList.prototype.draw = function() { |
|
|
60 |
this.$.addClass("Ldt-MediaListWidget") |
|
|
61 |
this.renderTemplate(); |
|
965
|
62 |
var _this = this; |
|
|
63 |
if (typeof this.media.getMedias === "function") { |
|
|
64 |
this.media.getMedias().forEach(function(_m) { |
|
|
65 |
_m.on("enter", function() { |
|
|
66 |
_this.redraw(_m); |
|
|
67 |
}); |
|
|
68 |
}) |
|
|
69 |
} |
|
902
|
70 |
this.redraw(); |
|
|
71 |
}; |
|
|
72 |
|
|
917
|
73 |
IriSP.Widgets.MediaList.prototype.getSegments = function(_media) { |
|
|
74 |
var _this = this, |
|
|
75 |
_scale = this.$.width()/_media.duration.milliseconds; |
|
|
76 |
return this.getWidgetAnnotations() |
|
|
77 |
.filter(function(_annotation) { |
|
|
78 |
return _annotation.getMedia().id == _media.id; |
|
|
79 |
}) |
|
|
80 |
.map(function(_a) { |
|
|
81 |
var _annotation = ( _a.type = "mashedAnnotation" ? _a.annotation : _a ); |
|
|
82 |
return { |
|
|
83 |
left: _scale * _annotation.begin, |
|
|
84 |
width: _scale * (_annotation.end - _annotation.begin), |
|
|
85 |
color: ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.default_color ) |
|
|
86 |
} |
|
|
87 |
}) |
|
|
88 |
} |
|
|
89 |
|
|
903
|
90 |
IriSP.Widgets.MediaList.prototype.redraw = function(_media) { |
|
902
|
91 |
if (typeof _media !== "undefined") { |
|
|
92 |
this.$.find('.Ldt-MediaList-Other h2').html(this.l10n.other_media); |
|
|
93 |
this.$.find('.Ldt-MediaList-NowPlaying').show(); |
|
|
94 |
this.$.find('.Ldt-MediaList-Now-Thumbnail').attr("src", _media.thumbnail || this.default_thumbnail); |
|
|
95 |
this.$.find('.Ldt-MediaList-Now-Title a').html(_media.title); |
|
|
96 |
this.$.find('.Ldt-MediaList-Now-Description').html(_media.description); |
|
|
97 |
var _url = _media.url || Mustache.to_html( |
|
|
98 |
this.media_url_template, { |
|
916
|
99 |
media: _media.id |
|
902
|
100 |
}); |
|
|
101 |
this.$.find('.Ldt-MediaList-NowContainer a').attr("href", _url); |
|
917
|
102 |
var _mediaView = Mustache.to_html( this.mediaViewTemplate, { |
|
|
103 |
segments: this.getSegments(_media) |
|
|
104 |
}); |
|
|
105 |
this.$.find('.Ldt-MediaList-Now-MediaView').html(_mediaView); |
|
902
|
106 |
} else { |
|
|
107 |
this.$.find('.Ldt-MediaList-Other h2').html(this.l10n.all_media); |
|
|
108 |
this.$.find('.Ldt-MediaList-NowPlaying').hide(); |
|
|
109 |
} |
|
|
110 |
var _this = this, |
|
903
|
111 |
_otherlist = this.source.getMedias().filter(function(_m) { |
|
|
112 |
return (_m.id !== _this.lastMedia) |
|
902
|
113 |
}); |
|
|
114 |
if (_otherlist.length) { |
|
|
115 |
this.$.find('.Ldt-MediaList-Other').show(); |
|
|
116 |
var _html = _otherlist.map(function(_media) { |
|
|
117 |
return Mustache.to_html(_this.mediaTemplate, { |
|
|
118 |
thumbnail: _media.thumbnail || _this.default_thumbnail, |
|
|
119 |
url: _media.url || Mustache.to_html( |
|
|
120 |
_this.media_url_template, { |
|
916
|
121 |
media: _media.id |
|
902
|
122 |
}), |
|
|
123 |
title: _media.title, |
|
917
|
124 |
description: _media.description, |
|
|
125 |
segments: _this.getSegments(_media) |
|
902
|
126 |
}) |
|
|
127 |
}).join(""); |
|
|
128 |
this.$.find('.Ldt-MediaList-OtherList').html(_html); |
|
|
129 |
} else { |
|
|
130 |
this.$.find('.Ldt-MediaList-Other').hide(); |
|
|
131 |
} |
|
|
132 |
}; |