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