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