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