|
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 |
|
1013
|
11 |
}; |
|
938
|
12 |
|
|
|
13 |
IriSP.Widgets.Renkan.prototype.messages = { |
|
|
14 |
"fr": { |
|
|
15 |
}, |
|
|
16 |
"en": { |
|
|
17 |
} |
|
1013
|
18 |
}; |
|
938
|
19 |
|
|
|
20 |
IriSP.Widgets.Renkan.prototype.template = |
|
997
|
21 |
'<div class="Ldt-Renkan-Container"><div class="Ldt-Renkan"></div></div>'; |
|
938
|
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({ |
|
997
|
28 |
container: _id, |
|
|
29 |
editor_mode: false, |
|
|
30 |
show_bins: false, |
|
|
31 |
show_top_bar: false, |
|
|
32 |
force_resize: true, |
|
|
33 |
language: IriSP.language |
|
938
|
34 |
}); |
|
997
|
35 |
this.node_times = []; |
|
938
|
36 |
var _this = this, |
|
|
37 |
_list = this.getWidgetAnnotations(); |
|
997
|
38 |
this.renkan.project.on("add:nodes", function(_node) { |
|
|
39 |
var _uri = _node.get("uri"), |
|
|
40 |
_annmatch = _uri.match(_this.annotation_regexp); |
|
|
41 |
if (_annmatch) { |
|
|
42 |
var _annotations = _list.filter(function(_ann) { |
|
|
43 |
return _ann.getMedia().id == _annmatch[1] && _ann.id == _annmatch[2]; |
|
|
44 |
}); |
|
|
45 |
_annotations.forEach(function(_ann) { |
|
|
46 |
var _duration = _ann.getDuration(), |
|
|
47 |
_preroll = + ( _duration < _this.min_duration ) * ( _this.min_duration / 2); |
|
|
48 |
var _nt = { |
|
|
49 |
uri: _uri, |
|
|
50 |
selected: false, |
|
|
51 |
node: _node, |
|
998
|
52 |
annotation: _ann, |
|
997
|
53 |
begin: _ann.begin - _preroll, |
|
|
54 |
end: _ann.end + _preroll |
|
1013
|
55 |
}; |
|
997
|
56 |
_this.node_times.push(_nt); |
|
|
57 |
var _annselected = false, |
|
|
58 |
_nodeselected = false; |
|
|
59 |
_ann.on("select", function() { |
|
|
60 |
_annselected = true; |
|
|
61 |
if (!_nodeselected) { |
|
|
62 |
_node.trigger("select",true); |
|
|
63 |
} |
|
938
|
64 |
}); |
|
997
|
65 |
_node.on("selected", function() { |
|
|
66 |
_nodeselected = true; |
|
|
67 |
if (!_annselected) { |
|
|
68 |
_ann.trigger("select",true); |
|
|
69 |
} |
|
|
70 |
}); |
|
|
71 |
_ann.on("unselect", function() { |
|
|
72 |
_annselected = false; |
|
|
73 |
if (_nodeselected) { |
|
|
74 |
_node.trigger("unselect",true); |
|
938
|
75 |
} |
|
997
|
76 |
}); |
|
|
77 |
_node.on("unselected", function() { |
|
|
78 |
_nodeselected = false; |
|
|
79 |
_nt.selected = false; |
|
|
80 |
if (_annselected) { |
|
|
81 |
_ann.trigger("unselect",true); |
|
|
82 |
} |
|
|
83 |
}); |
|
|
84 |
_node.on("clicked", function() { |
|
998
|
85 |
_ann.trigger("click"); |
|
938
|
86 |
}); |
|
997
|
87 |
}); |
|
|
88 |
} |
|
|
89 |
var _tagmatch = _uri.match(_this.tag_regexp); |
|
|
90 |
if (_tagmatch) { |
|
|
91 |
_node.on("select", function() { |
|
|
92 |
_this.source.getAnnotations().search(_tagmatch[1]); |
|
1013
|
93 |
}); |
|
997
|
94 |
_node.on("unselect", function() { |
|
|
95 |
_this.source.getAnnotations().search(""); |
|
1013
|
96 |
}); |
|
997
|
97 |
} |
|
|
98 |
}); |
|
|
99 |
Rkns.jsonIO(this.renkan, { |
|
|
100 |
url: this.data |
|
|
101 |
}); |
|
|
102 |
|
|
957
|
103 |
this.onMediaEvent("timeupdate","onTimeupdate"); |
|
997
|
104 |
|
|
|
105 |
this.$.find(".Rk-Editor").on("click", "a", function() { |
|
|
106 |
var href = this.href, |
|
|
107 |
times = _this.node_times.filter(function(t) { |
|
|
108 |
return t.uri == href; |
|
|
109 |
}); |
|
|
110 |
if (times.length) { |
|
998
|
111 |
IriSP._(times).each(function(t) { |
|
|
112 |
t.annotation.trigger("click"); |
|
|
113 |
}); |
|
997
|
114 |
return false; |
|
|
115 |
} |
|
|
116 |
}); |
|
1013
|
117 |
}; |
|
938
|
118 |
|
|
957
|
119 |
IriSP.Widgets.Renkan.prototype.onTimeupdate = function(_time) { |
|
938
|
120 |
IriSP._(this.node_times).each(function(_nt) { |
|
|
121 |
if (_nt.begin <= _time && _nt.end >= _time) { |
|
|
122 |
if (!_nt.selected) { |
|
|
123 |
_nt.selected = true; |
|
997
|
124 |
_nt.node.trigger("select"); |
|
938
|
125 |
} |
|
|
126 |
} else { |
|
|
127 |
if (_nt.selected) { |
|
997
|
128 |
_nt.node.trigger("unselect"); |
|
938
|
129 |
} |
|
|
130 |
} |
|
|
131 |
}); |
|
1013
|
132 |
}; |