client/js/paper-renderer.js
changeset 110 55454c900296
parent 105 810a1c1015df
child 111 fbe12f54453a
equal deleted inserted replaced
109:b6b20e8c4a1a 110:55454c900296
     9     _NODE_FONT_SIZE: 10,
     9     _NODE_FONT_SIZE: 10,
    10     _EDGE_FONT_SIZE: 9,
    10     _EDGE_FONT_SIZE: 9,
    11     _EDGE_DISTANCE: 3,
    11     _EDGE_DISTANCE: 3,
    12     _NODE_MAX_CHAR: 50,
    12     _NODE_MAX_CHAR: 50,
    13     _EDGE_MAX_CHAR: 40,
    13     _EDGE_MAX_CHAR: 40,
    14     _ARROW_LENGTH: 16,
    14     _ARROW_LENGTH: 18,
    15     _ARROW_WIDTH: 8,
    15     _ARROW_WIDTH: 12,
    16     _EDITOR_ARROW_LENGTH : 20,
    16     _EDITOR_ARROW_LENGTH : 20,
    17     _EDITOR_ARROW_WIDTH : 40,
    17     _EDITOR_ARROW_WIDTH : 40,
       
    18     _EDITOR_WIDTH : 275,
    18     _EDITOR_MARGIN : 15,
    19     _EDITOR_MARGIN : 15,
    19     _EDITOR_PADDING : 10,
    20     _EDITOR_PADDING : 10,
    20     _EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']),
    21     _EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']),
    21     _CLICKMODE_ADDNODE : 1,
    22     _CLICKMODE_ADDNODE : 1,
    22     _CLICKMODE_STARTEDGE : 2,
    23     _CLICKMODE_STARTEDGE : 2,
    38 	    + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();"
    39 	    + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();"
    39     }
    40     }
    40 }
    41 }
    41 
    42 
    42 Rkns.Renderer.Utils = {
    43 Rkns.Renderer.Utils = {
       
    44 	shortenText : function(_text, _maxlength) {
       
    45 		return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
       
    46 	},
    43     drawEditBox : function(_coords, _path, _width, _xmargin, _selector) {
    47     drawEditBox : function(_coords, _path, _width, _xmargin, _selector) {
    44         _selector.css({
    48         _selector.css({
    45             width: (_width - 2* Rkns.Renderer._EDITOR_PADDING),
    49             width: (_width - 2* Rkns.Renderer._EDITOR_PADDING),
    46         })
    50         })
    47         var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING,
    51         var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING,
   299         }
   303         }
   300     }
   304     }
   301     this.last_circle_radius = this.circle_radius;
   305     this.last_circle_radius = this.circle_radius;
   302     
   306     
   303     var _text = this.model.get("title") || this.renderer.renkan.translate("(untitled)");
   307     var _text = this.model.get("title") || this.renderer.renkan.translate("(untitled)");
   304     this.title.content = _text.length > Rkns.Renderer._NODE_MAX_CHAR ? (_text.substr(0,Rkns.Renderer._NODE_MAX_CHAR) + '…') : _text;
   308     this.title.content = Rkns.Renderer.Utils.shortenText(_text, Rkns.Renderer._NODE_MAX_CHAR);
   305 
   309 
   306     this.title.position = this.paper_coords.add([0, this.circle_radius + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]);
   310     this.title.position = this.paper_coords.add([0, this.circle_radius + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]);
   307     var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color");
   311     var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color");
   308     this.circle.strokeColor = _color;
   312     this.circle.strokeColor = _color;
   309     this.edit_button.moveTo(this.paper_coords);
   313     this.edit_button.moveTo(this.paper_coords);
   497         this.remove_button.edge_representation = this;
   501         this.remove_button.edge_representation = this;
   498     }
   502     }
   499 }
   503 }
   500 
   504 
   501 Rkns.Renderer.Edge.prototype.redraw = function() {
   505 Rkns.Renderer.Edge.prototype.redraw = function() {
       
   506     this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from"));
       
   507     this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to"));
   502     var _p0a = this.from_representation.paper_coords,
   508     var _p0a = this.from_representation.paper_coords,
   503         _p1a = this.to_representation.paper_coords,
   509         _p1a = this.to_representation.paper_coords,
   504         _v = _p1a.subtract(_p0a),
   510         _v = _p1a.subtract(_p0a),
   505         _r = _v.length,
   511         _r = _v.length,
   506         _u = _v.divide(_r),
   512         _u = _v.divide(_r),
   532         _a += 180;
   538         _a += 180;
   533         _textdelta = _textdelta.multiply(-1);
   539         _textdelta = _textdelta.multiply(-1);
   534     }
   540     }
   535     this.text.rotate(_a - this.text_angle);
   541     this.text.rotate(_a - this.text_angle);
   536     var _text = this.model.get("title");
   542     var _text = this.model.get("title");
   537     this.text.content = _text.length > Rkns.Renderer._EDGE_MAX_CHAR ? (_text.substr(0,Rkns.Renderer._EDGE_MAX_CHAR) + '…') : _text;
   543     this.text.content = Rkns.Renderer.Utils.shortenText(_text, Rkns.Renderer._EDGE_MAX_CHAR);
   538     this.text.position = this.paper_coords.add(_textdelta);
   544     this.text.position = this.paper_coords.add(_textdelta);
   539     this.text_angle = _a;
   545     this.text_angle = _a;
   540     this.edit_button.moveTo(this.paper_coords);
   546     this.edit_button.moveTo(this.paper_coords);
   541     this.remove_button.moveTo(this.paper_coords);
   547     this.remove_button.moveTo(this.paper_coords);
   542 }
   548 }
   700     + '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>'
   706     + '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>'
   701     + '<p><label><%-translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p>'
   707     + '<p><label><%-translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p>'
   702     + '<p><label><%-translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p>'
   708     + '<p><label><%-translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p>'
   703     + '<p><span class="Rk-Editor-Label"><%-translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p>'
   709     + '<p><span class="Rk-Editor-Label"><%-translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p>'
   704     + '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
   710     + '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
   705     + '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>'
   711     + '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text"><%- translate("Choose color") %></span></div></div>'
   706     + '<img class="Rk-Edit-ImgPreview" src="<%-node.image || node.image_placeholder%>" />'
   712     + '<img class="Rk-Edit-ImgPreview" src="<%-node.image || node.image_placeholder%>" />'
   707     + '<p><label><%-translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>'
   713     + '<p><label><%-translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>'
   708     + '<p><label><%-translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p>'    
   714     + '<p><label><%-translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p>'    
   709     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%-node.created_by_title%></p>'
   715     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %></p>'
   710 );
   716 );
   711 
   717 
   712 Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
   718 Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
   713     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><%-node.title%></span></h2>'
   719     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-node.color%>;"></span>'
   714     + '<p><a href="<%-node.uri%>" target="_blank"><%-node.uri%></a></p>'
   720     + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
       
   721     + '<% if (node.uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
   715     + '<p><%-node.description%></p>'
   722     + '<p><%-node.description%></p>'
   716     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%-node.created_by_title%></p>'
   723     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %></p>'
   717 );
   724 );
   718 
   725 
   719 Rkns.Renderer.NodeEditor.prototype.draw = function() {
   726 Rkns.Renderer.NodeEditor.prototype.draw = function() {
   720     var _model = this.node_representation.model,
   727     var _model = this.node_representation.model,
   721         _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER,
   728         _created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER,
   725     this.editor_$
   732     this.editor_$
   726         .html(_template({
   733         .html(_template({
   727             node: {
   734             node: {
   728                 title: _model.get("title"),
   735                 title: _model.get("title"),
   729                 uri: _model.get("uri"),
   736                 uri: _model.get("uri"),
       
   737                 short_uri:  Rkns.Renderer.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
   730                 description: _model.get("description"),
   738                 description: _model.get("description"),
   731                 image: _model.get("image") || "",
   739                 image: _model.get("image") || "",
   732                 image_placeholder: _image_placeholder,
   740                 image_placeholder: _image_placeholder,
   733                 color: _model.get("color") || _created_by.get("color"),
   741                 color: _model.get("color") || _created_by.get("color"),
   734                 created_by_color: _created_by.get("color"),
   742                 created_by_color: _created_by.get("color"),
   791         this.editor_$.find(".Rk-Edit-ColorPicker li").hover(
   799         this.editor_$.find(".Rk-Edit-ColorPicker li").hover(
   792             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); },
   800             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); },
   793             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) }
   801             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) }
   794         ).click(function() {
   802         ).click(function() {
   795             _model.set("color", $(this).attr("data-color"));
   803             _model.set("color", $(this).attr("data-color"));
       
   804             paper.view.draw();
   796         });
   805         });
   797         
   806         
   798         function shiftSize(n) {
   807         function shiftSize(n) {
   799         	var _newsize = n+(_model.get("size") || 0);
   808         	var _newsize = n+(_model.get("size") || 0);
   800         	_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
   809         	_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
   816     });
   825     });
   817 }
   826 }
   818 
   827 
   819 Rkns.Renderer.NodeEditor.prototype.redraw = function() {
   828 Rkns.Renderer.NodeEditor.prototype.redraw = function() {
   820     var _coords = this.node_representation.paper_coords;
   829     var _coords = this.node_representation.paper_coords;
   821     Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$);
   830     Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, Rkns.Renderer._EDITOR_WIDTH, 20, this.editor_$);
   822     this.editor_$.show();
   831     this.editor_$.show();
   823     paper.view.draw();
   832     paper.view.draw();
   824 }
   833 }
   825 
   834 
   826 Rkns.Renderer.NodeEditor.prototype.destroy = function() {
   835 Rkns.Renderer.NodeEditor.prototype.destroy = function() {
   859     + '<% _(properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- translate(ontology.label) %></option>'
   868     + '<% _(properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- translate(ontology.label) %></option>'
   860     + '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>'
   869     + '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>'
   861     + '"<% if (uri === edge.uri) { %> selected<% } %>><%- translate(property.label) %></option>'
   870     + '"<% if (uri === edge.uri) { %> selected<% } %>><%- translate(property.label) %></option>'
   862     + '<% }) %><% }) %></select></p><% } %>'
   871     + '<% }) %><% }) %></select></p><% } %>'
   863     + '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-translate("Edge color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
   872     + '<div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-translate("Edge color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
   864     + '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text">Choose color</span></div></div>'
   873     + '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text"><%- translate("Choose color") %></span></div></div>'
   865     + '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%-edge.from_title%></p>'
   874     + '<p><span class="Rk-Edit-Direction"><%- translate("Change edge direction") %></span></p>'
   866     + '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%-edge.to_title%></p>'
   875     + '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.from_title, 25) %></p>'
   867     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%-edge.created_by_title%></p>'
   876     + '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.to_title, 25) %></p>'
       
   877     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.created_by_title, 25) %></p>'
   868 );
   878 );
   869 
   879 
   870 Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template(
   880 Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template(
   871     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span><%- edge.title %></span></h2>'
   881     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span>'
   872     + '<p><a href="<%-edge.uri%>" target="_blank"><%-edge.uri%></a></p>'
   882     + '<span class="Rk-Display-Title"><% if (edge.uri) { %><a href="<%-edge.uri%>" target="_blank"><% } %><%-edge.title%><% if (edge.uri) { %></a><% } %></span></h2>'
       
   883     + '<% if (edge.uri) { %><p class="Rk-Display-URI"><a href="<%-edge.uri%>" target="_blank"><%-edge.short_uri%></a></p><% } %>'
   873     + '<p><%-edge.description%></p>'
   884     + '<p><%-edge.description%></p>'
   874     + '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%-edge.from_title%></p>'
   885     + '<p><span class="Rk-Editor-Label"><%-translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.from_title, 25) %></p>'
   875     + '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%-edge.to_title%></p>'
   886     + '<p><span class="Rk-Editor-Label"><%-translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.to_title, 25) %></p>'
   876     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%-edge.created_by_title%></p>'
   887     + '<p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(edge.created_by_title, 25) %></p>'
   877 );
   888 );
   878 
   889 
   879 Rkns.Renderer.EdgeEditor.prototype.draw = function() {
   890 Rkns.Renderer.EdgeEditor.prototype.draw = function() {
   880     var _model = this.edge_representation.model,
   891     var _model = this.edge_representation.model,
   881         _from_model = _model.get("from"),
   892         _from_model = _model.get("from"),
   885     this.editor_$
   896     this.editor_$
   886         .html(_template({
   897         .html(_template({
   887             edge: {
   898             edge: {
   888                 title: _model.get("title"),
   899                 title: _model.get("title"),
   889                 uri: _model.get("uri"),
   900                 uri: _model.get("uri"),
       
   901                 short_uri:  Rkns.Renderer.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
   890                 description: _model.get("description"),
   902                 description: _model.get("description"),
   891                 color: _model.get("color") || _created_by.get("color"),
   903                 color: _model.get("color") || _created_by.get("color"),
   892                 from_title: _from_model.get("title"),
   904                 from_title: _from_model.get("title"),
   893                 to_title: _to_model.get("title"),
   905                 to_title: _to_model.get("title"),
   894                 from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"),
   906                 from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"),
   913 	            var _data = {
   925 	            var _data = {
   914 	                title: _this.editor_$.find(".Rk-Edit-Title").val(),
   926 	                title: _this.editor_$.find(".Rk-Edit-Title").val(),
   915 	                uri: _this.editor_$.find(".Rk-Edit-URI").val()
   927 	                uri: _this.editor_$.find(".Rk-Edit-URI").val()
   916 	            }
   928 	            }
   917 	            _model.set(_data);
   929 	            _model.set(_data);
   918 	            _this.edge_representation.redraw();
       
   919 	            paper.view.draw();
   930 	            paper.view.draw();
   920     		}).defer();
   931     		}).defer();
   921     	}).throttle(500);
   932     	}).throttle(500);
   922     	
   933     	
   923         this.editor_$.find("input").bind("keyup change paste", onFieldChange);
   934         this.editor_$.find("input").bind("keyup change paste", onFieldChange);
   928         		_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
   939         		_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
   929         		_this.editor_$.find(".Rk-Edit-URI").val(v);
   940         		_this.editor_$.find(".Rk-Edit-URI").val(v);
   930         		onFieldChange();
   941         		onFieldChange();
   931         	}
   942         	}
   932         });
   943         });
       
   944         this.editor_$.find(".Rk-Edit-Direction").click(function() {
       
   945         	_model.set({
       
   946         		from: _model.get("to"),
       
   947         		to: _model.get("from")
       
   948         	});
       
   949         	_this.draw();
       
   950         });
   933         this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
   951         this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
   934             function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); },
   952             function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); },
   935             function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); }
   953             function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); }
   936         );
   954         );
   937         this.editor_$.find(".Rk-Edit-ColorPicker li").hover(
   955         this.editor_$.find(".Rk-Edit-ColorPicker li").hover(
   938             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); },
   956             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); },
   939             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); }
   957             function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); }
   940         ).click(function() {
   958         ).click(function() {
   941             _model.set("color", $(this).attr("data-color"));
   959             _model.set("color", $(this).attr("data-color"));
   942             _this.redraw();
   960             paper.view.draw();
   943         });
   961         });
   944     }
   962     }
   945 }
   963 }
   946 
   964 
   947 Rkns.Renderer.EdgeEditor.prototype.redraw = function() {
   965 Rkns.Renderer.EdgeEditor.prototype.redraw = function() {
   948     var _coords = this.edge_representation.paper_coords;
   966     var _coords = this.edge_representation.paper_coords;
   949     Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$);
   967     Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, Rkns.Renderer._EDITOR_WIDTH, 5, this.editor_$);
   950     this.editor_$.show();
   968     this.editor_$.show();
   951     paper.view.draw();
   969     paper.view.draw();
   952 }
   970 }
   953 
   971 
   954 Rkns.Renderer.EdgeEditor.prototype.destroy = function() {
   972 Rkns.Renderer.EdgeEditor.prototype.destroy = function() {