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