diff -r 1563d9be4a71 -r 1796e0220bef client/js/paper-renderer.js
--- a/client/js/paper-renderer.js Fri Apr 19 11:30:33 2013 +0200
+++ b/client/js/paper-renderer.js Fri Apr 19 13:39:39 2013 +0200
@@ -12,6 +12,9 @@
_MIN_SCALE: 1/20,
_MAX_SCALE: 20,
_AUTOSCALE_MARGIN: 50,
+ _MOUSEMOVE_RATE: 80,
+ _DOUBLETAP_DELAY: 800,
+ _DOUBLETAP_DISTANCE: 20*20,
_USER_PLACEHOLDER : function(_renkan) {
return {
color: _renkan.options.default_user_color,
@@ -25,11 +28,8 @@
return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='"
+ _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_")
+ "
'.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);})();"
- }
-}
-
-Rkns.Renderer.Utils = {
- shortenText : function(_text, _maxlength) {
+ },
+ shortenText : function(_text, _maxlength) {
return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
},
drawEditBox : function(_options, _coords, _path, _xmargin, _selector) {
@@ -75,106 +75,6 @@
top: (_options.tooltip_padding + _top)
});
return _path;
- },
- sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) {
- var _options = _repr.renderer.renkan.options,
- _startRads = _startAngle * Math.PI / 180,
- _endRads = _endAngle * Math.PI / 180,
- _img = new Image(),
- _span = _endRads - _startRads,
- _startdx = - Math.sin(_startRads),
- _startdy = Math.cos(_startRads),
- _startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
- _startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
- _startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
- _startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
- _enddx = - Math.sin(_endRads),
- _enddy = Math.cos(_endRads),
- _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
- _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
- _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
- _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
- _centerR = (_inR + _outR)/2,
- _centerRads = (_startRads + _endRads) / 2,
- _centerX = Math.cos(_centerRads) * _centerR,
- _centerY = Math.sin(_centerRads) * _centerR,
- _centerXIn = Math.cos(_centerRads) * _inR,
- _centerXOut = Math.cos(_centerRads) * _outR,
- _centerYIn = Math.sin(_centerRads) * _inR,
- _centerYOut = Math.sin(_centerRads) * _outR,
- _textX = Math.cos(_centerRads) * (_outR + 3),
- _textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2,
- _segments = [];
- _repr.renderer.buttons_layer.activate();
- var _path = new paper.Path();
- _path.add([_startXIn, _startYIn]);
- _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
- _path.lineTo([_endXOut, _endYOut]);
- _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
- _path.fillColor = _options.buttons_background;
- _path.opacity = .5;
- _path.closed = true;
- _path.__representation = _repr;
- var _text = new paper.PointText(_textX,_textY);
- _text.characterStyle = {
- fontSize: _options.buttons_label_font_size,
- fillColor: _options.buttons_label_color
- };
- if (_textX > 2) {
- _text.paragraphStyle.justification = 'left';
- } else if (_textX < -2) {
- _text.paragraphStyle.justification = 'right';
- } else {
- _text.paragraphStyle.justification = 'center';
- }
- _text.visible = false;
- var _visible = false,
- _restPos = new paper.Point(-200, -200),
- _grp = new paper.Group([_path, _text]),
- _delta = _grp.position,
- _imgdelta = new paper.Point([_centerX, _centerY]),
- _currentPos = new paper.Point(0,0);
- _text.content = _caption;
- _grp.visible = false;
- _grp.position = _restPos;
- var _res = {
- show: function() {
- _visible = true;
- _grp.position = _currentPos.add(_delta);
- _grp.visible = true;
- },
- moveTo: function(_point) {
- _currentPos = _point;
- if (_visible) {
- _grp.position = _point.add(_delta);
- }
- },
- hide: function() {
- _visible = false;
- _grp.visible = false;
- _grp.position = _restPos;
- },
- select: function() {
- _path.opacity = .8;
- _text.visible = true;
- },
- unselect: function() {
- _path.opacity = .5;
- _text.visible = false;
- },
- destroy: function() {
- _grp.remove();
- }
- }
- _img.onload = function() {
- var _h = _img.height;
- var _raster = new paper.Raster(_img);
- _raster.position = _imgdelta.add(_grp.position).subtract(_delta);
- _grp.addChild(_raster);
- _repr.renderer.throttledPaperDraw();
- }
- _img.src = _imgsrc;
- return _res
}
}
@@ -333,8 +233,8 @@
}
this.last_circle_radius = this.circle_radius;
- var _text = this.model.get("title") || this.renkan.translate("(untitled)");
- _text = Rkns.Renderer.Utils.shortenText(_text, this.options.node_label_max_length);
+ var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
+ _text = Rkns.Renderer.shortenText(_text, this.options.node_label_max_length);
this.title.text(_text);
this.title.css({
left: this.paper_coords.x,
@@ -608,8 +508,8 @@
_a += 180;
_textdelta = _textdelta.multiply(-1);
}
- var _text = this.model.get("title");
- _text = Rkns.Renderer.Utils.shortenText(_text, this.options.node_label_max_length);
+ var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_edges) || "";
+ _text = Rkns.Renderer.shortenText(_text, this.options.node_label_max_length);
this.text.text(_text);
var _textpos = this.paper_coords.add(_textdelta);
this.text.css({
@@ -804,38 +704,29 @@
/* */
-Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
+Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
-Rkns.Renderer.NodeEditor.prototype._init = function() {
- this.renderer.buttons_layer.activate();
- this.type = "editor";
- this.editor_block = new paper.Path();
- var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]});
- this.editor_block.add.apply(this.editor_block, _pts);
- this.editor_block.strokeWidth = this.options.tooltip_border_width;
- this.editor_block.strokeColor = this.options.tooltip_border_color;
- this.editor_block.opacity = .8;
- this.editor_$ = Rkns.$('')
- .appendTo(this.renderer.editor_$)
- .css({
- position: "absolute",
- opacity: .8
- })
- .hide();
+Rkns.Renderer._BaseEditor.prototype.destroy = function() {
+ this.editor_block.remove();
+ this.editor_$.detach();
}
+/* */
+
+Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
+
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template(
- '
×<%-translate("Edit Node")%>
'
- + '
'
- + '
'
- + '
'
- + '
<%-translate("Size:")%>-<%-node.size%>+
'
- + '
<%-translate("Node color:")%>'
- + '<% _(Rkns.pickerColors).each(function(c) { %><% }); %>
<%- translate("Choose color") %> '
+ '
×<%-renkan.translate("Edit Node")%>
'
+ + '
'
+ + '
'
+ + '
'
+ + '
<%-renkan.translate("Size:")%>-<%-node.size%>+
'
+ + '
<%-renkan.translate("Node color:")%>'
+ + '<% _(Rkns.pickerColors).each(function(c) { %><% }); %>
<%- renkan.translate("Choose color") %> '
+ '

'
- + '
'
- + '
'
- + '<% if (node.has_creator) { %>
<%-translate("Created by:")%> <%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %>
<% } %>'
+ + '
'
+ + '
'
+ + '<% if (node.has_creator) { %>
<%-renkan.translate("Created by:")%> <%- Rkns.Renderer.shortenText(node.created_by_title, 25) %>
<% } %>'
);
Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
@@ -844,7 +735,7 @@
+ '<% if (node.uri) { %>
<%-node.short_uri%>
<% } %>'
+ '
<%-node.description%>
'
+ '<% if (node.image) { %>

