|
938
|
1 |
IriSP.Widgets.Renkan = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
}; |
|
|
4 |
|
|
|
5 |
IriSP.Widgets.Renkan.prototype = new IriSP.Widgets.Widget(); |
|
|
6 |
|
|
|
7 |
IriSP.Widgets.Renkan.prototype.defaults = { |
|
|
8 |
annotation_regexp: /player\/([a-zA-Z0-9_-]+)\/.*id=([a-zA-Z0-9_-]+)/, |
|
|
9 |
tag_regexp: /search=([^&=]+)/, |
|
|
10 |
min_duration: 5000 |
|
|
11 |
} |
|
|
12 |
|
|
|
13 |
IriSP.Widgets.Renkan.prototype.messages = { |
|
|
14 |
"fr": { |
|
|
15 |
}, |
|
|
16 |
"en": { |
|
|
17 |
} |
|
|
18 |
} |
|
|
19 |
|
|
|
20 |
IriSP.Widgets.Renkan.prototype.template = |
|
|
21 |
'<div class="Ldt-Renkan"></div>'; |
|
|
22 |
|
|
|
23 |
IriSP.Widgets.Renkan.prototype.draw = function() { |
|
|
24 |
this.renderTemplate(); |
|
|
25 |
var _id = IriSP.Model.getUID(); |
|
|
26 |
this.$.find(".Ldt-Renkan").attr("id", _id); |
|
|
27 |
this.renkan = new Rkns.Renkan({ |
|
|
28 |
container: _id |
|
|
29 |
}); |
|
955
|
30 |
if (typeof this.data === "string") { |
|
|
31 |
this.data = [ this.data ]; |
|
|
32 |
} |
|
938
|
33 |
var _this = this, |
|
|
34 |
_list = this.getWidgetAnnotations(); |
|
|
35 |
this.node_times = []; |
|
955
|
36 |
Rkns._(this.data).each(function(_url, _key) { |
|
|
37 |
var _opts = { |
|
|
38 |
url: _url |
|
|
39 |
} |
|
|
40 |
if (!_key) { |
|
|
41 |
_opts.callback = function(_p) { |
|
|
42 |
_this.renkan.renderProject(_p); |
|
|
43 |
} |
|
|
44 |
} |
|
|
45 |
var _proj = _this.renkan.addProject(_opts); |
|
|
46 |
_proj.on("add:nodes", function(_node) { |
|
|
47 |
var _uri = _node.get("uri"), |
|
|
48 |
_annmatch = _uri.match(_this.annotation_regexp); |
|
|
49 |
if (_annmatch) { |
|
|
50 |
var _annotations = _list.filter(function(_ann) { |
|
|
51 |
return _ann.getMedia().id == _annmatch[1] && _ann.id == _annmatch[2]; |
|
938
|
52 |
}); |
|
955
|
53 |
_annotations.forEach(function(_ann) { |
|
|
54 |
var _duration = _ann.getDuration(), |
|
|
55 |
_preroll = + ( _duration < _this.min_duration ) * ( _this.min_duration / 2); |
|
|
56 |
var _nt = { |
|
|
57 |
selected: false, |
|
|
58 |
node: _node, |
|
|
59 |
begin: _ann.begin - _preroll, |
|
|
60 |
end: _ann.end + _preroll |
|
938
|
61 |
} |
|
955
|
62 |
_this.node_times.push(_nt); |
|
|
63 |
_ann.on("select", function(_stop) { |
|
|
64 |
if (!_stop) { |
|
|
65 |
_node.trigger("select",true); |
|
|
66 |
} |
|
|
67 |
}); |
|
|
68 |
_node.on("select", function(_stop) { |
|
|
69 |
if (!_stop) { |
|
|
70 |
_ann.trigger("select",true); |
|
|
71 |
} |
|
|
72 |
}); |
|
|
73 |
_ann.on("unselect", function(_stop) { |
|
|
74 |
if (!_stop) { |
|
|
75 |
_node.trigger("unselect",true); |
|
|
76 |
} |
|
|
77 |
}); |
|
|
78 |
_node.on("unselect", function(_stop) { |
|
|
79 |
_nt.selected = false; |
|
|
80 |
if (!_stop) { |
|
|
81 |
_ann.trigger("unselect",true); |
|
|
82 |
} |
|
|
83 |
}); |
|
|
84 |
_node.on("click", function() { |
|
957
|
85 |
_this.media.setCurrentTime(_ann.begin); |
|
|
86 |
_this.player.trigger("Mediafragment.setHashToAnnotation", _ann.id); |
|
955
|
87 |
}); |
|
938
|
88 |
}); |
|
955
|
89 |
} |
|
|
90 |
var _tagmatch = _uri.match(_this.tag_regexp); |
|
|
91 |
if (_tagmatch) { |
|
|
92 |
_node.on("select", function() { |
|
983
|
93 |
_this.source.getAnnotations().search(_tagmatch[1]); |
|
955
|
94 |
}) |
|
|
95 |
_node.on("unselect", function() { |
|
983
|
96 |
_this.source.getAnnotations().search(""); |
|
955
|
97 |
}) |
|
|
98 |
} |
|
|
99 |
}); |
|
|
100 |
}) |
|
957
|
101 |
this.onMediaEvent("timeupdate","onTimeupdate"); |
|
938
|
102 |
} |
|
|
103 |
|
|
957
|
104 |
IriSP.Widgets.Renkan.prototype.onTimeupdate = function(_time) { |
|
938
|
105 |
IriSP._(this.node_times).each(function(_nt) { |
|
|
106 |
if (_nt.begin <= _time && _nt.end >= _time) { |
|
|
107 |
if (!_nt.selected) { |
|
|
108 |
_nt.selected = true; |
|
|
109 |
_nt.node.trigger("select", true); |
|
|
110 |
} |
|
|
111 |
} else { |
|
|
112 |
if (_nt.selected) { |
|
|
113 |
_nt.node.trigger("unselect", true); |
|
|
114 |
} |
|
|
115 |
} |
|
|
116 |
}); |
|
|
117 |
} |