| author | veltr |
| Fri, 16 Nov 2012 17:36:56 +0100 | |
| changeset 982 | cfcbac34d020 |
| parent 964 | d7d56ea2d0a6 |
| child 983 | 97fef7a4b189 |
| permissions | -rw-r--r-- |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
1 |
// TODO: Trigger IriSP.SegmentsWidget.click |
| 876 | 2 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
3 |
IriSP.Widgets.Segments = function(player, config) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
4 |
IriSP.Widgets.Widget.call(this, player, config); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
5 |
}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
6 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
7 |
IriSP.Widgets.Segments.prototype = new IriSP.Widgets.Widget(); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
8 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
9 |
IriSP.Widgets.Segments.prototype.defaults = { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
10 |
annotation_type : "chap", |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
11 |
colors: ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"], |
| 982 | 12 |
line_height: 8, |
13 |
background: "#e0e0e0", |
|
14 |
overlap: .25 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
15 |
}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
16 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
17 |
IriSP.Widgets.Segments.prototype.template = |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
18 |
'<div class="Ldt-Segments-List"></div>' |
| 924 | 19 |
+ '<div class="Ldt-Segments-Position"></div>' |
20 |
+ '<div class="Ldt-Segments-Tooltip"></div>'; |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
21 |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
22 |
IriSP.Widgets.Segments.prototype.annotationTemplate = |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
23 |
'<div class="Ldt-Segments-Segment Ldt-TraceMe" trace-info="segment-id:{{id}}, media-id:{{media_id}}" segment-text="{{text}}"' |
| 982 | 24 |
+ 'style="top:{{top}}px; height:{{height}}px; left:{{left}}px; width:{{width}}px; background:{{medcolor}}" data-base-color="{{color}}" data-low-color="{{lowcolor}}" data-medium-color="{{medcolor}}"></div>' |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
25 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
26 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
27 |
IriSP.Widgets.Segments.prototype.draw = function() { |
| 957 | 28 |
this.onMdpEvent("search", "onSearch"); |
29 |
this.onMdpEvent("search.closed", "onSearch"); |
|
30 |
this.onMdpEvent("search.cleared", "onSearch"); |
|
31 |
this.onMediaEvent("timeupdate", "onTimeupdate"); |
|
| 876 | 32 |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
33 |
this.renderTemplate(); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
34 |
|
| 982 | 35 |
var _list = this.getWidgetAnnotations().filter(function(_ann) { |
36 |
return _ann.getDuration() > 0; |
|
37 |
}), |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
38 |
_this = this, |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
39 |
_scale = this.width / this.source.getDuration(); |
| 982 | 40 |
var list_$ = this.$.find('.Ldt-Segments-List'), |
41 |
lines = [], |
|
42 |
zindex = 1; |
|
43 |
|
|
44 |
function saturate(r, g, b, s) { |
|
45 |
function satcomp(c) { |
|
46 |
return Math.floor(240 * (1 - s) + c * s); |
|
47 |
} |
|
48 |
var res = ( 0x10000 * satcomp(r) + 0x100 * satcomp(g) + satcomp(b)).toString(16); |
|
49 |
while (res.length < 6) { |
|
50 |
res = "0" + res; |
|
51 |
} |
|
52 |
return "#" + res; |
|
53 |
} |
|
54 |
|
|
55 |
function unselect() { |
|
56 |
_this.tooltip.hide(); |
|
57 |
_this.$segments.each(function() { |
|
58 |
var _segment = IriSP.jQuery(this); |
|
59 |
_segment.css("background", _segment.attr("data-medium-color")); |
|
60 |
}); |
|
61 |
} |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
62 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
63 |
_list.forEach(function(_annotation, _k) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
64 |
var _left = _annotation.begin * _scale, |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
65 |
_width = ( _annotation.getDuration() ) * _scale, |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
66 |
_center = Math.floor( _left + _width / 2 ), |
| 982 | 67 |
_fulltext = _annotation.title + ( _annotation.description ? ( '<br/>' + _annotation.description ) : '' ), |
68 |
line = IriSP._(lines).find(function(line) { |
|
69 |
return !IriSP._(line.annotations).find(function(a) { |
|
70 |
return a.begin < _annotation.end && a.end > _annotation.begin |
|
71 |
}); |
|
72 |
}); |
|
73 |
if (!line) { |
|
74 |
line = { index: lines.length, annotations: []}; |
|
75 |
lines.push(line); |
|
76 |
} |
|
77 |
line.annotations.push(_annotation); |
|
78 |
var _top = ((1 - _this.overlap) * line.index) * _this.line_height, |
|
79 |
color = ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.colors[_k % _this.colors.length] ), |
|
80 |
r = parseInt(color.substr(1,2),16), |
|
81 |
g = parseInt(color.substr(3,2),16), |
|
82 |
b = parseInt(color.substr(5,2),16), |
|
83 |
medcolor = saturate(r, g, b, .5), |
|
84 |
lowcolor = saturate(r, g, b, .2); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
85 |
var _data = { |
| 982 | 86 |
color : color, |
87 |
medcolor: medcolor, |
|
88 |
lowcolor: lowcolor, |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
89 |
text: _fulltext.replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{120,140})[\s].+$/m,'$1…'), |
| 982 | 90 |
left : _left, |
91 |
width : _width, |
|
92 |
top: _top, |
|
93 |
height: _this.line_height - 1, |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
94 |
id : _annotation.id, |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
95 |
media_id : _annotation.getMedia().id |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
96 |
}; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
97 |
var _html = Mustache.to_html(_this.annotationTemplate, _data), |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
98 |
_el = IriSP.jQuery(_html); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
99 |
_el.mouseover(function() { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
100 |
_annotation.trigger("select"); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
101 |
}) |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
102 |
.mouseout(function() { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
103 |
_annotation.trigger("unselect"); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
104 |
}) |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
105 |
.click(function() { |
| 964 | 106 |
_annotation.trigger("click"); |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
107 |
}) |
| 982 | 108 |
.appendTo(list_$) |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
109 |
_annotation.on("select", function() { |
| 982 | 110 |
_this.$segments.each(function() { |
111 |
var _segment = IriSP.jQuery(this); |
|
112 |
_segment.css({ |
|
113 |
background: _segment.attr("data-low-color") |
|
114 |
}); |
|
115 |
}); |
|
116 |
_this.tooltip.show( _center, _top, _data.text, _data.color ); |
|
117 |
_el.css({ |
|
118 |
background: color, |
|
119 |
"z-index": ++zindex |
|
120 |
}); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
121 |
}); |
| 982 | 122 |
_annotation.on("unselect", unselect); |
123 |
}); |
|
124 |
|
|
125 |
this.$.css({ |
|
126 |
width : this.width + "px", |
|
127 |
height : (((1 - this.overlap) * lines.length + this.overlap) * this.line_height) + "px", |
|
128 |
background : this.background, |
|
129 |
margin: "1px 0" |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
130 |
}); |
| 959 | 131 |
this.insertSubwidget(this.$.find(".Ldt-Segments-Tooltip"), { type: "Tooltip" }, "tooltip"); |
| 876 | 132 |
this.$segments = this.$.find('.Ldt-Segments-Segment'); |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
133 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
134 |
|
| 876 | 135 |
IriSP.Widgets.Segments.prototype.onSearch = function(searchString) { |
136 |
this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
137 |
var _found = 0, |
|
| 925 | 138 |
_re = IriSP.Model.regexpFromTextOrArray(searchString, true); |
| 876 | 139 |
if (this.searchString) { |
140 |
this.$segments.each(function() { |
|
141 |
var _el = IriSP.jQuery(this); |
|
142 |
if (_re.test(_el.attr("segment-text"))) { |
|
| 982 | 143 |
_el.css("background", _el.attr("data-base-color")); |
| 876 | 144 |
_found++; |
145 |
} else { |
|
| 982 | 146 |
_el.css("background", _el.attr("data-low-color")); |
| 876 | 147 |
} |
148 |
}); |
|
149 |
if (_found) { |
|
| 957 | 150 |
this.player.trigger("search.matchFound"); |
| 876 | 151 |
} else { |
| 957 | 152 |
this.player.trigger("search.noMatchFound"); |
| 876 | 153 |
} |
154 |
} else { |
|
| 982 | 155 |
_this.$segments.each(function() { |
156 |
var _segment = IriSP.jQuery(this); |
|
157 |
_segment.css("background", _segment.attr("data-medium-color")); |
|
158 |
}); |
|
| 876 | 159 |
} |
160 |
} |
|
161 |
||
| 957 | 162 |
IriSP.Widgets.Segments.prototype.onTimeupdate = function(_time) { |
163 |
var _x = Math.floor( this.width * _time / this.media.duration); |
|
| 876 | 164 |
this.$.find('.Ldt-Segments-Position').css({ |
165 |
left: _x + "px" |
|
166 |
}) |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
167 |
} |