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