src/widgets/Renkan.js
changeset 955 5055aa35340f
parent 950 b7e236e4ec1c
child 957 4da0a5740b6c
--- a/src/widgets/Renkan.js	Wed Sep 05 11:30:01 2012 +0200
+++ b/src/widgets/Renkan.js	Fri Sep 07 18:18:47 2012 +0200
@@ -27,67 +27,78 @@
     this.renkan = new Rkns.Renkan({
         container: _id
     });
+    if (typeof this.data === "string") {
+        this.data = [ this.data ];
+    }
     var _this = this,
         _list = this.getWidgetAnnotations();
     this.node_times = [];
-    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 = {
-                    selected: false,
-                    node: _node,
-                    begin: _ann.begin - _preroll,
-                    end: _ann.end + _preroll
-                }
-                _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);
-                    }
+    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];
                 });
-                _ann.on("unselect", function(_stop) {
-                    if (!_stop) {
-                        _node.trigger("unselect",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("unselect", function(_stop) {
-                    _nt.selected = false;
-                    if (!_stop) {
-                        _ann.trigger("unselect",true);
-                    }
-                });
-                _node.on("click", function() {
-                    _this.player.popcorn.currentTime(_ann.begin.getSeconds());
-                    _this.player.popcorn.trigger("IriSP.Mediafragment.setHashToAnnotation", _ann.id);
+                    _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.player.popcorn.currentTime(_ann.begin.getSeconds());
+                        _this.player.popcorn.trigger("IriSP.Mediafragment.setHashToAnnotation", _ann.id);
+                    });
                 });
-            });
-        }
-        var _tagmatch = _uri.match(_this.tag_regexp);
-        if (_tagmatch) {
-            _node.on("select", function() {
-                _this.player.popcorn.trigger("IriSP.search.triggeredSearch",_tagmatch[1]);
-            })
-            _node.on("unselect", function() {
-                _this.player.popcorn.trigger("IriSP.search.cleared");
-            })
-        }
-    });
-    Rkns.jsonImport(this.renkan, {
-        url: this.data
-    });
-    this.bindPopcorn("timeupdate","onTimeupdate")
+            }
+            var _tagmatch = _uri.match(_this.tag_regexp);
+            if (_tagmatch) {
+                _node.on("select", function() {
+                    _this.player.popcorn.trigger("IriSP.search.triggeredSearch",_tagmatch[1]);
+                })
+                _node.on("unselect", function() {
+                    _this.player.popcorn.trigger("IriSP.search.cleared");
+                })
+            }
+        });
+    })
+    this.bindPopcorn("timeupdate","onTimeupdate");
 }
 
 IriSP.Widgets.Renkan.prototype.onTimeupdate = function() {