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