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