|
1 IriSP.Widgets.Segments = function(player, config) { |
|
2 IriSP.Widgets.Widget.call(this, player, config); |
|
3 }; |
|
4 |
|
5 IriSP.Widgets.Segments.prototype = new IriSP.Widgets.Widget(); |
|
6 |
|
7 IriSP.Widgets.Segments.prototype.defaults = { |
|
8 annotation_type : "chap", |
|
9 colors: ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"], |
|
10 requires : [ |
|
11 { |
|
12 type: "Tooltip" |
|
13 } |
|
14 ], |
|
15 height: 10 |
|
16 }; |
|
17 |
|
18 IriSP.Widgets.Segments.prototype.template = |
|
19 '<div class="Ldt-Segments-List">{{#segments}}' |
|
20 + '<div class="Ldt-Segments-Segment" segment-id="{{id}}" segment-text="{{text}}" segment-color="{{color}}" center-pos="{{center}}" style="left:{{left}}px; width:{{width}}px; background:{{color}}"></div>' |
|
21 + '{{/segments}}</div>' |
|
22 + '<div class="Ldt-Segments-Position"></div>'; |
|
23 |
|
24 IriSP.Widgets.Segments.prototype.draw = function() { |
|
25 var _list = this.annotation_type ? this.source.getAnnotationsByTypeTitle(this.annotation_type) : this.source.getAnnotations(), |
|
26 _this = this, |
|
27 _scale = this.width / this.source.getDuration(); |
|
28 this.$.css({ |
|
29 width : this.width + "px", |
|
30 height : this.height + "px" |
|
31 }); |
|
32 this.$.append(Mustache.to_html(this.template, { |
|
33 segments : _list.map(function(_annotation, _k) { |
|
34 var _left = _annotation.begin * _scale, |
|
35 _width = ( _annotation.end - _annotation.begin ) * _scale, |
|
36 _center = _left + _width / 2; |
|
37 return { |
|
38 text : _annotation.title + ( _annotation.description ? '<br />' + _annotation.description.replace(/(^.{120,140})[\s].+$/,'$1…') : ''), |
|
39 color : ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.colors[_k % _this.colors.length] ), |
|
40 left : Math.floor( _left ), |
|
41 width : Math.floor( _width ), |
|
42 center : Math.floor( _center ), |
|
43 id : _annotation.namespacedId.name |
|
44 } |
|
45 }) |
|
46 })); |
|
47 var _seglist = this.$.find('.Ldt-Segments-Segment'); |
|
48 |
|
49 _seglist.mouseover(function() { |
|
50 var _el = IriSP.jQuery(this); |
|
51 _seglist.removeClass("active").addClass("inactive"); |
|
52 _this.tooltip.show( _el.attr("center-pos"), 0, _el.attr("segment-text"), _el.attr("segment-color")); |
|
53 _el.removeClass("inactive").addClass("active"); |
|
54 }).mouseout(function() { |
|
55 _seglist.removeClass("inactive active"); |
|
56 }); |
|
57 } |
|
58 |
|
59 IriSP.Widgets.Segments.prototype.searchHandler = function(searchString) { |
|
60 |
|
61 } |