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