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