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