1 IriSP.SegmentsWidget = function(Popcorn, config, Serializer) { |
1 IriSP.SegmentsWidget = function(Popcorn, config, Serializer) { |
2 IriSP.Widget.call(this, Popcorn, config, Serializer); |
2 |
|
3 var self = this; |
|
4 IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
5 this.oldSearchMatches = []; |
|
6 |
|
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); }); |
3 }; |
10 }; |
4 |
11 |
5 IriSP.SegmentsWidget.prototype = new IriSP.Widget(); |
12 IriSP.SegmentsWidget.prototype = new IriSP.Widget(); |
6 |
13 |
7 IriSP.SegmentsWidget.prototype.draw = function() { |
14 IriSP.SegmentsWidget.prototype.draw = function() { |
60 function(middle) { |
67 function(middle) { |
61 return function() { |
68 return function() { |
62 IriSP.jQuery("#Ldt-Show-Arrow").animate({left: real_middle + '%'}, 1000); }}(middle) |
69 IriSP.jQuery("#Ldt-Show-Arrow").animate({left: real_middle + '%'}, 1000); }}(middle) |
63 }; |
70 }; |
64 this._Popcorn = this._Popcorn.code(conf); |
71 this._Popcorn = this._Popcorn.code(conf); |
65 } |
72 } |
66 |
|
67 this._Popcorn.listen("IriSP.search", function(searchWord) { self.searchHandler.call(self, searchWord); }); |
|
68 }; |
73 }; |
69 |
74 |
70 IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
75 IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) { |
71 var begin = Math.round((+ annotation.begin) / 1000); |
76 var begin = Math.round((+ annotation.begin) / 1000); |
72 this._Popcorn.currentTime(begin) |
77 this._Popcorn.currentTime(begin) |
73 }; |
78 }; |
74 |
79 |
75 IriSP.SegmentsWidget.prototype.searchHandler = function(searchWord) { |
80 IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) { |
76 console.log("received" + searchWord); |
81 |
|
82 if (searchString == "") |
|
83 return; |
|
84 |
|
85 console.log(searchString); |
|
86 var matches = this._serializer.searchOccurences(searchString); |
|
87 |
|
88 for (var id in matches) { |
|
89 var factor = matches[id] * 8; |
|
90 IriSP.jQuery("#"+id).dequeue(); |
|
91 IriSP.jQuery("#"+id).animate({height: factor},200); |
|
92 IriSP.jQuery("#"+id).css('border','2px'); |
|
93 IriSP.jQuery("#"+id).css('border-color','red'); |
|
94 IriSP.jQuery("#"+id).animate({opacity:0.6},200); |
|
95 |
|
96 //IriSP.jQuery("#LdtSearchInput").css('background-color','#e1ffe1'); |
|
97 } |
|
98 |
|
99 // clean up the blocks that were in the previous search |
|
100 // but who aren't in the current one. |
|
101 for (var id in this.oldSearchMatches) { |
|
102 if (!matches.hasOwnProperty(id)) { |
|
103 IriSP.jQuery("#"+id).dequeue(); |
|
104 IriSP.jQuery("#"+id).animate({height:0},250); |
|
105 IriSP.jQuery("#"+id).animate({opacity:0.3},200); |
|
106 } |
|
107 } |
|
108 this.oldSearchMatches = matches; |
77 }; |
109 }; |
|
110 |
|
111 IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() { |
|
112 // reinit the fields |
|
113 for (var id in this.oldSearchMatches) { |
|
114 |
|
115 IriSP.jQuery("#"+id).dequeue(); |
|
116 IriSP.jQuery("#"+id).animate({height:0},100); |
|
117 IriSP.jQuery("#"+id).css('border','0px'); |
|
118 IriSP.jQuery("#"+id).css('border-color','red'); |
|
119 IriSP.jQuery("#"+id).animate({opacity:0.3},100); |
|
120 } |
|
121 |
|
122 |
|
123 }; |