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