| author | cavaliet |
| Thu, 02 Jan 2014 16:49:20 +0100 | |
| branch | new-model |
| changeset 1020 | 198c2b79f5e1 |
| parent 1019 | 3ab36f402b0c |
| 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"], |
| 1020 | 12 |
height: 10 |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
13 |
}; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
14 |
|
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
15 |
IriSP.Widgets.Segments.prototype.template = |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
16 |
'<div class="Ldt-Segments-List"></div>' |
| 924 | 17 |
+ '<div class="Ldt-Segments-Position"></div>' |
18 |
+ '<div class="Ldt-Segments-Tooltip"></div>'; |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
19 |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
20 |
IriSP.Widgets.Segments.prototype.annotationTemplate = |
| 1020 | 21 |
'<div class="Ldt-Segments-Segment Ldt-TraceMe" trace-info="segment-id:{{id}}, media-id:{{media_id}}" segment-text="{{text}}"' |
22 |
+ 'style="left:{{left}}px; width:{{width}}px; background:{{color}}"></div>' |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
23 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
24 |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
25 |
IriSP.Widgets.Segments.prototype.draw = function() { |
| 1020 | 26 |
this.bindPopcorn("IriSP.search", "onSearch"); |
27 |
this.bindPopcorn("IriSP.search.closed", "onSearch"); |
|
28 |
this.bindPopcorn("IriSP.search.cleared", "onSearch"); |
|
29 |
this.bindPopcorn("timeupdate", "onTimeupdate"); |
|
30 |
|
|
|
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 |
|
| 1020 | 33 |
var _list = this.getWidgetAnnotations(), |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
34 |
_this = this, |
| 1020 | 35 |
_scale = this.width / this.source.getDuration(); |
36 |
this.$.css({ |
|
37 |
width : this.width + "px", |
|
38 |
height : (this.height - 2) + "px", |
|
39 |
margin : "1px 0" |
|
40 |
}); |
|
41 |
this.list_$ = this.$.find('.Ldt-Segments-List'); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
42 |
|
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
43 |
_list.forEach(function(_annotation, _k) { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
44 |
var _left = _annotation.begin * _scale, |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
45 |
_width = ( _annotation.getDuration() ) * _scale, |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
46 |
_center = Math.floor( _left + _width / 2 ), |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
47 |
_fulltext = _annotation.title + ( _annotation.description ? ( '<br/>' + _annotation.description ) : '' ), |
| 1020 | 48 |
_beginseconds = _annotation.begin.getSeconds(); |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
49 |
var _data = { |
| 1020 | 50 |
color : ( typeof _annotation.color !== "undefined" && _annotation.color ? _annotation.color : _this.colors[_k % _this.colors.length] ), |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
51 |
text: _fulltext.replace(/(\n|\r|\r\n)/mg,' ').replace(/(^.{120,140})[\s].+$/m,'$1…'), |
| 1020 | 52 |
left : Math.floor( _left ), |
53 |
width : Math.floor( _width ), |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
54 |
id : _annotation.id, |
| 1020 | 55 |
media_id : _annotation.getMedia().id |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
56 |
}; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
57 |
var _html = Mustache.to_html(_this.annotationTemplate, _data), |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
58 |
_el = IriSP.jQuery(_html); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
59 |
_el.mouseover(function() { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
60 |
_annotation.trigger("select"); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
61 |
}) |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
62 |
.mouseout(function() { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
63 |
_annotation.trigger("unselect"); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
64 |
}) |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
65 |
.click(function() { |
| 1020 | 66 |
_this.player.popcorn.currentTime(_beginseconds); |
67 |
_this.player.popcorn.trigger("IriSP.Mediafragment.setHashToAnnotation", _data.id); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
68 |
}) |
| 1020 | 69 |
.appendTo(_this.list_$) |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
70 |
_annotation.on("select", function() { |
| 1020 | 71 |
_this.$segments.removeClass("active").addClass("inactive"); |
72 |
_this.tooltip.show( _center, 0, _data.text, _data.color ); |
|
73 |
_el.removeClass("inactive").addClass("active"); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
74 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
75 |
_annotation.on("unselect", function() { |
| 1020 | 76 |
_this.tooltip.hide(); |
77 |
_this.$segments.removeClass("inactive active"); |
|
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
78 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
79 |
}); |
| 1020 | 80 |
this.insertSubwidget(this.$.find(".Ldt-Segments-Tooltip"), "tooltip", { type: "Tooltip" }); |
| 876 | 81 |
this.$segments = this.$.find('.Ldt-Segments-Segment'); |
| 1020 | 82 |
} |
83 |
||
84 |
IriSP.Widgets.Segments.prototype.onSearch = function(searchString) { |
|
85 |
this.searchString = typeof searchString !== "undefined" ? searchString : ''; |
|
86 |
var _found = 0, |
|
87 |
_re = IriSP.Model.regexpFromTextOrArray(searchString, true); |
|
88 |
if (this.searchString) { |
|
89 |
this.$segments.each(function() { |
|
90 |
var _el = IriSP.jQuery(this); |
|
91 |
if (_re.test(_el.attr("segment-text"))) { |
|
92 |
_el.removeClass("unfound").addClass("found"); |
|
93 |
_found++; |
|
94 |
} else { |
|
95 |
_el.removeClass("found").addClass("unfound"); |
|
96 |
} |
|
|
1019
3ab36f402b0c
update widgets after enhance in annotation platform.
cavaliet
parents:
937
diff
changeset
|
97 |
}); |
| 1020 | 98 |
if (_found) { |
99 |
this.player.popcorn.trigger("IriSP.search.matchFound"); |
|
100 |
} else { |
|
101 |
this.player.popcorn.trigger("IriSP.search.noMatchFound"); |
|
102 |
} |
|
103 |
} else { |
|
104 |
this.$segments.removeClass("found unfound"); |
|
105 |
} |
|
106 |
} |
|
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
diff
changeset
|
107 |
|
| 1020 | 108 |
IriSP.Widgets.Segments.prototype.onTimeupdate = function() { |
109 |
var _x = Math.floor( this.width * this.player.popcorn.currentTime() / this.source.getDuration().getSeconds()); |
|
| 876 | 110 |
this.$.find('.Ldt-Segments-Position').css({ |
111 |
left: _x + "px" |
|
| 1020 | 112 |
}) |
113 |
} |