| author | hamidouk |
| Tue, 03 Jan 2012 12:25:57 +0100 | |
| branch | popcorn-port |
| changeset 567 | ada550479aaf |
| parent 552 | 3e8be3e6bdfb |
| child 593 | a4c63f13f021 |
| 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); }); |
| 100 | 11 |
}; |
12 |
||
| 139 | 13 |
IriSP.SegmentsWidget.prototype = new IriSP.Widget(); |
| 100 | 14 |
|
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
15 |
/* Get the width of a segment, in pixels. */ |
| 514 | 16 |
IriSP.SegmentsWidget.prototype.segmentToPixel = function(annotation) { |
17 |
var begin = Math.round((+ annotation.begin) / 1000); |
|
18 |
var end = Math.round((+ annotation.end) / 1000); |
|
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
19 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
| 514 | 20 |
|
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
21 |
var startPourcent = IriSP.timeToPourcent(begin, duration); |
| 514 | 22 |
var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100)); |
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
23 |
|
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
24 |
var endPourcent = Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent); |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
25 |
var endPixel = Math.floor(this.selector.parent().width() * (endPourcent / 100)); |
| 514 | 26 |
|
27 |
return endPixel; |
|
28 |
}; |
|
29 |
||
30 |
/* compute the total length of a group of segments */ |
|
31 |
IriSP.SegmentsWidget.prototype.segmentsLength = function(segmentsList) { |
|
32 |
var self = this; |
|
33 |
var total = 0; |
|
34 |
|
|
35 |
for (var i = 0; i < segmentsList.length; i++) |
|
36 |
total += self.segmentToPixel(segmentsList[i].annotation); |
|
37 |
|
|
38 |
return total; |
|
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
39 |
}; |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
40 |
|
| 100 | 41 |
IriSP.SegmentsWidget.prototype.draw = function() { |
42 |
||
| 148 | 43 |
var self = this; |
| 100 | 44 |
var annotations = this._serializer._data.annotations; |
| 164 | 45 |
|
|
334
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
46 |
this.selector.addClass("Ldt-SegmentsWidget"); |
|
229
808768eb5930
rewriting the slider-port to not use jquery ui slider.
hamidouk
parents:
223
diff
changeset
|
47 |
this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); |
| 514 | 48 |
|
49 |
var view_type = this._serializer.getNonTweetIds()[0]; |
|
|
220
6498b89eabcd
changed the widget to use a template for the segment marker.
hamidouk
parents:
218
diff
changeset
|
50 |
|
| 217 | 51 |
this.positionMarker = this.selector.children(":first"); |
52 |
|
|
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
53 |
this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater)); |
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
54 |
|
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
55 |
|
| 104 | 56 |
var i = 0; |
| 514 | 57 |
|
|
508
00054959ee92
began working on pixel-precise segmentWidget positioning.
hamidouk
parents:
483
diff
changeset
|
58 |
var segments_annotations = []; |
|
00054959ee92
began working on pixel-precise segmentWidget positioning.
hamidouk
parents:
483
diff
changeset
|
59 |
|
| 164 | 60 |
for (i = 0; i < annotations.length; i++) { |
| 100 | 61 |
var annotation = annotations[i]; |
| 104 | 62 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
63 |
/* filter the annotations whose type is not the one we want */ |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
64 |
if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined" |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
65 |
&& annotation.meta["id-ref"] != view_type) { |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
66 |
continue; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
67 |
} |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
68 |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
69 |
segments_annotations.push(annotation); |
| 514 | 70 |
} |
71 |
|
|
72 |
var totalWidth = this.selector.width() - segments_annotations.length; |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
73 |
var lastSegment = IriSP.underscore.max(segments_annotations, function(annotation) { return annotation.end; }); |
| 514 | 74 |
|
75 |
for (i = 0; i < segments_annotations.length; i++) { |
|
76 |
|
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
77 |
var annotation = segments_annotations[i]; |
|
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
78 |
var begin = (+ annotation.begin); |
|
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
79 |
var end = (+ annotation.end); |
|
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
80 |
var duration = this._serializer.currentMedia().meta["dc:duration"]; |
| 164 | 81 |
var id = annotation.id; |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
82 |
|
|
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
83 |
var startPixel = Math.floor(this.selector.parent().width() * (begin / duration)); |
| 164 | 84 |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
85 |
var endPixel = Math.floor(this.selector.parent().width() * (end / duration)); |
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
86 |
|
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
87 |
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
|
88 |
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
|
89 |
else |
|
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
90 |
/* 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
|
91 |
var pxWidth = endPixel - startPixel; |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
92 |
|
| 474 | 93 |
var divTitle = (annotation.content.title + " - " + annotation.content.description).substr(0,55); |
| 164 | 94 |
|
| 473 | 95 |
if (typeof(annotation.content.color) !== "undefined") |
96 |
var color = annotation.content.color; |
|
97 |
else |
|
98 |
var color = annotation.color; |
|
99 |
|
|
100 |
var hexa_color = IriSP.DEC_HEXA_COLOR(color); |
|
| 479 | 101 |
|
| 473 | 102 |
if (hexa_color === "FFCC00") |
103 |
hexa_color = "333"; |
|
| 479 | 104 |
if (hexa_color.length == 4) |
105 |
hexa_color = hexa_color + '00'; |
|
| 473 | 106 |
|
| 100 | 107 |
var annotationTemplate = Mustache.to_html(IriSP.annotation_template, |
| 514 | 108 |
{"divTitle" : divTitle, "id" : id, "startPixel" : startPixel, |
109 |
"pxWidth" : pxWidth, "hexa_color" : hexa_color, |
|
| 100 | 110 |
"seekPlace" : Math.round(begin/1000)}); |
| 164 | 111 |
|
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
112 |
|
| 164 | 113 |
this.selector.append(annotationTemplate); |
|
515
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
114 |
|
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
115 |
/* 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
|
116 |
if (annotation.id === lastSegment.id) { |
|
54324c5d82ab
got a more or less correct (+- 1px) version of the segmentsWidget.
hamidouk
parents:
514
diff
changeset
|
117 |
this.selector.find("#" + id).addClass("Ldt-lastSegment"); |
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
118 |
this.selector.find(".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
|
119 |
} |
| 164 | 120 |
|
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
121 |
IriSP.jQuery("#" + id).fadeTo(0, 0.3); |
| 164 | 122 |
|
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
123 |
IriSP.jQuery("#" + id).mouseover( |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
124 |
/* we wrap the handler in another function because js's scoping |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
125 |
rules are function-based - otherwise, the internal vars like |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
126 |
divTitle are preserved but they are looked-up from the draw |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
127 |
method scope, so after that the loop is run, so they're not |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
128 |
preserved */ |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
129 |
(function(divTitle) { |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
130 |
return function(event) { |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
131 |
IriSP.jQuery(this).animate({opacity: 0.6}, 5); |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
132 |
var offset = IriSP.jQuery(this).offset(); |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
133 |
var correction = IriSP.jQuery(this).outerWidth() / 2; |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
134 |
|
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
135 |
var offset_x = offset.left + correction - 106; |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
136 |
if (offset_x < 0) |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
137 |
offset_x = 0; |
| 550 | 138 |
|
139 |
var offset_y = offset.top; |
|
| 552 | 140 |
|
| 550 | 141 |
self.TooltipWidget.show(divTitle, color, offset_x, offset_y - 160); |
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
142 |
} })(divTitle)).mouseout(function(){ |
|
334
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
143 |
IriSP.jQuery(this).animate({opacity: 0.3}, 5); |
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
144 |
self.TooltipWidget.hide(); |
| 104 | 145 |
}); |
| 164 | 146 |
|
147 |
IriSP.jQuery("#" + id).click(function(_this, annotation) { |
|
| 104 | 148 |
return function() { _this.clickHandler(annotation)}; |
149 |
}(this, annotation)); |
|
| 164 | 150 |
} |
| 104 | 151 |
}; |
152 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
153 |
/* restores the view after a search */ |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
154 |
IriSP.SegmentsWidget.prototype.clear = function() { |
|
516
fe8c9f4791cb
added a pixel to the last segment. Made search play nice with the borders.
hamidouk
parents:
515
diff
changeset
|
155 |
this.selector.children(".Ldt-iri-chapter").animate({opacity:0.3}, 100); |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
156 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
157 |
|
| 104 | 158 |
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
| 464 | 159 |
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
|
160 |
var begin = (+ annotation.begin) / 1000; |
| 392 | 161 |
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
|
162 |
}; |
| 148 | 163 |
|
| 152 | 164 |
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
165 |
||
166 |
if (searchString == "") |
|
167 |
return; |
|
| 164 | 168 |
|
| 152 | 169 |
var matches = this._serializer.searchOccurences(searchString); |
| 164 | 170 |
|
| 355 | 171 |
if (IriSP.countProperties(matches) > 0) { |
| 398 | 172 |
this._Popcorn.trigger("IriSP.search.matchFound"); |
| 355 | 173 |
} else { |
| 398 | 174 |
this._Popcorn.trigger("IriSP.search.noMatchFound"); |
| 355 | 175 |
} |
176 |
||
| 397 | 177 |
// un-highlight all the blocks |
178 |
this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1); |
|
179 |
|
|
180 |
// then highlight the ones with matches. |
|
| 152 | 181 |
for (var id in matches) { |
| 380 | 182 |
var factor = 0.5 + matches[id] * 0.2; |
| 223 | 183 |
this.selector.find("#"+id).dequeue(); |
|
353
21f3a1d501eb
changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents:
336
diff
changeset
|
184 |
this.selector.find("#"+id).animate({opacity:factor}, 200); |
| 152 | 185 |
} |
| 164 | 186 |
|
| 397 | 187 |
|
| 152 | 188 |
this.oldSearchMatches = matches; |
| 148 | 189 |
}; |
| 152 | 190 |
|
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
191 |
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
192 |
this.clear(); |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
193 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
194 |
|
| 152 | 195 |
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
196 |
this.clear(); |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
197 |
}; |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
198 |
|
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
199 |
IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
200 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
201 |
var time = this._Popcorn.currentTime(); |
| 483 | 202 |
//var position = ((time / duration) * 100).toFixed(2); |
| 217 | 203 |
var position = ((time / duration) * 100).toFixed(2); |
204 |
||
205 |
this.positionMarker.css("left", position + "%"); |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
206 |
}; |