diff -r c472984db275 -r 1615c7e4ef9d src/widgets/Renkan.js --- a/src/widgets/Renkan.js Wed Apr 03 15:44:17 2013 +0200 +++ b/src/widgets/Renkan.js Tue Apr 23 15:23:20 2013 +0200 @@ -18,87 +18,100 @@ } IriSP.Widgets.Renkan.prototype.template = - '
'; + '
'; IriSP.Widgets.Renkan.prototype.draw = function() { this.renderTemplate(); var _id = IriSP.Model.getUID(); this.$.find(".Ldt-Renkan").attr("id", _id); this.renkan = new Rkns.Renkan({ - container: _id + container: _id, + editor_mode: false, + show_bins: false, + show_top_bar: false, + force_resize: true, + language: IriSP.language }); - if (typeof this.data === "string") { - this.data = [ this.data ]; - } + this.node_times = []; var _this = this, _list = this.getWidgetAnnotations(); - this.node_times = []; - Rkns._(this.data).each(function(_url, _key) { - var _opts = { - url: _url - } - if (!_key) { - _opts.callback = function(_p) { - _this.renkan.renderProject(_p); - } - } - var _proj = _this.renkan.addProject(_opts); - _proj.on("add:nodes", function(_node) { - var _uri = _node.get("uri"), - _annmatch = _uri.match(_this.annotation_regexp); - if (_annmatch) { - var _annotations = _list.filter(function(_ann) { - return _ann.getMedia().id == _annmatch[1] && _ann.id == _annmatch[2]; + this.renkan.project.on("add:nodes", function(_node) { + var _uri = _node.get("uri"), + _annmatch = _uri.match(_this.annotation_regexp); + if (_annmatch) { + var _annotations = _list.filter(function(_ann) { + return _ann.getMedia().id == _annmatch[1] && _ann.id == _annmatch[2]; + }); + _annotations.forEach(function(_ann) { + var _duration = _ann.getDuration(), + _preroll = + ( _duration < _this.min_duration ) * ( _this.min_duration / 2); + var _nt = { + uri: _uri, + selected: false, + node: _node, + begin: _ann.begin - _preroll, + end: _ann.end + _preroll + } + _this.node_times.push(_nt); + var _annselected = false, + _nodeselected = false; + _ann.on("select", function() { + _annselected = true; + if (!_nodeselected) { + _node.trigger("select",true); + } }); - _annotations.forEach(function(_ann) { - var _duration = _ann.getDuration(), - _preroll = + ( _duration < _this.min_duration ) * ( _this.min_duration / 2); - var _nt = { - selected: false, - node: _node, - begin: _ann.begin - _preroll, - end: _ann.end + _preroll + _node.on("selected", function() { + _nodeselected = true; + if (!_annselected) { + _ann.trigger("select",true); + } + }); + _ann.on("unselect", function() { + _annselected = false; + if (_nodeselected) { + _node.trigger("unselect",true); } - _this.node_times.push(_nt); - _ann.on("select", function(_stop) { - if (!_stop) { - _node.trigger("select",true); - } - }); - _node.on("select", function(_stop) { - if (!_stop) { - _ann.trigger("select",true); - } - }); - _ann.on("unselect", function(_stop) { - if (!_stop) { - _node.trigger("unselect",true); - } - }); - _node.on("unselect", function(_stop) { - _nt.selected = false; - if (!_stop) { - _ann.trigger("unselect",true); - } - }); - _node.on("click", function() { - _this.media.setCurrentTime(_ann.begin); - _this.player.trigger("Mediafragment.setHashToAnnotation", _ann.id); - }); + }); + _node.on("unselected", function() { + _nodeselected = false; + _nt.selected = false; + if (_annselected) { + _ann.trigger("unselect",true); + } + }); + _node.on("clicked", function() { + _this.media.setCurrentTime(_ann.begin); + _this.player.trigger("Mediafragment.setHashToAnnotation", _ann.id); }); - } - var _tagmatch = _uri.match(_this.tag_regexp); - if (_tagmatch) { - _node.on("select", function() { - _this.source.getAnnotations().search(_tagmatch[1]); - }) - _node.on("unselect", function() { - _this.source.getAnnotations().search(""); - }) - } - }); - }) + }); + } + var _tagmatch = _uri.match(_this.tag_regexp); + if (_tagmatch) { + _node.on("select", function() { + _this.source.getAnnotations().search(_tagmatch[1]); + }) + _node.on("unselect", function() { + _this.source.getAnnotations().search(""); + }) + } + }); + Rkns.jsonIO(this.renkan, { + url: this.data + }); + this.onMediaEvent("timeupdate","onTimeupdate"); + + this.$.find(".Rk-Editor").on("click", "a", function() { + var href = this.href, + times = _this.node_times.filter(function(t) { + return t.uri == href; + }); + if (times.length) { + _this.media.setCurrentTime(times[0].begin); + return false; + } + }); } IriSP.Widgets.Renkan.prototype.onTimeupdate = function(_time) { @@ -106,11 +119,11 @@ if (_nt.begin <= _time && _nt.end >= _time) { if (!_nt.selected) { _nt.selected = true; - _nt.node.trigger("select", true); + _nt.node.trigger("select"); } } else { if (_nt.selected) { - _nt.node.trigger("unselect", true); + _nt.node.trigger("unselect"); } } });