| author | veltr |
| Tue, 20 Mar 2012 21:17:48 +0100 | |
| branch | popcorn-port |
| changeset 835 | a8af9da7c622 |
| parent 834 | 573c7ca752e0 |
| child 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.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 |
|
84 |
: IriSP.clean_substr(annotation.content.title + " -<br>" + annotation.content.description, 0, 132) + "..."; |
|
| 473 | 85 |
|
| 834 | 86 |
var hexa_color = typeof(annotation.content.color) !== "undefined" |
87 |
? '#' + IriSP.DEC_HEXA_COLOR(annotation.content.color) |
|
88 |
: typeof(annotation.color) !== "undefined" |
|
89 |
? '#' + IriSP.DEC_HEXA_COLOR(annotation.color) |
|
90 |
: this.defaultColors[i % this.defaultColors.length]; |
|
| 479 | 91 |
|
| 637 | 92 |
/* |
| 473 | 93 |
if (hexa_color === "FFCC00") |
94 |
hexa_color = "333"; |
|
| 637 | 95 |
*/ |
| 834 | 96 |
if (hexa_color.length == 5) |
| 479 | 97 |
hexa_color = hexa_color + '00'; |
| 473 | 98 |
|
| 834 | 99 |
|
| 100 | 100 |
var annotationTemplate = Mustache.to_html(IriSP.annotation_template, |
| 514 | 101 |
{"divTitle" : divTitle, "id" : id, "startPixel" : startPixel, |
102 |
"pxWidth" : pxWidth, "hexa_color" : hexa_color, |
|
| 100 | 103 |
"seekPlace" : Math.round(begin/1000)}); |
| 164 | 104 |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
105 |
|
| 164 | 106 |
this.selector.append(annotationTemplate); |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
107 |
|
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
108 |
/* 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
|
109 |
if (annotation.id === lastSegment.id) { |
| 834 | 110 |
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
|
111 |
} |
| 834 | 112 |
} |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
113 |
// react to mediafragment messages. |
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
114 |
this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", |
| 834 | 115 |
function(id, divTitle) { |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
116 |
|
| 834 | 117 |
var divObject = IriSP.jqId(id); |
118 |
if (divObject.length) { |
|
119 |
divObject.fadeTo(0,1); |
|
120 |
var offset_x = divObject.position().left + divObject.outerWidth() / 2; |
|
121 |
self.TooltipWidget.show(divObject.attr("title"), IriSP.jQuery(this).css("background-color"), offset_x, 0); |
|
122 |
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
|
123 |
self.TooltipWidget.hide(); }); |
| 834 | 124 |
} |
125 |
}); |
|
126 |
|
|
127 |
this.selector.find(".Ldt-iri-chapter") |
|
128 |
.fadeTo(0, .5) |
|
129 |
.click(function() { |
|
130 |
self._Popcorn.trigger("IriSP.SegmentsWidget.click", this.id); |
|
131 |
self._Popcorn.currentTime(IriSP.jQuery(this).attr("data-seek")); |
|
132 |
}) |
|
133 |
.mouseover( function(event) { |
|
134 |
var divObject = IriSP.jQuery(this); |
|
135 |
divObject.fadeTo(0,1); |
|
136 |
var offset_x = divObject.position().left + divObject.outerWidth() / 2; |
|
137 |
self.TooltipWidget.show(divObject.attr("title"), IriSP.jQuery(this).css("background-color"), offset_x, 0); |
|
138 |
}) |
|
139 |
.mouseout(function(){ |
|
140 |
IriSP.jQuery(this).fadeTo(0,.5); |
|
141 |
self.TooltipWidget.hide(); |
|
142 |
}); |
|
| 104 | 143 |
}; |
144 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
145 |
/* restores the view after a search */ |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
146 |
IriSP.SegmentsWidget.prototype.clear = function() { |
| 834 | 147 |
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
|
148 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
149 |
|
| 104 | 150 |
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
| 464 | 151 |
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
|
152 |
var begin = (+ annotation.begin) / 1000; |
| 392 | 153 |
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
|
154 |
}; |
| 148 | 155 |
|
| 152 | 156 |
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
157 |
||
158 |
if (searchString == "") |
|
159 |
return; |
|
| 164 | 160 |
|
| 152 | 161 |
var matches = this._serializer.searchOccurences(searchString); |
| 164 | 162 |
|
| 355 | 163 |
if (IriSP.countProperties(matches) > 0) { |
| 398 | 164 |
this._Popcorn.trigger("IriSP.search.matchFound"); |
| 355 | 165 |
} else { |
| 398 | 166 |
this._Popcorn.trigger("IriSP.search.noMatchFound"); |
| 355 | 167 |
} |
168 |
||
| 397 | 169 |
// un-highlight all the blocks |
170 |
this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1); |
|
171 |
|
|
172 |
// then highlight the ones with matches. |
|
| 152 | 173 |
for (var id in matches) { |
| 380 | 174 |
var factor = 0.5 + matches[id] * 0.2; |
| 223 | 175 |
this.selector.find("#"+id).dequeue(); |
|
353
21f3a1d501eb
changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents:
336
diff
changeset
|
176 |
this.selector.find("#"+id).animate({opacity:factor}, 200); |
| 152 | 177 |
} |
| 164 | 178 |
|
| 397 | 179 |
|
| 152 | 180 |
this.oldSearchMatches = matches; |
| 148 | 181 |
}; |
| 152 | 182 |
|
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
183 |
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
184 |
this.clear(); |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
185 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
186 |
|
| 152 | 187 |
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
188 |
this.clear(); |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
189 |
}; |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
190 |
|
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
191 |
IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
| 835 | 192 |
var duration = this._serializer.getDuration() / 1000; |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
193 |
var time = this._Popcorn.currentTime(); |
| 483 | 194 |
//var position = ((time / duration) * 100).toFixed(2); |
| 217 | 195 |
var position = ((time / duration) * 100).toFixed(2); |
196 |
||
197 |
this.positionMarker.css("left", position + "%"); |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
198 |
}; |
|
771
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
199 |
|
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
200 |
IriSP.SegmentsWidget.prototype.showAnnotation = function() { |
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
201 |
|
|
0a5194b39ffb
highlight an annotation when mediafragment tells us so.
hamidouk
parents:
687
diff
changeset
|
202 |
}; |