| author | hamidouk |
| Tue, 22 Nov 2011 17:22:50 +0100 | |
| branch | popcorn-port |
| changeset 300 | a50aea26ec89 |
| parent 229 | 808768eb5930 |
| child 303 | cb091d204ba9 |
| 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; |
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
19 |
var view = this._serializer._data.views[0]; |
| 164 | 20 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
21 |
/* in case we have different types of annotations, we want to display only the first type */ |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
22 |
var view_type = ""; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
23 |
|
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
24 |
if(typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) { |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
25 |
view_type = view.annotation_types[0]; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
26 |
} |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
27 |
|
| 218 | 28 |
this.selector.css("overflow", "auto"); // clear the floats - FIXME : to refactor ? |
|
229
808768eb5930
rewriting the slider-port to not use jquery ui slider.
hamidouk
parents:
223
diff
changeset
|
29 |
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
|
30 |
|
| 217 | 31 |
this.positionMarker = this.selector.children(":first"); |
32 |
|
|
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
33 |
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
|
34 |
|
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
35 |
this.selector.after("<div class='cleaner'></div>"); // we need to do this because the segments are floated |
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
36 |
|
| 104 | 37 |
var i = 0; |
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
38 |
var totalWidth = this.selector.width(); |
|
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
39 |
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
|
40 |
|
| 164 | 41 |
for (i = 0; i < annotations.length; i++) { |
| 100 | 42 |
var annotation = annotations[i]; |
| 104 | 43 |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
44 |
/* 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
|
45 |
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
|
46 |
&& annotation.meta["id-ref"] != view_type) { |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
47 |
continue; |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
48 |
} |
|
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
49 |
|
| 100 | 50 |
var begin = Math.round((+ annotation.begin) / 1000); |
51 |
var end = Math.round((+ annotation.end) / 1000); |
|
| 104 | 52 |
var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; |
| 164 | 53 |
var id = annotation.id; |
| 222 | 54 |
var startPourcent = IriSP.timeToPourcent(begin, duration); |
55 |
|
|
56 |
/* some sort of collapsing occurs, so we only have to substract one pixel to each box instead of |
|
57 |
two |
|
58 |
*/ |
|
59 |
var endPourcent = IriSP.timeToPourcent(end, duration) - startPourcent - onePxPercent * 1; |
|
60 |
|
|
61 |
/* on the other hand, we have to substract one pixel from the first box because it's the only |
|
62 |
one to have to effective 1px margins */ |
|
63 |
if (i == 0) { |
|
| 164 | 64 |
|
| 222 | 65 |
endPourcent -= onePxPercent; |
66 |
} |
|
67 |
|
|
| 223 | 68 |
var divTitle = annotation.content.title.substr(0,55); |
| 100 | 69 |
var color = annotation.content.color |
| 164 | 70 |
|
71 |
||
| 100 | 72 |
var annotationTemplate = Mustache.to_html(IriSP.annotation_template, |
73 |
{"divTitle" : divTitle, "id" : id, "startPourcent" : startPourcent, |
|
74 |
"endPourcent" : endPourcent, "hexa_color" : IriSP.DEC_HEXA_COLOR(color), |
|
75 |
"seekPlace" : Math.round(begin/1000)}); |
|
| 164 | 76 |
|
77 |
||
78 |
var toolTipTemplate = Mustache.to_html(IriSP.tooltip_template, |
|
| 100 | 79 |
{"title" : divTitle, "begin" : begin, "end" : end, |
80 |
"description": annotation.content.description}); |
|
| 164 | 81 |
|
82 |
this.selector.append(annotationTemplate); |
|
83 |
||
| 100 | 84 |
IriSP.jQuery("#" + id).tooltip({ effect: 'slide'}); |
| 164 | 85 |
|
|
212
3a6e4089eef0
fixed teh segments display bug and another bug related to float positioning.
hamidouk
parents:
210
diff
changeset
|
86 |
IriSP.jQuery("#" + id).fadeTo(0, 0.3); |
| 164 | 87 |
|
| 100 | 88 |
IriSP.jQuery("#" + id).mouseover(function() { |
89 |
IriSP.jQuery("#" + id).animate({opacity: 0.6}, 5); |
|
| 164 | 90 |
}).mouseout(function(){ |
| 100 | 91 |
IriSP.jQuery("#" + id).animate({opacity: 0.3}, 5); |
| 104 | 92 |
}); |
| 164 | 93 |
|
94 |
IriSP.jQuery("#" + id).click(function(_this, annotation) { |
|
| 104 | 95 |
return function() { _this.clickHandler(annotation)}; |
96 |
}(this, annotation)); |
|
| 164 | 97 |
} |
| 104 | 98 |
}; |
99 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
100 |
/* restores the view after a search */ |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
101 |
IriSP.SegmentsWidget.prototype.clear = function() { |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
102 |
// reinit the fields |
| 164 | 103 |
for (var id in this.oldSearchMatches) { |
104 |
||
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
105 |
IriSP.jQuery("#"+id).dequeue(); |
| 223 | 106 |
IriSP.jQuery("#"+id).animate({height:0}, 100); |
107 |
IriSP.jQuery("#"+id).css('border-color','lightgray'); |
|
108 |
IriSP.jQuery("#"+id).animate({opacity:0.3}, 100); |
|
| 164 | 109 |
} |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
110 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
111 |
|
| 104 | 112 |
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
113 |
var begin = Math.round((+ annotation.begin) / 1000); |
|
| 217 | 114 |
this._Popcorn.currentTime(begin); |
|
108
62da43e72e30
broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
104
diff
changeset
|
115 |
}; |
| 148 | 116 |
|
| 152 | 117 |
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
118 |
||
119 |
if (searchString == "") |
|
120 |
return; |
|
| 164 | 121 |
|
| 152 | 122 |
var matches = this._serializer.searchOccurences(searchString); |
| 164 | 123 |
|
| 152 | 124 |
for (var id in matches) { |
125 |
var factor = matches[id] * 8; |
|
| 223 | 126 |
this.selector.find("#"+id).dequeue(); |
127 |
this.selector.find("#"+id).animate({height: factor}, 200); |
|
128 |
this.selector.find("#"+id).css('border-color','red'); |
|
129 |
this.selector.find("#"+id).animate({opacity:0.6}, 200); |
|
| 152 | 130 |
|
| 223 | 131 |
IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1'); |
| 152 | 132 |
} |
| 164 | 133 |
|
| 152 | 134 |
// clean up the blocks that were in the previous search |
135 |
// but who aren't in the current one. |
|
| 164 | 136 |
for (var id in this.oldSearchMatches) { |
| 152 | 137 |
if (!matches.hasOwnProperty(id)) { |
138 |
IriSP.jQuery("#"+id).dequeue(); |
|
| 223 | 139 |
IriSP.jQuery("#"+id).animate({height:0}, 250); |
140 |
IriSP.jQuery("#"+id).animate({opacity:0.3}, 200); |
|
141 |
this.selector.find("#"+id).css('border','solid 1px #aaaaaa'); |
|
| 152 | 142 |
} |
143 |
} |
|
| 223 | 144 |
|
| 152 | 145 |
this.oldSearchMatches = matches; |
| 148 | 146 |
}; |
| 152 | 147 |
|
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
148 |
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() { |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
149 |
this.clear(); |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
150 |
}; |
|
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
151 |
|
| 152 | 152 |
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
|
154
6e115a094858
another tweak to the searchBox : the visualization is cleared when the searchbox
hamidouk
parents:
152
diff
changeset
|
153 |
this.clear(); |
|
214
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
154 |
}; |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
155 |
|
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
156 |
IriSP.SegmentsWidget.prototype.positionUpdater = function() { |
|
50c4609e50f4
WIP - added a div that should move over the widget.
hamidouk
parents:
212
diff
changeset
|
157 |
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
|
158 |
var time = this._Popcorn.currentTime(); |
| 217 | 159 |
var position = ((time / duration) * 100).toFixed(2); |
160 |
||
161 |
this.positionMarker.css("left", position + "%"); |
|
|
300
a50aea26ec89
fixed annotation bug in the segmentswidget - we were displaying every annotation,
hamidouk
parents:
229
diff
changeset
|
162 |
}; |