| author | veltr |
| Mon, 25 Mar 2013 18:54:23 +0100 | |
| changeset 111 | fbe12f54453a |
| parent 110 | 55454c900296 |
| child 113 | fac7354c55d2 |
| permissions | -rw-r--r-- |
| 28 | 1 |
Rkns.Renderer = { |
| 69 | 2 |
_MINIMAP_MARGIN_X: 20, |
3 |
_MINIMAP_MARGIN_Y: 20, |
|
| 28 | 4 |
_MIN_DRAG_DISTANCE: 2, |
| 67 | 5 |
_NODE_SIZE_BASE: 25, |
6 |
_NODE_BUTTON_WIDTH: 40, |
|
7 |
_EDGE_BUTTON_INNER: 2, |
|
| 31 | 8 |
_EDGE_BUTTON_OUTER: 40, |
| 28 | 9 |
_NODE_FONT_SIZE: 10, |
10 |
_EDGE_FONT_SIZE: 9, |
|
| 73 | 11 |
_EDGE_DISTANCE: 3, |
| 28 | 12 |
_NODE_MAX_CHAR: 50, |
13 |
_EDGE_MAX_CHAR: 40, |
|
| 110 | 14 |
_ARROW_LENGTH: 18, |
15 |
_ARROW_WIDTH: 12, |
|
| 5 | 16 |
_EDITOR_ARROW_LENGTH : 20, |
17 |
_EDITOR_ARROW_WIDTH : 40, |
|
| 110 | 18 |
_EDITOR_WIDTH : 275, |
| 5 | 19 |
_EDITOR_MARGIN : 15, |
20 |
_EDITOR_PADDING : 10, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
21 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
22 |
_CLICKMODE_ADDNODE : 1, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
23 |
_CLICKMODE_STARTEDGE : 2, |
| 53 | 24 |
_CLICKMODE_ENDEDGE : 3, |
| 66 | 25 |
_IMAGE_MAX_KB : 500, |
| 67 | 26 |
_NODE_SIZE_STEP: Math.LN2/4, |
| 69 | 27 |
_MINIMAP_WIDTH: 160, |
28 |
_MINIMAP_HEIGHT: 120, |
|
| 53 | 29 |
_USER_PLACEHOLDER : { |
30 |
color: "#000000", |
|
31 |
title: "(unknown user)", |
|
32 |
get: function(attr) { |
|
33 |
return this[attr] || false; |
|
34 |
} |
|
| 70 | 35 |
}, |
36 |
_BOOKMARKLET_CODE: function(_renkan) { |
|
| 72 | 37 |
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='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
| 70 | 38 |
+ _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
| 72 | 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);})();" |
| 53 | 40 |
} |
| 28 | 41 |
} |
42 |
||
43 |
Rkns.Renderer.Utils = { |
|
| 110 | 44 |
shortenText : function(_text, _maxlength) { |
45 |
return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
|
46 |
}, |
|
| 28 | 47 |
drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
48 |
_selector.css({ |
|
49 |
width: (_width - 2* Rkns.Renderer._EDITOR_PADDING), |
|
50 |
}) |
|
51 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING, |
|
52 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
53 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH ), |
|
54 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH + _width ), |
|
| 5 | 55 |
_top = _coords.y - _height / 2; |
| 28 | 56 |
if (_top < Rkns.Renderer._EDITOR_MARGIN) { |
57 |
_top = Math.min( Rkns.Renderer._EDITOR_MARGIN, _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 58 |
} |
59 |
var _bottom = _top + _height; |
|
| 28 | 60 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN)) { |
61 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN, _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 62 |
_top = _bottom - _height; |
63 |
} |
|
64 |
_path.segments[0].point |
|
65 |
= _path.segments[7].point |
|
| 28 | 66 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 5 | 67 |
_path.segments[1].point.x |
68 |
= _path.segments[2].point.x |
|
69 |
= _path.segments[5].point.x |
|
70 |
= _path.segments[6].point.x |
|
71 |
= _left; |
|
72 |
_path.segments[3].point.x |
|
73 |
= _path.segments[4].point.x |
|
74 |
= _right; |
|
75 |
_path.segments[2].point.y |
|
76 |
= _path.segments[3].point.y |
|
77 |
= _top; |
|
78 |
_path.segments[4].point.y |
|
79 |
= _path.segments[5].point.y |
|
80 |
= _bottom; |
|
| 28 | 81 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
82 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
|
83 |
_path.closed = true; |
|
84 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._EDITOR_GRADIENT, [0,_top], [0, _bottom]); |
|
85 |
_selector.css({ |
|
86 |
left: (Rkns.Renderer._EDITOR_PADDING + Math.min(_left, _right)), |
|
87 |
top: (Rkns.Renderer._EDITOR_PADDING + _top) |
|
88 |
}); |
|
| 7 | 89 |
}, |
| 38 | 90 |
sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) { |
| 7 | 91 |
var _startRads = _startAngle * Math.PI / 180, |
92 |
_endRads = _endAngle * Math.PI / 180, |
|
93 |
_img = new Image(), |
|
94 |
_span = _endRads - _startRads, |
|
95 |
_k = .0879 * _span, |
|
96 |
_kin = _k * _inR, |
|
97 |
_kout = _k * _outR, |
|
98 |
_startdx = - Math.sin(_startRads), |
|
99 |
_startdy = Math.cos(_startRads), |
|
100 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
101 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
102 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
103 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
104 |
_enddx = - Math.sin(_endRads), |
|
105 |
_enddy = Math.cos(_endRads), |
|
106 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
107 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
108 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
109 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
110 |
_centerR = (_inR + _outR)/2, |
|
111 |
_centerRads = (_startRads + _endRads) / 2, |
|
112 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
113 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
| 67 | 114 |
_centerXIn = Math.cos(_centerRads) * _inR, |
115 |
_centerXOut = Math.cos(_centerRads) * _outR, |
|
116 |
_centerYIn = Math.sin(_centerRads) * _inR, |
|
117 |
_centerYOut = Math.sin(_centerRads) * _outR, |
|
| 38 | 118 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
119 |
_textY = Math.sin(_centerRads) * (_outR + 3), |
|
| 7 | 120 |
_segments = []; |
| 69 | 121 |
_repr.renderer.buttons_layer.activate(); |
| 18 | 122 |
var _path = new paper.Path(); |
| 67 | 123 |
_path.add([_startXIn, _startYIn]); |
124 |
_path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
|
125 |
_path.lineTo([_endXOut, _endYOut]); |
|
126 |
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
|
| 7 | 127 |
_path.fillColor = "#333333"; |
| 15 | 128 |
_path.opacity = .5; |
| 7 | 129 |
_path.closed = true; |
| 23 | 130 |
_path.__representation = _repr; |
| 38 | 131 |
if (_textX >= -2 && _textX <= 2) { |
132 |
if (_textY > 0) { |
|
133 |
_textY += 6; |
|
134 |
} |
|
135 |
} |
|
136 |
var _text = new paper.PointText(_textX,_textY); |
|
137 |
_text.characterStyle = { |
|
138 |
fontSize: 9, |
|
139 |
fillColor: '#c000c0' |
|
140 |
}; |
|
141 |
if (_textX > 2) { |
|
142 |
_text.paragraphStyle.justification = 'left'; |
|
143 |
} else if (_textX < -2) { |
|
144 |
_text.paragraphStyle.justification = 'right'; |
|
145 |
} else { |
|
146 |
_text.paragraphStyle.justification = 'center'; |
|
147 |
} |
|
148 |
_text.visible = false; |
|
| 18 | 149 |
var _visible = false, |
150 |
_restPos = new paper.Point(-200, -200), |
|
| 38 | 151 |
_grp = new paper.Group([_path, _text]), |
| 18 | 152 |
_delta = _grp.position, |
153 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
154 |
_currentPos = new paper.Point(0,0); |
|
| 38 | 155 |
_text.content = _caption; |
| 18 | 156 |
_grp.visible = false; |
157 |
_grp.position = _restPos; |
|
158 |
var _res = { |
|
159 |
show: function() { |
|
160 |
_visible = true; |
|
161 |
_grp.position = _currentPos.add(_delta); |
|
162 |
_grp.visible = true; |
|
163 |
}, |
|
164 |
moveTo: function(_point) { |
|
165 |
_currentPos = _point; |
|
166 |
if (_visible) { |
|
167 |
_grp.position = _point.add(_delta); |
|
168 |
} |
|
169 |
}, |
|
170 |
hide: function() { |
|
171 |
_visible = false; |
|
172 |
_grp.visible = false; |
|
173 |
_grp.position = _restPos; |
|
174 |
}, |
|
175 |
select: function() { |
|
176 |
_path.opacity = .8; |
|
| 38 | 177 |
_text.visible = true; |
| 18 | 178 |
}, |
179 |
unselect: function() { |
|
180 |
_path.opacity = .5; |
|
| 38 | 181 |
_text.visible = false; |
| 18 | 182 |
}, |
183 |
destroy: function() { |
|
184 |
_grp.remove(); |
|
| 7 | 185 |
} |
| 18 | 186 |
} |
| 7 | 187 |
_img.onload = function() { |
| 38 | 188 |
var _h = _img.height; |
| 7 | 189 |
var _raster = new paper.Raster(_img); |
| 18 | 190 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
| 7 | 191 |
_grp.addChild(_raster); |
192 |
} |
|
193 |
_img.src = _imgsrc; |
|
194 |
return _res |
|
| 5 | 195 |
} |
196 |
} |
|
197 |
||
| 23 | 198 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
| 1 | 199 |
if (typeof _renderer !== "undefined") { |
| 23 | 200 |
this.renderer = _renderer; |
201 |
this.project = _renderer.renkan.project; |
|
202 |
this.model = _model; |
|
| 39 | 203 |
if (this.model) { |
204 |
var _this = this; |
|
205 |
this._changeBinding = function() { |
|
206 |
_this.redraw(); |
|
207 |
} |
|
208 |
this._removeBinding = function() { |
|
209 |
_renderer.removeRepresentation(_this); |
|
210 |
_renderer.redraw(); |
|
211 |
} |
|
212 |
this.model.on("change", this._changeBinding ); |
|
213 |
this.model.on("remove", this._removeBinding ); |
|
214 |
} |
|
| 1 | 215 |
} |
216 |
} |
|
217 |
||
| 39 | 218 |
Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
219 |
Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
|
220 |
} |
|
221 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
222 |
Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
223 |
|
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
224 |
Rkns.Renderer._BaseRepresentation.prototype.show = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
225 |
|
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
226 |
Rkns.Renderer._BaseRepresentation.prototype.hide = function() {} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
227 |
|
| 23 | 228 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
| 4 | 229 |
|
| 23 | 230 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
| 7 | 231 |
|
| 26 | 232 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
233 |
||
234 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
235 |
||
| 23 | 236 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
| 4 | 237 |
|
| 39 | 238 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
239 |
if (this.model) { |
|
240 |
this.model.off("change", this._changeBinding ); |
|
241 |
this.model.off("remove", this._removeBinding ); |
|
242 |
} |
|
243 |
} |
|
| 5 | 244 |
|
| 23 | 245 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 1 | 246 |
|
| 7 | 247 |
Rkns.Renderer.Node.prototype._init = function() { |
| 23 | 248 |
this.renderer.node_layer.activate(); |
| 20 | 249 |
this.type = "Node"; |
| 67 | 250 |
this.circle = new paper.Path.Circle([0, 0], 1); |
| 7 | 251 |
this.circle.fillColor = '#ffffff'; |
| 23 | 252 |
this.circle.__representation = this; |
| 52 | 253 |
this.circle.strokeWidth = 2; |
| 7 | 254 |
this.title = new paper.PointText([0,0]); |
255 |
this.title.characterStyle = { |
|
| 28 | 256 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
| 2 | 257 |
fillColor: 'black' |
258 |
}; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
259 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
260 |
this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
261 |
this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
262 |
this.link_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
263 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
264 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
265 |
this.edit_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
266 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
267 |
this.remove_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
268 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
269 |
this.link_button.node_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
270 |
} |
| 67 | 271 |
this.last_circle_radius = 1; |
| 7 | 272 |
this.title.paragraphStyle.justification = 'center'; |
| 69 | 273 |
|
274 |
this.renderer.minimap.node_layer.activate(); |
|
275 |
this.minimap_circle = new paper.Path.Circle([0, 0], 1); |
|
276 |
this.renderer.minimap.node_group.addChild(this.minimap_circle); |
|
| 1 | 277 |
} |
278 |
||
| 7 | 279 |
Rkns.Renderer.Node.prototype.redraw = function() { |
| 69 | 280 |
var _model_coords = new paper.Point(this.model.get("position")), |
281 |
_baseRadius = Rkns.Renderer._NODE_SIZE_BASE * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP); |
|
| 105 | 282 |
if (!this.is_dragging || !this.paper_coords) { |
| 57 | 283 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
284 |
} |
|
| 69 | 285 |
this.circle_radius = _baseRadius * this.renderer.scale; |
| 67 | 286 |
if (this.last_circle_radius !== this.circle_radius) { |
287 |
if (!this.renderer.renkan.read_only) { |
|
288 |
this.edit_button.setSectorSize(); |
|
289 |
this.remove_button.setSectorSize(); |
|
290 |
this.link_button.setSectorSize(); |
|
291 |
} |
|
292 |
var square = new paper.Size(this.circle_radius, this.circle_radius), |
|
293 |
topleft = this.paper_coords.subtract(square), |
|
294 |
bounds = new paper.Rectangle(topleft, square.multiply(2)); |
|
295 |
this.circle.fitBounds(bounds); |
|
296 |
if (this.node_image) { |
|
297 |
this.node_image.fitBounds(bounds); |
|
298 |
} |
|
299 |
} else { |
|
300 |
this.circle.position = this.paper_coords; |
|
301 |
if (this.node_image) { |
|
302 |
this.node_image.position = this.paper_coords; |
|
303 |
} |
|
304 |
} |
|
| 68 | 305 |
this.last_circle_radius = this.circle_radius; |
| 67 | 306 |
|
| 73 | 307 |
var _text = this.model.get("title") || this.renderer.renkan.translate("(untitled)"); |
| 110 | 308 |
this.title.content = Rkns.Renderer.Utils.shortenText(_text, Rkns.Renderer._NODE_MAX_CHAR); |
| 73 | 309 |
|
| 67 | 310 |
this.title.position = this.paper_coords.add([0, this.circle_radius + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
| 69 | 311 |
var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
312 |
this.circle.strokeColor = _color; |
|
| 7 | 313 |
this.edit_button.moveTo(this.paper_coords); |
314 |
this.remove_button.moveTo(this.paper_coords); |
|
| 11 | 315 |
this.link_button.moveTo(this.paper_coords); |
| 37 | 316 |
var _img = this.model.get("image"); |
317 |
if (_img && _img !== this.img) { |
|
318 |
var _image = new Image(), |
|
319 |
_this = this; |
|
320 |
_image.onload = function() { |
|
321 |
if (_this.node_image) { |
|
322 |
_this.node_image.remove(); |
|
323 |
} |
|
324 |
_this.renderer.node_layer.activate(); |
|
| 68 | 325 |
var _ratio = Math.min(2 / _image.width, 2 / _image.height ); |
| 37 | 326 |
var _raster = new paper.Raster(_image); |
| 73 | 327 |
if (_this.renderer.renkan.clip_images) { |
328 |
var _clip = new paper.Path.Circle([0, 0], 1); |
|
329 |
_raster.scale(_ratio); |
|
330 |
_this.node_image = new paper.Group(_clip, _raster); |
|
331 |
_this.node_image.opacity = .9; |
|
332 |
/* This is a workaround to allow clipping at group level |
|
333 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
|
334 |
*/ |
|
335 |
_this.node_image.clipped = true; |
|
336 |
} else { |
|
337 |
_this.node_image = _raster; |
|
338 |
} |
|
| 37 | 339 |
_this.node_image.__representation = _this; |
| 68 | 340 |
var square = new paper.Size(_this.circle_radius, _this.circle_radius), |
341 |
topleft = _this.paper_coords.subtract(square), |
|
342 |
bounds = new paper.Rectangle(topleft, square.multiply(2)); |
|
343 |
_this.node_image.fitBounds(bounds); |
|
| 38 | 344 |
_clip.__representation = _this; |
| 37 | 345 |
paper.view.draw(); |
346 |
} |
|
347 |
_image.src = _img; |
|
348 |
} |
|
349 |
this.img = _img; |
|
| 67 | 350 |
if (this.node_image && !this.img) { |
351 |
this.node_image.remove(); |
|
352 |
delete this.node_image; |
|
| 37 | 353 |
} |
| 69 | 354 |
|
355 |
this.minimap_circle.fillColor = _color; |
|
356 |
var minipos = this.renderer.toMinimapCoords(_model_coords), |
|
357 |
miniradius = this.renderer.minimap.scale * _baseRadius, |
|
358 |
minisize = new paper.Size([miniradius, miniradius]); |
|
359 |
this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2)); |
|
| 56 | 360 |
|
361 |
Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){ |
|
362 |
var repr = this.renderer.getRepresentationByModel(edge); |
|
363 |
if(repr != null && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
364 |
repr.redraw(); |
|
365 |
} |
|
366 |
}, this); |
|
| 1 | 367 |
} |
368 |
||
| 7 | 369 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
| 82 | 370 |
if (!this.renderer.renkan.read_only) { |
| 105 | 371 |
this.is_dragging = true; |
| 82 | 372 |
this.paper_coords = this.paper_coords.add(_delta); |
373 |
this.redraw(); |
|
374 |
} else { |
|
375 |
this.renderer.paperShift(_delta); |
|
376 |
} |
|
| 2 | 377 |
} |
378 |
||
| 8 | 379 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
| 23 | 380 |
this.renderer.removeRepresentationsOfType("editor"); |
381 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
382 |
_editor.node_representation = this; |
|
| 37 | 383 |
_editor.draw(); |
| 8 | 384 |
} |
385 |
||
| 7 | 386 |
Rkns.Renderer.Node.prototype.select = function() { |
| 52 | 387 |
this.circle.strokeWidth = 4; |
| 7 | 388 |
this.edit_button.show(); |
389 |
this.remove_button.show(); |
|
| 11 | 390 |
this.link_button.show(); |
| 26 | 391 |
var _uri = this.model.get("uri"); |
| 75 | 392 |
if (_uri) { |
393 |
Rkns.$('.Rk-Bin-Item').each(function() { |
|
394 |
var _el = Rkns.$(this); |
|
395 |
if (_el.attr("data-uri") == _uri) { |
|
396 |
_el.addClass("selected"); |
|
397 |
} |
|
398 |
}); |
|
399 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
400 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
401 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
402 |
} |
| 69 | 403 |
this.minimap_circle.fillColor = "#ff00fc"; |
| 7 | 404 |
} |
405 |
||
406 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
| 35 | 407 |
if (!_newTarget || _newTarget.node_representation !== this) { |
| 7 | 408 |
this.edit_button.hide(); |
409 |
this.remove_button.hide(); |
|
| 11 | 410 |
this.link_button.hide(); |
| 52 | 411 |
this.circle.strokeWidth = 2; |
| 35 | 412 |
Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
| 69 | 413 |
this.minimap_circle.fillColor = this.circle.strokeColor; |
| 7 | 414 |
} |
| 26 | 415 |
} |
416 |
||
417 |
Rkns.Renderer.Node.prototype.highlight = function() { |
|
| 37 | 418 |
this.circle.fillColor = "#ffff80"; |
419 |
if (this.node_image) { |
|
420 |
this.node_image.opacity = .5; |
|
421 |
} |
|
| 26 | 422 |
} |
423 |
||
424 |
Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
|
425 |
this.circle.fillColor = "#ffffff"; |
|
| 37 | 426 |
if (this.node_image) { |
427 |
this.node_image.opacity = .9; |
|
428 |
} |
|
| 4 | 429 |
} |
430 |
||
| 57 | 431 |
Rkns.Renderer.Node.prototype.saveCoords = function() { |
432 |
var _coords = this.renderer.toModelCoords(this.paper_coords), |
|
433 |
_data = { |
|
434 |
position: { |
|
435 |
x: _coords.x, |
|
436 |
y: _coords.y |
|
437 |
} |
|
438 |
}; |
|
439 |
this.model.set(_data); |
|
440 |
} |
|
441 |
||
| 7 | 442 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
443 |
if (!this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
444 |
if (this.renderer.is_dragging) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
445 |
this.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
446 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
447 |
else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
448 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
449 |
} |
| 7 | 450 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
451 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
452 |
this.renderer.is_dragging = false; |
| 105 | 453 |
this.is_dragging = false; |
| 7 | 454 |
} |
455 |
||
456 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
| 39 | 457 |
this.super("destroy"); |
| 7 | 458 |
this.edit_button.destroy(); |
459 |
this.remove_button.destroy(); |
|
| 26 | 460 |
this.link_button.destroy(); |
| 7 | 461 |
this.circle.remove(); |
462 |
this.title.remove(); |
|
| 69 | 463 |
this.minimap_circle.remove(); |
| 37 | 464 |
if (this.node_image) { |
465 |
this.node_image.remove(); |
|
466 |
} |
|
| 4 | 467 |
} |
468 |
||
| 2 | 469 |
/* */ |
470 |
||
| 23 | 471 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 2 | 472 |
|
| 7 | 473 |
Rkns.Renderer.Edge.prototype._init = function() { |
| 23 | 474 |
this.renderer.edge_layer.activate(); |
| 20 | 475 |
this.type = "Edge"; |
| 23 | 476 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
477 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 478 |
this.bundle = this.renderer.addToBundles(this); |
| 7 | 479 |
this.line = new paper.Path(); |
| 31 | 480 |
this.line.add([0,0],[0,0],[0,0]); |
| 23 | 481 |
this.line.__representation = this; |
| 52 | 482 |
this.line.strokeWidth = 2; |
| 7 | 483 |
this.arrow = new paper.Path(); |
| 28 | 484 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 485 |
this.arrow.__representation = this; |
| 7 | 486 |
this.text = new paper.PointText(); |
487 |
this.text.characterStyle = { |
|
| 28 | 488 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
| 2 | 489 |
fillColor: 'black' |
490 |
}; |
|
| 7 | 491 |
this.text.paragraphStyle.justification = 'center'; |
492 |
this.text_angle = 0; |
|
493 |
this.arrow_angle = 0; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
494 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
495 |
this.edit_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
496 |
this.remove_button = new Rkns.Renderer._BaseRepresentation(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
497 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
498 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
499 |
this.edit_button.edge_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
500 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
501 |
this.remove_button.edge_representation = this; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
502 |
} |
| 2 | 503 |
} |
504 |
||
| 7 | 505 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
| 110 | 506 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
507 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 508 |
var _p0a = this.from_representation.paper_coords, |
509 |
_p1a = this.to_representation.paper_coords, |
|
510 |
_v = _p1a.subtract(_p0a), |
|
| 15 | 511 |
_r = _v.length, |
| 18 | 512 |
_u = _v.divide(_r), |
| 73 | 513 |
_ortho = new paper.Point([- _u.y, _u.x]), |
| 31 | 514 |
_group_pos = this.bundle.getPosition(this), |
| 73 | 515 |
_delta = _ortho.multiply( 12 * _group_pos ), |
| 31 | 516 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
517 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
| 15 | 518 |
_a = _v.angle, |
| 73 | 519 |
_textdelta = _ortho.multiply(-Rkns.Renderer._EDGE_DISTANCE), |
| 31 | 520 |
_handle = _v.divide(3), |
| 56 | 521 |
_color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 31 | 522 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
| 7 | 523 |
this.line.strokeColor = _color; |
| 31 | 524 |
this.line.segments[0].point = _p0a; |
525 |
this.line.segments[1].point = this.paper_coords; |
|
526 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
527 |
this.line.segments[1].handleOut = _handle; |
|
528 |
this.line.segments[2].point = _p1a; |
|
| 7 | 529 |
this.arrow.rotate(_a - this.arrow_angle); |
530 |
this.arrow.fillColor = _color; |
|
| 18 | 531 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
| 7 | 532 |
this.arrow_angle = _a; |
| 2 | 533 |
if (_a > 90) { |
534 |
_a -= 180; |
|
| 73 | 535 |
_textdelta = _textdelta.multiply(-1); |
| 2 | 536 |
} |
537 |
if (_a < -90) { |
|
538 |
_a += 180; |
|
| 73 | 539 |
_textdelta = _textdelta.multiply(-1); |
| 2 | 540 |
} |
| 7 | 541 |
this.text.rotate(_a - this.text_angle); |
| 73 | 542 |
var _text = this.model.get("title"); |
| 110 | 543 |
this.text.content = Rkns.Renderer.Utils.shortenText(_text, Rkns.Renderer._EDGE_MAX_CHAR); |
| 73 | 544 |
this.text.position = this.paper_coords.add(_textdelta); |
| 7 | 545 |
this.text_angle = _a; |
| 15 | 546 |
this.edit_button.moveTo(this.paper_coords); |
547 |
this.remove_button.moveTo(this.paper_coords); |
|
| 7 | 548 |
} |
549 |
||
| 18 | 550 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
| 23 | 551 |
this.renderer.removeRepresentationsOfType("editor"); |
552 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
|
553 |
_editor.edge_representation = this; |
|
| 37 | 554 |
_editor.draw(); |
| 18 | 555 |
} |
556 |
||
| 7 | 557 |
Rkns.Renderer.Edge.prototype.select = function() { |
| 52 | 558 |
this.line.strokeWidth = 4; |
| 15 | 559 |
this.edit_button.show(); |
560 |
this.remove_button.show(); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
561 |
if (this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
562 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
563 |
} |
| 7 | 564 |
} |
565 |
||
566 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
| 35 | 567 |
if (!_newTarget || _newTarget.edge_representation !== this) { |
| 15 | 568 |
this.edit_button.hide(); |
569 |
this.remove_button.hide(); |
|
| 52 | 570 |
this.line.strokeWidth = 2; |
| 15 | 571 |
} |
| 4 | 572 |
} |
573 |
||
| 7 | 574 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
575 |
if (!this.renderer.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
576 |
if (this.renderer.is_dragging) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
577 |
this.from_representation.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
578 |
this.to_representation.saveCoords(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
579 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
580 |
this.openEditor(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
581 |
} |
| 7 | 582 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
583 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
584 |
this.renderer.is_dragging = false; |
| 4 | 585 |
} |
586 |
||
| 7 | 587 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
| 82 | 588 |
if (!this.renderer.renkan.read_only) { |
589 |
this.from_representation.paperShift(_delta); |
|
590 |
this.to_representation.paperShift(_delta); |
|
591 |
} else { |
|
592 |
this.renderer.paperShift(_delta); |
|
593 |
} |
|
| 2 | 594 |
} |
595 |
||
| 7 | 596 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
| 39 | 597 |
this.super("destroy"); |
| 7 | 598 |
this.line.remove(); |
599 |
this.arrow.remove(); |
|
600 |
this.text.remove(); |
|
| 15 | 601 |
this.edit_button.destroy(); |
602 |
this.remove_button.destroy(); |
|
| 31 | 603 |
var _this = this; |
604 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
605 |
return _edge === _this; |
|
606 |
}); |
|
| 2 | 607 |
} |
| 5 | 608 |
|
| 4 | 609 |
/* */ |
610 |
||
| 23 | 611 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 4 | 612 |
|
| 7 | 613 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
| 23 | 614 |
this.renderer.edge_layer.activate(); |
| 4 | 615 |
this.type = "temp-edge"; |
| 23 | 616 |
|
| 64 | 617 |
var _color = (this.project.get("users").get(this.renderer.renkan.current_user) || Rkns.Renderer._USER_PLACEHOLDER).get("color"); |
| 7 | 618 |
this.line = new paper.Path(); |
619 |
this.line.strokeColor = _color; |
|
620 |
this.line.add([0,0],[0,0]); |
|
| 23 | 621 |
this.line.__representation = this; |
| 7 | 622 |
this.arrow = new paper.Path(); |
623 |
this.arrow.fillColor = _color; |
|
| 28 | 624 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 625 |
this.arrow.__representation = this; |
| 7 | 626 |
this.arrow_angle = 0; |
| 4 | 627 |
} |
628 |
||
| 7 | 629 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
| 23 | 630 |
var _p0 = this.from_representation.paper_coords, |
| 4 | 631 |
_p1 = this.end_pos, |
632 |
_a = _p1.subtract(_p0).angle, |
|
633 |
_c = _p0.add(_p1).divide(2); |
|
| 7 | 634 |
this.line.segments[0].point = _p0; |
635 |
this.line.segments[1].point = _p1; |
|
636 |
this.arrow.rotate(_a - this.arrow_angle); |
|
637 |
this.arrow.position = _c; |
|
638 |
this.arrow_angle = _a; |
|
| 4 | 639 |
} |
640 |
||
| 7 | 641 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
| 4 | 642 |
this.end_pos = this.end_pos.add(_delta); |
| 21 | 643 |
var _hitResult = paper.project.hitTest(this.end_pos); |
| 23 | 644 |
this.renderer.findTarget(_hitResult); |
| 4 | 645 |
this.redraw(); |
646 |
} |
|
647 |
||
| 7 | 648 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
649 |
var _hitResult = paper.project.hitTest(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
650 |
_model = this.from_representation.model, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
651 |
_endDrag = true; |
| 23 | 652 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
653 |
var _target = _hitResult.item.__representation; |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
654 |
if (_target.type === "Node" && _model !== _target.model) { |
| 23 | 655 |
var _data = { |
656 |
id: Rkns.Utils.getUID('edge'), |
|
657 |
created_by: this.renderer.renkan.current_user, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
658 |
from: _model.get("_id"), |
| 30 | 659 |
to: _target.model.get("_id") |
| 23 | 660 |
}; |
661 |
this.project.addEdge(_data); |
|
| 4 | 662 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
663 |
if (_model === _target.model || (_target.node_representation && _target.node_representation.model === _model)) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
664 |
_endDrag = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
665 |
this.renderer.is_dragging = true; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
666 |
} |
| 4 | 667 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
668 |
if (_endDrag) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
669 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
670 |
this.renderer.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
671 |
this.renderer.removeRepresentation(this); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
672 |
paper.view.draw(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
673 |
} |
| 5 | 674 |
} |
675 |
||
| 7 | 676 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
677 |
this.arrow.remove(); |
|
678 |
this.line.remove(); |
|
| 5 | 679 |
} |
680 |
||
681 |
/* */ |
|
682 |
||
| 23 | 683 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 684 |
|
| 7 | 685 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
| 67 | 686 |
this.renderer.buttons_layer.activate(); |
| 5 | 687 |
this.type = "editor"; |
688 |
this.editor_block = new paper.Path(); |
|
689 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
690 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
691 |
this.editor_block.strokeWidth = 2; |
|
692 |
this.editor_block.strokeColor = "#999999"; |
|
693 |
this.editor_block.fillColor = "#e0e0e0"; |
|
694 |
this.editor_block.opacity = .8; |
|
695 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 696 |
.appendTo(this.renderer.editor_$) |
| 5 | 697 |
.css({ |
698 |
position: "absolute", |
|
699 |
opacity: .8 |
|
700 |
}) |
|
701 |
.hide(); |
|
702 |
} |
|
703 |
||
| 7 | 704 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
| 66 | 705 |
'<h2><span class="Rk-CloseX">×</span><%-translate("Edit Node")%></span></h2>' |
| 70 | 706 |
+ '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></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>' |
|
708 |
+ '<p><label><%-translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></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>' |
|
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">' |
|
| 110 | 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>' |
| 70 | 712 |
+ '<img class="Rk-Edit-ImgPreview" src="<%-node.image || node.image_placeholder%>" />' |
713 |
+ '<p><label><%-translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>' |
|
| 68 | 714 |
+ '<p><label><%-translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p>' |
| 110 | 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>' |
| 5 | 716 |
); |
717 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
718 |
Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template( |
| 110 | 719 |
'<h2><span class="Rk-CloseX">×</span><span class="Rk-UserColor" style="background:<%-node.color%>;"></span>' |
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><% } %>' |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
722 |
+ '<p><%-node.description%></p>' |
| 110 | 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>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
724 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
725 |
|
| 37 | 726 |
Rkns.Renderer.NodeEditor.prototype.draw = function() { |
| 53 | 727 |
var _model = this.node_representation.model, |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
728 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, |
| 67 | 729 |
_template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template), |
730 |
_image_placeholder = this.renderer.renkan.static_url + "img/image-placeholder.png", |
|
731 |
_size = (_model.get("size") || 0); |
|
| 5 | 732 |
this.editor_$ |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
733 |
.html(_template({ |
| 23 | 734 |
node: { |
735 |
title: _model.get("title"), |
|
736 |
uri: _model.get("uri"), |
|
| 110 | 737 |
short_uri: Rkns.Renderer.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
| 23 | 738 |
description: _model.get("description"), |
| 37 | 739 |
image: _model.get("image") || "", |
| 67 | 740 |
image_placeholder: _image_placeholder, |
| 53 | 741 |
color: _model.get("color") || _created_by.get("color"), |
742 |
created_by_color: _created_by.get("color"), |
|
| 67 | 743 |
created_by_title: _created_by.get("title"), |
744 |
size: (_size > 0 ? "+" : "") + _size |
|
| 23 | 745 |
}, |
| 66 | 746 |
translate: this.renderer.renkan.translate |
| 37 | 747 |
})); |
748 |
this.redraw(); |
|
| 5 | 749 |
var _this = this; |
750 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 751 |
_this.renderer.removeRepresentation(_this); |
| 5 | 752 |
paper.view.draw(); |
753 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
754 |
if (!this.renderer.renkan.read_only) { |
| 66 | 755 |
|
756 |
var onFieldChange = Rkns._(function() { |
|
757 |
Rkns._(function() { |
|
758 |
var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), |
|
759 |
_image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
| 67 | 760 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image || _image_placeholder); |
| 66 | 761 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); |
762 |
var _data = { |
|
763 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
764 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
765 |
uri: _uri, |
|
766 |
image: _image |
|
767 |
} |
|
768 |
_model.set(_data); |
|
769 |
_this.redraw(); |
|
770 |
}).defer(); |
|
771 |
}).throttle(500); |
|
772 |
|
|
773 |
this.editor_$.find("input, textarea").bind("change keyup paste", onFieldChange); |
|
774 |
|
|
775 |
this.editor_$.find(".Rk-Edit-Image-File").bind("change", function() { |
|
776 |
if (this.files.length) { |
|
777 |
var f = this.files[0], |
|
778 |
fr = new FileReader(); |
|
779 |
if (f.type.substr(0,5) !== "image") { |
|
780 |
alert(_this.renderer.renkan.translate("This file is not an image")); |
|
781 |
return; |
|
782 |
} |
|
783 |
if (f.size > (Rkns.Renderer._IMAGE_MAX_KB * 1024)) { |
|
784 |
alert(_this.renderer.renkan.translate("Image size must be under ")+Rkns.Renderer._IMAGE_MAX_KB+_this.renderer.renkan.translate("KB")); |
|
785 |
return; |
|
786 |
} |
|
787 |
fr.onload = function(e) { |
|
788 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result); |
|
789 |
onFieldChange(); |
|
790 |
} |
|
791 |
fr.readAsDataURL(f); |
|
792 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
793 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
794 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
795 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
796 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
797 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
798 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
799 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
800 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
801 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")) } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
802 |
).click(function() { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
803 |
_model.set("color", $(this).attr("data-color")); |
| 110 | 804 |
paper.view.draw(); |
| 67 | 805 |
}); |
806 |
|
|
807 |
function shiftSize(n) { |
|
808 |
var _newsize = n+(_model.get("size") || 0); |
|
809 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize); |
|
810 |
_model.set("size", _newsize); |
|
| 68 | 811 |
paper.view.draw(); |
| 67 | 812 |
} |
813 |
|
|
814 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() { |
|
815 |
shiftSize(-1); |
|
816 |
return false; |
|
817 |
}); |
|
818 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() { |
|
819 |
shiftSize(1); |
|
820 |
return false; |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
821 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
822 |
} |
| 38 | 823 |
this.editor_$.find("img").load(function() { |
824 |
_this.redraw(); |
|
| 52 | 825 |
}); |
| 37 | 826 |
} |
827 |
||
828 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
829 |
var _coords = this.node_representation.paper_coords; |
|
| 110 | 830 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, Rkns.Renderer._EDITOR_WIDTH, 20, this.editor_$); |
| 37 | 831 |
this.editor_$.show(); |
| 23 | 832 |
paper.view.draw(); |
| 5 | 833 |
} |
834 |
||
| 7 | 835 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
| 5 | 836 |
this.editor_block.remove(); |
837 |
this.editor_$.detach(); |
|
838 |
} |
|
839 |
||
840 |
/* */ |
|
841 |
||
| 23 | 842 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 843 |
|
| 7 | 844 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
| 67 | 845 |
this.renderer.buttons_layer.activate(); |
| 5 | 846 |
this.type = "editor"; |
847 |
this.editor_block = new paper.Path(); |
|
848 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
849 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
850 |
this.editor_block.strokeWidth = 2; |
|
851 |
this.editor_block.strokeColor = "#999999"; |
|
852 |
this.editor_block.fillColor = "#e0e0e0"; |
|
853 |
this.editor_block.opacity = .8; |
|
854 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 855 |
.appendTo(this.renderer.editor_$) |
| 5 | 856 |
.css({ |
857 |
position: "absolute", |
|
858 |
opacity: .8 |
|
859 |
}) |
|
860 |
.hide(); |
|
861 |
} |
|
862 |
||
| 7 | 863 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
| 66 | 864 |
'<h2><span class="Rk-CloseX">×</span><%-translate("Edit Edge")%></span></h2>' |
| 70 | 865 |
+ '<p><label><%-translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>' |
866 |
+ '<p><label><%-translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>' |
|
| 68 | 867 |
+ '<% if (properties.length) { %><p><label><%-translate("Choose from vocabulary:")%></label><select class="Rk-Edit-Vocabulary">' |
868 |
+ '<% _(properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- translate(ontology.label) %></option>' |
|
869 |
+ '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>' |
|
870 |
+ '"<% if (uri === edge.uri) { %> selected<% } %>><%- translate(property.label) %></option>' |
|
871 |
+ '<% }) %><% }) %></select></p><% } %>' |
|
| 70 | 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">' |
| 110 | 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>' |
874 |
+ '<p><span class="Rk-Edit-Direction"><%- translate("Change edge direction") %></span></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>' |
|
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>' |
|
| 5 | 878 |
); |
879 |
||
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
880 |
Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template( |
| 110 | 881 |
'<h2><span class="Rk-CloseX">×</span><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span>' |
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><% } %>' |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
884 |
+ '<p><%-edge.description%></p>' |
| 110 | 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>' |
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>' |
|
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>' |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
888 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
889 |
|
| 37 | 890 |
Rkns.Renderer.EdgeEditor.prototype.draw = function() { |
| 53 | 891 |
var _model = this.edge_representation.model, |
892 |
_from_model = _model.get("from"), |
|
893 |
_to_model = _model.get("to"), |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
894 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
895 |
_template = (this.renderer.renkan.read_only ? this.readOnlyTemplate : this.template); |
| 5 | 896 |
this.editor_$ |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
897 |
.html(_template({ |
| 25 | 898 |
edge: { |
899 |
title: _model.get("title"), |
|
900 |
uri: _model.get("uri"), |
|
| 110 | 901 |
short_uri: Rkns.Renderer.Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
| 25 | 902 |
description: _model.get("description"), |
| 53 | 903 |
color: _model.get("color") || _created_by.get("color"), |
904 |
from_title: _from_model.get("title"), |
|
905 |
to_title: _to_model.get("title"), |
|
906 |
from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
907 |
to_color: _to_model.get("color") || (_to_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color"), |
|
908 |
created_by_color: _created_by.get("color"), |
|
909 |
created_by_title: _created_by.get("title") |
|
| 25 | 910 |
}, |
| 68 | 911 |
translate: this.renderer.renkan.translate, |
912 |
properties: this.renderer.renkan.properties |
|
| 37 | 913 |
})); |
914 |
this.redraw(); |
|
| 5 | 915 |
var _this = this; |
916 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 917 |
_this.renderer.removeRepresentation(_this); |
| 5 | 918 |
paper.view.draw(); |
919 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
920 |
if (!this.renderer.renkan.read_only) { |
| 66 | 921 |
|
922 |
var onFieldChange = Rkns._(function() { |
|
923 |
Rkns._(function() { |
|
924 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
|
925 |
var _data = { |
|
926 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
927 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
928 |
} |
|
929 |
_model.set(_data); |
|
| 68 | 930 |
paper.view.draw(); |
| 66 | 931 |
}).defer(); |
932 |
}).throttle(500); |
|
933 |
|
|
| 68 | 934 |
this.editor_$.find("input").bind("keyup change paste", onFieldChange); |
935 |
this.editor_$.find(".Rk-Edit-Vocabulary").change(function() { |
|
936 |
var e = $(this), |
|
937 |
v = e.val(); |
|
938 |
if (v) { |
|
939 |
_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text()); |
|
940 |
_this.editor_$.find(".Rk-Edit-URI").val(v); |
|
941 |
onFieldChange(); |
|
942 |
} |
|
943 |
}); |
|
| 110 | 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 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
951 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
952 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").show(); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
953 |
function() { _this.editor_$.find(".Rk-Edit-ColorPicker").hide(); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
954 |
); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
955 |
this.editor_$.find(".Rk-Edit-ColorPicker li").hover( |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
956 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); }, |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
957 |
function() { _this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER).get("color")); } |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
958 |
).click(function() { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
959 |
_model.set("color", $(this).attr("data-color")); |
| 110 | 960 |
paper.view.draw(); |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
961 |
}); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
962 |
} |
| 37 | 963 |
} |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
964 |
|
| 37 | 965 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
966 |
var _coords = this.edge_representation.paper_coords; |
|
| 110 | 967 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, Rkns.Renderer._EDITOR_WIDTH, 5, this.editor_$); |
| 37 | 968 |
this.editor_$.show(); |
| 23 | 969 |
paper.view.draw(); |
| 5 | 970 |
} |
971 |
||
| 7 | 972 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
| 5 | 973 |
this.editor_block.remove(); |
974 |
this.editor_$.detach(); |
|
| 4 | 975 |
} |
| 2 | 976 |
|
977 |
/* */ |
|
| 1 | 978 |
|
| 23 | 979 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 980 |
|
981 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
| 20 | 982 |
this.type = "Node-edit-button"; |
| 67 | 983 |
this.lastSectorInner = 0; |
984 |
} |
|
985 |
||
986 |
Rkns.Renderer.NodeEditButton.prototype.setSectorSize = function() { |
|
987 |
var sectorInner = this.node_representation.circle_radius; |
|
988 |
if (sectorInner !== this.lastSectorInner) { |
|
989 |
if (this.sector) { |
|
990 |
this.sector.destroy(); |
|
991 |
} |
|
992 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, - 90, 30, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.translate("Edit")); |
|
993 |
this.lastSectorInner = sectorInner; |
|
994 |
} |
|
| 7 | 995 |
} |
996 |
||
997 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 998 |
this.sector.moveTo(_pos); |
| 7 | 999 |
} |
1000 |
||
1001 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
| 18 | 1002 |
this.sector.show(); |
| 7 | 1003 |
} |
1004 |
||
1005 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
| 18 | 1006 |
this.sector.hide(); |
| 7 | 1007 |
} |
1008 |
||
1009 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
| 18 | 1010 |
this.sector.select(); |
| 7 | 1011 |
} |
1012 |
||
| 35 | 1013 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 1014 |
this.sector.unselect(); |
| 35 | 1015 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
1016 |
this.node_representation.unselect(); |
|
1017 |
} |
|
| 7 | 1018 |
} |
1019 |
||
1020 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
| 23 | 1021 |
if (!this.renderer.is_dragging) { |
1022 |
this.node_representation.openEditor(); |
|
| 7 | 1023 |
} |
1024 |
} |
|
1025 |
||
1026 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
| 18 | 1027 |
this.sector.destroy(); |
| 7 | 1028 |
} |
1029 |
||
1030 |
/* */ |
|
1031 |
||
| 23 | 1032 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 1033 |
|
1034 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
| 20 | 1035 |
this.type = "Node-remove-button"; |
| 67 | 1036 |
this.lastSectorInner = 0; |
1037 |
} |
|
1038 |
||
1039 |
Rkns.Renderer.NodeRemoveButton.prototype.setSectorSize = function() { |
|
1040 |
var sectorInner = this.node_representation.circle_radius; |
|
1041 |
if (sectorInner !== this.lastSectorInner) { |
|
1042 |
if (this.sector) { |
|
1043 |
this.sector.destroy(); |
|
1044 |
} |
|
1045 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, - 210, - 90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.translate("Remove")); |
|
1046 |
this.lastSectorInner = sectorInner; |
|
1047 |
} |
|
| 7 | 1048 |
} |
1049 |
||
1050 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1051 |
this.sector.moveTo(_pos); |
| 7 | 1052 |
} |
1053 |
||
1054 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
| 18 | 1055 |
this.sector.show(); |
| 7 | 1056 |
} |
1057 |
||
1058 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
| 18 | 1059 |
this.sector.hide(); |
| 7 | 1060 |
} |
1061 |
||
1062 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
| 18 | 1063 |
this.sector.select(); |
| 7 | 1064 |
} |
1065 |
||
| 35 | 1066 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 1067 |
this.sector.unselect(); |
| 35 | 1068 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
1069 |
this.node_representation.unselect(); |
|
1070 |
} |
|
| 7 | 1071 |
} |
1072 |
||
1073 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1074 |
this.renderer.removeRepresentationsOfType("editor"); |
| 66 | 1075 |
if (confirm(this.renderer.renkan.translate('Do you really wish to remove node ') + '"' + this.node_representation.model.get("title") + '"?')) { |
| 23 | 1076 |
this.project.removeNode(this.node_representation.model); |
| 10 | 1077 |
} |
| 7 | 1078 |
} |
1079 |
||
1080 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
| 18 | 1081 |
this.sector.destroy(); |
| 7 | 1082 |
} |
1083 |
||
1084 |
/* */ |
|
1085 |
||
| 23 | 1086 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 11 | 1087 |
|
1088 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
| 20 | 1089 |
this.type = "Node-link-button"; |
| 67 | 1090 |
this.lastSectorInner = 0; |
1091 |
} |
|
1092 |
||
1093 |
Rkns.Renderer.NodeLinkButton.prototype.setSectorSize = function() { |
|
1094 |
var sectorInner = this.node_representation.circle_radius; |
|
1095 |
if (sectorInner !== this.lastSectorInner) { |
|
1096 |
if (this.sector) { |
|
1097 |
this.sector.destroy(); |
|
1098 |
} |
|
1099 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + sectorInner, Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner, 30, 150, 1, this.renderer.renkan.static_url+'img/link.png', this.renderer.renkan.translate("Link to another node")); |
|
1100 |
this.lastSectorInner = sectorInner; |
|
1101 |
} |
|
| 11 | 1102 |
} |
1103 |
||
1104 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1105 |
this.sector.moveTo(_pos); |
| 11 | 1106 |
} |
1107 |
||
1108 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
| 18 | 1109 |
this.sector.show(); |
| 11 | 1110 |
} |
1111 |
||
1112 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
| 18 | 1113 |
this.sector.hide(); |
| 11 | 1114 |
} |
1115 |
||
1116 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
| 18 | 1117 |
this.sector.select(); |
| 11 | 1118 |
} |
1119 |
||
| 35 | 1120 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function(_newTarget) { |
| 18 | 1121 |
this.sector.unselect(); |
| 35 | 1122 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
1123 |
this.node_representation.unselect(); |
|
1124 |
} |
|
| 11 | 1125 |
} |
1126 |
||
1127 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
| 18 | 1128 |
this.sector.destroy(); |
| 11 | 1129 |
} |
1130 |
||
1131 |
/* */ |
|
1132 |
||
| 23 | 1133 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 1134 |
|
1135 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
| 20 | 1136 |
this.type = "Edge-edit-button"; |
| 66 | 1137 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 90, 90, 1, this.renderer.renkan.static_url+'img/edit.png', this.renderer.renkan.translate("Edit")); |
| 15 | 1138 |
} |
1139 |
||
1140 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1141 |
this.sector.moveTo(_pos); |
| 15 | 1142 |
} |
1143 |
||
1144 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
| 18 | 1145 |
this.sector.show(); |
| 15 | 1146 |
} |
1147 |
||
1148 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
| 18 | 1149 |
this.sector.hide(); |
| 15 | 1150 |
} |
1151 |
||
1152 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
| 18 | 1153 |
this.sector.select(); |
| 15 | 1154 |
} |
1155 |
||
| 35 | 1156 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 1157 |
this.sector.unselect(); |
| 35 | 1158 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
1159 |
this.edge_representation.unselect(); |
|
1160 |
} |
|
| 15 | 1161 |
} |
1162 |
||
1163 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
| 23 | 1164 |
if (!this.renderer.is_dragging) { |
1165 |
this.edge_representation.openEditor(); |
|
| 15 | 1166 |
} |
1167 |
} |
|
1168 |
||
1169 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
| 18 | 1170 |
this.sector.destroy(); |
| 15 | 1171 |
} |
1172 |
||
1173 |
/* */ |
|
1174 |
||
| 23 | 1175 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 1176 |
|
1177 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
| 20 | 1178 |
this.type = "Edge-remove-button"; |
| 66 | 1179 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 270, -90, 1, this.renderer.renkan.static_url+'img/remove.png', this.renderer.renkan.translate("Remove")); |
| 15 | 1180 |
} |
1181 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 1182 |
this.sector.moveTo(_pos); |
| 15 | 1183 |
} |
1184 |
||
1185 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
| 18 | 1186 |
this.sector.show(); |
| 15 | 1187 |
} |
1188 |
||
1189 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
| 18 | 1190 |
this.sector.hide(); |
| 15 | 1191 |
} |
1192 |
||
1193 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
| 18 | 1194 |
this.sector.select(); |
| 15 | 1195 |
} |
1196 |
||
| 35 | 1197 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 1198 |
this.sector.unselect(); |
| 35 | 1199 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
1200 |
this.edge_representation.unselect(); |
|
1201 |
} |
|
| 15 | 1202 |
} |
1203 |
||
1204 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1205 |
this.renderer.removeRepresentationsOfType("editor"); |
| 66 | 1206 |
if (confirm(this.renderer.renkan.translate('Do you really wish to remove edge ') + '"' + this.edge_representation.model.get("title") + '"?')) { |
| 23 | 1207 |
this.project.removeEdge(this.edge_representation.model); |
| 15 | 1208 |
} |
1209 |
} |
|
1210 |
||
1211 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
| 18 | 1212 |
this.sector.destroy(); |
| 15 | 1213 |
} |
1214 |
||
1215 |
/* */ |
|
1216 |
||
| 70 | 1217 |
Rkns.Renderer.MiniFrame = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
1218 |
||
1219 |
Rkns.Renderer.MiniFrame.prototype.paperShift = function(_delta) { |
|
1220 |
this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale)); |
|
1221 |
this.renderer.redraw(); |
|
1222 |
} |
|
1223 |
||
1224 |
Rkns.Renderer.MiniFrame.prototype.mouseup = function(_delta) { |
|
1225 |
this.renderer.click_target = null; |
|
1226 |
this.renderer.is_dragging = false; |
|
1227 |
} |
|
1228 |
||
1229 |
/* */ |
|
1230 |
||
| 23 | 1231 |
Rkns.Renderer.Scene = function(_renkan) { |
1232 |
this.renkan = _renkan; |
|
| 20 | 1233 |
this.$ = Rkns.$(".Rk-Render"); |
| 23 | 1234 |
this.representations = []; |
| 44 | 1235 |
this.$.html(this.template(_renkan)); |
| 111 | 1236 |
this.onStatusChange(); |
| 20 | 1237 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
1238 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1239 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
| 20 | 1240 |
paper.setup(this.canvas_$[0]); |
| 2 | 1241 |
this.scale = 1; |
1242 |
this.offset = paper.view.center; |
|
1243 |
this.totalScroll = 0; |
|
| 5 | 1244 |
this.click_target = null; |
| 4 | 1245 |
this.selected_target = null; |
| 2 | 1246 |
this.edge_layer = new paper.Layer(); |
1247 |
this.node_layer = new paper.Layer(); |
|
| 67 | 1248 |
this.buttons_layer = new paper.Layer(); |
| 69 | 1249 |
|
1250 |
this.minimap = { |
|
1251 |
background_layer: new paper.Layer(), |
|
1252 |
node_layer: new paper.Layer(), |
|
1253 |
node_group: new paper.Group(), |
|
1254 |
size: new paper.Size( Rkns.Renderer._MINIMAP_WIDTH, Rkns.Renderer._MINIMAP_HEIGHT ) |
|
1255 |
} |
|
1256 |
|
|
1257 |
this.minimap.background_layer.activate(); |
|
1258 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
|
1259 |
this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
|
1260 |
this.minimap.rectangle.fillColor = '#ffffff'; |
|
1261 |
this.minimap.rectangle.strokeColor = '#cccccc'; |
|
1262 |
this.minimap.rectangle.strokeWidth = 4; |
|
1263 |
this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
|
| 70 | 1264 |
this.minimap.scale = .1; |
| 69 | 1265 |
|
1266 |
this.node_layer.activate(); |
|
1267 |
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
1268 |
this.minimap.node_group.addChild(this.minimap.cliprectangle); |
|
1269 |
this.minimap.node_group.clipped = true; |
|
1270 |
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
1271 |
this.minimap.node_group.addChild(this.minimap.miniframe); |
|
1272 |
this.minimap.miniframe.fillColor = '#f0f0ff'; |
|
1273 |
this.minimap.miniframe.strokeColor = '#8080ff'; |
|
1274 |
this.minimap.miniframe.strokeWidth = 2; |
|
| 70 | 1275 |
this.minimap.miniframe.__representation = new Rkns.Renderer.MiniFrame(this, null); |
| 69 | 1276 |
|
| 31 | 1277 |
this.bundles = []; |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1278 |
this.click_mode = false; |
| 2 | 1279 |
var _tool = new paper.Tool(), |
| 70 | 1280 |
_this = this, |
1281 |
_allowScroll = true; |
|
1282 |
|
|
| 28 | 1283 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
| 4 | 1284 |
_tool.onMouseMove = function(_event) { |
1285 |
_this.onMouseMove(_event); |
|
1286 |
} |
|
| 2 | 1287 |
_tool.onMouseDown = function(_event) { |
1288 |
_this.onMouseDown(_event); |
|
1289 |
} |
|
1290 |
_tool.onMouseDrag = function(_event) { |
|
1291 |
_this.onMouseDrag(_event); |
|
1292 |
} |
|
| 21 | 1293 |
this.canvas_$.mouseup(function(_event) { |
| 4 | 1294 |
_this.onMouseUp(_event); |
| 21 | 1295 |
}); |
| 20 | 1296 |
this.canvas_$.mousewheel(function(_event, _delta) { |
| 70 | 1297 |
if (_allowScroll) { |
1298 |
_this.onScroll(_event, _delta); |
|
1299 |
} |
|
| 21 | 1300 |
}); |
| 20 | 1301 |
this.canvas_$.dblclick(function(_event) { |
| 4 | 1302 |
_this.onDoubleClick(_event); |
| 11 | 1303 |
}); |
| 66 | 1304 |
this.canvas_$.on("dragover", function(_event) { |
1305 |
_event.stopPropagation(); |
|
1306 |
_event.preventDefault(); |
|
| 70 | 1307 |
}); |
1308 |
this.canvas_$.on("dragenter", function(_e) { |
|
1309 |
_allowScroll = false; |
|
1310 |
}); |
|
1311 |
this.canvas_$.on("dragleave", function(_e) { |
|
1312 |
_allowScroll = true; |
|
1313 |
}); |
|
| 66 | 1314 |
this.canvas_$.on("drop", function(_event) { |
1315 |
_event.stopPropagation(); |
|
1316 |
_event.preventDefault(); |
|
| 70 | 1317 |
_allowScroll = true; |
| 69 | 1318 |
if (_this.renkan.read_only) { |
1319 |
return; |
|
1320 |
} |
|
| 66 | 1321 |
var res = {} |
1322 |
Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) { |
|
1323 |
return res[t] = _event.originalEvent.dataTransfer.getData(t); |
|
1324 |
}); |
|
1325 |
var newNode = {}; |
|
| 70 | 1326 |
switch(res["text/x-iri-specific-site"]) { |
1327 |
case "twitter": |
|
1328 |
var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]), |
|
1329 |
tweetdiv = snippet.find(".tweet") |
|
1330 |
newNode.title = _renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
|
1331 |
newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
|
1332 |
newNode.image = tweetdiv.find(".avatar").attr("src"); |
|
1333 |
newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
|
1334 |
break; |
|
1335 |
case "google": |
|
1336 |
var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]); |
|
1337 |
newNode.title = snippet.find("h3:first").text().trim(); |
|
1338 |
newNode.uri = snippet.find("h3 a").attr("href"); |
|
1339 |
newNode.description = snippet.find(".st:first").text().trim(); |
|
1340 |
break; |
|
1341 |
case undefined: |
|
1342 |
default: |
|
1343 |
if (res["text/x-iri-source-uri"]) { |
|
1344 |
newNode.uri = res["text/x-iri-source-uri"]; |
|
1345 |
} |
|
1346 |
if (res["text/plain"] || res["text/x-iri-selected-text"]) { |
|
1347 |
newNode.description = (res["text/plain"] || res["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
|
1348 |
} |
|
1349 |
if (res["text/html"] || res["text/x-iri-selected-html"]) { |
|
1350 |
var snippet = Rkns.$('<div>').html(res["text/html"] || res["text/x-iri-selected-html"]); |
|
1351 |
newNode.image = snippet.find("img").attr("src") || ''; |
|
1352 |
newNode.uri = snippet.find("a").attr("href") || newNode.uri; |
|
1353 |
newNode.title = snippet.find("[title]").attr("title"); |
|
| 72 | 1354 |
newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim(); |
| 70 | 1355 |
} |
1356 |
if (res["text/uri-list"]) { |
|
1357 |
newNode.uri = res["text/uri-list"]; |
|
1358 |
} |
|
1359 |
if (res["text/x-moz-url"] && !newNode.title) { |
|
1360 |
newNode.title = (res["text/x-moz-url"].split("\n")[1] || "").trim(); |
|
1361 |
if (newNode.title === newNode.uri) { |
|
1362 |
newNode.title = false; |
|
1363 |
} |
|
1364 |
} |
|
1365 |
if (res["text/x-iri-source-title"] && !newNode.title) { |
|
1366 |
newNode.title = res["text/x-iri-source-title"]; |
|
1367 |
} |
|
| 69 | 1368 |
} |
| 68 | 1369 |
var fields = ["title", "description", "uri", "image"]; |
1370 |
for (var i = 0; i < fields.length; i++) { |
|
1371 |
var f = fields[i]; |
|
1372 |
if (res["text/x-iri-" + f]) { |
|
1373 |
newNode[f] = res["text/x-iri-" + f]; |
|
1374 |
} |
|
1375 |
} |
|
| 66 | 1376 |
if (newNode.title || newNode.description || newNode.uri) { |
1377 |
var _off = _this.canvas_$.offset(), |
|
1378 |
_point = new paper.Point([ |
|
1379 |
_event.originalEvent.pageX - _off.left, |
|
1380 |
_event.originalEvent.pageY - _off.top |
|
1381 |
]), |
|
1382 |
_coords = _this.toModelCoords(_point), |
|
1383 |
_data = { |
|
1384 |
id: Rkns.Utils.getUID('node'), |
|
1385 |
created_by: _this.renkan.current_user, |
|
1386 |
uri: newNode.uri || "", |
|
1387 |
title: newNode.title || _this.renkan.translate("Dragged resource"), |
|
1388 |
description: newNode.description || "", |
|
1389 |
image: newNode.image || "", |
|
| 70 | 1390 |
color: newNode.color || undefined, |
| 66 | 1391 |
position: { |
1392 |
x: _coords.x, |
|
1393 |
y: _coords.y |
|
1394 |
} |
|
1395 |
}; |
|
1396 |
var _node = _this.renkan.project.addNode(_data); |
|
1397 |
_this.getRepresentationByModel(_node).openEditor(); |
|
1398 |
} |
|
1399 |
}) |
|
| 11 | 1400 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
1401 |
_this.offset = new paper.Point([ |
|
| 20 | 1402 |
_this.canvas_$.width(), |
1403 |
_this.canvas_$.height() |
|
| 11 | 1404 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
| 28 | 1405 |
_this.setScale( _this.scale * Math.SQRT1_2 ); |
| 11 | 1406 |
_this.redraw(); |
1407 |
}); |
|
1408 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
1409 |
_this.offset = new paper.Point([ |
|
| 20 | 1410 |
_this.canvas_$.width(), |
1411 |
_this.canvas_$.height() |
|
| 11 | 1412 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
| 28 | 1413 |
_this.setScale( _this.scale * Math.SQRT2 ); |
| 11 | 1414 |
_this.redraw(); |
1415 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1416 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1417 |
function() { _this.$.find(".Rk-UserList").slideDown() } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1418 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1419 |
this.$.find(".Rk-Users").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1420 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1421 |
); |
| 34 | 1422 |
this.$.find(".Rk-FullScreen-Button").click(function() { |
1423 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
1424 |
_el = _this.renkan.$[0], |
|
1425 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
1426 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
1427 |
if (_isFull) { |
|
1428 |
for (var i = 0; i < _cancelMethods.length; i++) { |
|
1429 |
if (typeof document[_cancelMethods[i]] === "function") { |
|
1430 |
document[_cancelMethods[i]](); |
|
1431 |
break; |
|
1432 |
} |
|
1433 |
} |
|
1434 |
} else { |
|
1435 |
for (var i = 0; i < _requestMethods.length; i++) { |
|
1436 |
if (typeof _el[_requestMethods[i]] === "function") { |
|
1437 |
_el[_requestMethods[i]](); |
|
1438 |
break; |
|
1439 |
} |
|
1440 |
} |
|
1441 |
} |
|
1442 |
}); |
|
1443 |
this.$.find(".Rk-AddNode-Button").click(function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1444 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1445 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1446 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1447 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1448 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE; |
| 69 | 1449 |
_this.notif_$.text(_renkan.translate("Click on the background canvas to add a node")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1450 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1451 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1452 |
this.$.find(".Rk-AddEdge-Button").click(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1453 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE || _this.click_mode === Rkns.Renderer._CLICKMODE_ENDEDGE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1454 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1455 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1456 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1457 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE; |
| 69 | 1458 |
_this.notif_$.text(_renkan.translate("Click on a first node to start the edge")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1459 |
} |
| 34 | 1460 |
}); |
| 70 | 1461 |
this.$.find(".Rk-Bookmarklet-Button") |
1462 |
.attr("href","javascript:" + Rkns.Renderer._BOOKMARKLET_CODE(_renkan)) |
|
1463 |
.click(function(){ |
|
1464 |
_this.notif_$ |
|
1465 |
.text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan.")) |
|
1466 |
.fadeIn() |
|
1467 |
.delay(5000) |
|
1468 |
.fadeOut(); |
|
1469 |
return false; |
|
1470 |
}); |
|
| 34 | 1471 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
1472 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show(); |
|
1473 |
}).mouseout(function() { |
|
1474 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
1475 |
}); |
|
| 70 | 1476 |
this.$.find(".Rk-Fold-Bins").click(function() { |
1477 |
var bins = _renkan.$.find(".Rk-Bins"); |
|
1478 |
if (bins.offset().left < 0) { |
|
1479 |
bins.animate({left: 0},250); |
|
1480 |
_this.$.animate({left: 300},250,function() { |
|
1481 |
var w = _this.$.width(); |
|
1482 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1483 |
}); |
|
1484 |
$(this).html("«"); |
|
1485 |
} else { |
|
1486 |
bins.animate({left: -300},250); |
|
1487 |
_this.$.animate({left: 0},250,function() { |
|
1488 |
var w = _this.$.width(); |
|
1489 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1490 |
}); |
|
1491 |
$(this).html("»"); |
|
1492 |
} |
|
1493 |
}); |
|
| 34 | 1494 |
|
| 2 | 1495 |
paper.view.onResize = function(_event) { |
| 70 | 1496 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
| 69 | 1497 |
_this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size) |
1498 |
_this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4])); |
|
1499 |
_this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size); |
|
| 2 | 1500 |
_this.redraw(); |
1501 |
} |
|
| 23 | 1502 |
|
1503 |
var _thRedraw = Rkns._.throttle(function() { |
|
1504 |
_this.redraw(); |
|
1505 |
},50); |
|
1506 |
|
|
1507 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
1508 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
| 44 | 1509 |
this.renkan.project.on("change:title", function() { |
1510 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
|
1511 |
}); |
|
1512 |
|
|
1513 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() { |
|
1514 |
_renkan.project.set({"title": $(this).val()}); |
|
1515 |
}) |
|
1516 |
|
|
| 34 | 1517 |
this.renkan.project.get("users").each(function(_user) { |
1518 |
_this.addUser(_user); |
|
| 44 | 1519 |
}); |
| 23 | 1520 |
|
| 34 | 1521 |
this.renkan.project.on("add:users", function(_user) { |
1522 |
_this.addUser(_user); |
|
1523 |
}); |
|
| 23 | 1524 |
this.renkan.project.on("add:nodes", function(_node) { |
1525 |
_this.addRepresentation("Node", _node); |
|
1526 |
_thRedraw(); |
|
1527 |
}); |
|
1528 |
this.renkan.project.on("add:edges", function(_edge) { |
|
1529 |
_this.addRepresentation("Edge", _edge); |
|
1530 |
_thRedraw(); |
|
1531 |
}); |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1532 |
this.renkan.project.on("change:title", function(_model, _title) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1533 |
var el = $(".Rk-PadTitle"); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1534 |
if (el.is("input")) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1535 |
if (el.val() !== _title) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1536 |
el.val(_title); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1537 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1538 |
} else { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1539 |
el.text(_title); |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1540 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1541 |
}); |
| 23 | 1542 |
|
1543 |
this.redraw(); |
|
| 69 | 1544 |
window.setInterval(function() { |
1545 |
_this.rescaleMinimap() |
|
1546 |
}, 2000); |
|
| 2 | 1547 |
} |
1548 |
||
| 20 | 1549 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
| 66 | 1550 |
'<div class="Rk-TopBar"><% if (read_only) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>' |
1551 |
+ '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>' |
|
| 34 | 1552 |
+ '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
| 66 | 1553 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Full Screen")%></div></div></div>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1554 |
+ '<% if (!read_only) { %>' |
| 66 | 1555 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div>' |
1556 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div>' |
|
| 111 | 1557 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div>' |
| 70 | 1558 |
+ '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">' |
1559 |
+ '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a>' |
|
| 34 | 1560 |
+ '<div class="Rk-TopBar-Separator"></div></div>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1561 |
+ '<% } %>' |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1562 |
+ '<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>' |
| 70 | 1563 |
+ '<% if (show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>' |
| 66 | 1564 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>' |
| 20 | 1565 |
+ '</div>' |
| 11 | 1566 |
); |
1567 |
||
| 31 | 1568 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1569 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
1570 |
return ( |
|
1571 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
1572 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
1573 |
); |
|
1574 |
}); |
|
1575 |
if (typeof _bundle !== "undefined") { |
|
1576 |
_bundle.edges.push(_edgeRepr) |
|
1577 |
} else { |
|
1578 |
_bundle = { |
|
1579 |
from: _edgeRepr.from_representation, |
|
1580 |
to: _edgeRepr.to_representation, |
|
1581 |
edges: [ _edgeRepr ], |
|
1582 |
getPosition: function(_er) { |
|
1583 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
1584 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
1585 |
} |
|
1586 |
} |
|
1587 |
this.bundles.push(_bundle); |
|
1588 |
} |
|
1589 |
return _bundle; |
|
1590 |
} |
|
1591 |
||
| 111 | 1592 |
Rkns.Renderer.Scene.prototype.onStatusChange = function() { |
1593 |
var savebtn = this.$.find(".Rk-Save-Button"), |
|
1594 |
tip = savebtn.find(".Rk-TopBar-Tooltip-Contents"); |
|
1595 |
if (this.renkan.read_only) { |
|
1596 |
savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly"); |
|
1597 |
tip.text(this.renkan.translate("Connection lost")); |
|
1598 |
} else { |
|
1599 |
if (this.renkan.snapshot_mode) { |
|
1600 |
savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online"); |
|
1601 |
tip.text(this.renkan.translate("Archive Project")); |
|
1602 |
} else { |
|
1603 |
savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online"); |
|
1604 |
tip.text(this.renkan.translate("Auto-save enabled")); |
|
1605 |
} |
|
1606 |
} |
|
1607 |
} |
|
1608 |
||
| 28 | 1609 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { |
1610 |
this.scale = _newScale; |
|
1611 |
this.redraw(); |
|
1612 |
} |
|
| 69 | 1613 |
|
1614 |
Rkns.Renderer.Scene.prototype.redrawMiniframe = function() { |
|
1615 |
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
|
1616 |
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
|
1617 |
this.minimap.miniframe.fitBounds(topleft, bottomright); |
|
1618 |
} |
|
1619 |
||
1620 |
Rkns.Renderer.Scene.prototype.rescaleMinimap = function() { |
|
| 43 | 1621 |
var nodes = this.renkan.project.get("nodes") |
1622 |
if (nodes.length > 1) { |
|
1623 |
var _xx = nodes.map(function(_node) { return _node.get("position").x }), |
|
1624 |
_yy = nodes.map(function(_node) { return _node.get("position").y }), |
|
| 26 | 1625 |
_minx = Math.min.apply(Math, _xx), |
1626 |
_miny = Math.min.apply(Math, _yy), |
|
1627 |
_maxx = Math.max.apply(Math, _xx), |
|
1628 |
_maxy = Math.max.apply(Math, _yy); |
|
| 69 | 1629 |
var _scale = Math.min(this.scale * .8 * Rkns.Renderer._MINIMAP_WIDTH / paper.view.bounds.width, this.scale * .8 * Rkns.Renderer._MINIMAP_HEIGHT / paper.view.bounds.height, (Rkns.Renderer._MINIMAP_WIDTH - 2 * Rkns.Renderer._MINIMAP_MARGIN_X) / (_maxx - _minx), (Rkns.Renderer._MINIMAP_HEIGHT - 2 * Rkns.Renderer._MINIMAP_MARGIN_Y) / (_maxy - _miny)); |
1630 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
1631 |
this.minimap.scale = _scale; |
|
| 26 | 1632 |
} |
| 43 | 1633 |
if (nodes.length === 1) { |
| 70 | 1634 |
this.minimap.scale = .1; |
1635 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale)); |
|
| 43 | 1636 |
} |
| 69 | 1637 |
this.redraw(); |
| 25 | 1638 |
} |
| 69 | 1639 |
|
| 7 | 1640 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
| 2 | 1641 |
return _point.multiply(this.scale).add(this.offset); |
1642 |
} |
|
1643 |
||
| 69 | 1644 |
Rkns.Renderer.Scene.prototype.toMinimapCoords = function(_point) { |
1645 |
return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
|
1646 |
} |
|
| 2 | 1647 |
|
| 7 | 1648 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
| 2 | 1649 |
return _point.subtract(this.offset).divide(this.scale); |
| 1 | 1650 |
} |
1651 |
||
| 23 | 1652 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
1653 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
1654 |
this.representations.push(_repr); |
|
1655 |
return _repr; |
|
1656 |
} |
|
1657 |
||
1658 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
1659 |
var _this = this; |
|
1660 |
_collection.forEach(function(_model) { |
|
1661 |
_this.addRepresentation(_type, _model); |
|
| 1 | 1662 |
}); |
1663 |
} |
|
1664 |
||
| 34 | 1665 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
1666 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
1667 |
); |
|
1668 |
||
1669 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) { |
|
1670 |
if (_user.get("_id") === this.renkan.current_user) { |
|
1671 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title")); |
|
1672 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color")); |
|
1673 |
} else { |
|
1674 |
this.$.find(".Rk-UserList").append( |
|
1675 |
Rkns.$( |
|
1676 |
this.userTemplate({ |
|
1677 |
name: _user.get("title"), |
|
1678 |
background: _user.get("color") |
|
1679 |
}) |
|
1680 |
) |
|
1681 |
); |
|
1682 |
} |
|
1683 |
} |
|
1684 |
||
| 23 | 1685 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
1686 |
_representation.destroy(); |
|
1687 |
this.representations = Rkns._(this.representations).reject( |
|
1688 |
function(_repr) { |
|
1689 |
return _repr == _representation |
|
1690 |
} |
|
1691 |
); |
|
| 4 | 1692 |
} |
1693 |
||
| 23 | 1694 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
1695 |
return Rkns._(this.representations).find(function(_repr) { |
|
1696 |
return _repr.model === _model; |
|
1697 |
}); |
|
| 5 | 1698 |
} |
1699 |
||
| 23 | 1700 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
1701 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
1702 |
return _repr.type == _type; |
|
| 5 | 1703 |
}), |
1704 |
_this = this; |
|
| 23 | 1705 |
Rkns._(_representations).each(function(_repr) { |
1706 |
_this.removeRepresentation(_repr); |
|
| 5 | 1707 |
}); |
1708 |
} |
|
1709 |
||
| 26 | 1710 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
1711 |
var _repr = this.getRepresentationByModel(_model); |
|
1712 |
if (_repr) { |
|
1713 |
_repr.highlight(); |
|
1714 |
} |
|
1715 |
} |
|
1716 |
||
1717 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
|
1718 |
Rkns._(this.representations).each(function(_repr) { |
|
1719 |
_repr.unhighlight(); |
|
1720 |
}); |
|
1721 |
} |
|
1722 |
||
| 7 | 1723 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
| 23 | 1724 |
Rkns._(this.representations).each(function(_representation) { |
1725 |
_representation.redraw(); |
|
| 2 | 1726 |
}); |
| 69 | 1727 |
this.redrawMiniframe(); |
| 2 | 1728 |
paper.view.draw(); |
1729 |
} |
|
1730 |
||
| 11 | 1731 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
| 23 | 1732 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
| 11 | 1733 |
_tmpEdge.end_pos = _point; |
| 23 | 1734 |
_tmpEdge.from_representation = _from; |
| 11 | 1735 |
_tmpEdge.redraw(); |
1736 |
this.click_target = _tmpEdge; |
|
1737 |
} |
|
1738 |
||
| 21 | 1739 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
| 23 | 1740 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
1741 |
var _newTarget = _hitResult.item.__representation; |
|
1742 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
| 4 | 1743 |
if (this.selected_target) { |
| 7 | 1744 |
this.selected_target.unselect(_newTarget); |
| 4 | 1745 |
} |
| 7 | 1746 |
_newTarget.select(this.selected_target); |
1747 |
this.selected_target = _newTarget; |
|
| 4 | 1748 |
} |
1749 |
} else { |
|
1750 |
if (this.selected_target) { |
|
| 7 | 1751 |
this.selected_target.unselect(null); |
| 4 | 1752 |
} |
1753 |
this.selected_target = null; |
|
1754 |
} |
|
1755 |
} |
|
1756 |
||
| 82 | 1757 |
Rkns.Renderer.Scene.prototype.paperShift = function(_delta) { |
1758 |
this.offset = this.offset.add(_delta); |
|
1759 |
this.redraw(); |
|
1760 |
} |
|
1761 |
||
| 21 | 1762 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
1763 |
var _hitResult = paper.project.hitTest(_event.point); |
|
1764 |
if (this.is_dragging) { |
|
| 82 | 1765 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
| 21 | 1766 |
this.click_target.paperShift(_event.delta); |
1767 |
} else { |
|
| 95 | 1768 |
this.paperShift(_event.delta); |
| 21 | 1769 |
} |
1770 |
} else { |
|
1771 |
this.findTarget(_hitResult); |
|
1772 |
} |
|
1773 |
} |
|
1774 |
||
| 7 | 1775 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1776 |
if (!this.click_target || this.click_target.type !== "temp-edge") { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1777 |
this.removeRepresentationsOfType("editor"); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1778 |
this.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1779 |
var _hitResult = paper.project.hitTest(_event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1780 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1781 |
this.click_target = _hitResult.item.__representation; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1782 |
if (this.click_target.type === "Node-link-button") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1783 |
this.removeRepresentationsOfType("editor"); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1784 |
this.addTempEdge(this.click_target.node_representation, _event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1785 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1786 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1787 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1788 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1789 |
var _coords = this.toModelCoords(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1790 |
_data = { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1791 |
id: Rkns.Utils.getUID('node'), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1792 |
created_by: this.renkan.current_user, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1793 |
position: { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1794 |
x: _coords.x, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1795 |
y: _coords.y |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1796 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1797 |
}; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1798 |
_node = this.renkan.project.addNode(_data); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1799 |
this.getRepresentationByModel(_node).openEditor(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1800 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1801 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1802 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1803 |
if (this.click_mode) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1804 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1805 |
this.removeRepresentationsOfType("editor"); |
| 11 | 1806 |
this.addTempEdge(this.click_target, _event.point); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1807 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1808 |
this.notif_$.fadeOut(function() { |
| 66 | 1809 |
Rkns.$(this).html(_renkan.translate("Click on a second node to complete the edge")).fadeIn(); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1810 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1811 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1812 |
this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1813 |
this.click_mode = false; |
| 11 | 1814 |
} |
| 2 | 1815 |
} |
| 1 | 1816 |
} |
| 2 | 1817 |
|
| 7 | 1818 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
| 5 | 1819 |
this.is_dragging = true; |
| 21 | 1820 |
this.onMouseMove(_event); |
| 2 | 1821 |
} |
1822 |
||
| 7 | 1823 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
| 5 | 1824 |
if (this.click_target) { |
| 21 | 1825 |
var _off = this.canvas_$.offset(); |
1826 |
this.click_target.mouseup( |
|
1827 |
{ |
|
1828 |
point: new paper.Point([ |
|
1829 |
_event.pageX - _off.left, |
|
1830 |
_event.pageY - _off.top |
|
1831 |
]) |
|
1832 |
} |
|
1833 |
); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1834 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1835 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1836 |
this.is_dragging = false; |
| 4 | 1837 |
} |
1838 |
} |
|
1839 |
||
| 7 | 1840 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
| 3 | 1841 |
this.totalScroll += _scrolldelta; |
| 2 | 1842 |
if (Math.abs(this.totalScroll) >= 1) { |
| 20 | 1843 |
var _off = this.canvas_$.offset(), |
| 3 | 1844 |
_delta = new paper.Point([ |
1845 |
_event.pageX - _off.left, |
|
1846 |
_event.pageY - _off.top |
|
1847 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
| 2 | 1848 |
if (this.totalScroll > 0) { |
| 3 | 1849 |
this.offset = this.offset.subtract(_delta); |
| 28 | 1850 |
this.setScale( this.scale * Math.SQRT2 ); |
| 2 | 1851 |
} else { |
| 3 | 1852 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
| 28 | 1853 |
this.setScale( this.scale * Math.SQRT1_2); |
| 2 | 1854 |
} |
1855 |
this.totalScroll = 0; |
|
1856 |
this.redraw(); |
|
1857 |
} |
|
1858 |
} |
|
| 4 | 1859 |
|
| 7 | 1860 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1861 |
if (this.renkan.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1862 |
return; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
57
diff
changeset
|
1863 |
} |
| 20 | 1864 |
var _off = this.canvas_$.offset(), |
| 4 | 1865 |
_point = new paper.Point([ |
1866 |
_event.pageX - _off.left, |
|
1867 |
_event.pageY - _off.top |
|
1868 |
]); |
|
1869 |
var _hitResult = paper.project.hitTest(_point); |
|
| 23 | 1870 |
if (!_hitResult || typeof _hitResult.item.__representation === "undefined") { |
| 8 | 1871 |
var _coords = this.toModelCoords(_point), |
| 23 | 1872 |
_data = { |
1873 |
id: Rkns.Utils.getUID('node'), |
|
1874 |
created_by: this.renkan.current_user, |
|
| 8 | 1875 |
position: { |
1876 |
x: _coords.x, |
|
1877 |
y: _coords.y |
|
1878 |
} |
|
| 23 | 1879 |
}; |
1880 |
_node = this.renkan.project.addNode(_data); |
|
1881 |
this.getRepresentationByModel(_node).openEditor(); |
|
| 4 | 1882 |
} |
1883 |
paper.view.draw(); |
|
1884 |
} |