41 keyword: "==", |
42 keyword: "==", |
42 background_color: "#f9f4c6" |
43 background_color: "#f9f4c6" |
43 }] |
44 }] |
44 }; |
45 }; |
45 |
46 |
|
47 IriSP.Widgets.AnnotationsList.prototype.messages = { |
|
48 en: { |
|
49 voice_annotation: "Voice Annotation", |
|
50 now_playing: "Now playing..." |
|
51 }, |
|
52 fr: { |
|
53 voice_annotation: "Annotation Vocale", |
|
54 now_playing: "Lecture en cours..." |
|
55 } |
|
56 }; |
|
57 |
46 IriSP.Widgets.AnnotationsList.prototype.template = |
58 IriSP.Widgets.AnnotationsList.prototype.template = |
47 '<div class="Ldt-AnnotationsListWidget">' |
59 '<div class="Ldt-AnnotationsListWidget">' |
|
60 + '{{#show_audio}}<div class="Ldt-AnnotationsList-Audio"></div>{{/show_audio}}' |
48 + '<ul class="Ldt-AnnotationsList-ul">' |
61 + '<ul class="Ldt-AnnotationsList-ul">' |
49 + '</ul>' |
62 + '</ul>' |
50 + '</div>'; |
63 + '</div>'; |
51 |
64 |
52 IriSP.Widgets.AnnotationsList.prototype.annotationTemplate = |
65 IriSP.Widgets.AnnotationsList.prototype.annotationTemplate = |
53 '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}" style="{{specific_style}}">' |
66 '<li class="Ldt-AnnotationsList-li Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}" style="{{specific_style}}">' |
54 + '<div class="Ldt-AnnotationsList-ThumbContainer">' |
67 + '<div class="Ldt-AnnotationsList-ThumbContainer">' |
55 + '<a href="{{url}}">' |
68 + '<a href="{{url}}" draggable="true">' |
56 + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />' |
69 + '<img class="Ldt-AnnotationsList-Thumbnail" src="{{thumbnail}}" />' |
57 + '</a>' |
70 + '</a>' |
58 + '</div>' |
71 + '</div>' |
59 + '<div class="Ldt-AnnotationsList-Duration">{{begin}} - {{end}}</div>' |
72 + '<div class="Ldt-AnnotationsList-Duration">{{begin}} - {{end}}</div>' |
60 + '<h3 class="Ldt-AnnotationsList-Title">' |
73 + '<h3 class="Ldt-AnnotationsList-Title" draggable="true">' |
61 + '<a href="{{url}}">{{title}}</a>' |
74 + '<a href="{{url}}">{{{htitle}}}</a>' |
62 + '</h3>' |
75 + '</h3>' |
63 + '<p class="Ldt-AnnotationsList-Description">{{description}}</p>' |
76 + '<p class="Ldt-AnnotationsList-Description">{{{hdescription}}}</p>' |
64 + '{{#tags.length}}' |
77 + '{{#tags.length}}' |
65 + '<ul class="Ldt-AnnotationsList-Tags">' |
78 + '<ul class="Ldt-AnnotationsList-Tags">' |
66 + '{{#tags}}' |
79 + '{{#tags}}' |
67 + '{{#.}}' |
80 + '{{#.}}' |
68 + '<li class="Ldt-AnnotationsList-Tag-Li">' |
81 + '<li class="Ldt-AnnotationsList-Tag-Li">' |
70 + '</li>' |
83 + '</li>' |
71 + '{{/.}}' |
84 + '{{/.}}' |
72 + '{{/tags}}' |
85 + '{{/tags}}' |
73 + '</ul>' |
86 + '</ul>' |
74 + '{{/tags.length}}' |
87 + '{{/tags.length}}' |
|
88 + '{{#audio}}<div class="Ldt-AnnotationsList-Play" data-annotation-id="{{id}}">{{l10n.voice_annotation}}</div>{{/audio}}' |
75 + '</li>'; |
89 + '</li>'; |
76 |
90 |
77 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) { |
|
78 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
79 var _n = this.refresh(true); |
|
80 if (this.searchString) { |
|
81 if (_n) { |
|
82 this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
83 } else { |
|
84 this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id; |
91 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id; |
90 |
92 |
91 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() { |
93 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() { |
92 var _currentTime = this.player.popcorn.currentTime(), |
94 var _currentTime = this.media.getCurrentTime(), |
93 _duration = this.source.getDuration(); |
95 _duration = this.media.duration; |
94 if (typeof _currentTime == "undefined") { |
|
95 _currentTime = 0; |
|
96 } |
|
97 this.lastAjaxQuery = _currentTime; |
96 this.lastAjaxQuery = _currentTime; |
98 _currentTime = Math.floor(1000 * _currentTime); |
|
99 var _url = Mustache.to_html(this.ajax_url, { |
97 var _url = Mustache.to_html(this.ajax_url, { |
100 media : this.source.currentMedia.id, |
98 media : this.source.currentMedia.id, |
101 begin : Math.max(0, _currentTime - this.ajax_granularity), |
99 begin : Math.max(0, _currentTime - this.ajax_granularity), |
102 end : Math.min(_duration.milliseconds, _currentTime + this.ajax_granularity) |
100 end : Math.min(_duration.milliseconds, _currentTime + this.ajax_granularity) |
103 }); |
101 }); |
104 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
102 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
105 "url" : _url |
103 "url" : _url |
106 }, this.metadata)); |
104 }, this.metadata)); |
107 } |
105 }; |
108 |
106 |
109 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() { |
107 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() { |
110 var _currentTime = this.player.popcorn.currentTime(); |
108 var _currentTime = this.media.getCurrentTime(); |
111 if (typeof _currentTime == "undefined") { |
109 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime); |
112 _currentTime = 0; |
|
113 } |
|
114 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000); |
|
115 if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) { |
110 if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) { |
116 this.lastMashupAnnotation = _currentAnnotation.id; |
111 this.lastMashupAnnotation = _currentAnnotation.id; |
117 var _currentMedia = _currentAnnotation.getMedia(), |
112 var _currentMedia = _currentAnnotation.getMedia(), |
118 _url = Mustache.to_html(this.ajax_url, { |
113 _url = Mustache.to_html(this.ajax_url, { |
119 media : _currentMedia.id, |
114 media : _currentMedia.id, |
122 }); |
117 }); |
123 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
118 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
124 "url" : _url |
119 "url" : _url |
125 }, this.metadata)); |
120 }, this.metadata)); |
126 } |
121 } |
127 } |
122 }; |
128 |
123 |
129 IriSP.Widgets.AnnotationsList.prototype.refresh = function(_forceRedraw) { |
124 IriSP.Widgets.AnnotationsList.prototype.refresh = function(_forceRedraw) { |
130 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
125 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
131 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
126 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
132 return 0; |
127 return 0; |
133 } |
128 } |
134 var _this = this, |
129 var _this = this, |
135 _currentTime = this.player.popcorn.currentTime(); |
130 _currentTime = this.media.getCurrentTime(); |
136 if (typeof _currentTime == "undefined") { |
|
137 _currentTime = 0; |
|
138 } |
|
139 var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations(); |
131 var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations(); |
140 if (this.mashupMode) { |
132 if (this.mashupMode) { |
141 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000); |
133 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime); |
142 if (typeof _currentAnnotation !== "undefined") { |
134 if (typeof _currentAnnotation !== "undefined") { |
143 _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds(); |
135 _currentTime = _currentTime - _currentAnnotation.begin + _currentAnnotation.annotation.begin; |
144 var _mediaId = _currentAnnotation.getMedia().id; |
136 var _mediaId = _currentAnnotation.getMedia().id; |
145 _list = _list.filter(function(_annotation) { |
137 _list = _list.filter(function(_annotation) { |
146 return _annotation.getMedia().id === _mediaId; |
138 return _annotation.getMedia().id === _mediaId; |
147 }); |
139 }); |
148 } |
140 } |
149 } |
141 } |
150 if (this.searchString) { |
142 _list = _list.filter(function(_annotation) { |
151 _list = _list.searchByTextFields(this.searchString); |
143 return _annotation.found !== false; |
152 } |
144 }); |
153 if (this.limit_count) { |
145 if (this.limit_count) { |
|
146 /* Get the n annotations closest to current timecode */ |
154 _list = _list.sortBy(function(_annotation) { |
147 _list = _list.sortBy(function(_annotation) { |
155 return Math.abs(_annotation.begin.getSeconds() - _currentTime); |
148 return Math.abs((_annotation.begin + _annotation.end) / 2 - _currentTime); |
156 }).slice(0, this.limit_count) |
149 }).slice(0, this.limit_count); |
157 } |
150 } |
158 if (this.newest_first) { |
151 if (this.newest_first) { |
159 _list = _list.sortBy(function(_annotation) { |
152 _list = _list.sortBy(function(_annotation) { |
160 return -_annotation.created.valueOf(); |
153 return -_annotation.created.valueOf(); |
161 }); |
154 }); |
184 media : _annotation.media.id, |
178 media : _annotation.media.id, |
185 annotation : _annotation.id, |
179 annotation : _annotation.id, |
186 annotationType : _annotation.annotationType.id |
180 annotationType : _annotation.annotationType.id |
187 } |
181 } |
188 ) |
182 ) |
189 : '#id=' + _annotation.id |
183 : document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id |
190 ) |
184 ) |
191 ); |
185 ); |
192 var _title = (_annotation.title || "").replace(_annotation.description,''), |
186 var _title = "", |
193 _description = _annotation.description; |
187 _description = _annotation.description, |
194 if (!_annotation.title) { |
188 _thumbnail = (typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail); |
195 _title = _annotation.creator; |
189 // Update : display creator |
196 } |
190 if (_annotation.creator) { |
197 if (!_annotation.description && _annotation.creator) { |
191 _title = _annotation.creator; |
198 _description = _annotation.title; |
192 } |
199 _title = _annotation.creator; |
193 if (_annotation.title) { |
|
194 var tempTitle = _annotation.title; |
|
195 if( tempTitle.substr(0, _title.length + 1) == (_title + ":") ){ |
|
196 _title = ""; |
|
197 } |
|
198 _title = _title + ( (_title=="") ? "" : ": ") + _annotation.title; |
200 } |
199 } |
201 var _bgcolor; |
200 var _bgcolor; |
202 IriSP._(_this.polemics).each(function(_polemic) { |
201 IriSP._(_this.polemics).each(function(_polemic) { |
203 var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword, true); |
202 var _rgxp = IriSP.Model.regexpFromTextOrArray(_polemic.keyword, true); |
204 if (_rgxp.test(_title + " " + _description)) { |
203 if (_rgxp.test(_title + " " + _description)) { |
206 } |
205 } |
207 }); |
206 }); |
208 var _data = { |
207 var _data = { |
209 id : _annotation.id, |
208 id : _annotation.id, |
210 media_id : _annotation.getMedia().id, |
209 media_id : _annotation.getMedia().id, |
211 title : _title, |
210 htitle : IriSP.textFieldHtml(_title), |
212 description : _description, |
211 hdescription : IriSP.textFieldHtml(_description), |
213 begin : _annotation.begin.toString(), |
212 begin : _annotation.begin.toString(), |
214 end : _annotation.end.toString(), |
213 end : _annotation.end.toString(), |
215 thumbnail : typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail, |
214 thumbnail : _thumbnail, |
216 url : _url, |
215 url : _url, |
217 tags : _annotation.getTagTexts(), |
216 tags : _annotation.getTagTexts(), |
218 specific_style : (typeof _bgcolor !== "undefined" ? "background-color: " + _bgcolor : "") |
217 specific_style : (typeof _bgcolor !== "undefined" ? "background-color: " + _bgcolor : ""), |
|
218 l10n: _this.l10n |
219 }; |
219 }; |
220 var _html = Mustache.to_html(_this.annotationTemplate, _data); |
220 if (_this.show_audio && _annotation.audio && _annotation.audio.href && _annotation.audio.href != "null") { |
221 var _el = IriSP.jQuery(_html); |
221 _data.audio = true; |
|
222 if (!_this.jwplayers[_annotation.id]) { |
|
223 var _audiofile = _annotation.audio.href; |
|
224 if (_this.audio_url_transform) { |
|
225 _audiofile = _this.audio_url_transform(_annotation.audio.href); |
|
226 } |
|
227 var _tmpId = "jwplayer-" + IriSP.Model.getUID(); |
|
228 _this.jwplayers[_annotation.id] = _tmpId; |
|
229 _this.$.find(".Ldt-AnnotationsList-Audio").append(IriSP.jQuery("<div>").attr("id", _tmpId)); |
|
230 jwplayer(_tmpId).setup({ |
|
231 flashplayer: IriSP.getLib("jwPlayerSWF"), |
|
232 file: _audiofile, |
|
233 fallback: false, |
|
234 primary: "flash", |
|
235 controls: false, |
|
236 width: 1, |
|
237 height: 1, |
|
238 events: { |
|
239 onPause: function() { |
|
240 _this.$.find(".Ldt-AnnotationsList-Play[data-annotation-id=" + _annotation.id + "]").text(_this.l10n.voice_annotation); |
|
241 }, |
|
242 onPlay: function() { |
|
243 _this.$.find(".Ldt-AnnotationsList-Play[data-annotation-id=" + _annotation.id + "]").text(_this.l10n.now_playing); |
|
244 } |
|
245 } |
|
246 }); |
|
247 } |
|
248 } |
|
249 var _html = Mustache.to_html(_this.annotationTemplate, _data), |
|
250 _el = IriSP.jQuery(_html), |
|
251 _onselect = function() { |
|
252 _this.$.find('.Ldt-AnnotationsList-li').removeClass("selected"); |
|
253 _el.addClass("selected"); |
|
254 }, |
|
255 _onunselect = function() { |
|
256 _this.$.find('.Ldt-AnnotationsList-li').removeClass("selected"); |
|
257 }; |
222 _el.mouseover(function() { |
258 _el.mouseover(function() { |
223 _annotation.trigger("select"); |
259 _annotation.trigger("select"); |
224 }) |
260 }) |
225 .mouseout(function() { |
261 .mouseout(function() { |
226 _annotation.trigger("unselect"); |
262 _annotation.trigger("unselect"); |
227 }) |
263 }) |
228 .appendTo(_this.list_$); |
264 .appendTo(_this.list_$); |
229 _annotation.on("select", function() { |
265 IriSP.attachDndData(_el.find("[draggable]"), { |
230 _this.annotations_$.removeClass("selected"); |
266 title: _title, |
231 _el.addClass("selected"); |
267 description: _description, |
232 }); |
268 uri: _url, |
233 _annotation.on("unselect", function() { |
269 image: _annotation.thumbnail |
234 _this.annotations_$.removeClass("selected"); |
270 }); |
235 });; |
271 _el.on("remove", function() { |
236 }); |
272 _annotation.off("select", _onselect); |
237 |
273 _annotation.off("unselect", _onunselect); |
238 this.annotations_$ = this.$.find('.Ldt-AnnotationsList-li'); |
274 }); |
|
275 _annotation.on("select", _onselect); |
|
276 _annotation.on("unselect", _onunselect); |
|
277 }); |
239 |
278 |
240 /* Correct the empty tag bug */ |
279 /* Correct the empty tag bug */ |
241 this.$.find('.Ldt-AnnotationsList-Tag-Li').each(function() { |
280 this.$.find('.Ldt-AnnotationsList-Tag-Li').each(function() { |
242 var _el = IriSP.jQuery(this); |
281 var _el = IriSP.jQuery(this); |
243 if (!_el.text().replace(/(^\s+|\s+$)/g,'')) { |
282 if (!_el.text().replace(/(^\s+|\s+$)/g,'')) { |
244 _el.detach(); |
283 _el.remove(); |
245 } |
284 } |
246 }); |
285 }); |
247 |
286 |
248 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
287 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
249 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
288 _this.source.getAnnotations().search(IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
250 }) |
289 }); |
251 |
290 |
252 if(this.searchString) { |
291 this.$.find(".Ldt-AnnotationsList-Play").click(function() { |
253 var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString); |
292 var _el = IriSP.jQuery(this), |
|
293 _annid = _el.attr("data-annotation-id"); |
|
294 if (_this.jwplayers[_annid]) { |
|
295 jwplayer(_this.jwplayers[_annid]).play(); |
|
296 } |
|
297 _this.media.pause(); |
|
298 }); |
|
299 |
|
300 if (this.source.getAnnotations().searching) { |
|
301 var rx = _this.source.getAnnotations().regexp || false; |
254 this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
302 this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
255 var _$ = IriSP.jQuery(this); |
303 var _$ = IriSP.jQuery(this); |
256 _$.html(_$.text().replace(/(^\s+|\s+$)/g,'').replace(_searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>')) |
304 _$.html(IriSP.textFieldHtml(_$.text(), rx)); |
257 }) |
305 }); |
258 } |
306 } |
259 } |
307 } |
260 |
308 |
261 if (this.ajax_url) { |
309 if (this.ajax_url) { |
262 if (this.mashupMode) { |
310 if (this.mashupMode) { |
263 this.ajaxMashup(); |
311 this.ajaxMashup(); |
264 } else { |
312 } else { |
265 if (Math.abs(_currentTime - this.lastAjaxQuery) > (this.ajax_granularity / 2000)) { |
313 if (Math.abs(_currentTime - this.lastAjaxQuery) > (this.ajax_granularity)) { |
266 this.ajaxSource(); |
314 this.ajaxSource(); |
267 } |
315 } |
268 } |
316 } |
269 } |
317 } |
270 return _list.length; |
318 return _list.length; |
271 } |
319 }; |
272 |
320 |
273 IriSP.Widgets.AnnotationsList.prototype.draw = function() { |
321 IriSP.Widgets.AnnotationsList.prototype.draw = function() { |
274 |
322 |
|
323 this.jwplayers = {}; |
|
324 this.mashupMode = (this.media.elementType === "mashup"); |
|
325 |
275 this.renderTemplate(); |
326 this.renderTemplate(); |
276 |
327 |
|
328 var _this = this; |
|
329 |
277 this.list_$ = this.$.find(".Ldt-AnnotationsList-ul"); |
330 this.list_$ = this.$.find(".Ldt-AnnotationsList-ul"); |
278 |
331 |
279 this.bindPopcorn("IriSP.search", "onSearch"); |
332 |
280 this.bindPopcorn("IriSP.search.closed", "onSearch"); |
333 this.source.getAnnotations().on("search", function(_text) { |
281 this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
334 _this.searchString = _text; |
282 this.bindPopcorn("IriSP.AnnotationsList.refresh","refresh"); |
335 if (_this.source !== _this.currentSource) { |
283 |
336 _this.currentSource.getAnnotations().search(_text); |
284 var _this = this; |
337 _this.throttledRefresh(); |
|
338 } |
|
339 }); |
|
340 this.source.getAnnotations().on("found", function() { |
|
341 _this.throttledRefresh(); |
|
342 }); |
|
343 this.source.getAnnotations().on("not-found", function() { |
|
344 _this.throttledRefresh(); |
|
345 }); |
|
346 this.source.getAnnotations().on("clear-search", function() { |
|
347 _this.searchString = false; |
|
348 if (_this.source !== _this.currentSource) { |
|
349 _this.currentSource.getAnnotations().trigger("clear-search"); |
|
350 } |
|
351 }); |
|
352 this.source.getAnnotations().on("search-cleared", function() { |
|
353 _this.throttledRefresh(); |
|
354 }); |
|
355 |
|
356 this.onMdpEvent("AnnotationsList.refresh", function() { |
|
357 if (_this.ajax_url) { |
|
358 if (_this.mashupMode) { |
|
359 _this.ajaxMashup(); |
|
360 } else { |
|
361 _this.ajaxSource(); |
|
362 } |
|
363 } |
|
364 _this.throttledRefresh(); |
|
365 }); |
285 |
366 |
286 if (this.ajax_url) { |
367 if (this.ajax_url) { |
287 if (this.mashupMode) { |
368 if (this.mashupMode) { |
288 this.ajaxMashup(); |
369 this.ajaxMashup(); |
289 } else { |
370 } else { |