| author | veltr |
| Fri, 06 Apr 2012 16:49:32 +0200 | |
| branch | popcorn-port |
| changeset 842 | 4ae2247a59f4 |
| parent 836 | 526f91f5253e |
| permissions | -rw-r--r-- |
| 100 | 1 |
IriSP.SegmentsWidget = function(Popcorn, config, Serializer) { |
| 164 | 2 |
|
| 152 | 3 |
var self = this; |
4 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
5 |
this.oldSearchMatches = []; |
|
| 164 | 6 |
|
| 152 | 7 |
// event handlers |
8 |
this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); }); |
|
9 |
this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); }); |
|
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
10 |
this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); }); |
| 834 | 11 |
|
12 |
this.defaultColors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"] |
|
| 100 | 13 |
}; |
14 |
||
| 139 | 15 |
IriSP.SegmentsWidget.prototype = new IriSP.Widget(); |
| 100 | 16 |
|
17 |
IriSP.SegmentsWidget.prototype.draw = function() { |
|
18 |
||
| 148 | 19 |
var self = this; |
| 100 | 20 |
var annotations = this._serializer._data.annotations; |
| 164 | 21 |
|
|
334
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
22 |
this.selector.addClass("Ldt-SegmentsWidget"); |
|
229
808768eb5930
rewriting the slider-port to not use jquery ui slider.
hamidouk
parents:
223
diff
changeset
|
23 |
this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); |
| 834 | 24 |
|
|
829
ae16691d183d
Corrected segments widget, added excludePattern option to tagcloud widget
veltr
parents:
827
diff
changeset
|
25 |
this.positionMarker = this.selector.find(".Ldt-SegmentPositionMarker"); |
| 217 | 26 |
|
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
27 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); |
| 842 | 28 |
var duration = this.getDuration(); |
| 835 | 29 |
|
| 834 | 30 |
if (this.cinecast_version) { |
31 |
var segments_annotations = IriSP.underscore.filter( |
|
32 |
this._serializer._data.annotations, |
|
33 |
function(_a) { |
|
| 835 | 34 |
return _a.type == "cinecast:MovieExtract"; |
| 834 | 35 |
} |
36 |
); |
|
37 |
} |
|
38 |
else { |
|
| 104 | 39 |
|
| 834 | 40 |
var view_type = this._serializer.getChapitrage(); |
41 |
if (typeof(view_type) === "undefined") { |
|
42 |
view_type = this._serializer.getNonTweetIds()[0]; |
|
43 |
} |
|
| 514 | 44 |
|
| 834 | 45 |
|
46 |
var i = 0; |
|
47 |
|
|
48 |
var segments_annotations = []; |
|
49 |
|
|
50 |
for (i = 0; i < annotations.length; i++) { |
|
51 |
var annotation = annotations[i]; |
|
52 |
|
|
53 |
/* filter the annotations whose type is not the one we want */ |
|
54 |
if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
55 |
&& annotation.meta["id-ref"] != view_type) { |
|
56 |
continue; |
|
57 |
} |
|
58 |
|
|
59 |
segments_annotations.push(annotation); |
|
60 |
} |
|
61 |
} |
|
62 |
var _w = this.selector.width(); |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
63 |
var lastSegment = IriSP.underscore.max(segments_annotations, function(annotation) { return annotation.end; }); |
| 514 | 64 |
|
65 |
for (i = 0; i < segments_annotations.length; i++) { |
|
66 |
|
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
67 |
var annotation = segments_annotations[i]; |
| 835 | 68 |
var begin = (+ annotation.begin); |
69 |
var end = (+ annotation.end); |
|
| 164 | 70 |
var id = annotation.id; |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
71 |
|
| 834 | 72 |
var startPixel = Math.floor(_w * (begin / duration)); |
| 164 | 73 |
|
| 834 | 74 |
var endPixel = Math.floor(_w * (end / duration)); |
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
75 |
if (annotation.id !== lastSegment.id) |
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
76 |
var pxWidth = endPixel - startPixel -1; |
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
77 |
else |
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
78 |
/* the last segment has no segment following it */ |
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
79 |
var pxWidth = endPixel - startPixel; |
| 834 | 80 |
|
81 |
var divTitle = this.cinecast_version |
|
82 |
? annotation.content.data |
|
| 836 | 83 |
: annotation.content.title + ( annotation.content.title ? "<br />" : "" ) + annotation.content.description.replace(/(^.{120,140})[\s].+$/,'$1…'); |
84 |
|
|
85 |
var thumbUrl = annotation.meta.thumbnail || ''; |
|
| 473 | 86 |
|
| 834 | 87 |
var hexa_color = typeof(annotation.content.color) !== "undefined" |
88 |
? '#' + IriSP.DEC_HEXA_COLOR(annotation.content.color) |
|
89 |
: typeof(annotation.color) !== "undefined" |
|
90 |
? '#' + IriSP.DEC_HEXA_COLOR(annotation.color) |
|
91 |
: this.defaultColors[i % this.defaultColors.length]; |
|
| 479 | 92 |
|
| 637 | 93 |
/* |
| 473 | 94 |
if (hexa_color === "FFCC00") |
95 |
hexa_color = "333"; |
|
| 637 | 96 |
*/ |
| 834 | 97 |
if (hexa_color.length == 5) |
| 479 | 98 |
hexa_color = hexa_color + '00'; |
| 473 | 99 |
|
| 834 | 100 |
|
| 100 | 101 |
var annotationTemplate = Mustache.to_html(IriSP.annotation_template, |
| 514 | 102 |
{"divTitle" : divTitle, "id" : id, "startPixel" : startPixel, |
103 |
"pxWidth" : pxWidth, "hexa_color" : hexa_color, |
|
| 836 | 104 |
"seekPlace" : Math.round(begin/1000), "thumbnailUrl": thumbUrl}); |
| 164 | 105 |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
106 |
|
| 164 | 107 |
this.selector.append(annotationTemplate); |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
108 |
|
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
109 |
/* add a special class to the last segment and change its border */ |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
110 |
if (annotation.id === lastSegment.id) { |
| 834 | 111 |
IriSP.jqId(id).addClass("Ldt-lastSegment").css("border-color", hexa_color); |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
112 |
} |
| 834 | 113 |
} |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
114 |
// react to mediafragment messages. |
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
115 |
this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", |
| 834 | 116 |
function(id, divTitle) { |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
117 |
|
| 834 | 118 |
var divObject = IriSP.jqId(id); |
119 |
if (divObject.length) { |
|
120 |
divObject.fadeTo(0,1); |
|
121 |
var offset_x = divObject.position().left + divObject.outerWidth() / 2; |
|
122 |
self.TooltipWidget.show(divObject.attr("title"), IriSP.jQuery(this).css("background-color"), offset_x, 0); |
|
123 |
IriSP.jQuery(document).one("mousemove", function() { divObject.fadeTo(0,.5); |
|
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
124 |
self.TooltipWidget.hide(); }); |
| 834 | 125 |
} |
126 |
}); |
|
127 |
|
|
128 |
this.selector.find(".Ldt-iri-chapter") |
|
129 |
.fadeTo(0, .5) |
|
130 |
.click(function() { |
|
131 |
self._Popcorn.trigger("IriSP.SegmentsWidget.click", this.id); |
|
132 |
self._Popcorn.currentTime(IriSP.jQuery(this).attr("data-seek")); |
|
133 |
}) |
|
134 |
.mouseover( function(event) { |
|
135 |
var divObject = IriSP.jQuery(this); |
|
136 |
divObject.fadeTo(0,1); |
|
137 |
var offset_x = divObject.position().left + divObject.outerWidth() / 2; |
|
| 836 | 138 |
var thumb = divObject.attr("thumbnail-url"); |
139 |
var txt = divObject.attr("title") + (thumb && thumb.length ? '<br /><img src="' + thumb + '" />' : ''); |
|
140 |
self.TooltipWidget.show(txt, IriSP.jQuery(this).css("background-color"), offset_x, 0); |
|
| 834 | 141 |
}) |
142 |
.mouseout(function(){ |
|
143 |
IriSP.jQuery(this).fadeTo(0,.5); |
|
144 |
self.TooltipWidget.hide(); |
|
145 |
}); |
|
| 104 | 146 |
}; |
147 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
148 |
/* restores the view after a search */ |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
149 |
IriSP.SegmentsWidget.prototype.clear = function() { |
| 834 | 150 |
this.selector.children(".Ldt-iri-chapter").fadeTo(0,.5); |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
151 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
152 |
|
| 104 | 153 |
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
| 464 | 154 |
this._Popcorn.trigger("IriSP.SegmentsWidget.click", annotation.id); |
|
313
7df805ebb75e
fixed some rounding errrors in segmentsWidget.js and animated the arrow and added
hamidouk
parents:
304
diff
changeset
|
155 |
var begin = (+ annotation.begin) / 1000; |
| 392 | 156 |
this._Popcorn.currentTime(Math.round(begin)); |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
104
diff
changeset
|
157 |
}; |
| 148 | 158 |
|
| 152 | 159 |
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
160 |
||
161 |
if (searchString == "") |
|
162 |
return; |
|
| 164 | 163 |
|
| 152 | 164 |
var matches = this._serializer.searchOccurences(searchString); |
| 164 | 165 |
|
| 355 | 166 |
if (IriSP.countProperties(matches) > 0) { |
| 398 | 167 |
this._Popcorn.trigger("IriSP.search.matchFound"); |
| 355 | 168 |
} else { |
| 398 | 169 |
this._Popcorn.trigger("IriSP.search.noMatchFound"); |
| 355 | 170 |
} |
171 |
||
| 397 | 172 |
// un-highlight all the blocks |
173 |
this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1); |
|
174 |
|
|
175 |
// then highlight the ones with matches. |
|
| 152 | 176 |
for (var id in matches) { |
| 380 | 177 |
var factor = 0.5 + matches[id] * 0.2; |
| 223 | 178 |
this.selector.find("#"+id).dequeue(); |
|
353
21f3a1d501eb
changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents:
336
diff
changeset
|
179 |
this.selector.find("#"+id).animate({opacity:factor}, 200); |
| 152 | 180 |
} |
| 164 | 181 |
|
| 397 | 182 |
|
| 152 | 183 |
this.oldSearchMatches = matches; |
| 148 | 184 |
}; |
| 152 | 185 |
|
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
186 |
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
187 |
this.clear(); |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
188 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
189 |
|
| 152 | 190 |
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
191 |
this.clear(); |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
192 |
}; |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
193 |
|
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
194 |
IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
| 842 | 195 |
var duration = this.getDuration() / 1000; |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
196 |
var time = this._Popcorn.currentTime(); |
| 483 | 197 |
//var position = ((time / duration) * 100).toFixed(2); |
| 217 | 198 |
var position = ((time / duration) * 100).toFixed(2); |
199 |
||
200 |
this.positionMarker.css("left", position + "%"); |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
201 |
}; |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
202 |
|
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
203 |
IriSP.SegmentsWidget.prototype.showAnnotation = function() { |
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
204 |
|
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
205 |
}; |