77 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) { |
77 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) { |
78 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
78 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
79 var _n = this.refresh(true); |
79 var _n = this.refresh(true); |
80 if (this.searchString) { |
80 if (this.searchString) { |
81 if (_n) { |
81 if (_n) { |
82 this.player.popcorn.trigger("IriSP.search.matchFound"); |
82 this.player.trigger("search.matchFound"); |
83 } else { |
83 } else { |
84 this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
84 this.player.trigger("search.noMatchFound"); |
85 } |
85 } |
86 } |
86 } |
87 } |
87 } |
88 |
88 |
89 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id; |
89 //obj.url = this.project_url + "/" + media + "/" + annotations[i].meta.project + "/" + annotations[i].meta["id-ref"] + '#id=' + annotations[i].id; |
90 |
90 |
91 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() { |
91 IriSP.Widgets.AnnotationsList.prototype.ajaxSource = function() { |
92 var _currentTime = this.player.popcorn.currentTime(), |
92 var _currentTime = this.media.getCurrentTime(), |
93 _duration = this.source.getDuration(); |
93 _duration = this.media.duration; |
94 if (typeof _currentTime == "undefined") { |
|
95 _currentTime = 0; |
|
96 } |
|
97 this.lastAjaxQuery = _currentTime; |
94 this.lastAjaxQuery = _currentTime; |
98 _currentTime = Math.floor(1000 * _currentTime); |
95 _currentTime = Math.floor(1000 * _currentTime); |
99 var _url = Mustache.to_html(this.ajax_url, { |
96 var _url = Mustache.to_html(this.ajax_url, { |
100 media : this.source.currentMedia.id, |
97 media : this.source.currentMedia.id, |
101 begin : Math.max(0, _currentTime - this.ajax_granularity), |
98 begin : Math.max(0, _currentTime - this.ajax_granularity), |
105 "url" : _url |
102 "url" : _url |
106 }, this.metadata)); |
103 }, this.metadata)); |
107 } |
104 } |
108 |
105 |
109 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() { |
106 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() { |
110 var _currentTime = this.player.popcorn.currentTime(); |
107 var _currentTime = this.media.getCurrentTime(); |
111 if (typeof _currentTime == "undefined") { |
108 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) { |
109 if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.id !== this.lastMashupAnnotation) { |
116 this.lastMashupAnnotation = _currentAnnotation.id; |
110 this.lastMashupAnnotation = _currentAnnotation.id; |
117 var _currentMedia = _currentAnnotation.getMedia(), |
111 var _currentMedia = _currentAnnotation.getMedia(), |
118 _url = Mustache.to_html(this.ajax_url, { |
112 _url = Mustache.to_html(this.ajax_url, { |
119 media : _currentMedia.id, |
113 media : _currentMedia.id, |
130 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
124 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
131 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
125 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
132 return 0; |
126 return 0; |
133 } |
127 } |
134 var _this = this, |
128 var _this = this, |
135 _currentTime = this.player.popcorn.currentTime(); |
129 _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(); |
130 var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations(); |
140 if (this.mashupMode) { |
131 if (this.mashupMode) { |
141 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000); |
132 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime); |
142 if (typeof _currentAnnotation !== "undefined") { |
133 if (typeof _currentAnnotation !== "undefined") { |
143 _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds(); |
134 _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds(); |
144 var _mediaId = _currentAnnotation.getMedia().id; |
135 var _mediaId = _currentAnnotation.getMedia().id; |
145 _list = _list.filter(function(_annotation) { |
136 _list = _list.filter(function(_annotation) { |
146 return _annotation.getMedia().id === _mediaId; |
137 return _annotation.getMedia().id === _mediaId; |
244 _el.detach(); |
235 _el.detach(); |
245 } |
236 } |
246 }); |
237 }); |
247 |
238 |
248 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
239 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
249 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
240 _this.player.trigger("search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
250 }) |
241 }) |
251 |
242 |
252 if(this.searchString) { |
243 if(this.searchString) { |
253 var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString); |
244 var _searchRe = IriSP.Model.regexpFromTextOrArray(this.searchString); |
254 this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
245 this.$.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description").each(function() { |
274 |
265 |
275 this.renderTemplate(); |
266 this.renderTemplate(); |
276 |
267 |
277 this.list_$ = this.$.find(".Ldt-AnnotationsList-ul"); |
268 this.list_$ = this.$.find(".Ldt-AnnotationsList-ul"); |
278 |
269 |
279 this.bindPopcorn("IriSP.search", "onSearch"); |
270 this.onMdpEvent("search", "onSearch"); |
280 this.bindPopcorn("IriSP.search.closed", "onSearch"); |
271 this.onMdpEvent("search.closed", "onSearch"); |
281 this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
272 this.onMdpEvent("search.cleared", "onSearch"); |
282 this.bindPopcorn("IriSP.AnnotationsList.refresh","refresh"); |
273 this.onMdpEvent("AnnotationsList.refresh","refresh"); |
283 |
274 |
284 var _this = this; |
275 var _this = this; |
285 |
276 |
286 if (this.ajax_url) { |
277 if (this.ajax_url) { |
287 if (this.mashupMode) { |
278 if (this.mashupMode) { |
297 window.setInterval(function() { |
288 window.setInterval(function() { |
298 _this.currentSource.get() |
289 _this.currentSource.get() |
299 }, this.refresh_interval); |
290 }, this.refresh_interval); |
300 } |
291 } |
301 |
292 |
|
293 this.onMdpEvent("createAnnotationWidget.addedAnnotation"); |
302 var _events = [ |
294 var _events = [ |
303 "IriSP.createAnnotationWidget.addedAnnotation", |
|
304 "timeupdate", |
295 "timeupdate", |
305 "seeked", |
296 "seeked", |
306 "loadedmetadata" |
297 "loadedmetadata" |
307 ]; |
298 ]; |
308 for (var _i = 0; _i < _events.length; _i++) { |
299 for (var _i = 0; _i < _events.length; _i++) { |
309 this.player.popcorn.listen(_events[_i], this.throttledRefresh); |
300 this.onMediaEvent(_events[_i], this.throttledRefresh); |
310 } |
301 } |
311 |
302 |
312 this.throttledRefresh(); |
303 this.throttledRefresh(); |
313 |
304 |
314 }; |
305 }; |