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