90 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
91 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
91 "url" : _url |
92 "url" : _url |
92 }, this.metadata)); |
93 }, this.metadata)); |
93 } |
94 } |
94 |
95 |
|
96 IriSP.Widgets.AnnotationsList.prototype.ajaxMashup = function() { |
|
97 var _currentTime = this.player.popcorn.currentTime(); |
|
98 if (typeof _currentTime == "undefined") { |
|
99 _currentTime = 0; |
|
100 } |
|
101 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000); |
|
102 if (typeof _currentAnnotation !== "undefined" && _currentAnnotation.namespacedId.name !== this.lastMashupAnnotation) { |
|
103 this.lastMashupAnnotation = _currentAnnotation.namespacedId.name; |
|
104 var _currentMedia = _currentAnnotation.getMedia(), |
|
105 _url = Mustache.to_html(this.ajax_url, { |
|
106 media : _currentMedia.namespacedId.name, |
|
107 begin : Math.max(0, _currentAnnotation.annotation.begin.milliseconds - this.ajax_granularity), |
|
108 end : Math.min(_currentMedia.duration.milliseconds, _currentAnnotation.annotation.end.milliseconds + this.ajax_granularity) |
|
109 }); |
|
110 console.log("Getting", _url); |
|
111 this.currentSource = this.player.loadMetadata(IriSP._.defaults({ |
|
112 "url" : _url |
|
113 }, this.metadata)); |
|
114 } |
|
115 } |
|
116 |
95 IriSP.Widgets.AnnotationsList.prototype.refresh = function(_forceRedraw) { |
117 IriSP.Widgets.AnnotationsList.prototype.refresh = function(_forceRedraw) { |
96 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
118 _forceRedraw = (typeof _forceRedraw !== "undefined" && _forceRedraw); |
97 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
119 if (this.currentSource.status !== IriSP.Model._SOURCE_STATUS_READY) { |
98 return 0; |
120 return 0; |
99 } |
121 } |
100 var _this = this, |
122 var _this = this, |
101 _currentTime = this.player.popcorn.currentTime(); |
123 _currentTime = this.player.popcorn.currentTime(); |
102 if (typeof _currentTime == "undefined") { |
124 if (typeof _currentTime == "undefined") { |
103 _currentTime = 0; |
125 _currentTime = 0; |
104 } |
126 } |
105 var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type, true) : this.currentSource.getAnnotations(); |
127 var _list = this.annotation_type ? this.currentSource.getAnnotationsByTypeTitle(this.annotation_type) : this.currentSource.getAnnotations(); |
|
128 if (this.mashupMode) { |
|
129 var _currentAnnotation = this.source.currentMedia.getAnnotationAtTime(_currentTime * 1000); |
|
130 if (typeof _currentAnnotation !== "undefined") { |
|
131 _currentTime = _currentTime - _currentAnnotation.begin.getSeconds() + _currentAnnotation.annotation.begin.getSeconds(); |
|
132 var _mediaId = _currentAnnotation.getMedia().namespacedId.name; |
|
133 _list = _list.filter(function(_annotation) { |
|
134 return _annotation.getMedia().namespacedId.name === _mediaId; |
|
135 }); |
|
136 } |
|
137 } |
106 if (this.searchString) { |
138 if (this.searchString) { |
107 _list = _list.searchByTextFields(this.searchString); |
139 _list = _list.searchByTextFields(this.searchString); |
108 } |
140 } |
109 if (this.limit_count) { |
141 if (this.limit_count) { |
110 _list = _list.sortBy(function(_annotation) { |
142 _list = _list.sortBy(function(_annotation) { |
161 { |
193 { |
162 annotations : _data |
194 annotations : _data |
163 }); |
195 }); |
164 |
196 |
165 this.$.html(_html); |
197 this.$.html(_html); |
|
198 |
|
199 /* Correct the empty tag bug */ |
|
200 this.$.find('.Ldt-AnnotationsList-Tag-Li').each(function() { |
|
201 var _el = IriSP.jQuery(this); |
|
202 if (!_el.text().replace(/(^\s+|\s+$)/g,'')) { |
|
203 _el.detach(); |
|
204 } |
|
205 }); |
166 |
206 |
167 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
207 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
168 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
208 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
169 }) |
209 }) |
170 |
210 |
191 this.bindPopcorn("IriSP.search.closed", "onSearch"); |
235 this.bindPopcorn("IriSP.search.closed", "onSearch"); |
192 this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
236 this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
193 |
237 |
194 var _this = this; |
238 var _this = this; |
195 |
239 |
196 if (this.ajax_url && this.ajax_granularity) { |
240 if (this.ajax_url) { |
197 this.ajaxSource(); |
241 if (this.mashupMode) { |
|
242 this.ajaxMashup(); |
|
243 } else { |
|
244 this.ajaxSource(); |
|
245 } |
198 } else { |
246 } else { |
199 this.currentSource = this.source; |
247 this.currentSource = this.source; |
200 } |
248 } |
201 |
249 |
202 if (this.refresh_interval) { |
250 if (this.refresh_interval) { |