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