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