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