| author | hamidouk |
| Wed, 21 Dec 2011 17:24:07 +0100 | |
| branch | calage-segmentsWidget |
| changeset 509 | 756ecd1645a5 |
| parent 508 | 00054959ee92 |
| child 514 | f5865a99be69 |
| 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. */ |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
16 |
IriSP.SegmentsWidget.prototype.segmentToPixel(annotation) { |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
17 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
18 |
var id = annotation.id; |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
19 |
var startPourcent = IriSP.timeToPourcent(begin, duration); |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
20 |
var startPixel = Math.floor(this.selector.parent().width() * (endPourcent / 100)); |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
21 |
|
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
22 |
/* surprisingly, the following code doesn't work on webkit - for some reason, most of the |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
23 |
boxes are 3 pixels smaller. |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
24 |
*/ |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
25 |
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
|
26 |
var endPixel = Math.floor(this.selector.parent().width() * (endPourcent / 100)); |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
27 |
}; |
|
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
28 |
|
| 100 | 29 |
IriSP.SegmentsWidget.prototype.draw = function() { |
30 |
||
| 148 | 31 |
var self = this; |
| 100 | 32 |
var annotations = this._serializer._data.annotations; |
| 164 | 33 |
|
|
334
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
34 |
this.selector.addClass("Ldt-SegmentsWidget"); |
|
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
35 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
36 |
/* in case we have different types of annotations, we want to display only the first type */ |
|
303
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
37 |
/* the next two lines are a bit verbose because for some test data, _serializer.data.view is either |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
38 |
null or undefined. |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
39 |
*/ |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
40 |
var view; |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
41 |
|
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
42 |
if (typeof(this._serializer._data.views) !== "undefined" && this._serializer._data.views !== null) |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
43 |
view = this._serializer._data.views[0]; |
|
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
44 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
45 |
var view_type = ""; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
46 |
|
|
303
cb091d204ba9
added a more restrictive test to check for the annotation type.
hamidouk
parents:
300
diff
changeset
|
47 |
if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
48 |
view_type = view.annotation_types[0]; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
49 |
} |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
50 |
|
|
229
808768eb5930
rewriting the slider-port to not use jquery ui slider.
hamidouk
parents:
223
diff
changeset
|
51 |
this.selector.append(Mustache.to_html(IriSP.overlay_marker_template)); |
|
220
6498b89eabcd
changed the widget to use a template for the segment marker.
hamidouk
parents:
218
diff
changeset
|
52 |
|
| 217 | 53 |
this.positionMarker = this.selector.children(":first"); |
54 |
|
|
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
55 |
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
|
56 |
|
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
57 |
|
| 104 | 58 |
var i = 0; |
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
59 |
var totalWidth = this.selector.width(); |
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
60 |
var onePxPercent = 100 / totalWidth; /* the value of a pixel, in percents */ |
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
61 |
|
|
508
00054959ee92
began working on pixel-precise segmentWidget positioning.
hamidouk
parents:
483
diff
changeset
|
62 |
var segments_annotations = []; |
|
00054959ee92
began working on pixel-precise segmentWidget positioning.
hamidouk
parents:
483
diff
changeset
|
63 |
|
| 164 | 64 |
for (i = 0; i < annotations.length; i++) { |
| 100 | 65 |
var annotation = annotations[i]; |
| 104 | 66 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
67 |
/* 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
|
68 |
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
|
69 |
&& annotation.meta["id-ref"] != view_type) { |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
70 |
continue; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
71 |
} |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
72 |
|
|
509
756ecd1645a5
defined a func to compute the width in pixels of a segment.
hamidouk
parents:
508
diff
changeset
|
73 |
segments_annotations.push(annotation); |
| 100 | 74 |
var begin = Math.round((+ annotation.begin) / 1000); |
75 |
var end = Math.round((+ annotation.end) / 1000); |
|
| 104 | 76 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
| 164 | 77 |
var id = annotation.id; |
| 483 | 78 |
var startPourcent = IriSP.timeToPourcent(begin, duration); |
| 222 | 79 |
|
| 483 | 80 |
/* surprisingly, the following code doesn't work on webkit - for some reason, most of the |
81 |
boxes are 3 pixels smaller. |
|
| 222 | 82 |
*/ |
| 483 | 83 |
var endPourcent = Math.floor(IriSP.timeToPourcent(end, duration) - startPourcent); |
84 |
var endPixel = Math.floor(this.selector.parent().width() * (endPourcent / 100)) - 2; |
|
85 |
|
|
| 222 | 86 |
if (i == 0) { |
| 164 | 87 |
|
| 222 | 88 |
endPourcent -= onePxPercent; |
89 |
} |
|
90 |
|
|
| 474 | 91 |
var divTitle = (annotation.content.title + " - " + annotation.content.description).substr(0,55); |
| 164 | 92 |
|
| 473 | 93 |
if (typeof(annotation.content.color) !== "undefined") |
94 |
var color = annotation.content.color; |
|
95 |
else |
|
96 |
var color = annotation.color; |
|
97 |
|
|
98 |
var hexa_color = IriSP.DEC_HEXA_COLOR(color); |
|
| 479 | 99 |
|
| 473 | 100 |
if (hexa_color === "FFCC00") |
101 |
hexa_color = "333"; |
|
| 479 | 102 |
if (hexa_color.length == 4) |
103 |
hexa_color = hexa_color + '00'; |
|
| 473 | 104 |
|
| 100 | 105 |
var annotationTemplate = Mustache.to_html(IriSP.annotation_template, |
106 |
{"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent, |
|
| 483 | 107 |
"endPixel" : endPixel, "hexa_color" : hexa_color, |
| 100 | 108 |
"seekPlace" : Math.round(begin/1000)}); |
| 164 | 109 |
|
110 |
this.selector.append(annotationTemplate); |
|
111 |
||
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
112 |
// IriSP.jQuery("#" + id).tooltip({ effect: 'slide'}); |
| 164 | 113 |
|
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
114 |
IriSP.jQuery("#" + id).fadeTo(0, 0.3); |
| 164 | 115 |
|
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
116 |
IriSP.jQuery("#" + id).mouseover( |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
117 |
/* 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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
preserved */ |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
122 |
(function(divTitle) { |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
123 |
return function(event) { |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
124 |
IriSP.jQuery(this).animate({opacity: 0.6}, 5); |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
125 |
var offset = IriSP.jQuery(this).offset(); |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
126 |
var correction = IriSP.jQuery(this).outerWidth() / 2; |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
127 |
|
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
128 |
var offset_x = offset.left + correction - 106; |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
129 |
if (offset_x < 0) |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
130 |
offset_x = 0; |
| 474 | 131 |
|
|
336
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
132 |
self.TooltipWidget.show(divTitle, color, offset_x, event.pageY - 160); |
|
8da13562cfea
segmentsWidget now uses the TooltipWidget instead of the jQuerytools tooltip.
hamidouk
parents:
334
diff
changeset
|
133 |
} })(divTitle)).mouseout(function(){ |
|
334
e20f97514d44
move the styling of a segment from the templates to the css.
hamidouk
parents:
321
diff
changeset
|
134 |
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
|
135 |
self.TooltipWidget.hide(); |
| 104 | 136 |
}); |
| 164 | 137 |
|
138 |
IriSP.jQuery("#" + id).click(function(_this, annotation) { |
|
| 104 | 139 |
return function() { _this.clickHandler(annotation)}; |
140 |
}(this, annotation)); |
|
| 164 | 141 |
} |
| 104 | 142 |
}; |
143 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
144 |
/* restores the view after a search */ |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
145 |
IriSP.SegmentsWidget.prototype.clear = function() { |
| 397 | 146 |
this.selector.children(".Ldt-iri-chapter").css('border','none').animate({opacity:0.3}, 100); |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
147 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
148 |
|
| 104 | 149 |
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
| 464 | 150 |
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
|
151 |
var begin = (+ annotation.begin) / 1000; |
| 392 | 152 |
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
|
153 |
}; |
| 148 | 154 |
|
| 152 | 155 |
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
156 |
||
157 |
if (searchString == "") |
|
158 |
return; |
|
| 164 | 159 |
|
| 152 | 160 |
var matches = this._serializer.searchOccurences(searchString); |
| 164 | 161 |
|
| 355 | 162 |
if (IriSP.countProperties(matches) > 0) { |
| 398 | 163 |
this._Popcorn.trigger("IriSP.search.matchFound"); |
| 355 | 164 |
} else { |
| 398 | 165 |
this._Popcorn.trigger("IriSP.search.noMatchFound"); |
| 355 | 166 |
} |
167 |
||
| 397 | 168 |
// un-highlight all the blocks |
169 |
this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1); |
|
170 |
|
|
171 |
// then highlight the ones with matches. |
|
| 152 | 172 |
for (var id in matches) { |
| 380 | 173 |
var factor = 0.5 + matches[id] * 0.2; |
| 223 | 174 |
this.selector.find("#"+id).dequeue(); |
|
353
21f3a1d501eb
changed the way the segmentsWidget highlights the matching segments.
hamidouk
parents:
336
diff
changeset
|
175 |
this.selector.find("#"+id).css('border','1px red'); |
|
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() { |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
192 |
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
|
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 |
}; |