1 IriSP.Widgets.AnnotationsList = function(player, config) { |
1 IriSP.Widgets.AnnotationsList = function(player, config) { |
2 IriSP.Widgets.Widget.call(this, player, config); |
2 IriSP.Widgets.Widget.call(this, player, config); |
3 this.bindPopcorn("IriSP.search", "searchHandler"); |
|
4 this.bindPopcorn("IriSP.search.closed", "searchHandler"); |
|
5 this.bindPopcorn("IriSP.search.cleared", "searchHandler"); |
|
6 this.searchString = false; |
3 this.searchString = false; |
7 this.lastIds = []; |
4 this.lastIds = []; |
8 var _this = this; |
5 var _this = this; |
9 this.throttledRefresh = IriSP._.throttle(function() { |
6 this.throttledRefresh = IriSP._.throttle(function() { |
10 _this.refresh(false); |
7 _this.refresh(false); |
68 }; |
65 }; |
69 |
66 |
70 IriSP.Widgets.AnnotationsList.prototype.clearWidget = function() { |
67 IriSP.Widgets.AnnotationsList.prototype.clearWidget = function() { |
71 }; |
68 }; |
72 |
69 |
73 IriSP.Widgets.AnnotationsList.prototype.searchHandler = function(searchString) { |
70 IriSP.Widgets.AnnotationsList.prototype.onSearch = function(searchString) { |
74 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
71 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
75 var _n = this.refresh(true); |
72 var _n = this.refresh(true); |
76 if (this.searchString) { |
73 if (this.searchString) { |
77 if (_n) { |
74 if (_n) { |
78 this.player.popcorn.trigger("IriSP.search.matchFound"); |
75 this.player.popcorn.trigger("IriSP.search.matchFound"); |
134 var _ids = _list.idIndex; |
131 var _ids = _list.idIndex; |
135 |
132 |
136 if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds)) { |
133 if (_forceRedraw || !IriSP._.isEqual(_ids, this.lastIds)) { |
137 /* This part only gets executed if the list needs updating */ |
134 /* This part only gets executed if the list needs updating */ |
138 this.lastIds = _ids; |
135 this.lastIds = _ids; |
139 |
136 var _data = _list.map(function(_annotation) { |
140 var _html = Mustache.to_html( |
|
141 this.template, |
|
142 { |
|
143 annotations : _list.map(function(_annotation) { |
|
144 var _url = ( |
137 var _url = ( |
145 ( typeof _annotation.url !== "undefined" ) |
138 ( typeof _annotation.url !== "undefined" && _annotation.url) |
146 ? _annotation.url |
139 ? _annotation.url |
147 : ( |
140 : ( |
148 ( typeof _this.source.projectId !== "undefined" && typeof _annotation.project !== "undefined" && _this.source.projectId !== _annotation.project ) |
141 ( typeof _this.source.projectId !== "undefined" && typeof _annotation.project !== "undefined" && _annotation.project && _this.source.projectId !== _annotation.project ) |
149 ? Mustache.to_html( |
142 ? Mustache.to_html( |
150 this.foreign_url, |
143 _this.foreign_url, |
151 { |
144 { |
152 project : _annotation.project, |
145 project : _annotation.project, |
153 media : _annotation.media.id.replace(/^.*:/,''), |
146 media : _annotation.media.id.replace(/^.*:/,''), |
154 annotation : _annotation.namespacedId.name, |
147 annotation : _annotation.namespacedId.name, |
155 annotationType : _annotation.annotationType.id.replace(/^.*:/,'') |
148 annotationType : _annotation.annotationType.id.replace(/^.*:/,'') |
162 id : _annotation.id, |
155 id : _annotation.id, |
163 title : _annotation.title.replace(_annotation.description,''), |
156 title : _annotation.title.replace(_annotation.description,''), |
164 description : _annotation.description, |
157 description : _annotation.description, |
165 begin : _annotation.begin.toString(), |
158 begin : _annotation.begin.toString(), |
166 end : _annotation.end.toString(), |
159 end : _annotation.end.toString(), |
167 thumbnail : typeof _annotation.thumbnail !== "undefined" ? _annotation.thumbnail : _this.default_thumbnail, |
160 thumbnail : typeof _annotation.thumbnail !== "undefined" && _annotation.thumbnail ? _annotation.thumbnail : _this.default_thumbnail, |
168 url : _url, |
161 url : _url, |
169 tags : _annotation.getTagTexts() |
162 tags : _annotation.getTagTexts() |
170 } |
163 } |
171 return _res; |
164 return _res; |
172 }) |
165 }), |
173 }); |
166 _html = Mustache.to_html( |
|
167 this.template, |
|
168 { |
|
169 annotations : _data |
|
170 }); |
174 |
171 |
175 this.$.html(_html); |
172 this.$.html(_html); |
176 |
173 |
177 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
174 this.$.find('.Ldt-AnnotationsList-Tag-Li').click(function() { |
178 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |
175 _this.player.popcorn.trigger("IriSP.search.triggeredSearch", IriSP.jQuery(this).text().replace(/(^\s+|\s+$)/g,'')); |