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