46 "color" : "#036AAE" |
45 "color" : "#036AAE" |
47 } |
46 } |
48 ] |
47 ] |
49 }; |
48 }; |
50 |
49 |
|
50 IriSP.Widgets.Polemic.prototype.onSearch = function(searchString) { |
|
51 this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
52 var _found = 0, |
|
53 _re = IriSP.Model.regexpFromTextOrArray(searchString, true), |
|
54 _this = this; |
|
55 this.$tweets.each(function() { |
|
56 var _el = IriSP.jQuery(this); |
|
57 if (_this.searchString) { |
|
58 if (_re.test(_el.attr("tweet-title"))) { |
|
59 _el.css({ |
|
60 "background" : _this.foundcolor, |
|
61 "opacity" : 1 |
|
62 }); |
|
63 _found++; |
|
64 } else { |
|
65 _el.css({ |
|
66 "background" : _el.attr("polemic-color"), |
|
67 "opacity" : .3 |
|
68 }); |
|
69 } |
|
70 } else { |
|
71 _el.css({ |
|
72 "background" : _el.attr("polemic-color"), |
|
73 "opacity" : 1 |
|
74 }); |
|
75 } |
|
76 }); |
|
77 if (this.searchString) { |
|
78 if (_found) { |
|
79 this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
80 } else { |
|
81 this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
82 } |
|
83 } |
|
84 } |
|
85 |
51 IriSP.Widgets.Polemic.prototype.draw = function() { |
86 IriSP.Widgets.Polemic.prototype.draw = function() { |
52 |
87 |
53 this.onMediaEvent("timeupdate", "onTimeupdate"); |
88 this.bindPopcorn("timeupdate", "onTimeupdate"); |
54 this.$zone = IriSP.jQuery('<div>'); |
89 this.$zone = IriSP.jQuery('<div>'); |
55 this.$zone.addClass("Ldt-Polemic"); |
90 this.$zone.addClass("Ldt-Polemic"); |
56 this.$.append(this.$zone); |
91 this.$.append(this.$zone); |
57 |
92 |
58 this.$elapsed = IriSP.jQuery('<div>') |
93 this.$elapsed = IriSP.jQuery('<div>') |
81 _count = 0, |
115 _count = 0, |
82 _res = { |
116 _res = { |
83 begin : _begin.toString(), |
117 begin : _begin.toString(), |
84 end : _end.toString(), |
118 end : _end.toString(), |
85 annotations : _list.filter(function(_annotation) { |
119 annotations : _list.filter(function(_annotation) { |
86 return _annotation.begin >= _begin && _annotation.begin < _end; |
120 return _annotation.begin >= _begin && _annotation.end < _end; |
87 }), |
121 }), |
88 polemicStacks : [] |
122 polemicStacks : [] |
89 }; |
123 } |
90 |
124 |
91 for (var _j = 0; _j < this.polemics.length; _j++) { |
125 for (var _j = 0; _j < this.polemics.length; _j++) { |
92 var _polemic = _res.annotations.searchByDescription(this.polemics[_j].keywords); |
126 var _polemic = _res.annotations.searchByDescription(this.polemics[_j].keywords); |
93 _count += _polemic.length; |
127 _count += _polemic.length; |
94 _res.polemicStacks.push(_polemic); |
128 _res.polemicStacks.push(_polemic); |
113 |
147 |
114 var _x = 0; |
148 var _x = 0; |
115 |
149 |
116 function displayAnnotation(_elx, _ely, _pol, _col, _annotation) { |
150 function displayAnnotation(_elx, _ely, _pol, _col, _annotation) { |
117 var _html = Mustache.to_html( |
151 var _html = Mustache.to_html( |
118 '<div class="Ldt-Polemic-TweetDiv Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id:{{media_id}}, polemic:{{polemic}}, time:{{time}}" polemic-color="{{color}}"' |
152 '<div class="Ldt-Polemic-TweetDiv Ldt-TraceMe" trace-info="annotation-id:{{id}}, media-id={{media_id}}, polemic={{polemic}}" polemic-color="{{color}}"' |
119 + ' tweet-title="{{title}}" annotation-id="{{id}}" style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>', |
153 + ' tweet-title="{{title}}" annotation-id="{{id}}" style="width: {{width}}px; height: {{height}}px; top: {{top}}px; left: {{left}}px; background: {{color}}"></div>', |
120 { |
154 { |
121 id: _annotation.id, |
155 id: _annotation.id, |
122 media_id: _this.source.currentMedia.id, |
156 media_id: _this.source.currentMedia.id, |
123 polemic: _pol, |
157 polemic: _pol, |
124 left: _elx, |
158 left: _elx, |
125 top: _ely, |
159 top: _ely, |
126 color: _col, |
160 color: _col, |
127 width: (_this.element_width-1), |
161 width: (_this.element_width-1), |
128 height: _this.element_height, |
162 height: _this.element_height, |
129 title: _annotation.title, |
163 title: _annotation.title |
130 time: _annotation.begin.toString() |
|
131 }); |
164 }); |
132 var _el = IriSP.jQuery(_html); |
165 var _el = IriSP.jQuery(_html); |
133 _el.mouseover(function() { |
166 _el.mouseover(function() { |
134 _annotation.trigger("select"); |
167 _annotation.trigger("select"); |
135 }).mouseout(function() { |
168 }).mouseout(function() { |
136 _annotation.trigger("unselect"); |
169 _annotation.trigger("unselect"); |
137 }).click(function() { |
170 }).click(function() { |
138 _annotation.trigger("click"); |
171 _this.player.popcorn.trigger("IriSP.Mediafragment.setHashToAnnotation", _annotation.id); |
139 return false; |
172 _this.player.popcorn.trigger("IriSP.Tweet.show", _annotation.id); |
140 }); |
173 }); |
141 IriSP.attachDndData(_el, { |
|
142 title: _annotation.title, |
|
143 description: _annotation.description, |
|
144 image: _annotation.thumbnail, |
|
145 uri: (typeof _annotation.url !== "undefined" |
|
146 ? _annotation.url |
|
147 : (document.location.href.replace(/#.*$/,'') + '#id=' + _annotation.id)) |
|
148 }); |
|
149 // test if annotation has several colors. |
|
150 var colAr = []; |
|
151 for (var _j = 0; _j < _this.polemics.length; _j++) { |
|
152 if( IriSP.Model.regexpFromTextOrArray( _this.polemics[_j].keywords ).test( _annotation.title ) ){ |
|
153 colAr.push(_this.polemics[_j].color); |
|
154 } |
|
155 } |
|
156 // display annotation |
|
157 _annotation.on("select", function() { |
174 _annotation.on("select", function() { |
158 if (_this.tooltip) { |
175 _this.tooltip.show( |
159 _this.tooltip.show( |
176 Math.floor(_elx + (_this.element_width - 1) / 2), |
160 + Math.floor(_elx + (_this.element_width - 1) / 2), |
177 _ely, |
161 + _ely, |
178 _annotation.title, |
162 _annotation.title, |
179 _col |
163 ( (colAr.length>1) ? colAr : _col ) |
180 ); |
164 ); |
|
165 } |
|
166 _this.$tweets.each(function() { |
181 _this.$tweets.each(function() { |
167 var _e = IriSP.jQuery(this); |
182 var _e = IriSP.jQuery(this); |
168 _e.css( |
183 _e.css( |
169 "opacity", |
184 "opacity", |
170 ( _e.attr("annotation-id") == _annotation.id ? 1 : .3 ) |
185 ( _e.attr("annotation-id") == _annotation.id ? 1 : .3 ) |
171 ); |
186 ); |
172 }); |
187 }); |
173 }); |
188 }); |
174 _annotation.on("unselect", function() { |
189 _annotation.on("unselect", function() { |
175 if (_this.tooltip) { |
190 _this.tooltip.hide(); |
176 _this.tooltip.hide(); |
|
177 } |
|
178 _this.$tweets.css("opacity",1); |
191 _this.$tweets.css("opacity",1); |
179 }); |
|
180 _annotation.on("found", function() { |
|
181 _el.css({ |
|
182 "background" : _this.foundcolor, |
|
183 "opacity" : 1 |
|
184 }); |
|
185 }); |
|
186 _annotation.on("not-found", function() { |
|
187 _el.css({ |
|
188 "background" : _col, |
|
189 "opacity" : .3 |
|
190 }); |
|
191 }); |
192 }); |
192 _this.$zone.append(_el); |
193 _this.$zone.append(_el); |
193 } |
194 } |
194 |
195 |
195 IriSP._(_slices).forEach(function(_slice) { |
196 IriSP._(_slices).forEach(function(_slice) { |
260 } |
255 } |
261 |
256 |
262 IriSP._(_slices).forEach(function(_slice) { |
257 IriSP._(_slices).forEach(function(_slice) { |
263 var _y = _this.height, |
258 var _y = _this.height, |
264 _nums = _slice.annotations.length + "," + IriSP._(_slice.polemicStacks).map(function(_annotations) { |
259 _nums = _slice.annotations.length + "," + IriSP._(_slice.polemicStacks).map(function(_annotations) { |
265 return _annotations.length; |
260 return _annotations.length |
266 }).join(","); |
261 }).join(","); |
267 if (_slice.annotations.length) { |
262 if (_slice.annotations.length) { |
268 var _h = Math.ceil(_scale * _slice.annotations.length); |
263 var _h = Math.ceil(_scale * _slice.annotations.length); |
269 _y -= _h; |
264 _y -= _h; |
270 displayStackElement(_x, _y, _h, _this.defaultcolor, _nums, _slice.begin, _slice.end, "none"); |
265 displayStackElement(_x, _y, _h, _this.defaultcolor, _nums, _slice.begin, _slice.end, "none"); |
290 var _el = IriSP.jQuery(this), |
285 var _el = IriSP.jQuery(this), |
291 _nums = _el.attr("annotation-counts").split(","), |
286 _nums = _el.attr("annotation-counts").split(","), |
292 _html = '<p>' + _this.l10n.from_ + _el.attr("begin-time") + _this.l10n._to_ + _el.attr("end-time") + '</p>'; |
287 _html = '<p>' + _this.l10n.from_ + _el.attr("begin-time") + _this.l10n._to_ + _el.attr("end-time") + '</p>'; |
293 for (var _i = 0; _i <= _this.polemics.length; _i++) { |
288 for (var _i = 0; _i <= _this.polemics.length; _i++) { |
294 var _color = _i ? _this.polemics[_i - 1].color : _this.defaultcolor; |
289 var _color = _i ? _this.polemics[_i - 1].color : _this.defaultcolor; |
295 _html += '<div class="Ldt-Tooltip-AltColor" style="background: ' + _color + '"></div><p>' + _nums[_i] + _this.l10n._annotations + '</p>'; |
290 _html += '<div class="Ldt-Tooltip-Color" style="background: ' + _color + '"></div><p>' + _nums[_i] + _this.l10n._annotations + '</p>' |
296 } |
291 } |
297 if (_this.tooltip) { |
292 _this.tooltip.show(_el.attr("pos-x"), _el.attr("pos-y"), _html); |
298 _this.tooltip.show(+ _el.attr("pos-x"), + _el.attr("pos-y"), _html); |
|
299 } |
|
300 }) |
293 }) |
301 .mouseout(function() { |
294 .mouseout(function() { |
302 if (_this.tooltip) { |
295 _this.tooltip.hide(); |
303 _this.tooltip.hide(); |
296 }) |
304 } |
297 |
305 }); |
298 } |
306 |
|
307 }; |
|
308 |
299 |
309 this.$position = IriSP.jQuery('<div>').addClass("Ldt-Polemic-Position"); |
300 this.$position = IriSP.jQuery('<div>').addClass("Ldt-Polemic-Position"); |
310 |
301 |
311 this.$zone.append(this.$position); |
302 this.$zone.append(this.$position); |
312 |
303 |
313 this.$zone.click(function(_e) { |
304 this.$zone.click(function(_e) { |
314 var _x = _e.pageX - _this.$zone.offset().left; |
305 var _x = _e.pageX - _this.$zone.offset().left; |
315 _this.media.setCurrentTime(_this.media.duration * _x / _this.width); |
306 _this.player.popcorn.currentTime(_this.source.getDuration().getSeconds() * _x / _this.width); |
316 }); |
307 }); |
317 |
308 |
318 this.$.append('<div class="Ldt-Polemic-Tooltip"></div>'); |
309 this.$.append('<div class="Ldt-Polemic-Tooltip"></div>'); |
319 |
310 |
320 this.insertSubwidget( |
311 this.insertSubwidget(this.$.find(".Ldt-Polemic-Tooltip"), "tooltip", { type: "Tooltip" }); |
321 this.$.find(".Ldt-Polemic-Tooltip"), |
312 } |
322 { |
313 |
323 type: "Tooltip", |
314 IriSP.Widgets.Polemic.prototype.onTimeupdate = function() { |
324 min_x: 0, |
315 var _x = Math.floor( this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds()); |
325 max_x: this.width |
|
326 }, |
|
327 "tooltip" |
|
328 ); |
|
329 }; |
|
330 |
|
331 IriSP.Widgets.Polemic.prototype.onTimeupdate = function(_time) { |
|
332 var _x = Math.floor( this.width * _time / this.media.duration); |
|
333 this.$elapsed.css({ |
316 this.$elapsed.css({ |
334 width: _x + "px" |
317 width: _x + "px" |
335 }); |
318 }); |
336 this.$position.css({ |
319 this.$position.css({ |
337 left: _x + "px" |
320 left: _x + "px" |
338 }); |
321 }) |
339 }; |
322 } |