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