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