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