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