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