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