<% } %>'
- + '<% if (node.has_creator) { %>
<%-translate("Created by:")%><%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %>
<% } %>'
+ + '<% if (node.has_creator) { %>
<%-renkan.translate("Created by:")%><%- Rkns.Renderer.shortenText(node.created_by_title, 25) %>
<% } %>'
);
Rkns.Renderer.NodeEditor.prototype.draw = function() {
@@ -859,7 +750,7 @@
has_creator: !!_model.get("created_by"),
title: _model.get("title"),
uri: _model.get("uri"),
- short_uri: Rkns.Renderer.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
+ short_uri: Rkns.Renderer.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
description: _model.get("description"),
image: _model.get("image") || "",
image_placeholder: _image_placeholder,
@@ -868,7 +759,7 @@
created_by_title: _created_by.get("title"),
size: (_size > 0 ? "+" : "") + _size
},
- translate: this.renkan.translate
+ renkan: this.renkan
}));
this.redraw();
var _this = this,
@@ -931,16 +822,34 @@
}
});
this.editor_$.find(".Rk-Edit-Title")[0].focus();
+
+ var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
+
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
- function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); },
- function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); }
+ function(_e) {
+ _e.preventDefault();
+ _picker.show();
+ },
+ function(_e) {
+ _e.preventDefault();
+ _picker.hide();
+ }
);
- this.editor_$.find(".Rk-Edit-ColorPicker li").hover(
- function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); },
- function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(_this.renkan)).get("color")) }
- ).click(function() {
+
+ _picker.find("li").hover(
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
+ },
+ function(_e) {
+ _e.preventDefault();
+ _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(_this.renkan)).get("color"))
+ }
+ ).click(function(_e) {
+ _e.preventDefault();
if (_this.renderer.isEditable()) {
_model.set("color", $(this).attr("data-color"));
+ _picker.hide();
paper.view.draw();
} else {
closeEditor();
@@ -974,19 +883,14 @@
Rkns.Renderer.NodeEditor.prototype.redraw = function() {
var _coords = this.source_representation.paper_coords;
- Rkns.Renderer.Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * .75, this.editor_$);
+ Rkns.Renderer.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * .75, this.editor_$);
this.editor_$.show();
paper.view.draw();
}
-Rkns.Renderer.NodeEditor.prototype.destroy = function() {
- this.editor_block.remove();
- this.editor_$.detach();
-}
-
/* */
-Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
+Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
Rkns.Renderer.EdgeEditor.prototype._init = function() {
this.renderer.buttons_layer.activate();
@@ -1007,20 +911,20 @@
}
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
- '
×<%-translate("Edit Edge")%>
'
- + '
'
- + '
'
- + '<% if (properties.length) { %>
'
);
+Rkns.Renderer.Scene.prototype.drawSector = function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
+ var _options = this.renkan.options,
+ _startRads = _startAngle * Math.PI / 180,
+ _endRads = _endAngle * Math.PI / 180,
+ _img = this.imageCache[_imgname],
+ _span = _endRads - _startRads,
+ _startdx = - Math.sin(_startRads),
+ _startdy = Math.cos(_startRads),
+ _startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
+ _startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
+ _startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
+ _startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
+ _enddx = - Math.sin(_endRads),
+ _enddy = Math.cos(_endRads),
+ _endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
+ _endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
+ _endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
+ _endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
+ _centerR = (_inR + _outR)/2,
+ _centerRads = (_startRads + _endRads) / 2,
+ _centerX = Math.cos(_centerRads) * _centerR,
+ _centerY = Math.sin(_centerRads) * _centerR,
+ _centerXIn = Math.cos(_centerRads) * _inR,
+ _centerXOut = Math.cos(_centerRads) * _outR,
+ _centerYIn = Math.sin(_centerRads) * _inR,
+ _centerYOut = Math.sin(_centerRads) * _outR,
+ _textX = Math.cos(_centerRads) * (_outR + 3),
+ _textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2,
+ _segments = [];
+ this.buttons_layer.activate();
+ var _path = new paper.Path();
+ _path.add([_startXIn, _startYIn]);
+ _path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
+ _path.lineTo([_endXOut, _endYOut]);
+ _path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
+ _path.fillColor = _options.buttons_background;
+ _path.opacity = .5;
+ _path.closed = true;
+ _path.__representation = _repr;
+ var _text = new paper.PointText(_textX,_textY);
+ _text.characterStyle = {
+ fontSize: _options.buttons_label_font_size,
+ fillColor: _options.buttons_label_color
+ };
+ if (_textX > 2) {
+ _text.paragraphStyle.justification = 'left';
+ } else if (_textX < -2) {
+ _text.paragraphStyle.justification = 'right';
+ } else {
+ _text.paragraphStyle.justification = 'center';
+ }
+ _text.visible = false;
+ var _visible = false,
+ _restPos = new paper.Point(-200, -200),
+ _grp = new paper.Group([_path, _text]),
+ _delta = _grp.position,
+ _imgdelta = new paper.Point([_centerX, _centerY]),
+ _currentPos = new paper.Point(0,0);
+ _text.content = _caption;
+ _grp.visible = false;
+ _grp.position = _restPos;
+ var _res = {
+ show: function() {
+ _visible = true;
+ _grp.position = _currentPos.add(_delta);
+ _grp.visible = true;
+ },
+ moveTo: function(_point) {
+ _currentPos = _point;
+ if (_visible) {
+ _grp.position = _point.add(_delta);
+ }
+ },
+ hide: function() {
+ _visible = false;
+ _grp.visible = false;
+ _grp.position = _restPos;
+ },
+ select: function() {
+ _path.opacity = .8;
+ _text.visible = true;
+ },
+ unselect: function() {
+ _path.opacity = .5;
+ _text.visible = false;
+ },
+ destroy: function() {
+ _grp.remove();
+ }
+ }
+ function showImage() {
+ var _raster = new paper.Raster(_img);
+ _raster.position = _imgdelta.add(_grp.position).subtract(_delta);
+ _grp.addChild(_raster);
+ }
+ if (_img.width) {
+ showImage();
+ } else {
+ Rkns.$(_img).on("load",showImage);
+ }
+
+ return _res
+}
+
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) {
var _bundle = Rkns._(this.bundles).find(function(_bundle) {
return (
@@ -2135,6 +2207,9 @@
newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
}
}
+ if (!newNode.title) {
+ newNode.title = this.renkan.translate("Dragged resource");
+ }
var fields = ["title", "description", "uri", "image"];
for (var i = 0; i < fields.length; i++) {
var f = fields[i];
@@ -2145,8 +2220,7 @@
newNode[f] = undefined;
}
}
- if (newNode.title || newNode.description || newNode.uri) {
- var _off = this.canvas_$.offset(),
+ var _off = this.canvas_$.offset(),
_point = new paper.Point([
_event.pageX - _off.left,
_event.pageY - _off.top
@@ -2156,7 +2230,7 @@
id: Rkns.Utils.getUID('node'),
created_by: this.renkan.current_user,
uri: newNode.uri || "",
- title: newNode.title || this.renkan.translate("Dragged resource"),
+ title: newNode.title || "",
description: newNode.description || "",
image: newNode.image || "",
color: newNode.color || undefined,
@@ -2165,10 +2239,9 @@
y: _coords.y
}
};
- var _node = this.renkan.project.addNode(_nodedata),
- _repr = this.getRepresentationByModel(_node);
- if (_event.type === "drop") {
- _repr.openEditor();
- }
- }
+ var _node = this.renkan.project.addNode(_nodedata),
+ _repr = this.getRepresentationByModel(_node);
+ if (_event.type === "drop") {
+ _repr.openEditor();
+ }
}