| author | rougeronj |
| Tue, 02 Jun 2015 16:42:02 +0200 | |
| changeset 455 | 18b9be54174d |
| parent 453 | 04b7d46e9d67 |
| parent 443 | 4c7ab16e5845 |
| child 463 | 41325cc50574 |
| child 471 | e0c7be5dc02c |
| permissions | -rw-r--r-- |
| 284 | 1 |
|
| 297 | 2 |
define(['jquery', 'underscore', 'filesaver', 'requtils', 'renderer/miniframe'], function ($, _, filesaver, requtils, MiniFrame) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
3 |
'use strict'; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
4 |
|
| 284 | 5 |
var Utils = requtils.getUtils(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
6 |
|
| 284 | 7 |
/* Scene Begin */ |
8 |
||
9 |
var Scene = function(_renkan) { |
|
10 |
this.renkan = _renkan; |
|
11 |
this.$ = $(".Rk-Render"); |
|
12 |
this.representations = []; |
|
|
419
4f458e6d32bd
export the templates of scene and edgeeditor to html files
rougeronj
parents:
414
diff
changeset
|
13 |
this.$.html(_renkan.options.templates['templates/scene.html'](_renkan)); |
| 284 | 14 |
this.onStatusChange(); |
15 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
16 |
this.labels_$ = this.$.find(".Rk-Labels"); |
|
|
445
705a2e9c6c9d
Add popup_editor and editor_panel option to allow the editor panel to bin in an external div
rougeronj
parents:
435
diff
changeset
|
17 |
if (!_renkan.options.popup_editor){ |
| 447 | 18 |
this.editor_$ = $("#" + _renkan.options.editor_panel); |
19 |
}else{ |
|
20 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
445
705a2e9c6c9d
Add popup_editor and editor_panel option to allow the editor panel to bin in an external div
rougeronj
parents:
435
diff
changeset
|
21 |
} |
| 284 | 22 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
23 |
paper.setup(this.canvas_$[0]); |
|
24 |
this.scale = 1; |
|
25 |
this.initialScale = 1; |
|
26 |
this.offset = paper.view.center; |
|
27 |
this.totalScroll = 0; |
|
| 450 | 28 |
this.hiddenNodes = []; |
| 284 | 29 |
this.mouse_down = false; |
30 |
this.click_target = null; |
|
31 |
this.selected_target = null; |
|
32 |
this.edge_layer = new paper.Layer(); |
|
33 |
this.node_layer = new paper.Layer(); |
|
34 |
this.buttons_layer = new paper.Layer(); |
|
35 |
this.delete_list = []; |
|
| 307 | 36 |
this.redrawActive = true; |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
37 |
|
| 284 | 38 |
if (_renkan.options.show_minimap) { |
39 |
this.minimap = { |
|
40 |
background_layer: new paper.Layer(), |
|
41 |
edge_layer: new paper.Layer(), |
|
42 |
node_layer: new paper.Layer(), |
|
43 |
node_group: new paper.Group(), |
|
44 |
size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height ) |
|
45 |
}; |
|
46 |
||
47 |
this.minimap.background_layer.activate(); |
|
48 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
|
49 |
this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
|
50 |
this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
|
51 |
this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color; |
|
52 |
this.minimap.rectangle.strokeWidth = 4; |
|
53 |
this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
54 |
this.minimap.scale = 0.1; |
| 284 | 55 |
|
56 |
this.minimap.node_layer.activate(); |
|
57 |
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
58 |
this.minimap.node_group.addChild(this.minimap.cliprectangle); |
|
59 |
this.minimap.node_group.clipped = true; |
|
60 |
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
61 |
this.minimap.node_group.addChild(this.minimap.miniframe); |
|
62 |
this.minimap.miniframe.fillColor = '#c0c0ff'; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
63 |
this.minimap.miniframe.opacity = 0.3; |
| 284 | 64 |
this.minimap.miniframe.strokeColor = '#000080'; |
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
65 |
this.minimap.miniframe.strokeWidth = 2; |
| 284 | 66 |
this.minimap.miniframe.__representation = new MiniFrame(this, null); |
67 |
} |
|
68 |
||
69 |
this.throttledPaperDraw = _(function() { |
|
70 |
paper.view.draw(); |
|
| 433 | 71 |
}).throttle(100).value(); |
| 284 | 72 |
|
73 |
this.bundles = []; |
|
74 |
this.click_mode = false; |
|
75 |
||
76 |
var _this = this, |
|
77 |
_allowScroll = true, |
|
78 |
_originalScale = 1, |
|
79 |
_zooming = false, |
|
80 |
_lastTapX = 0, |
|
81 |
_lastTapY = 0; |
|
82 |
||
83 |
this.image_cache = {}; |
|
84 |
this.icon_cache = {}; |
|
85 |
||
| 453 | 86 |
['edit', 'remove', 'hide', 'show', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) { |
| 284 | 87 |
var img = new Image(); |
88 |
img.src = _renkan.options.static_url + 'img/' + imgname + '.png'; |
|
89 |
_this.icon_cache[imgname] = img; |
|
90 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
91 |
|
| 284 | 92 |
var throttledMouseMove = _.throttle(function(_event, _isTouch) { |
93 |
_this.onMouseMove(_event, _isTouch); |
|
94 |
}, Utils._MOUSEMOVE_RATE); |
|
95 |
||
96 |
this.canvas_$.on({ |
|
97 |
mousedown: function(_event) { |
|
98 |
_event.preventDefault(); |
|
99 |
_this.onMouseDown(_event, false); |
|
100 |
}, |
|
101 |
mousemove: function(_event) { |
|
102 |
_event.preventDefault(); |
|
103 |
throttledMouseMove(_event, false); |
|
104 |
}, |
|
105 |
mouseup: function(_event) { |
|
106 |
_event.preventDefault(); |
|
107 |
_this.onMouseUp(_event, false); |
|
108 |
}, |
|
109 |
mousewheel: function(_event, _delta) { |
|
110 |
if(_renkan.options.zoom_on_scroll) { |
|
111 |
_event.preventDefault(); |
|
112 |
if (_allowScroll) { |
|
113 |
_this.onScroll(_event, _delta); |
|
114 |
} |
|
115 |
} |
|
116 |
}, |
|
117 |
touchstart: function(_event) { |
|
118 |
_event.preventDefault(); |
|
119 |
var _touches = _event.originalEvent.touches[0]; |
|
120 |
if ( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
121 |
_renkan.options.allow_double_click && |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
122 |
new Date() - _lastTap < Utils._DOUBLETAP_DELAY && |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
123 |
( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE ) |
| 284 | 124 |
) { |
125 |
_lastTap = 0; |
|
126 |
_this.onDoubleClick(_touches); |
|
127 |
} else { |
|
128 |
_lastTap = new Date(); |
|
129 |
_lastTapX = _touches.pageX; |
|
130 |
_lastTapY = _touches.pageY; |
|
131 |
_originalScale = _this.scale; |
|
132 |
_zooming = false; |
|
133 |
_this.onMouseDown(_touches, true); |
|
134 |
} |
|
135 |
}, |
|
136 |
touchmove: function(_event) { |
|
137 |
_event.preventDefault(); |
|
138 |
_lastTap = 0; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
139 |
if (_event.originalEvent.touches.length === 1) { |
| 284 | 140 |
_this.onMouseMove(_event.originalEvent.touches[0], true); |
141 |
} else { |
|
142 |
if (!_zooming) { |
|
143 |
_this.onMouseUp(_event.originalEvent.touches[0], true); |
|
144 |
_this.click_target = null; |
|
145 |
_this.is_dragging = false; |
|
146 |
_zooming = true; |
|
147 |
} |
|
148 |
if (_event.originalEvent.scale === "undefined") { |
|
149 |
return; |
|
150 |
} |
|
151 |
var _newScale = _event.originalEvent.scale * _originalScale, |
|
152 |
_scaleRatio = _newScale / _this.scale, |
|
153 |
_newOffset = new paper.Point([ |
|
154 |
_this.canvas_$.width(), |
|
155 |
_this.canvas_$.height() |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
156 |
]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio )); |
| 284 | 157 |
_this.setScale(_newScale, _newOffset); |
158 |
} |
|
159 |
}, |
|
160 |
touchend: function(_event) { |
|
161 |
_event.preventDefault(); |
|
162 |
_this.onMouseUp(_event.originalEvent.changedTouches[0], true); |
|
163 |
}, |
|
164 |
dblclick: function(_event) { |
|
165 |
_event.preventDefault(); |
|
166 |
if (_renkan.options.allow_double_click) { |
|
167 |
_this.onDoubleClick(_event); |
|
168 |
} |
|
169 |
}, |
|
170 |
mouseleave: function(_event) { |
|
171 |
_event.preventDefault(); |
|
172 |
_this.onMouseUp(_event, false); |
|
173 |
_this.click_target = null; |
|
174 |
_this.is_dragging = false; |
|
175 |
}, |
|
176 |
dragover: function(_event) { |
|
177 |
_event.preventDefault(); |
|
178 |
}, |
|
179 |
dragenter: function(_event) { |
|
180 |
_event.preventDefault(); |
|
181 |
_allowScroll = false; |
|
182 |
}, |
|
183 |
dragleave: function(_event) { |
|
184 |
_event.preventDefault(); |
|
185 |
_allowScroll = true; |
|
186 |
}, |
|
187 |
drop: function(_event) { |
|
188 |
_event.preventDefault(); |
|
189 |
_allowScroll = true; |
|
190 |
var res = {}; |
|
| 433 | 191 |
_.each(_event.originalEvent.dataTransfer.types, function(t) { |
| 284 | 192 |
try { |
193 |
res[t] = _event.originalEvent.dataTransfer.getData(t); |
|
194 |
} catch(e) {} |
|
195 |
}); |
|
196 |
var text = _event.originalEvent.dataTransfer.getData("Text"); |
|
197 |
if (typeof text === "string") { |
|
198 |
switch(text[0]) { |
|
199 |
case "{": |
|
200 |
case "[": |
|
201 |
try { |
|
202 |
var data = JSON.parse(text); |
|
| 433 | 203 |
_.extend(res,data); |
| 284 | 204 |
} |
205 |
catch(e) { |
|
206 |
if (!res["text/plain"]) { |
|
207 |
res["text/plain"] = text; |
|
208 |
} |
|
209 |
} |
|
210 |
break; |
|
211 |
case "<": |
|
212 |
if (!res["text/html"]) { |
|
213 |
res["text/html"] = text; |
|
214 |
} |
|
215 |
break; |
|
216 |
default: |
|
217 |
if (!res["text/plain"]) { |
|
218 |
res["text/plain"] = text; |
|
219 |
} |
|
220 |
} |
|
221 |
} |
|
222 |
var url = _event.originalEvent.dataTransfer.getData("URL"); |
|
223 |
if (url && !res["text/uri-list"]) { |
|
224 |
res["text/uri-list"] = url; |
|
225 |
} |
|
226 |
_this.dropData(res, _event.originalEvent); |
|
227 |
} |
|
228 |
}); |
|
229 |
||
230 |
var bindClick = function(selector, fname) { |
|
231 |
_this.$.find(selector).click(function(evt) { |
|
232 |
_this[fname](evt); |
|
233 |
return false; |
|
234 |
}); |
|
235 |
}; |
|
236 |
||
237 |
bindClick(".Rk-ZoomOut", "zoomOut"); |
|
238 |
bindClick(".Rk-ZoomIn", "zoomIn"); |
|
239 |
bindClick(".Rk-ZoomFit", "autoScale"); |
|
240 |
this.$.find(".Rk-ZoomSave").click( function() { |
|
241 |
// Save scale and offset point |
|
| 450 | 242 |
_this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.hiddenNodes } ); |
| 284 | 243 |
}); |
244 |
this.$.find(".Rk-ZoomSetSaved").click( function() { |
|
245 |
var view = _this.renkan.project.get("views").last(); |
|
246 |
if(view){ |
|
| 299 | 247 |
_this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); |
|
451
278f8da09c04
Add retro-compatibility with previous model - If no "hidden_nodes attributes in the previous view, we set the current HiddenNodes to an empty array
rougeronj
parents:
450
diff
changeset
|
248 |
_this.hiddenNodes = view.get("hidden_nodes") || []; |
| 450 | 249 |
_this.hideNodes(); |
| 284 | 250 |
} |
251 |
}); |
|
| 450 | 252 |
this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() { |
253 |
_this.showNodes(true); |
|
254 |
_this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() { |
|
255 |
_this.hideNodes(false); |
|
256 |
}); |
|
257 |
}); |
|
258 |
this.$.find(".Rk-ShowHiddenNodes").click( function() { |
|
259 |
_this.showNodes(false); |
|
260 |
_this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" ); |
|
261 |
}); |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
262 |
if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){ |
| 284 | 263 |
this.$.find(".Rk-ZoomSetSaved").show(); |
264 |
} |
|
265 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
266 |
function() { _this.$.find(".Rk-UserList").slideDown(); } |
|
267 |
); |
|
268 |
this.$.find(".Rk-Users").mouseleave( |
|
269 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
270 |
); |
|
271 |
bindClick(".Rk-FullScreen-Button", "fullScreen"); |
|
272 |
bindClick(".Rk-AddNode-Button", "addNodeBtn"); |
|
273 |
bindClick(".Rk-AddEdge-Button", "addEdgeBtn"); |
|
274 |
bindClick(".Rk-Save-Button", "save"); |
|
275 |
bindClick(".Rk-Open-Button", "open"); |
|
| 297 | 276 |
bindClick(".Rk-Export-Button", "exportProject"); |
| 284 | 277 |
this.$.find(".Rk-Bookmarklet-Button") |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
278 |
/*jshint scripturl:true */ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
279 |
.attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan)) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
280 |
.click(function(){ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
281 |
_this.notif_$ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
282 |
.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.")) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
283 |
.fadeIn() |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
284 |
.delay(5000) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
285 |
.fadeOut(); |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
286 |
return false; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
287 |
}); |
| 284 | 288 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
289 |
$(this).find(".Rk-TopBar-Tooltip").show(); |
|
290 |
}).mouseout(function() { |
|
291 |
$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
292 |
}); |
|
293 |
bindClick(".Rk-Fold-Bins", "foldBins"); |
|
294 |
||
295 |
paper.view.onResize = function(_event) { |
|
| 396 | 296 |
var _ratio, |
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
297 |
newWidth = _event.width, |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
298 |
newHeight = _event.height; |
| 396 | 299 |
|
| 284 | 300 |
if (_this.minimap) { |
301 |
_this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size); |
|
302 |
_this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4])); |
|
303 |
_this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size); |
|
304 |
} |
|
| 396 | 305 |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
306 |
var ratioH = newHeight/(newHeight-_event.delta.height), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
307 |
ratioW = newWidth/(newWidth-_event.delta.width); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
308 |
if (newHeight < newWidth) { |
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
309 |
_ratio = ratioH; |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
310 |
} else { |
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
311 |
_ratio = ratioW; |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
312 |
} |
| 396 | 313 |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
314 |
_this.resizeZoom(ratioW, ratioH, _ratio); |
| 396 | 315 |
|
316 |
_this.redraw(); |
|
317 |
||
| 284 | 318 |
}; |
319 |
||
320 |
var _thRedraw = _.throttle(function() { |
|
321 |
_this.redraw(); |
|
322 |
},50); |
|
323 |
||
324 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
325 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
326 |
this.renkan.project.on("change:title", function() { |
|
327 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
|
328 |
}); |
|
329 |
||
330 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() { |
|
331 |
_renkan.project.set({"title": $(this).val()}); |
|
332 |
}); |
|
333 |
||
334 |
var _thRedrawUsers = _.throttle(function() { |
|
335 |
_this.redrawUsers(); |
|
336 |
}, 100); |
|
337 |
||
338 |
_thRedrawUsers(); |
|
339 |
||
340 |
// register model events |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
341 |
this.renkan.project.on("change:saveStatus", function(){ |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
342 |
switch (_this.renkan.project.get("saveStatus")) { |
| 396 | 343 |
case 0: //clean |
344 |
_this.$.find(".Rk-Save-Button").removeClass("to-save"); |
|
345 |
_this.$.find(".Rk-Save-Button").removeClass("saving"); |
|
346 |
_this.$.find(".Rk-Save-Button").addClass("saved"); |
|
347 |
break; |
|
348 |
case 1: //dirty |
|
349 |
_this.$.find(".Rk-Save-Button").removeClass("saved"); |
|
350 |
_this.$.find(".Rk-Save-Button").removeClass("saving"); |
|
351 |
_this.$.find(".Rk-Save-Button").addClass("to-save"); |
|
352 |
break; |
|
353 |
case 2: //saving |
|
354 |
_this.$.find(".Rk-Save-Button").removeClass("saved"); |
|
355 |
_this.$.find(".Rk-Save-Button").removeClass("to-save"); |
|
356 |
_this.$.find(".Rk-Save-Button").addClass("saving"); |
|
357 |
break; |
|
358 |
} |
|
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
340
diff
changeset
|
359 |
}); |
| 396 | 360 |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
361 |
this.renkan.project.on("change:loadingStatus", function(){ |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
362 |
if (_this.renkan.project.get("loadingStatus")){ |
| 396 | 363 |
var animate = _this.$.find(".loader").addClass("run"); |
364 |
var timer = setTimeout(function(){ |
|
365 |
_this.$.find(".loader").hide(250); |
|
366 |
}, 3000); |
|
367 |
} |
|
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
368 |
}); |
| 396 | 369 |
|
| 284 | 370 |
this.renkan.project.on("add:users remove:users", _thRedrawUsers); |
371 |
||
372 |
this.renkan.project.on("add:views remove:views", function(_node) { |
|
373 |
if(_this.renkan.project.get('views').length > 0) { |
|
374 |
_this.$.find(".Rk-ZoomSetSaved").show(); |
|
375 |
} |
|
376 |
else { |
|
377 |
_this.$.find(".Rk-ZoomSetSaved").hide(); |
|
378 |
} |
|
379 |
}); |
|
380 |
||
381 |
this.renkan.project.on("add:nodes", function(_node) { |
|
382 |
_this.addRepresentation("Node", _node); |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
383 |
if (!_this.renkan.project.get("loadingStatus")){ |
| 396 | 384 |
_thRedraw(); |
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
385 |
} |
| 284 | 386 |
}); |
387 |
this.renkan.project.on("add:edges", function(_edge) { |
|
388 |
_this.addRepresentation("Edge", _edge); |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
389 |
if (!_this.renkan.project.get("loadingStatus")){ |
| 396 | 390 |
_thRedraw(); |
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
391 |
} |
| 284 | 392 |
}); |
393 |
this.renkan.project.on("change:title", function(_model, _title) { |
|
394 |
var el = _this.$.find(".Rk-PadTitle"); |
|
395 |
if (el.is("input")) { |
|
396 |
if (el.val() !== _title) { |
|
397 |
el.val(_title); |
|
398 |
} |
|
399 |
} else { |
|
400 |
el.text(_title); |
|
401 |
} |
|
402 |
}); |
|
403 |
||
404 |
if (_renkan.options.size_bug_fix) { |
|
405 |
var _delay = ( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
406 |
typeof _renkan.options.size_bug_fix === "number" ? |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
407 |
_renkan.options.size_bug_fix |
| 284 | 408 |
: 500 |
409 |
); |
|
410 |
window.setTimeout( |
|
411 |
function() { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
412 |
_this.fixSize(); |
| 284 | 413 |
}, |
414 |
_delay |
|
415 |
); |
|
416 |
} |
|
417 |
||
418 |
if (_renkan.options.force_resize) { |
|
419 |
$(window).resize(function() { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
420 |
_this.autoScale(); |
| 284 | 421 |
}); |
422 |
} |
|
423 |
||
424 |
if (_renkan.options.show_user_list && _renkan.options.user_color_editable) { |
|
425 |
var $cpwrapper = this.$.find(".Rk-Users .Rk-Edit-ColorPicker-Wrapper"), |
|
426 |
$cplist = this.$.find(".Rk-Users .Rk-Edit-ColorPicker"); |
|
427 |
||
428 |
$cpwrapper.hover( |
|
429 |
function(_e) { |
|
430 |
if (_this.isEditable()) { |
|
431 |
_e.preventDefault(); |
|
432 |
$cplist.show(); |
|
433 |
} |
|
434 |
}, |
|
435 |
function(_e) { |
|
436 |
_e.preventDefault(); |
|
437 |
$cplist.hide(); |
|
438 |
} |
|
439 |
); |
|
440 |
||
441 |
$cplist.find("li").mouseenter( |
|
442 |
function(_e) { |
|
443 |
if (_this.isEditable()) { |
|
444 |
_e.preventDefault(); |
|
445 |
_this.$.find(".Rk-CurrentUser-Color").css("background", $(this).attr("data-color")); |
|
446 |
} |
|
447 |
} |
|
448 |
); |
|
449 |
} |
|
450 |
||
451 |
if (_renkan.options.show_search_field) { |
|
452 |
||
453 |
var lastval = ''; |
|
454 |
||
455 |
this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() { |
|
456 |
var $this = $(this), |
|
457 |
val = $this.val(); |
|
458 |
if (val === lastval) { |
|
459 |
return; |
|
460 |
} |
|
461 |
lastval = val; |
|
462 |
if (val.length < 2) { |
|
463 |
_renkan.project.get("nodes").each(function(n) { |
|
464 |
_this.getRepresentationByModel(n).unhighlight(); |
|
465 |
}); |
|
466 |
} else { |
|
467 |
var rxs = Utils.regexpFromTextOrArray(val); |
|
468 |
_renkan.project.get("nodes").each(function(n) { |
|
469 |
if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) { |
|
470 |
_this.getRepresentationByModel(n).highlight(rxs); |
|
471 |
} else { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
472 |
_this.getRepresentationByModel(n).unhighlight(); |
| 284 | 473 |
} |
474 |
}); |
|
475 |
} |
|
476 |
}); |
|
477 |
} |
|
478 |
||
479 |
this.redraw(); |
|
480 |
||
481 |
window.setInterval(function() { |
|
482 |
var _now = new Date().valueOf(); |
|
483 |
_this.delete_list.forEach(function(d) { |
|
484 |
if (_now >= d.time) { |
|
485 |
var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}); |
|
486 |
if (el) { |
|
487 |
project.removeNode(el); |
|
488 |
} |
|
489 |
el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}); |
|
490 |
if (el) { |
|
491 |
project.removeEdge(el); |
|
492 |
} |
|
493 |
} |
|
494 |
}); |
|
495 |
_this.delete_list = _this.delete_list.filter(function(d) { |
|
496 |
return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}); |
|
497 |
}); |
|
498 |
}, 500); |
|
499 |
||
500 |
if (this.minimap) { |
|
501 |
window.setInterval(function() { |
|
502 |
_this.rescaleMinimap(); |
|
503 |
}, 2000); |
|
504 |
} |
|
505 |
||
506 |
}; |
|
507 |
||
508 |
_(Scene.prototype).extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
509 |
fixSize: function() { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
510 |
if( this.renkan.options.default_view && this.renkan.project.get("views").length > 0) { |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
511 |
var view = this.renkan.project.get("views").last(); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
512 |
this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
513 |
} |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
514 |
else{ |
|
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
515 |
this.autoScale(); |
| 284 | 516 |
} |
517 |
}, |
|
518 |
drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) { |
|
519 |
var _options = this.renkan.options, |
|
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
520 |
_startRads = _startAngle * Math.PI / 180, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
521 |
_endRads = _endAngle * Math.PI / 180, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
522 |
_img = this.icon_cache[_imgname], |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
523 |
_startdx = - Math.sin(_startRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
524 |
_startdy = Math.cos(_startRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
525 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
526 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
527 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
528 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
529 |
_enddx = - Math.sin(_endRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
530 |
_enddy = Math.cos(_endRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
531 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
532 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
533 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
534 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
535 |
_centerR = (_inR + _outR) / 2, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
536 |
_centerRads = (_startRads + _endRads) / 2, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
537 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
538 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
539 |
_centerXIn = Math.cos(_centerRads) * _inR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
540 |
_centerXOut = Math.cos(_centerRads) * _outR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
541 |
_centerYIn = Math.sin(_centerRads) * _inR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
542 |
_centerYOut = Math.sin(_centerRads) * _outR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
543 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
544 |
_textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2; |
| 284 | 545 |
this.buttons_layer.activate(); |
546 |
var _path = new paper.Path(); |
|
547 |
_path.add([_startXIn, _startYIn]); |
|
548 |
_path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
|
549 |
_path.lineTo([_endXOut, _endYOut]); |
|
550 |
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
|
551 |
_path.fillColor = _options.buttons_background; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
552 |
_path.opacity = 0.5; |
| 284 | 553 |
_path.closed = true; |
554 |
_path.__representation = _repr; |
|
555 |
var _text = new paper.PointText(_textX,_textY); |
|
556 |
_text.characterStyle = { |
|
557 |
fontSize: _options.buttons_label_font_size, |
|
558 |
fillColor: _options.buttons_label_color |
|
559 |
}; |
|
560 |
if (_textX > 2) { |
|
561 |
_text.paragraphStyle.justification = 'left'; |
|
562 |
} else if (_textX < -2) { |
|
563 |
_text.paragraphStyle.justification = 'right'; |
|
564 |
} else { |
|
565 |
_text.paragraphStyle.justification = 'center'; |
|
566 |
} |
|
567 |
_text.visible = false; |
|
568 |
var _visible = false, |
|
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
569 |
_restPos = new paper.Point(-200, -200), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
570 |
_grp = new paper.Group([_path, _text]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
571 |
//_grp = new paper.Group([_path]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
572 |
_delta = _grp.position, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
573 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
574 |
_currentPos = new paper.Point(0,0); |
| 284 | 575 |
_text.content = _caption; |
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
576 |
// set group pivot to not depend on text visibility that changes the group bounding box. |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
577 |
_grp.pivot = _grp.bounds.center; |
| 284 | 578 |
_grp.visible = false; |
579 |
_grp.position = _restPos; |
|
580 |
var _res = { |
|
581 |
show: function() { |
|
582 |
_visible = true; |
|
583 |
_grp.position = _currentPos.add(_delta); |
|
584 |
_grp.visible = true; |
|
585 |
}, |
|
586 |
moveTo: function(_point) { |
|
587 |
_currentPos = _point; |
|
588 |
if (_visible) { |
|
589 |
_grp.position = _point.add(_delta); |
|
590 |
} |
|
591 |
}, |
|
592 |
hide: function() { |
|
593 |
_visible = false; |
|
594 |
_grp.visible = false; |
|
595 |
_grp.position = _restPos; |
|
596 |
}, |
|
597 |
select: function() { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
598 |
_path.opacity = 0.8; |
| 284 | 599 |
_text.visible = true; |
600 |
}, |
|
601 |
unselect: function() { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
602 |
_path.opacity = 0.5; |
| 284 | 603 |
_text.visible = false; |
604 |
}, |
|
605 |
destroy: function() { |
|
606 |
_grp.remove(); |
|
607 |
} |
|
608 |
}; |
|
609 |
var showImage = function() { |
|
610 |
var _raster = new paper.Raster(_img); |
|
611 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
|
612 |
_raster.locked = true; // Disable mouse events on icon |
|
613 |
_grp.addChild(_raster); |
|
614 |
}; |
|
615 |
if (_img.width) { |
|
616 |
showImage(); |
|
617 |
} else { |
|
618 |
$(_img).on("load",showImage); |
|
619 |
} |
|
620 |
||
621 |
return _res; |
|
622 |
}, |
|
623 |
addToBundles: function(_edgeRepr) { |
|
624 |
var _bundle = _(this.bundles).find(function(_bundle) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
625 |
return ( |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
626 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) || |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
627 |
( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
| 284 | 628 |
); |
629 |
}); |
|
630 |
if (typeof _bundle !== "undefined") { |
|
631 |
_bundle.edges.push(_edgeRepr); |
|
632 |
} else { |
|
633 |
_bundle = { |
|
634 |
from: _edgeRepr.from_representation, |
|
635 |
to: _edgeRepr.to_representation, |
|
636 |
edges: [ _edgeRepr ], |
|
637 |
getPosition: function(_er) { |
|
638 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
639 |
return _dir * ( _(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
640 |
} |
|
641 |
}; |
|
642 |
this.bundles.push(_bundle); |
|
643 |
} |
|
644 |
return _bundle; |
|
645 |
}, |
|
646 |
isEditable: function() { |
|
647 |
return (this.renkan.options.editor_mode && !this.renkan.read_only); |
|
648 |
}, |
|
649 |
onStatusChange: function() { |
|
650 |
var savebtn = this.$.find(".Rk-Save-Button"), |
|
651 |
tip = savebtn.find(".Rk-TopBar-Tooltip-Contents"); |
|
652 |
if (this.renkan.read_only) { |
|
653 |
savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly"); |
|
654 |
tip.text(this.renkan.translate("Connection lost")); |
|
655 |
} else { |
|
| 322 | 656 |
if (this.renkan.options.manual_save) { |
| 284 | 657 |
savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online"); |
658 |
tip.text(this.renkan.translate("Save Project")); |
|
659 |
} else { |
|
660 |
savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online"); |
|
661 |
tip.text(this.renkan.translate("Auto-save enabled")); |
|
662 |
} |
|
663 |
} |
|
664 |
this.redrawUsers(); |
|
665 |
}, |
|
666 |
setScale: function(_newScale, _offset) { |
|
667 |
if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) { |
|
668 |
this.scale = _newScale; |
|
669 |
if (_offset) { |
|
670 |
this.offset = _offset; |
|
671 |
} |
|
672 |
this.redraw(); |
|
673 |
} |
|
674 |
}, |
|
675 |
autoScale: function(force_view) { |
|
676 |
var nodes = this.renkan.project.get("nodes"); |
|
677 |
if (nodes.length > 1) { |
|
678 |
var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
|
679 |
_yy = nodes.map(function(_node) { return _node.get("position").y; }), |
|
680 |
_minx = Math.min.apply(Math, _xx), |
|
681 |
_miny = Math.min.apply(Math, _yy), |
|
682 |
_maxx = Math.max.apply(Math, _xx), |
|
683 |
_maxy = Math.max.apply(Math, _yy); |
|
684 |
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)); |
|
685 |
this.initialScale = _scale; |
|
686 |
// Override calculated scale if asked |
|
| 299 | 687 |
if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset.x)>0 && parseFloat(force_view.offset.y)>0){ |
688 |
this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset.x), parseFloat(force_view.offset.y))); |
|
| 284 | 689 |
} |
690 |
else{ |
|
691 |
this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale))); |
|
692 |
} |
|
693 |
} |
|
694 |
if (nodes.length === 1) { |
|
695 |
this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]))); |
|
696 |
} |
|
697 |
}, |
|
698 |
redrawMiniframe: function() { |
|
699 |
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
700 |
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
| 284 | 701 |
this.minimap.miniframe.fitBounds(topleft, bottomright); |
702 |
}, |
|
703 |
rescaleMinimap: function() { |
|
704 |
var nodes = this.renkan.project.get("nodes"); |
|
705 |
if (nodes.length > 1) { |
|
706 |
var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
707 |
_yy = nodes.map(function(_node) { return _node.get("position").y; }), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
708 |
_minx = Math.min.apply(Math, _xx), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
709 |
_miny = Math.min.apply(Math, _yy), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
710 |
_maxx = Math.max.apply(Math, _xx), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
711 |
_maxy = Math.max.apply(Math, _yy); |
| 284 | 712 |
var _scale = Math.min( |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
713 |
this.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
714 |
this.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
| 284 | 715 |
( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
716 |
( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
|
717 |
); |
|
718 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
719 |
this.minimap.scale = _scale; |
|
720 |
} |
|
721 |
if (nodes.length === 1) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
722 |
this.minimap.scale = 0.1; |
| 284 | 723 |
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)); |
724 |
} |
|
725 |
this.redraw(); |
|
726 |
}, |
|
727 |
toPaperCoords: function(_point) { |
|
728 |
return _point.multiply(this.scale).add(this.offset); |
|
729 |
}, |
|
730 |
toMinimapCoords: function(_point) { |
|
731 |
return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
|
732 |
}, |
|
733 |
toModelCoords: function(_point) { |
|
734 |
return _point.subtract(this.offset).divide(this.scale); |
|
735 |
}, |
|
736 |
addRepresentation: function(_type, _model) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
737 |
var RendererType = requtils.getRenderer()[_type]; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
738 |
var _repr = new RendererType(this, _model); |
| 284 | 739 |
this.representations.push(_repr); |
740 |
return _repr; |
|
741 |
}, |
|
742 |
addRepresentations: function(_type, _collection) { |
|
743 |
var _this = this; |
|
744 |
_collection.forEach(function(_model) { |
|
745 |
_this.addRepresentation(_type, _model); |
|
746 |
}); |
|
747 |
}, |
|
748 |
userTemplate: _.template( |
|
749 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
750 |
), |
|
751 |
redrawUsers: function() { |
|
752 |
if (!this.renkan.options.show_user_list) { |
|
753 |
return; |
|
754 |
} |
|
755 |
var allUsers = [].concat((this.renkan.project.current_user_list || {}).models || [], (this.renkan.project.get("users") || {}).models || []), |
|
756 |
ulistHtml = '', |
|
757 |
$userpanel = this.$.find(".Rk-Users"), |
|
758 |
$name = $userpanel.find(".Rk-CurrentUser-Name"), |
|
759 |
$cpitems = $userpanel.find(".Rk-Edit-ColorPicker li"), |
|
760 |
$colorsquare = $userpanel.find(".Rk-CurrentUser-Color"), |
|
761 |
_this = this; |
|
762 |
$name.off("click").text(this.renkan.translate("<unknown user>")); |
|
763 |
$cpitems.off("mouseleave click"); |
|
764 |
allUsers.forEach(function(_user) { |
|
765 |
if (_user.get("_id") === _this.renkan.current_user) { |
|
766 |
$name.text(_user.get("title")); |
|
767 |
$colorsquare.css("background", _user.get("color")); |
|
768 |
if (_this.isEditable()) { |
|
769 |
||
770 |
if (_this.renkan.options.user_name_editable) { |
|
771 |
$name.click(function() { |
|
772 |
var $this = $(this), |
|
773 |
$input = $('<input>').val(_user.get("title")).blur(function() { |
|
774 |
_user.set("title", $(this).val()); |
|
775 |
_this.redrawUsers(); |
|
776 |
_this.redraw(); |
|
777 |
}); |
|
778 |
$this.empty().html($input); |
|
779 |
$input.select(); |
|
780 |
}); |
|
781 |
} |
|
782 |
||
783 |
if (_this.renkan.options.user_color_editable) { |
|
784 |
$cpitems.click( |
|
785 |
function(_e) { |
|
786 |
_e.preventDefault(); |
|
787 |
if (_this.isEditable()) { |
|
788 |
_user.set("color", $(this).attr("data-color")); |
|
789 |
} |
|
790 |
$(this).parent().hide(); |
|
791 |
} |
|
792 |
).mouseleave(function() { |
|
793 |
$colorsquare.css("background", _user.get("color")); |
|
794 |
}); |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
} else { |
|
799 |
ulistHtml += _this.userTemplate({ |
|
800 |
name: _user.get("title"), |
|
801 |
background: _user.get("color") |
|
802 |
}); |
|
803 |
} |
|
804 |
}); |
|
805 |
$userpanel.find(".Rk-UserList").html(ulistHtml); |
|
806 |
}, |
|
807 |
removeRepresentation: function(_representation) { |
|
808 |
_representation.destroy(); |
|
| 433 | 809 |
this.representations = _.reject(this.representations, |
810 |
function(_repr) { |
|
811 |
return _repr === _representation; |
|
812 |
} |
|
| 284 | 813 |
); |
814 |
}, |
|
815 |
getRepresentationByModel: function(_model) { |
|
816 |
if (!_model) { |
|
817 |
return undefined; |
|
818 |
} |
|
| 433 | 819 |
return _.find(this.representations, function(_repr) { |
| 284 | 820 |
return _repr.model === _model; |
821 |
}); |
|
822 |
}, |
|
823 |
removeRepresentationsOfType: function(_type) { |
|
| 433 | 824 |
var _representations = _.filter(this.representations,function(_repr) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
825 |
return _repr.type === _type; |
| 433 | 826 |
}), |
827 |
_this = this; |
|
828 |
_.each(_representations, function(_repr) { |
|
| 284 | 829 |
_this.removeRepresentation(_repr); |
830 |
}); |
|
831 |
}, |
|
832 |
highlightModel: function(_model) { |
|
833 |
var _repr = this.getRepresentationByModel(_model); |
|
834 |
if (_repr) { |
|
835 |
_repr.highlight(); |
|
836 |
} |
|
837 |
}, |
|
838 |
unhighlightAll: function(_model) { |
|
| 433 | 839 |
_.each(this.representations, function(_repr) { |
| 284 | 840 |
_repr.unhighlight(); |
841 |
}); |
|
842 |
}, |
|
843 |
unselectAll: function(_model) { |
|
| 433 | 844 |
_.each(this.representations, function(_repr) { |
| 284 | 845 |
_repr.unselect(); |
846 |
}); |
|
847 |
}, |
|
848 |
redraw: function() { |
|
| 450 | 849 |
var _this = this; |
| 307 | 850 |
if(! this.redrawActive ) { |
851 |
return; |
|
852 |
} |
|
| 433 | 853 |
_.each(this.representations, function(_representation) { |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
854 |
_representation.redraw({ dontRedrawEdges:true }); |
| 284 | 855 |
}); |
856 |
if (this.minimap) { |
|
857 |
this.redrawMiniframe(); |
|
858 |
} |
|
859 |
paper.view.draw(); |
|
860 |
}, |
|
861 |
addTempEdge: function(_from, _point) { |
|
862 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
|
863 |
_tmpEdge.end_pos = _point; |
|
864 |
_tmpEdge.from_representation = _from; |
|
865 |
_tmpEdge.redraw(); |
|
866 |
this.click_target = _tmpEdge; |
|
867 |
}, |
|
| 450 | 868 |
addHiddenNode: function(_model){ |
869 |
this.hideNode(_model); |
|
870 |
this.hiddenNodes.push(_model.id); |
|
871 |
}, |
|
872 |
hideNode: function(_model){ |
|
873 |
var _this = this; |
|
874 |
if (typeof _this.getRepresentationByModel(_model) !== 'undefined'){ |
|
875 |
_this.getRepresentationByModel(_model).hide(); |
|
876 |
} |
|
877 |
}, |
|
878 |
hideNodes: function(){ |
|
879 |
var _this = this; |
|
880 |
this.hiddenNodes.forEach(function(_id, index){ |
|
881 |
var node = _this.renkan.project.get("nodes").get(_id); |
|
882 |
if (typeof node !== 'undefined'){ |
|
883 |
return _this.hideNode(_this.renkan.project.get("nodes").get(_id)); |
|
884 |
}else{ |
|
885 |
_this.hiddenNodes.splice(index, 1); |
|
886 |
} |
|
887 |
}); |
|
888 |
paper.view.draw(); |
|
889 |
}, |
|
890 |
showNodes: function(ghost){ |
|
891 |
var _this = this; |
|
892 |
this.hiddenNodes.forEach(function(_id){ |
|
893 |
_this.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost); |
|
894 |
}); |
|
895 |
if (!ghost){ |
|
896 |
this.hiddenNodes = []; |
|
897 |
} |
|
898 |
paper.view.draw(); |
|
899 |
}, |
|
| 284 | 900 |
findTarget: function(_hitResult) { |
901 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
902 |
var _newTarget = _hitResult.item.__representation; |
|
903 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
904 |
if (this.selected_target) { |
|
905 |
this.selected_target.unselect(_newTarget); |
|
906 |
} |
|
907 |
_newTarget.select(this.selected_target); |
|
908 |
this.selected_target = _newTarget; |
|
909 |
} |
|
910 |
} else { |
|
911 |
if (this.selected_target) { |
|
912 |
this.selected_target.unselect(); |
|
913 |
} |
|
914 |
this.selected_target = null; |
|
915 |
} |
|
916 |
}, |
|
917 |
paperShift: function(_delta) { |
|
918 |
this.offset = this.offset.add(_delta); |
|
919 |
this.redraw(); |
|
920 |
}, |
|
921 |
onMouseMove: function(_event) { |
|
922 |
var _off = this.canvas_$.offset(), |
|
923 |
_point = new paper.Point([ |
|
924 |
_event.pageX - _off.left, |
|
925 |
_event.pageY - _off.top |
|
926 |
]), |
|
927 |
_delta = _point.subtract(this.last_point); |
|
928 |
this.last_point = _point; |
|
929 |
if (!this.is_dragging && this.mouse_down && _delta.length > Utils._MIN_DRAG_DISTANCE) { |
|
930 |
this.is_dragging = true; |
|
931 |
} |
|
932 |
var _hitResult = paper.project.hitTest(_point); |
|
933 |
if (this.is_dragging) { |
|
934 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
935 |
this.click_target.paperShift(_delta); |
|
936 |
} else { |
|
937 |
this.paperShift(_delta); |
|
938 |
} |
|
939 |
} else { |
|
940 |
this.findTarget(_hitResult); |
|
941 |
} |
|
942 |
paper.view.draw(); |
|
943 |
}, |
|
944 |
onMouseDown: function(_event, _isTouch) { |
|
945 |
var _off = this.canvas_$.offset(), |
|
946 |
_point = new paper.Point([ |
|
947 |
_event.pageX - _off.left, |
|
948 |
_event.pageY - _off.top |
|
949 |
]); |
|
950 |
this.last_point = _point; |
|
951 |
this.mouse_down = true; |
|
952 |
if (!this.click_target || this.click_target.type !== "Temp-edge") { |
|
953 |
this.removeRepresentationsOfType("editor"); |
|
954 |
this.is_dragging = false; |
|
955 |
var _hitResult = paper.project.hitTest(_point); |
|
956 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
957 |
this.click_target = _hitResult.item.__representation; |
|
958 |
this.click_target.mousedown(_event, _isTouch); |
|
959 |
} else { |
|
960 |
this.click_target = null; |
|
961 |
if (this.isEditable() && this.click_mode === Utils._CLICKMODE_ADDNODE) { |
|
962 |
var _coords = this.toModelCoords(_point), |
|
963 |
_data = { |
|
964 |
id: Utils.getUID('node'), |
|
965 |
created_by: this.renkan.current_user, |
|
966 |
position: { |
|
967 |
x: _coords.x, |
|
968 |
y: _coords.y |
|
969 |
} |
|
970 |
}; |
|
971 |
_node = this.renkan.project.addNode(_data); |
|
972 |
this.getRepresentationByModel(_node).openEditor(); |
|
973 |
} |
|
974 |
} |
|
975 |
} |
|
976 |
if (this.click_mode) { |
|
977 |
if (this.isEditable() && this.click_mode === Utils._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
978 |
this.removeRepresentationsOfType("editor"); |
|
979 |
this.addTempEdge(this.click_target, _point); |
|
980 |
this.click_mode = Utils._CLICKMODE_ENDEDGE; |
|
981 |
this.notif_$.fadeOut(function() { |
|
982 |
$(this).html(this.renkan.translate("Click on a second node to complete the edge")).fadeIn(); |
|
983 |
}); |
|
984 |
} else { |
|
985 |
this.notif_$.hide(); |
|
986 |
this.click_mode = false; |
|
987 |
} |
|
988 |
} |
|
989 |
paper.view.draw(); |
|
990 |
}, |
|
991 |
onMouseUp: function(_event, _isTouch) { |
|
992 |
this.mouse_down = false; |
|
993 |
if (this.click_target) { |
|
994 |
var _off = this.canvas_$.offset(); |
|
995 |
this.click_target.mouseup( |
|
996 |
{ |
|
997 |
point: new paper.Point([ |
|
998 |
_event.pageX - _off.left, |
|
999 |
_event.pageY - _off.top |
|
1000 |
]) |
|
1001 |
}, |
|
1002 |
_isTouch |
|
1003 |
); |
|
1004 |
} else { |
|
1005 |
this.click_target = null; |
|
1006 |
this.is_dragging = false; |
|
1007 |
if (_isTouch) { |
|
1008 |
this.unselectAll(); |
|
1009 |
} |
|
1010 |
} |
|
1011 |
paper.view.draw(); |
|
1012 |
}, |
|
1013 |
onScroll: function(_event, _scrolldelta) { |
|
1014 |
this.totalScroll += _scrolldelta; |
|
1015 |
if (Math.abs(this.totalScroll) >= 1) { |
|
1016 |
var _off = this.canvas_$.offset(), |
|
1017 |
_delta = new paper.Point([ |
|
1018 |
_event.pageX - _off.left, |
|
1019 |
_event.pageY - _off.top |
|
1020 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
1021 |
if (this.totalScroll > 0) { |
|
1022 |
this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) ); |
|
1023 |
} else { |
|
1024 |
this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2))); |
|
1025 |
} |
|
1026 |
this.totalScroll = 0; |
|
1027 |
} |
|
1028 |
}, |
|
1029 |
onDoubleClick: function(_event) { |
|
1030 |
var _off = this.canvas_$.offset(), |
|
1031 |
_point = new paper.Point([ |
|
1032 |
_event.pageX - _off.left, |
|
1033 |
_event.pageY - _off.top |
|
1034 |
]); |
|
1035 |
var _hitResult = paper.project.hitTest(_point); |
|
| 452 | 1036 |
|
1037 |
if (!this.isEditable()) { |
|
1038 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
1039 |
if (_hitResult.item.__representation.model.get('uri')){ |
|
1040 |
window.open(_hitResult.item.__representation.model.get('uri'), '_blank'); |
|
1041 |
} |
|
1042 |
} |
|
1043 |
return; |
|
1044 |
} |
|
| 284 | 1045 |
if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) { |
1046 |
var _coords = this.toModelCoords(_point), |
|
1047 |
_data = { |
|
1048 |
id: Utils.getUID('node'), |
|
1049 |
created_by: this.renkan.current_user, |
|
1050 |
position: { |
|
1051 |
x: _coords.x, |
|
1052 |
y: _coords.y |
|
1053 |
} |
|
1054 |
}, |
|
1055 |
_node = this.renkan.project.addNode(_data); |
|
1056 |
this.getRepresentationByModel(_node).openEditor(); |
|
1057 |
} |
|
1058 |
paper.view.draw(); |
|
1059 |
}, |
|
1060 |
defaultDropHandler: function(_data) { |
|
1061 |
var newNode = {}; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1062 |
var snippet = ""; |
| 284 | 1063 |
switch(_data["text/x-iri-specific-site"]) { |
| 286 | 1064 |
case "twitter": |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1065 |
snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1066 |
var tweetdiv = snippet.find(".tweet"); |
| 286 | 1067 |
newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
1068 |
newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
|
1069 |
newNode.image = tweetdiv.find(".avatar").attr("src"); |
|
1070 |
newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
|
1071 |
break; |
|
1072 |
case "google": |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1073 |
snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
| 286 | 1074 |
newNode.title = snippet.find("h3:first").text().trim(); |
1075 |
newNode.uri = snippet.find("h3 a").attr("href"); |
|
1076 |
newNode.description = snippet.find(".st:first").text().trim(); |
|
1077 |
break; |
|
1078 |
default: |
|
1079 |
if (_data["text/x-iri-source-uri"]) { |
|
1080 |
newNode.uri = _data["text/x-iri-source-uri"]; |
|
1081 |
} |
|
1082 |
} |
|
| 284 | 1083 |
if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1084 |
newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
|
1085 |
} |
|
1086 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1087 |
snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
| 284 | 1088 |
var _svgimgs = snippet.find("image"); |
1089 |
if (_svgimgs.length) { |
|
1090 |
newNode.image = _svgimgs.attr("xlink:href"); |
|
1091 |
} |
|
1092 |
var _svgpaths = snippet.find("path"); |
|
1093 |
if (_svgpaths.length) { |
|
1094 |
newNode.clipPath = _svgpaths.attr("d"); |
|
1095 |
} |
|
1096 |
var _imgs = snippet.find("img"); |
|
1097 |
if (_imgs.length) { |
|
1098 |
newNode.image = _imgs[0].src; |
|
1099 |
} |
|
1100 |
var _as = snippet.find("a"); |
|
1101 |
if (_as.length) { |
|
1102 |
newNode.uri = _as[0].href; |
|
1103 |
} |
|
1104 |
newNode.title = snippet.find("[title]").attr("title") || newNode.title; |
|
1105 |
newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim(); |
|
1106 |
} |
|
1107 |
if (_data["text/uri-list"]) { |
|
1108 |
newNode.uri = _data["text/uri-list"]; |
|
1109 |
} |
|
1110 |
if (_data["text/x-moz-url"] && !newNode.title) { |
|
1111 |
newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim(); |
|
1112 |
if (newNode.title === newNode.uri) { |
|
1113 |
newNode.title = false; |
|
1114 |
} |
|
1115 |
} |
|
1116 |
if (_data["text/x-iri-source-title"] && !newNode.title) { |
|
1117 |
newNode.title = _data["text/x-iri-source-title"]; |
|
1118 |
} |
|
1119 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1120 |
snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
| 284 | 1121 |
newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image; |
1122 |
newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
|
1123 |
newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
|
1124 |
newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
|
1125 |
newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
|
1126 |
} |
|
| 286 | 1127 |
|
1128 |
if (!newNode.title) { |
|
1129 |
newNode.title = this.renkan.translate("Dragged resource"); |
|
| 284 | 1130 |
} |
| 286 | 1131 |
var fields = ["title", "description", "uri", "image"]; |
1132 |
for (var i = 0; i < fields.length; i++) { |
|
1133 |
var f = fields[i]; |
|
1134 |
if (_data["text/x-iri-" + f] || _data[f]) { |
|
1135 |
newNode[f] = _data["text/x-iri-" + f] || _data[f]; |
|
1136 |
} |
|
1137 |
if (newNode[f] === "none" || newNode[f] === "null") { |
|
1138 |
newNode[f] = undefined; |
|
1139 |
} |
|
1140 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1141 |
|
| 284 | 1142 |
if(typeof this.renkan.options.drop_enhancer === "function"){ |
1143 |
newNode = this.renkan.options.drop_enhancer(newNode, _data); |
|
1144 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1145 |
|
| 284 | 1146 |
return newNode; |
1147 |
||
1148 |
}, |
|
1149 |
dropData: function(_data, _event) { |
|
1150 |
if (!this.isEditable()) { |
|
1151 |
return; |
|
1152 |
} |
|
1153 |
if (_data["text/json"] || _data["application/json"]) { |
|
1154 |
try { |
|
1155 |
var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]); |
|
| 433 | 1156 |
_.extend(_data,jsondata); |
| 284 | 1157 |
} |
1158 |
catch(e) {} |
|
1159 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1160 |
|
| 284 | 1161 |
var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1162 |
|
| 284 | 1163 |
var _off = this.canvas_$.offset(), |
1164 |
_point = new paper.Point([ |
|
1165 |
_event.pageX - _off.left, |
|
1166 |
_event.pageY - _off.top |
|
1167 |
]), |
|
1168 |
_coords = this.toModelCoords(_point), |
|
1169 |
_nodedata = { |
|
1170 |
id: Utils.getUID('node'), |
|
1171 |
created_by: this.renkan.current_user, |
|
1172 |
uri: newNode.uri || "", |
|
1173 |
title: newNode.title || "", |
|
1174 |
description: newNode.description || "", |
|
1175 |
image: newNode.image || "", |
|
1176 |
color: newNode.color || undefined, |
|
1177 |
clip_path: newNode.clipPath || undefined, |
|
1178 |
position: { |
|
1179 |
x: _coords.x, |
|
1180 |
y: _coords.y |
|
1181 |
} |
|
1182 |
}; |
|
1183 |
var _node = this.renkan.project.addNode(_nodedata), |
|
1184 |
_repr = this.getRepresentationByModel(_node); |
|
1185 |
if (_event.type === "drop") { |
|
1186 |
_repr.openEditor(); |
|
1187 |
} |
|
1188 |
}, |
|
1189 |
fullScreen: function() { |
|
1190 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1191 |
_el = this.renkan.$[0], |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1192 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1193 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"], |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1194 |
i; |
| 284 | 1195 |
if (_isFull) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1196 |
for (i = 0; i < _cancelMethods.length; i++) { |
| 284 | 1197 |
if (typeof document[_cancelMethods[i]] === "function") { |
1198 |
document[_cancelMethods[i]](); |
|
1199 |
break; |
|
1200 |
} |
|
1201 |
} |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1202 |
var widthAft = this.$.width(); |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1203 |
var heightAft = this.$.height(); |
| 396 | 1204 |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1205 |
if (this.renkan.options.show_top_bar) { |
| 396 | 1206 |
heightAft -= this.$.find(".Rk-TopBar").height(); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1207 |
} |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1208 |
if (this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) { |
| 396 | 1209 |
widthAft -= this.renkan.$.find(".Rk-Bins").width(); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1210 |
} |
| 396 | 1211 |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1212 |
paper.view.viewSize = new paper.Size([widthAft, heightAft]); |
| 396 | 1213 |
|
| 284 | 1214 |
} else { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1215 |
for (i = 0; i < _requestMethods.length; i++) { |
| 284 | 1216 |
if (typeof _el[_requestMethods[i]] === "function") { |
1217 |
_el[_requestMethods[i]](); |
|
1218 |
break; |
|
1219 |
} |
|
1220 |
} |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
1221 |
this.redraw(); |
| 284 | 1222 |
} |
1223 |
}, |
|
1224 |
zoomOut: function() { |
|
1225 |
var _newScale = this.scale * Math.SQRT1_2, |
|
1226 |
_offset = new paper.Point([ |
|
1227 |
this.canvas_$.width(), |
|
1228 |
this.canvas_$.height() |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1229 |
]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 )); |
| 284 | 1230 |
this.setScale( _newScale, _offset ); |
1231 |
}, |
|
1232 |
zoomIn: function() { |
|
1233 |
var _newScale = this.scale * Math.SQRT2, |
|
1234 |
_offset = new paper.Point([ |
|
1235 |
this.canvas_$.width(), |
|
1236 |
this.canvas_$.height() |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1237 |
]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
| 284 | 1238 |
this.setScale( _newScale, _offset ); |
1239 |
}, |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1240 |
resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) { |
| 396 | 1241 |
var _newScale = this.scale * _ratio, |
1242 |
_offset = new paper.Point([ |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1243 |
(this.offset.x * _scaleWidth), |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1244 |
(this.offset.y * _scaleHeight) |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1245 |
]); |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1246 |
this.setScale( _newScale, _offset ); |
|
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1247 |
}, |
| 284 | 1248 |
addNodeBtn: function() { |
1249 |
if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
|
1250 |
this.click_mode = false; |
|
1251 |
this.notif_$.hide(); |
|
1252 |
} else { |
|
1253 |
this.click_mode = Utils._CLICKMODE_ADDNODE; |
|
1254 |
this.notif_$.text(this.renkan.translate("Click on the background canvas to add a node")).fadeIn(); |
|
1255 |
} |
|
1256 |
return false; |
|
1257 |
}, |
|
1258 |
addEdgeBtn: function() { |
|
1259 |
if (this.click_mode === Utils._CLICKMODE_STARTEDGE || this.click_mode === Utils._CLICKMODE_ENDEDGE) { |
|
1260 |
this.click_mode = false; |
|
1261 |
this.notif_$.hide(); |
|
1262 |
} else { |
|
1263 |
this.click_mode = Utils._CLICKMODE_STARTEDGE; |
|
1264 |
this.notif_$.text(this.renkan.translate("Click on a first node to start the edge")).fadeIn(); |
|
1265 |
} |
|
1266 |
return false; |
|
1267 |
}, |
|
| 297 | 1268 |
exportProject: function() { |
1269 |
var projectJSON = this.renkan.project.toJSON(), |
|
1270 |
downloadLink = document.createElement("a"), |
|
1271 |
projectId = projectJSON.id, |
|
1272 |
fileNameToSaveAs = projectId + ".json"; |
|
1273 |
||
1274 |
// clean ids |
|
1275 |
delete projectJSON.id; |
|
| 298 | 1276 |
delete projectJSON._id; |
1277 |
delete projectJSON.space_id; |
|
1278 |
||
1279 |
var objId; |
|
1280 |
var idsMap = {}; |
|
1281 |
||
| 297 | 1282 |
_.each(projectJSON.nodes, function(e,i,l) { |
| 298 | 1283 |
objId = e.id || e._id; |
| 297 | 1284 |
delete e._id; |
1285 |
delete e.id; |
|
| 298 | 1286 |
idsMap[objId] = e['@id'] = Utils.getUUID4(); |
| 297 | 1287 |
}); |
1288 |
_.each(projectJSON.edges, function(e,i,l) { |
|
1289 |
delete e._id; |
|
1290 |
delete e.id; |
|
| 298 | 1291 |
e.to = idsMap[e.to]; |
1292 |
e.from = idsMap[e.from]; |
|
| 297 | 1293 |
}); |
1294 |
_.each(projectJSON.views, function(e,i,l) { |
|
| 298 | 1295 |
objId = e.id || e._id; |
| 297 | 1296 |
delete e._id; |
1297 |
delete e.id; |
|
1298 |
}); |
|
1299 |
projectJSON.users = []; |
|
1300 |
||
1301 |
var projectJSONStr = JSON.stringify(projectJSON, null, 2); |
|
1302 |
var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"}); |
|
1303 |
filesaver(blob,fileNameToSaveAs); |
|
1304 |
||
1305 |
}, |
|
| 284 | 1306 |
foldBins: function() { |
1307 |
var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
|
| 340 | 1308 |
bins = this.renkan.$.find(".Rk-Bins"); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1309 |
var _this = this, |
| 396 | 1310 |
sizeBef = _this.canvas_$.width(), |
1311 |
sizeAft; |
|
| 340 | 1312 |
if (bins.position().left < 0) { |
| 284 | 1313 |
bins.animate({left: 0},250); |
1314 |
this.$.animate({left: 300},250,function() { |
|
1315 |
var w = _this.$.width(); |
|
1316 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1317 |
}); |
|
|
379
81573f4331b5
minor correction to improve zooming while bins are closing
rougeronj
parents:
377
diff
changeset
|
1318 |
if ((sizeBef - bins.width()) < bins.height()){ |
| 396 | 1319 |
sizeAft = sizeBef; |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1320 |
} else { |
| 396 | 1321 |
sizeAft = sizeBef - bins.width(); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1322 |
} |
| 284 | 1323 |
foldBinsButton.html("«"); |
1324 |
} else { |
|
1325 |
bins.animate({left: -300},250); |
|
1326 |
this.$.animate({left: 0},250,function() { |
|
1327 |
var w = _this.$.width(); |
|
1328 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1329 |
}); |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1330 |
sizeAft = sizeBef+300; |
| 284 | 1331 |
foldBinsButton.html("»"); |
1332 |
} |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1333 |
_this.resizeZoom(1, 1, (sizeAft/sizeBef)); |
| 284 | 1334 |
}, |
1335 |
save: function() { }, |
|
1336 |
open: function() { } |
|
| 433 | 1337 |
}).value(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1338 |
|
| 284 | 1339 |
/* Scene End */ |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1340 |
|
| 284 | 1341 |
return Scene; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1342 |
|
| 284 | 1343 |
}); |