|
14
|
1 |
/* *********************************************************
|
|
|
2 |
File generated on Wed May 15 15:42:55 CEST 2013
|
|
|
3 |
************************************************************
|
|
|
4 |
start of main.js
|
|
|
5 |
********************************************************* */
|
|
|
6 |
|
|
|
7 |
/*
|
|
|
8 |
_____ _
|
|
|
9 |
| __ \ | |
|
|
|
10 |
| |__) |___ _ __ | | ____ _ _ __
|
|
|
11 |
| _ // _ \ '_ \| |/ / _` | '_ \
|
|
|
12 |
| | \ \ __/ | | | < (_| | | | |
|
|
|
13 |
|_| \_\___|_| |_|_|\_\__,_|_| |_|
|
|
|
14 |
|
|
|
15 |
* Copyright 2012-2013 Institut de recherche et d'innovation
|
|
|
16 |
* contributor(s) : Yves-Marie Haussonne, Raphael Velt, Samuel Huron
|
|
|
17 |
*
|
|
|
18 |
* contact@iri.centrepompidou.fr
|
|
|
19 |
* http://www.iri.centrepompidou.fr
|
|
|
20 |
*
|
|
|
21 |
* This software is a computer program whose purpose is to show and add annotations on a video .
|
|
|
22 |
* This software is governed by the CeCILL-C license under French law and
|
|
|
23 |
* abiding by the rules of distribution of free software. You can use,
|
|
|
24 |
* modify and/ or redistribute the software under the terms of the CeCILL-C
|
|
|
25 |
* license as circulated by CEA, CNRS and INRIA at the following URL
|
|
|
26 |
* "http://www.cecill.info".
|
|
|
27 |
*
|
|
|
28 |
* The fact that you are presently reading this means that you have had
|
|
|
29 |
* knowledge of the CeCILL-C license and that you accept its terms.
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
/* Declaring the Renkan Namespace Rkns and Default values */
|
|
|
33 |
|
|
|
34 |
if (typeof Rkns !== "object") {
|
|
|
35 |
Rkns = {};
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
Rkns.$ = jQuery;
|
|
|
39 |
|
|
|
40 |
Rkns._ = _;
|
|
|
41 |
|
|
|
42 |
Rkns.VERSION = '0.2';
|
|
|
43 |
|
|
|
44 |
Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc",
|
|
|
45 |
"#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc",
|
|
|
46 |
"#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc",
|
|
|
47 |
"#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc",
|
|
|
48 |
"#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe",
|
|
|
49 |
"#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe",
|
|
|
50 |
"#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe",
|
|
|
51 |
"#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"];
|
|
|
52 |
|
|
|
53 |
Rkns._BaseBin = function(_renkan, _opts) {
|
|
|
54 |
if (typeof _renkan !== "undefined") {
|
|
|
55 |
this.renkan = _renkan;
|
|
|
56 |
this.renkan.$.find(".Rk-Bin-Main").hide();
|
|
|
57 |
this.$ = Rkns.$('<li>')
|
|
|
58 |
.addClass("Rk-Bin")
|
|
|
59 |
.appendTo(_renkan.$.find(".Rk-Bin-List"));
|
|
|
60 |
this.title_icon_$ = Rkns.$('<span>')
|
|
|
61 |
.addClass("Rk-Bin-Title-Icon")
|
|
|
62 |
.appendTo(this.$);
|
|
|
63 |
|
|
|
64 |
var _this = this;
|
|
|
65 |
|
|
|
66 |
Rkns.$('<a>')
|
|
|
67 |
.attr({
|
|
|
68 |
href: "#",
|
|
|
69 |
title: _renkan.translate("Close bin")
|
|
|
70 |
})
|
|
|
71 |
.addClass("Rk-Bin-Close")
|
|
|
72 |
.html('×')
|
|
|
73 |
.appendTo(this.$)
|
|
|
74 |
.click(function() {
|
|
|
75 |
_this.destroy();
|
|
|
76 |
if (!_renkan.$.find(".Rk-Bin-Main:visible").length) {
|
|
|
77 |
_renkan.$.find(".Rk-Bin-Main:last").slideDown();
|
|
|
78 |
}
|
|
|
79 |
_renkan.resizeBins();
|
|
|
80 |
return false;
|
|
|
81 |
});
|
|
|
82 |
Rkns.$('<a>')
|
|
|
83 |
.attr({
|
|
|
84 |
href: "#",
|
|
|
85 |
title: _renkan.translate("Refresh bin")
|
|
|
86 |
})
|
|
|
87 |
.addClass("Rk-Bin-Refresh")
|
|
|
88 |
.appendTo(this.$)
|
|
|
89 |
.click(function() {
|
|
|
90 |
_this.refresh();
|
|
|
91 |
return false;
|
|
|
92 |
});
|
|
|
93 |
this.count_$ = Rkns.$('<div>')
|
|
|
94 |
.addClass("Rk-Bin-Count")
|
|
|
95 |
.appendTo(this.$);
|
|
|
96 |
this.title_$ = Rkns.$('<h2>')
|
|
|
97 |
.addClass("Rk-Bin-Title")
|
|
|
98 |
.appendTo(this.$);
|
|
|
99 |
this.main_$ = Rkns.$('<div>')
|
|
|
100 |
.addClass("Rk-Bin-Main")
|
|
|
101 |
.appendTo(this.$)
|
|
|
102 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>');
|
|
|
103 |
this.title_$.html(_opts.title || '(new bin)');
|
|
|
104 |
this.renkan.resizeBins();
|
|
|
105 |
|
|
|
106 |
if (_opts.auto_refresh) {
|
|
|
107 |
window.setInterval(function() {
|
|
|
108 |
_this.refresh();
|
|
|
109 |
},_opts.auto_refresh);
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
};
|
|
|
113 |
|
|
|
114 |
Rkns._BaseBin.prototype.destroy = function() {
|
|
|
115 |
this.$.detach();
|
|
|
116 |
this.renkan.resizeBins();
|
|
|
117 |
};
|
|
|
118 |
|
|
|
119 |
/* Point of entry */
|
|
|
120 |
|
|
|
121 |
Rkns.Renkan = function(_opts) {
|
|
|
122 |
var _this = this;
|
|
|
123 |
|
|
|
124 |
this.options = _.defaults(_opts, Rkns.defaults);
|
|
|
125 |
|
|
|
126 |
Rkns._(this.options.property_files).each(function(f) {
|
|
|
127 |
Rkns.$.getJSON(f, function(data) {
|
|
|
128 |
_this.options.properties = _this.options.properties.concat(data);
|
|
|
129 |
});
|
|
|
130 |
});
|
|
|
131 |
|
|
|
132 |
this.read_only = this.options.read_only || !this.options.editor_mode;
|
|
|
133 |
|
|
|
134 |
this.project = new Rkns.Models.Project();
|
|
|
135 |
|
|
|
136 |
if (typeof this.options.user_id !== "undefined") {
|
|
|
137 |
this.current_user = this.options.user_id;
|
|
|
138 |
}
|
|
|
139 |
this.$ = Rkns.$("#" + this.options.container);
|
|
|
140 |
this.$
|
|
|
141 |
.addClass("Rk-Main")
|
|
|
142 |
.html(this.template(this));
|
|
|
143 |
this.renderer = new Rkns.Renderer.Scene(this);
|
|
|
144 |
this.tabs = [];
|
|
|
145 |
this.search_engines = [];
|
|
|
146 |
|
|
|
147 |
this.current_user_list = new Rkns.Models.UsersList();
|
|
|
148 |
|
|
|
149 |
if (!this.options.search.length) {
|
|
|
150 |
this.$.find(".Rk-Web-Search-Form").detach();
|
|
|
151 |
} else {
|
|
|
152 |
var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'),
|
|
|
153 |
_select = this.$.find(".Rk-Search-List"),
|
|
|
154 |
_input = this.$.find(".Rk-Web-Search-Input"),
|
|
|
155 |
_form = this.$.find(".Rk-Web-Search-Form");
|
|
|
156 |
Rkns._(this.options.search).each(function(_search, _key) {
|
|
|
157 |
if (Rkns[_search.type] && Rkns[_search.type].Search) {
|
|
|
158 |
_this.search_engines.push(new Rkns[_search.type].Search(_this, _search));
|
|
|
159 |
}
|
|
|
160 |
});
|
|
|
161 |
_select.html(
|
|
|
162 |
Rkns._(this.search_engines).map(function(_search, _key) {
|
|
|
163 |
return _tmpl({
|
|
|
164 |
key: _key,
|
|
|
165 |
title: _search.getSearchTitle(),
|
|
|
166 |
className: _search.getBgClass()
|
|
|
167 |
});
|
|
|
168 |
}).join("")
|
|
|
169 |
);
|
|
|
170 |
_select.find("li").click(function() {
|
|
|
171 |
var _el = Rkns.$(this);
|
|
|
172 |
_this.setSearchEngine(_el.attr("data-key"));
|
|
|
173 |
_form.submit();
|
|
|
174 |
});
|
|
|
175 |
_form.submit(function() {
|
|
|
176 |
if (_input.val()) {
|
|
|
177 |
var _search = _this.search_engine;
|
|
|
178 |
_search.search(_input.val());
|
|
|
179 |
}
|
|
|
180 |
return false;
|
|
|
181 |
});
|
|
|
182 |
this.$.find(".Rk-Search-Current").mouseenter(
|
|
|
183 |
function() { _select.slideDown(); }
|
|
|
184 |
);
|
|
|
185 |
this.$.find(".Rk-Search-Select").mouseleave(
|
|
|
186 |
function() { _select.hide(); }
|
|
|
187 |
);
|
|
|
188 |
this.setSearchEngine(0);
|
|
|
189 |
}
|
|
|
190 |
Rkns._(this.options.bins).each(function(_bin) {
|
|
|
191 |
if (Rkns[_bin.type] && Rkns[_bin.type].Bin) {
|
|
|
192 |
_this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin));
|
|
|
193 |
}
|
|
|
194 |
});
|
|
|
195 |
|
|
|
196 |
var elementDropped = false;
|
|
|
197 |
|
|
|
198 |
this.$.find(".Rk-Bins")
|
|
|
199 |
.on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
|
|
|
200 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
|
|
|
201 |
if (_mainDiv.is(":hidden")) {
|
|
|
202 |
_this.$.find(".Rk-Bin-Main").slideUp();
|
|
|
203 |
_mainDiv.slideDown();
|
|
|
204 |
}
|
|
|
205 |
}).on("mouseover", ".Rk-Bin-Item", function(_e) {
|
|
|
206 |
var _t = Rkns.$(this);
|
|
|
207 |
if (_t && $(_t).attr("data-uri")) {
|
|
|
208 |
var _models = _this.project.get("nodes").where({
|
|
|
209 |
uri: $(_t).attr("data-uri")
|
|
|
210 |
});
|
|
|
211 |
Rkns._(_models).each(function(_model) {
|
|
|
212 |
_this.renderer.highlightModel(_model);
|
|
|
213 |
});
|
|
|
214 |
}
|
|
|
215 |
}).mouseout(function() {
|
|
|
216 |
_this.renderer.unhighlightAll();
|
|
|
217 |
}).on("mousemove", ".Rk-Bin-Item", function(e) {
|
|
|
218 |
try {
|
|
|
219 |
this.dragDrop();
|
|
|
220 |
}
|
|
|
221 |
catch(err) {}
|
|
|
222 |
}).on("touchstart", ".Rk-Bin-Item", function(e) {
|
|
|
223 |
elementDropped = false;
|
|
|
224 |
}).on("touchmove", ".Rk-Bin-Item", function(e) {
|
|
|
225 |
e.preventDefault();
|
|
|
226 |
var touch = e.originalEvent.changedTouches[0],
|
|
|
227 |
off = _this.renderer.canvas_$.offset(),
|
|
|
228 |
w = _this.renderer.canvas_$.width(),
|
|
|
229 |
h = _this.renderer.canvas_$.height();
|
|
|
230 |
if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) {
|
|
|
231 |
if (elementDropped) {
|
|
|
232 |
_this.renderer.onMouseMove(touch, true);
|
|
|
233 |
} else {
|
|
|
234 |
elementDropped = true;
|
|
|
235 |
var div = document.createElement('div');
|
|
|
236 |
div.appendChild(this.cloneNode(true));
|
|
|
237 |
_this.renderer.dropData({"text/html": div.innerHTML}, touch);
|
|
|
238 |
_this.renderer.onMouseDown(touch, true);
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
}).on("touchend", ".Rk-Bin-Item", function(e) {
|
|
|
242 |
if (elementDropped) {
|
|
|
243 |
_this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true);
|
|
|
244 |
}
|
|
|
245 |
elementDropped = false;
|
|
|
246 |
}).on("dragstart", ".Rk-Bin-Item", function(e) {
|
|
|
247 |
var div = document.createElement('div');
|
|
|
248 |
div.appendChild(this.cloneNode(true));
|
|
|
249 |
try {
|
|
|
250 |
e.originalEvent.dataTransfer.setData("text/html",div.innerHTML);
|
|
|
251 |
}
|
|
|
252 |
catch(err) {
|
|
|
253 |
e.originalEvent.dataTransfer.setData("text",div.innerHTML);
|
|
|
254 |
}
|
|
|
255 |
});
|
|
|
256 |
Rkns.$(window).resize(function() {
|
|
|
257 |
_this.resizeBins();
|
|
|
258 |
});
|
|
|
259 |
|
|
|
260 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() {
|
|
|
261 |
var val = Rkns.$(this).val();
|
|
|
262 |
Rkns._(_this.tabs).each(function(tab) {
|
|
|
263 |
tab.render(val);
|
|
|
264 |
});
|
|
|
265 |
});
|
|
|
266 |
this.$.find(".Rk-Bins-Search-Form").submit(function() {
|
|
|
267 |
return false;
|
|
|
268 |
});
|
|
|
269 |
};
|
|
|
270 |
|
|
|
271 |
Rkns.Renkan.prototype.template = Rkns._.template(
|
|
|
272 |
'<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>'
|
|
|
273 |
+ '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search the Web") %>" />'
|
|
|
274 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>'
|
|
|
275 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>'
|
|
|
276 |
+ '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="<%- translate("Search in Bins") %>" />'
|
|
|
277 |
+ '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>'
|
|
|
278 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>'
|
|
|
279 |
);
|
|
|
280 |
|
|
|
281 |
Rkns.Renkan.prototype.translate = function(_text) {
|
|
|
282 |
if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) {
|
|
|
283 |
return Rkns.i18n[this.options.language][_text];
|
|
|
284 |
}
|
|
|
285 |
if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) {
|
|
|
286 |
return Rkns.i18n[this.options.language.substr(0,2)][_text];
|
|
|
287 |
}
|
|
|
288 |
return _text;
|
|
|
289 |
};
|
|
|
290 |
|
|
|
291 |
Rkns.Renkan.prototype.onStatusChange = function() {
|
|
|
292 |
this.renderer.onStatusChange();
|
|
|
293 |
};
|
|
|
294 |
|
|
|
295 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) {
|
|
|
296 |
this.search_engine = this.search_engines[_key];
|
|
|
297 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass());
|
|
|
298 |
};
|
|
|
299 |
|
|
|
300 |
Rkns.Renkan.prototype.resizeBins = function() {
|
|
|
301 |
var _d = + this.$.find(".Rk-Bins-Head").outerHeight();
|
|
|
302 |
this.$.find(".Rk-Bin-Title:visible").each(function() {
|
|
|
303 |
_d += Rkns.$(this).outerHeight();
|
|
|
304 |
});
|
|
|
305 |
this.$.find(".Rk-Bin-Main").css({
|
|
|
306 |
height: this.$.find(".Rk-Bins").height() - _d
|
|
|
307 |
});
|
|
|
308 |
};
|
|
|
309 |
|
|
|
310 |
/* Utility functions */
|
|
|
311 |
|
|
|
312 |
Rkns.Utils = {
|
|
|
313 |
_ID_AUTO_INCREMENT : 0,
|
|
|
314 |
_ID_BASE : (function(_d) {
|
|
|
315 |
|
|
|
316 |
function pad(n){return n<10 ? '0'+n : n;}
|
|
|
317 |
function fillrand(n) {
|
|
|
318 |
var _res = '';
|
|
|
319 |
for (var i=0; i<n; i++) {
|
|
|
320 |
_res += Math.floor(16*Math.random()).toString(16);
|
|
|
321 |
}
|
|
|
322 |
return _res;
|
|
|
323 |
}
|
|
|
324 |
return _d.getUTCFullYear() + '-'
|
|
|
325 |
+ pad(_d.getUTCMonth()+1) + '-'
|
|
|
326 |
+ pad(_d.getUTCDate()) + '-'
|
|
|
327 |
+ fillrand(16);
|
|
|
328 |
|
|
|
329 |
})(new Date()),
|
|
|
330 |
getUID : function(_base) {
|
|
|
331 |
|
|
|
332 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16),
|
|
|
333 |
_base = (typeof _base === "undefined" ? "" : _base + "-" );
|
|
|
334 |
while (_n.length < 4) {
|
|
|
335 |
_n = '0' + _n;
|
|
|
336 |
}
|
|
|
337 |
return _base + this._ID_BASE + '-' + _n;
|
|
|
338 |
|
|
|
339 |
},
|
|
|
340 |
getFullURL : function(url) {
|
|
|
341 |
|
|
|
342 |
if(typeof(url) == 'undefined' || url == null ) {
|
|
|
343 |
return "";
|
|
|
344 |
}
|
|
|
345 |
if(/https?:\/\//.test(url)) {
|
|
|
346 |
return url;
|
|
|
347 |
}
|
|
|
348 |
var img = new Image();
|
|
|
349 |
img.src = url;
|
|
|
350 |
var res = img.src;
|
|
|
351 |
img.src = null;
|
|
|
352 |
return res;
|
|
|
353 |
|
|
|
354 |
},
|
|
|
355 |
inherit : function(_baseClass, _callbefore) {
|
|
|
356 |
|
|
|
357 |
var _class = function(_arg) {
|
|
|
358 |
if (typeof _callbefore === "function") {
|
|
|
359 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0));
|
|
|
360 |
}
|
|
|
361 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0));
|
|
|
362 |
if (typeof this._init == "function" && !this._initialized) {
|
|
|
363 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0));
|
|
|
364 |
this._initialized = true;
|
|
|
365 |
}
|
|
|
366 |
};
|
|
|
367 |
Rkns._(_class.prototype).extend(_baseClass.prototype);
|
|
|
368 |
return _class;
|
|
|
369 |
|
|
|
370 |
}
|
|
|
371 |
};
|
|
|
372 |
|
|
|
373 |
/* *********************************************************
|
|
|
374 |
end of main.js
|
|
|
375 |
************************************************************
|
|
|
376 |
************************************************************
|
|
|
377 |
start of models.js
|
|
|
378 |
********************************************************* */
|
|
|
379 |
|
|
|
380 |
(function() {
|
|
|
381 |
|
|
|
382 |
var root = this;
|
|
|
383 |
|
|
|
384 |
var Backbone = root.Backbone;
|
|
|
385 |
|
|
|
386 |
var Models = root.Rkns.Models = {};
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
Models.getUID = function(obj) {
|
|
|
390 |
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
|
391 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
|
|
392 |
return v.toString(16);
|
|
|
393 |
});
|
|
|
394 |
return obj.type + "-" + guid;
|
|
|
395 |
};
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
var RenkanModel = Backbone.RelationalModel.extend({
|
|
|
399 |
idAttribute : "_id",
|
|
|
400 |
constructor: function(options) {
|
|
|
401 |
|
|
|
402 |
if (typeof options !== "undefined") {
|
|
|
403 |
options._id = options._id || options.id || Models.getUID(this);
|
|
|
404 |
options.title = options.title || "";
|
|
|
405 |
options.description = options.description || "";
|
|
|
406 |
options.uri = options.uri || "";
|
|
|
407 |
|
|
|
408 |
if(typeof this.prepare === "function") {
|
|
|
409 |
options = this.prepare(options);
|
|
|
410 |
}
|
|
|
411 |
}
|
|
|
412 |
Backbone.RelationalModel.prototype.constructor.call(this, options);
|
|
|
413 |
},
|
|
|
414 |
validate: function() {
|
|
|
415 |
if(!this.type) {
|
|
|
416 |
return "object has no type";
|
|
|
417 |
}
|
|
|
418 |
},
|
|
|
419 |
addReference : function(_options, _propName, _list, _id, _default) {
|
|
|
420 |
var _element = _list.get(_id);
|
|
|
421 |
if (typeof _element === "undefined" && typeof _default !== "undefined") {
|
|
|
422 |
_options[_propName ] = _default;
|
|
|
423 |
}
|
|
|
424 |
else {
|
|
|
425 |
_options[_propName ] = _element;
|
|
|
426 |
}
|
|
|
427 |
}
|
|
|
428 |
});
|
|
|
429 |
|
|
|
430 |
// USER
|
|
|
431 |
var User = Models.User = RenkanModel.extend({
|
|
|
432 |
type: "user",
|
|
|
433 |
prepare: function(options) {
|
|
|
434 |
options.color = options.color || "#666666";
|
|
|
435 |
return options;
|
|
|
436 |
},
|
|
|
437 |
toJSON: function() {
|
|
|
438 |
return {
|
|
|
439 |
_id: this.get("_id"),
|
|
|
440 |
title: this.get("title"),
|
|
|
441 |
uri: this.get("uri"),
|
|
|
442 |
description: this.get("description"),
|
|
|
443 |
color: this.get("color"),
|
|
|
444 |
};
|
|
|
445 |
},
|
|
|
446 |
});
|
|
|
447 |
|
|
|
448 |
// NODE
|
|
|
449 |
var Node = Models.Node = RenkanModel.extend({
|
|
|
450 |
type: "node",
|
|
|
451 |
relations: [{
|
|
|
452 |
type: Backbone.HasOne,
|
|
|
453 |
key: "created_by",
|
|
|
454 |
relatedModel: User
|
|
|
455 |
}],
|
|
|
456 |
prepare: function(options) {
|
|
|
457 |
project = options.project;
|
|
|
458 |
this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user);
|
|
|
459 |
options.description = options.description || "";
|
|
|
460 |
return options;
|
|
|
461 |
},
|
|
|
462 |
toJSON: function() {
|
|
|
463 |
return {
|
|
|
464 |
_id: this.get("_id"),
|
|
|
465 |
title: this.get("title"),
|
|
|
466 |
uri: this.get("uri"),
|
|
|
467 |
description: this.get("description"),
|
|
|
468 |
position: this.get("position"),
|
|
|
469 |
image: this.get("image"),
|
|
|
470 |
color: this.get("color"),
|
|
|
471 |
created_by: this.get("created_by") ? this.get("created_by").get("_id") : null,
|
|
|
472 |
size: this.get("size"),
|
|
|
473 |
"clip-path": this.get("clip-path")
|
|
|
474 |
};
|
|
|
475 |
},
|
|
|
476 |
});
|
|
|
477 |
|
|
|
478 |
// EDGE
|
|
|
479 |
var Edge = Models.Edge = RenkanModel.extend({
|
|
|
480 |
type: "edge",
|
|
|
481 |
relations: [
|
|
|
482 |
{
|
|
|
483 |
type: Backbone.HasOne,
|
|
|
484 |
key: "created_by",
|
|
|
485 |
relatedModel: User
|
|
|
486 |
},
|
|
|
487 |
{
|
|
|
488 |
type: Backbone.HasOne,
|
|
|
489 |
key: "from",
|
|
|
490 |
relatedModel: Node
|
|
|
491 |
},
|
|
|
492 |
{
|
|
|
493 |
type: Backbone.HasOne,
|
|
|
494 |
key: "to",
|
|
|
495 |
relatedModel: Node
|
|
|
496 |
},
|
|
|
497 |
],
|
|
|
498 |
prepare: function(options) {
|
|
|
499 |
project = options.project;
|
|
|
500 |
this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user);
|
|
|
501 |
this.addReference(options, "from", project.get("nodes"), options.from);
|
|
|
502 |
this.addReference(options, "to", project.get("nodes"), options.to);
|
|
|
503 |
return options;
|
|
|
504 |
},
|
|
|
505 |
toJSON: function() {
|
|
|
506 |
return {
|
|
|
507 |
_id: this.get("_id"),
|
|
|
508 |
title: this.get("title"),
|
|
|
509 |
uri: this.get("uri"),
|
|
|
510 |
description: this.get("description"),
|
|
|
511 |
from: this.get("from") ? this.get("from").get("_id") : null,
|
|
|
512 |
to: this.get("to") ? this.get("to").get("_id") : null,
|
|
|
513 |
color: this.get("color"),
|
|
|
514 |
created_by: this.get("created_by") ? this.get("created_by").get("_id") : null
|
|
|
515 |
};
|
|
|
516 |
},
|
|
|
517 |
});
|
|
|
518 |
|
|
|
519 |
// PROJECT
|
|
|
520 |
var Project = Models.Project = RenkanModel.extend({
|
|
|
521 |
type: "project",
|
|
|
522 |
relations: [
|
|
|
523 |
{
|
|
|
524 |
type: Backbone.HasMany,
|
|
|
525 |
key: "users",
|
|
|
526 |
relatedModel: User,
|
|
|
527 |
reverseRelation: {
|
|
|
528 |
key: 'project',
|
|
|
529 |
includeInJSON: '_id'
|
|
|
530 |
},
|
|
|
531 |
},
|
|
|
532 |
{
|
|
|
533 |
type: Backbone.HasMany,
|
|
|
534 |
key: "nodes",
|
|
|
535 |
relatedModel: Node,
|
|
|
536 |
reverseRelation: {
|
|
|
537 |
key: 'project',
|
|
|
538 |
includeInJSON: '_id'
|
|
|
539 |
},
|
|
|
540 |
},
|
|
|
541 |
{
|
|
|
542 |
type: Backbone.HasMany,
|
|
|
543 |
key: "edges",
|
|
|
544 |
relatedModel: Edge,
|
|
|
545 |
reverseRelation: {
|
|
|
546 |
key: 'project',
|
|
|
547 |
includeInJSON: '_id'
|
|
|
548 |
},
|
|
|
549 |
}
|
|
|
550 |
],
|
|
|
551 |
addUser: function(_props, _options) {
|
|
|
552 |
_props.project = this;
|
|
|
553 |
var _user = User.findOrCreate(_props);
|
|
|
554 |
this.get("users").push(_user, _options);
|
|
|
555 |
return _user;
|
|
|
556 |
},
|
|
|
557 |
addNode: function(_props, _options) {
|
|
|
558 |
_props.project = this;
|
|
|
559 |
var _node = Node.findOrCreate(_props);
|
|
|
560 |
this.get("nodes").push(_node, _options);
|
|
|
561 |
return _node;
|
|
|
562 |
},
|
|
|
563 |
addEdge: function(_props, _options) {
|
|
|
564 |
_props.project = this;
|
|
|
565 |
var _edge = Edge.findOrCreate(_props);
|
|
|
566 |
this.get("edges").push(_edge, _options);
|
|
|
567 |
return _edge;
|
|
|
568 |
},
|
|
|
569 |
removeNode: function(_model) {
|
|
|
570 |
this.get("nodes").remove(_model);
|
|
|
571 |
},
|
|
|
572 |
removeEdge: function(_model) {
|
|
|
573 |
this.get("edges").remove(_model);
|
|
|
574 |
},
|
|
|
575 |
validate: function(options) {
|
|
|
576 |
var _project = this;
|
|
|
577 |
_(options.users).each(function(_item) {
|
|
|
578 |
_item.project = _project;
|
|
|
579 |
});
|
|
|
580 |
_(options.nodes).each(function(_item) {
|
|
|
581 |
_item.project = _project;
|
|
|
582 |
});
|
|
|
583 |
_(options.edges).each(function(_item) {
|
|
|
584 |
_item.project = _project;
|
|
|
585 |
});
|
|
|
586 |
},
|
|
|
587 |
// Add event handler to remove edges when a node is removed
|
|
|
588 |
initialize: function() {
|
|
|
589 |
var _this = this;
|
|
|
590 |
this.on("remove:nodes", function(_node) {
|
|
|
591 |
_this.get("edges").remove(
|
|
|
592 |
_this.get("edges").filter(function(_edge) {
|
|
|
593 |
return _edge.get("from") == _node || _edge.get("to") == _node;
|
|
|
594 |
})
|
|
|
595 |
);
|
|
|
596 |
});
|
|
|
597 |
}
|
|
|
598 |
});
|
|
|
599 |
|
|
|
600 |
var RosterUser = Models.RosterUser = Backbone.Model.extend({
|
|
|
601 |
type: "roster_user",
|
|
|
602 |
idAttribute : "_id",
|
|
|
603 |
|
|
|
604 |
constructor: function(options) {
|
|
|
605 |
|
|
|
606 |
if (typeof options !== "undefined") {
|
|
|
607 |
options._id = options._id || options.id || Models.getUID(this);
|
|
|
608 |
options.title = options.title || "(untitled " + this.type + ")";
|
|
|
609 |
options.description = options.description || "";
|
|
|
610 |
options.uri = options.uri || "";
|
|
|
611 |
options.project = options.project || null;
|
|
|
612 |
options.site_id = options.site_id || 0;
|
|
|
613 |
|
|
|
614 |
if(typeof this.prepare === "function") {
|
|
|
615 |
options = this.prepare(options);
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
Backbone.Model.prototype.constructor.call(this, options);
|
|
|
619 |
},
|
|
|
620 |
|
|
|
621 |
validate: function() {
|
|
|
622 |
if(!this.type) {
|
|
|
623 |
return "object has no type";
|
|
|
624 |
}
|
|
|
625 |
},
|
|
|
626 |
|
|
|
627 |
prepare: function(options) {
|
|
|
628 |
options.color = options.color || "#666666";
|
|
|
629 |
return options;
|
|
|
630 |
},
|
|
|
631 |
|
|
|
632 |
toJSON: function() {
|
|
|
633 |
return {
|
|
|
634 |
_id: this.get("_id"),
|
|
|
635 |
title: this.get("title"),
|
|
|
636 |
uri: this.get("uri"),
|
|
|
637 |
description: this.get("description"),
|
|
|
638 |
color: this.get("color"),
|
|
|
639 |
project: (this.get("project") != null)?this.get("project").get("id"):null,
|
|
|
640 |
site_id: this.get("site_id")
|
|
|
641 |
};
|
|
|
642 |
},
|
|
|
643 |
});
|
|
|
644 |
|
|
|
645 |
var UsersList = Models.UsersList = Backbone.Collection.extend({
|
|
|
646 |
model: RosterUser
|
|
|
647 |
});
|
|
|
648 |
|
|
|
649 |
|
|
|
650 |
}).call(window);
|
|
|
651 |
|
|
|
652 |
|
|
|
653 |
/* *********************************************************
|
|
|
654 |
end of models.js
|
|
|
655 |
************************************************************
|
|
|
656 |
************************************************************
|
|
|
657 |
start of defaults.js
|
|
|
658 |
********************************************************* */
|
|
|
659 |
|
|
|
660 |
Rkns.defaults = {
|
|
|
661 |
|
|
|
662 |
language: (navigator.language || navigator.userLanguage || "en"),
|
|
|
663 |
/* GUI Language */
|
|
|
664 |
container: "renkan",
|
|
|
665 |
/* GUI Container DOM element ID */
|
|
|
666 |
search: [],
|
|
|
667 |
/* List of Search Engines */
|
|
|
668 |
bins: [],
|
|
|
669 |
/* List of Bins */
|
|
|
670 |
static_url: "",
|
|
|
671 |
/* URL for static resources */
|
|
|
672 |
show_bins: true,
|
|
|
673 |
/* Show bins in left column */
|
|
|
674 |
properties: [],
|
|
|
675 |
/* Semantic properties for edges */
|
|
|
676 |
read_only: false,
|
|
|
677 |
/* Allows editing of renkan without changing the rest of the GUI. Can be switched on/off on the fly to block/enable editing */
|
|
|
678 |
editor_mode: true,
|
|
|
679 |
/* Switch for Publish/Edit GUI. If editor_mode is false, read_only will be true. */
|
|
|
680 |
snapshot_mode: false,
|
|
|
681 |
/* In snapshot mode, clicking on the floppy will save a snapshot. Otherwise, it will show the connection status */
|
|
|
682 |
show_top_bar: true,
|
|
|
683 |
/* Show the top bar, (title, buttons, users) */
|
|
|
684 |
default_user_color: "#303030",
|
|
|
685 |
size_bug_fix: true,
|
|
|
686 |
/* Resize the canvas after load (fixes a bug on iPad and FF Mac) */
|
|
|
687 |
force_resize: false,
|
|
|
688 |
allow_double_click: true,
|
|
|
689 |
/* Allows Double Click to create a node on an empty background */
|
|
|
690 |
element_delete_delay: 0,
|
|
|
691 |
/* Delay between clicking on the bin on an element and really deleting it
|
|
|
692 |
Set to 0 for delete confirm */
|
|
|
693 |
autoscale_padding: 50,
|
|
|
694 |
|
|
|
695 |
/* MINI-MAP OPTIONS */
|
|
|
696 |
|
|
|
697 |
show_minimap: true,
|
|
|
698 |
/* Show a small map at the bottom right */
|
|
|
699 |
minimap_width: 160,
|
|
|
700 |
minimap_height: 120,
|
|
|
701 |
minimap_padding: 20,
|
|
|
702 |
minimap_background_color: "#ffffff",
|
|
|
703 |
minimap_border_color: "#cccccc",
|
|
|
704 |
minimap_highlight_color: "#ffff00",
|
|
|
705 |
minimap_highlight_weight: 5,
|
|
|
706 |
|
|
|
707 |
/* EDGE/NODE COMMON OPTIONS */
|
|
|
708 |
|
|
|
709 |
buttons_background: "#202020",
|
|
|
710 |
buttons_label_color: "#c000c0",
|
|
|
711 |
buttons_label_font_size: 9,
|
|
|
712 |
|
|
|
713 |
/* NODE DISPLAY OPTIONS */
|
|
|
714 |
|
|
|
715 |
show_node_circles: true,
|
|
|
716 |
/* Show circles for nodes */
|
|
|
717 |
clip_node_images: true,
|
|
|
718 |
/* Constraint node images to circles */
|
|
|
719 |
node_images_fill_mode: false,
|
|
|
720 |
/* Set to false for "letterboxing" (height/width of node adapted to show full image)
|
|
|
721 |
Set to true for "crop" (adapted to fill circle) */
|
|
|
722 |
node_size_base: 25,
|
|
|
723 |
node_stroke_width: 2,
|
|
|
724 |
selected_node_stroke_width: 4,
|
|
|
725 |
node_fill_color: "#ffffff",
|
|
|
726 |
highlighted_node_fill_color: "#ffff00",
|
|
|
727 |
node_label_distance: 5,
|
|
|
728 |
/* Vertical distance between node and label */
|
|
|
729 |
node_label_max_length: 60,
|
|
|
730 |
/* Maximum displayed text length */
|
|
|
731 |
label_untitled_nodes: "(untitled)",
|
|
|
732 |
/* Label to display on untitled nodes */
|
|
|
733 |
|
|
|
734 |
/* EDGE DISPLAY OPTIONS */
|
|
|
735 |
|
|
|
736 |
edge_stroke_width: 2,
|
|
|
737 |
selected_edge_stroke_width: 4,
|
|
|
738 |
edge_label_distance: 0,
|
|
|
739 |
edge_label_max_length: 20,
|
|
|
740 |
edge_arrow_length: 18,
|
|
|
741 |
edge_arrow_width: 12,
|
|
|
742 |
edge_gap_in_bundles: 12,
|
|
|
743 |
label_untitled_edges: "",
|
|
|
744 |
|
|
|
745 |
/* CONTEXTUAL DISPLAY (TOOLTIP OR EDITOR) OPTIONS */
|
|
|
746 |
|
|
|
747 |
tooltip_width: 275,
|
|
|
748 |
tooltip_padding: 10,
|
|
|
749 |
tooltip_margin: 15,
|
|
|
750 |
tooltip_arrow_length : 20,
|
|
|
751 |
tooltip_arrow_width : 40,
|
|
|
752 |
tooltip_top_color: "#f0f0f0",
|
|
|
753 |
tooltip_bottom_color: "#d0d0d0",
|
|
|
754 |
tooltip_border_color: "#808080",
|
|
|
755 |
tooltip_border_width: 1,
|
|
|
756 |
|
|
|
757 |
/* NODE EDITOR OPTIONS */
|
|
|
758 |
|
|
|
759 |
show_node_editor_uri: true,
|
|
|
760 |
show_node_editor_description: true,
|
|
|
761 |
show_node_editor_size: true,
|
|
|
762 |
show_node_editor_color: true,
|
|
|
763 |
show_node_editor_image: true,
|
|
|
764 |
show_node_editor_creator: true,
|
|
|
765 |
|
|
|
766 |
/* NODE TOOLTIP OPTIONS */
|
|
|
767 |
|
|
|
768 |
show_node_tooltip_uri: true,
|
|
|
769 |
show_node_tooltip_description: true,
|
|
|
770 |
show_node_tooltip_color: true,
|
|
|
771 |
show_node_tooltip_image: true,
|
|
|
772 |
show_node_tooltip_creator: true,
|
|
|
773 |
|
|
|
774 |
/* EDGE EDITOR OPTIONS */
|
|
|
775 |
|
|
|
776 |
show_edge_editor_uri: true,
|
|
|
777 |
show_edge_editor_color: true,
|
|
|
778 |
show_edge_editor_direction: true,
|
|
|
779 |
show_edge_editor_nodes: true,
|
|
|
780 |
show_edge_editor_creator: true,
|
|
|
781 |
|
|
|
782 |
/* EDGE TOOLTIP OPTIONS */
|
|
|
783 |
|
|
|
784 |
show_edge_tooltip_uri: true,
|
|
|
785 |
show_edge_tooltip_color: true,
|
|
|
786 |
show_edge_tooltip_nodes: true,
|
|
|
787 |
show_edge_tooltip_creator: true
|
|
|
788 |
|
|
|
789 |
/* */
|
|
|
790 |
|
|
|
791 |
};
|
|
|
792 |
|
|
|
793 |
/* *********************************************************
|
|
|
794 |
end of defaults.js
|
|
|
795 |
************************************************************
|
|
|
796 |
************************************************************
|
|
|
797 |
start of i18n.js
|
|
|
798 |
********************************************************* */
|
|
|
799 |
|
|
|
800 |
Rkns.i18n = {
|
|
|
801 |
fr: {
|
|
|
802 |
"Edit Node": "Édition d’un nœud",
|
|
|
803 |
"Edit Edge": "Édition d’un lien",
|
|
|
804 |
"Title:": "Titre :",
|
|
|
805 |
"URI:": "URI :",
|
|
|
806 |
"Description:": "Description :",
|
|
|
807 |
"From:": "De :",
|
|
|
808 |
"To:": "Vers :",
|
|
|
809 |
"Image": "Image",
|
|
|
810 |
"Image URL:": "URL d'Image",
|
|
|
811 |
"Choose Image File:": "Choisir un fichier image",
|
|
|
812 |
"Full Screen": "Mode plein écran",
|
|
|
813 |
"Add Node": "Ajouter un nœud",
|
|
|
814 |
"Add Edge": "Ajouter un lien",
|
|
|
815 |
"Archive Project": "Archiver le projet",
|
|
|
816 |
"Auto-save enabled": "Enregistrement automatique activé",
|
|
|
817 |
"Connection lost": "Connexion perdue",
|
|
|
818 |
"Created by:": "Créé par :",
|
|
|
819 |
"Zoom In": "Agrandir l’échelle",
|
|
|
820 |
"Zoom Out": "Rapetisser l’échelle",
|
|
|
821 |
"Edit": "Éditer",
|
|
|
822 |
"Remove": "Supprimer",
|
|
|
823 |
"Cancel deletion": "Annuler la suppression",
|
|
|
824 |
"Link to another node": "Créer un lien",
|
|
|
825 |
"Enlarge": "Agrandir",
|
|
|
826 |
"Shrink": "Rétrécir",
|
|
|
827 |
"Click on the background canvas to add a node": "Cliquer sur le fond du graphe pour rajouter un nœud",
|
|
|
828 |
"Click on a first node to start the edge": "Cliquer sur un premier nœud pour commencer le lien",
|
|
|
829 |
"Click on a second node to complete the edge": "Cliquer sur un second nœud pour terminer le lien",
|
|
|
830 |
"Twitter": "Twitter",
|
|
|
831 |
"Wikipedia": "Wikipédia",
|
|
|
832 |
"Wikipedia in ": "Wikipédia en ",
|
|
|
833 |
"French": "Français",
|
|
|
834 |
"English": "Anglais",
|
|
|
835 |
"Japanese": "Japonais",
|
|
|
836 |
"Untitled project": "Projet sans titre",
|
|
|
837 |
"Lignes de Temps": "Lignes de Temps",
|
|
|
838 |
"Loading, please wait": "Chargement en cours, merci de patienter",
|
|
|
839 |
"Edge color:": "Couleur :",
|
|
|
840 |
"Node color:": "Couleur :",
|
|
|
841 |
"Choose color": "Choisir une couleur",
|
|
|
842 |
"Change edge direction": "Changer le sens du lien",
|
|
|
843 |
"Do you really wish to remove node ": "Voulez-vous réellement supprimer le nœud ",
|
|
|
844 |
"Do you really wish to remove edge ": "Voulez-vous réellement supprimer le lien ",
|
|
|
845 |
"This file is not an image": "Ce fichier n'est pas une image",
|
|
|
846 |
"Image size must be under ": "L'image doit peser moins de ",
|
|
|
847 |
"Size:": "Taille :",
|
|
|
848 |
"KB": "ko",
|
|
|
849 |
"Choose from vocabulary:": "Choisir dans un vocabulaire :",
|
|
|
850 |
"SKOS Documentation properties": "SKOS: Propriétés documentaires",
|
|
|
851 |
"has note": "a pour note",
|
|
|
852 |
"has example": "a pour exemple",
|
|
|
853 |
"has definition": "a pour définition",
|
|
|
854 |
"SKOS Semantic relations": "SKOS: Relations sémantiques",
|
|
|
855 |
"has broader": "a pour concept plus large",
|
|
|
856 |
"has narrower": "a pour concept plus étroit",
|
|
|
857 |
"has related": "a pour concept apparenté",
|
|
|
858 |
"Dublin Core Metadata": "Métadonnées Dublin Core",
|
|
|
859 |
"has contributor": "a pour contributeur",
|
|
|
860 |
"covers": "couvre",
|
|
|
861 |
"created by": "créé par",
|
|
|
862 |
"has date": "a pour date",
|
|
|
863 |
"published by": "édité par",
|
|
|
864 |
"has source": "a pour source",
|
|
|
865 |
"has subject": "a pour sujet",
|
|
|
866 |
"Dragged resource": "Ressource glisée-déposée",
|
|
|
867 |
"Search the Web": "Rechercher en ligne",
|
|
|
868 |
"Search in Bins": "Rechercher dans les chutiers",
|
|
|
869 |
"Close bin": "Fermer le chutier",
|
|
|
870 |
"Refresh bin": "Rafraîchir le chutier",
|
|
|
871 |
"(untitled)": "(sans titre)",
|
|
|
872 |
"Select contents:": "Sélectionner des contenus :",
|
|
|
873 |
"Drag items from this website, drop them in Renkan": "Glissez des éléments de ce site web vers Renkan",
|
|
|
874 |
"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.": "Glissez ce bouton vers votre barre de favoris. Ensuite, depuis un site tiers, cliquez dessus pour activer 'Drag-to-Add' puis glissez des éléments de ce site vers Renkan"
|
|
|
875 |
}
|
|
|
876 |
}
|
|
|
877 |
|
|
|
878 |
/* *********************************************************
|
|
|
879 |
end of i18n.js
|
|
|
880 |
************************************************************
|
|
|
881 |
************************************************************
|
|
|
882 |
start of paper-renderer.js
|
|
|
883 |
********************************************************* */
|
|
|
884 |
|
|
|
885 |
Rkns.Renderer = {
|
|
|
886 |
_MIN_DRAG_DISTANCE: 2,
|
|
|
887 |
_NODE_BUTTON_WIDTH: 40,
|
|
|
888 |
_EDGE_BUTTON_INNER: 2,
|
|
|
889 |
_EDGE_BUTTON_OUTER: 40,
|
|
|
890 |
_CLICKMODE_ADDNODE : 1,
|
|
|
891 |
_CLICKMODE_STARTEDGE : 2,
|
|
|
892 |
_CLICKMODE_ENDEDGE : 3,
|
|
|
893 |
_IMAGE_MAX_KB : 500,
|
|
|
894 |
_NODE_SIZE_STEP: Math.LN2/4,
|
|
|
895 |
_MIN_SCALE: 1/20,
|
|
|
896 |
_MAX_SCALE: 20,
|
|
|
897 |
_MOUSEMOVE_RATE: 80,
|
|
|
898 |
_DOUBLETAP_DELAY: 800,
|
|
|
899 |
_DOUBLETAP_DISTANCE: 20*20,
|
|
|
900 |
_USER_PLACEHOLDER : function(_renkan) {
|
|
|
901 |
return {
|
|
|
902 |
color: _renkan.options.default_user_color,
|
|
|
903 |
title: _renkan.translate("(unknown user)"),
|
|
|
904 |
get: function(attr) {
|
|
|
905 |
return this[attr] || false;
|
|
|
906 |
}
|
|
|
907 |
};
|
|
|
908 |
},
|
|
|
909 |
_BOOKMARKLET_CODE: function(_renkan) {
|
|
|
910 |
return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">"
|
|
|
911 |
+ _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_")
|
|
|
912 |
+ "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();";
|
|
|
913 |
},
|
|
|
914 |
shortenText : function(_text, _maxlength) {
|
|
|
915 |
return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text);
|
|
|
916 |
},
|
|
|
917 |
drawEditBox : function(_options, _coords, _path, _xmargin, _selector) {
|
|
|
918 |
_selector.css({
|
|
|
919 |
width: ( _options.tooltip_width - 2* _options.tooltip_padding ),
|
|
|
920 |
});
|
|
|
921 |
var _height = _selector.outerHeight() + 2* _options.tooltip_padding,
|
|
|
922 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1),
|
|
|
923 |
_left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ),
|
|
|
924 |
_right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ),
|
|
|
925 |
_top = _coords.y - _height / 2;
|
|
|
926 |
if (_top + _height > (paper.view.size.height - _options.tooltip_margin)) {
|
|
|
927 |
_top = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 ) - _height;
|
|
|
928 |
}
|
|
|
929 |
if (_top < _options.tooltip_margin) {
|
|
|
930 |
_top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
|
|
|
931 |
}
|
|
|
932 |
var _bottom = _top + _height;
|
|
|
933 |
_path.segments[0].point
|
|
|
934 |
= _path.segments[7].point
|
|
|
935 |
= _coords.add([_isLeft * _xmargin, 0]);
|
|
|
936 |
_path.segments[1].point.x
|
|
|
937 |
= _path.segments[2].point.x
|
|
|
938 |
= _path.segments[5].point.x
|
|
|
939 |
= _path.segments[6].point.x
|
|
|
940 |
= _left;
|
|
|
941 |
_path.segments[3].point.x
|
|
|
942 |
= _path.segments[4].point.x
|
|
|
943 |
= _right;
|
|
|
944 |
_path.segments[2].point.y
|
|
|
945 |
= _path.segments[3].point.y
|
|
|
946 |
= _top;
|
|
|
947 |
_path.segments[4].point.y
|
|
|
948 |
= _path.segments[5].point.y
|
|
|
949 |
= _bottom;
|
|
|
950 |
_path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2;
|
|
|
951 |
_path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2;
|
|
|
952 |
_path.closed = true;
|
|
|
953 |
_path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
|
|
|
954 |
_selector.css({
|
|
|
955 |
left: (_options.tooltip_padding + Math.min(_left, _right)),
|
|
|
956 |
top: (_options.tooltip_padding + _top)
|
|
|
957 |
});
|
|
|
958 |
return _path;
|
|
|
959 |
}
|
|
|
960 |
};
|
|
|
961 |
|
|
|
962 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) {
|
|
|
963 |
if (typeof _renderer !== "undefined") {
|
|
|
964 |
this.renderer = _renderer;
|
|
|
965 |
this.renkan = _renderer.renkan;
|
|
|
966 |
this.project = _renderer.renkan.project;
|
|
|
967 |
this.options = _renderer.renkan.options;
|
|
|
968 |
this.model = _model;
|
|
|
969 |
if (this.model) {
|
|
|
970 |
var _this = this;
|
|
|
971 |
this._changeBinding = function() {
|
|
|
972 |
_this.redraw();
|
|
|
973 |
};
|
|
|
974 |
this._removeBinding = function() {
|
|
|
975 |
_renderer.removeRepresentation(_this);
|
|
|
976 |
_(function() {
|
|
|
977 |
_renderer.redraw();
|
|
|
978 |
}).defer();
|
|
|
979 |
};
|
|
|
980 |
this._selectBinding = function() {
|
|
|
981 |
_this.select();
|
|
|
982 |
};
|
|
|
983 |
this._unselectBinding = function() {
|
|
|
984 |
_this.unselect();
|
|
|
985 |
};
|
|
|
986 |
this.model.on("change", this._changeBinding );
|
|
|
987 |
this.model.on("remove", this._removeBinding );
|
|
|
988 |
this.model.on("select", this._selectBinding );
|
|
|
989 |
this.model.on("unselect", this._unselectBinding );
|
|
|
990 |
}
|
|
|
991 |
}
|
|
|
992 |
};
|
|
|
993 |
|
|
|
994 |
Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) {
|
|
|
995 |
Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
|
|
|
996 |
};
|
|
|
997 |
|
|
|
998 |
Rkns.Renderer._BaseRepresentation.prototype.redraw = function() {};
|
|
|
999 |
|
|
|
1000 |
Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {};
|
|
|
1001 |
|
|
|
1002 |
Rkns.Renderer._BaseRepresentation.prototype.show = function() {};
|
|
|
1003 |
|
|
|
1004 |
Rkns.Renderer._BaseRepresentation.prototype.hide = function() {};
|
|
|
1005 |
|
|
|
1006 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {
|
|
|
1007 |
if (this.model) {
|
|
|
1008 |
this.model.trigger("selected");
|
|
|
1009 |
}
|
|
|
1010 |
};
|
|
|
1011 |
|
|
|
1012 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {
|
|
|
1013 |
if (this.model) {
|
|
|
1014 |
this.model.trigger("unselected");
|
|
|
1015 |
}
|
|
|
1016 |
};
|
|
|
1017 |
|
|
|
1018 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {};
|
|
|
1019 |
|
|
|
1020 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {};
|
|
|
1021 |
|
|
|
1022 |
Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {};
|
|
|
1023 |
|
|
|
1024 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {
|
|
|
1025 |
if (this.model) {
|
|
|
1026 |
this.model.trigger("clicked");
|
|
|
1027 |
}
|
|
|
1028 |
};
|
|
|
1029 |
|
|
|
1030 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
|
|
|
1031 |
if (this.model) {
|
|
|
1032 |
this.model.off("change", this._changeBinding );
|
|
|
1033 |
this.model.off("remove", this._removeBinding );
|
|
|
1034 |
this.model.off("select", this._selectBinding );
|
|
|
1035 |
this.model.off("unselect", this._unselectBinding );
|
|
|
1036 |
}
|
|
|
1037 |
};
|
|
|
1038 |
|
|
|
1039 |
/* */
|
|
|
1040 |
|
|
|
1041 |
Rkns.Renderer._BaseButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
1042 |
|
|
|
1043 |
Rkns.Renderer._BaseButton.prototype.moveTo = function(_pos) {
|
|
|
1044 |
this.sector.moveTo(_pos);
|
|
|
1045 |
};
|
|
|
1046 |
|
|
|
1047 |
Rkns.Renderer._BaseButton.prototype.show = function() {
|
|
|
1048 |
this.sector.show();
|
|
|
1049 |
};
|
|
|
1050 |
|
|
|
1051 |
Rkns.Renderer._BaseButton.prototype.hide = function() {
|
|
|
1052 |
this.sector.hide();
|
|
|
1053 |
};
|
|
|
1054 |
|
|
|
1055 |
Rkns.Renderer._BaseButton.prototype.select = function() {
|
|
|
1056 |
this.sector.select();
|
|
|
1057 |
};
|
|
|
1058 |
|
|
|
1059 |
Rkns.Renderer._BaseButton.prototype.unselect = function(_newTarget) {
|
|
|
1060 |
this.sector.unselect();
|
|
|
1061 |
if (!_newTarget || (_newTarget !== this.source_representation && _newTarget.source_representation !== this.source_representation)) {
|
|
|
1062 |
this.source_representation.unselect();
|
|
|
1063 |
}
|
|
|
1064 |
};
|
|
|
1065 |
|
|
|
1066 |
Rkns.Renderer._BaseButton.prototype.destroy = function() {
|
|
|
1067 |
this.sector.destroy();
|
|
|
1068 |
};
|
|
|
1069 |
|
|
|
1070 |
/* */
|
|
|
1071 |
|
|
|
1072 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
1073 |
|
|
|
1074 |
Rkns.Renderer.Node.prototype._init = function() {
|
|
|
1075 |
this.renderer.node_layer.activate();
|
|
|
1076 |
this.type = "Node";
|
|
|
1077 |
this.circle = new paper.Path.Circle([0, 0], 1);
|
|
|
1078 |
this.circle.__representation = this;
|
|
|
1079 |
if (this.options.show_node_circles) {
|
|
|
1080 |
this.circle.strokeWidth = this.options.node_stroke_width;
|
|
|
1081 |
this.h_ratio = 1;
|
|
|
1082 |
} else {
|
|
|
1083 |
this.h_ratio = 0;
|
|
|
1084 |
}
|
|
|
1085 |
this.title = Rkns.$('<div class="Rk-Label">').appendTo(this.renderer.labels_$);
|
|
|
1086 |
if (this.options.editor_mode) {
|
|
|
1087 |
this.normal_buttons = [
|
|
|
1088 |
new Rkns.Renderer.NodeEditButton(this.renderer, null),
|
|
|
1089 |
new Rkns.Renderer.NodeRemoveButton(this.renderer, null),
|
|
|
1090 |
new Rkns.Renderer.NodeLinkButton(this.renderer, null),
|
|
|
1091 |
new Rkns.Renderer.NodeEnlargeButton(this.renderer, null),
|
|
|
1092 |
new Rkns.Renderer.NodeShrinkButton(this.renderer, null)
|
|
|
1093 |
];
|
|
|
1094 |
this.pending_delete_buttons = [
|
|
|
1095 |
new Rkns.Renderer.NodeRevertButton(this.renderer, null)
|
|
|
1096 |
];
|
|
|
1097 |
this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
|
|
|
1098 |
for (var i = 0; i < this.all_buttons.length; i++) {
|
|
|
1099 |
this.all_buttons[i].source_representation = this;
|
|
|
1100 |
}
|
|
|
1101 |
this.active_buttons = [];
|
|
|
1102 |
} else {
|
|
|
1103 |
this.active_buttons = this.all_buttons = [];
|
|
|
1104 |
}
|
|
|
1105 |
this.last_circle_radius = 1;
|
|
|
1106 |
|
|
|
1107 |
if (this.renderer.minimap) {
|
|
|
1108 |
this.renderer.minimap.node_layer.activate();
|
|
|
1109 |
this.minimap_circle = new paper.Path.Circle([0, 0], 1);
|
|
|
1110 |
this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
|
|
|
1111 |
this.renderer.minimap.node_group.addChild(this.minimap_circle);
|
|
|
1112 |
}
|
|
|
1113 |
};
|
|
|
1114 |
|
|
|
1115 |
Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) {
|
|
|
1116 |
var _model_coords = new paper.Point(this.model.get("position")),
|
|
|
1117 |
_baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP);
|
|
|
1118 |
if (!this.is_dragging || !this.paper_coords) {
|
|
|
1119 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords);
|
|
|
1120 |
}
|
|
|
1121 |
this.circle_radius = _baseRadius * this.renderer.scale;
|
|
|
1122 |
if (this.last_circle_radius !== this.circle_radius) {
|
|
|
1123 |
this.all_buttons.forEach(function(b) {
|
|
|
1124 |
b.setSectorSize();
|
|
|
1125 |
});
|
|
|
1126 |
var square = new paper.Size(this.circle_radius, this.circle_radius),
|
|
|
1127 |
topleft = this.paper_coords.subtract(square),
|
|
|
1128 |
bounds = new paper.Rectangle(topleft, square.multiply(2));
|
|
|
1129 |
this.circle.scale(this.circle_radius / this.last_circle_radius);
|
|
|
1130 |
if (this.node_image) {
|
|
|
1131 |
this.node_image.scale(this.circle_radius / this.last_circle_radius);
|
|
|
1132 |
}
|
|
|
1133 |
}
|
|
|
1134 |
this.circle.position = this.paper_coords;
|
|
|
1135 |
if (this.node_image) {
|
|
|
1136 |
this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
|
|
|
1137 |
}
|
|
|
1138 |
this.last_circle_radius = this.circle_radius;
|
|
|
1139 |
|
|
|
1140 |
var old_act_btn = this.active_buttons;
|
|
|
1141 |
|
|
|
1142 |
if (this.model.get("delete_scheduled")) {
|
|
|
1143 |
var opacity = .5;
|
|
|
1144 |
this.active_buttons = this.pending_delete_buttons;
|
|
|
1145 |
this.circle.dashArray = [2,2];
|
|
|
1146 |
} else {
|
|
|
1147 |
var opacity = 1;
|
|
|
1148 |
this.active_buttons = this.normal_buttons;
|
|
|
1149 |
this.circle.dashArray = null;
|
|
|
1150 |
}
|
|
|
1151 |
|
|
|
1152 |
if (this.selected && this.renderer.isEditable()) {
|
|
|
1153 |
if (old_act_btn !== this.active_buttons) {
|
|
|
1154 |
old_act_btn.forEach(function(b) {
|
|
|
1155 |
b.hide();
|
|
|
1156 |
});
|
|
|
1157 |
}
|
|
|
1158 |
this.active_buttons.forEach(function(b) {
|
|
|
1159 |
b.show();
|
|
|
1160 |
});
|
|
|
1161 |
}
|
|
|
1162 |
|
|
|
1163 |
if (this.node_image) {
|
|
|
1164 |
this.node_image.opacity = this.highlighted ? opacity * .5 : (opacity - .01);
|
|
|
1165 |
}
|
|
|
1166 |
|
|
|
1167 |
this.circle.fillColor = this.highlighted ? this.options.highlighted_node_fill_color : this.options.node_fill_color;
|
|
|
1168 |
|
|
|
1169 |
this.circle.opacity = this.options.show_node_circles ? opacity : .01;
|
|
|
1170 |
|
|
|
1171 |
var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || "";
|
|
|
1172 |
_text = Rkns.Renderer.shortenText(_text, this.options.node_label_max_length);
|
|
|
1173 |
this.title.text(_text);
|
|
|
1174 |
this.title.css({
|
|
|
1175 |
left: this.paper_coords.x,
|
|
|
1176 |
top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance,
|
|
|
1177 |
opacity: opacity
|
|
|
1178 |
});
|
|
|
1179 |
var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
|
|
|
1180 |
this.circle.strokeColor = _color;
|
|
|
1181 |
var _pc = this.paper_coords;
|
|
|
1182 |
this.all_buttons.forEach(function(b) {
|
|
|
1183 |
b.moveTo(_pc);
|
|
|
1184 |
});
|
|
|
1185 |
var lastImage = this.img;
|
|
|
1186 |
this.img = this.model.get("image");
|
|
|
1187 |
if (this.img && this.img !== lastImage) {
|
|
|
1188 |
this.showImage();
|
|
|
1189 |
}
|
|
|
1190 |
if (this.node_image && !this.img) {
|
|
|
1191 |
this.node_image.remove();
|
|
|
1192 |
delete this.node_image;
|
|
|
1193 |
}
|
|
|
1194 |
|
|
|
1195 |
if (this.renderer.minimap) {
|
|
|
1196 |
this.minimap_circle.fillColor = _color;
|
|
|
1197 |
var minipos = this.renderer.toMinimapCoords(_model_coords),
|
|
|
1198 |
miniradius = this.renderer.minimap.scale * _baseRadius,
|
|
|
1199 |
minisize = new paper.Size([miniradius, miniradius]);
|
|
|
1200 |
this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2));
|
|
|
1201 |
}
|
|
|
1202 |
|
|
|
1203 |
if (!_dontRedrawEdges) {
|
|
|
1204 |
Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){
|
|
|
1205 |
var repr = this.renderer.getRepresentationByModel(edge);
|
|
|
1206 |
if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") {
|
|
|
1207 |
repr.redraw();
|
|
|
1208 |
}
|
|
|
1209 |
}, this);
|
|
|
1210 |
}
|
|
|
1211 |
|
|
|
1212 |
};
|
|
|
1213 |
|
|
|
1214 |
Rkns.Renderer.Node.prototype.showImage = function() {
|
|
|
1215 |
if (typeof this.renderer.image_cache[this.img] === "undefined") {
|
|
|
1216 |
var _image = new Image();
|
|
|
1217 |
this.renderer.image_cache[this.img] = _image;
|
|
|
1218 |
_image.src = this.img;
|
|
|
1219 |
} else {
|
|
|
1220 |
var _image = this.renderer.image_cache[this.img];
|
|
|
1221 |
}
|
|
|
1222 |
if (_image.width) {
|
|
|
1223 |
if (this.node_image) {
|
|
|
1224 |
this.node_image.remove();
|
|
|
1225 |
}
|
|
|
1226 |
this.renderer.node_layer.activate();
|
|
|
1227 |
var width = _image.width,
|
|
|
1228 |
height = _image.height,
|
|
|
1229 |
clipPath = this.model.get("clip-path"),
|
|
|
1230 |
hasClipPath = (typeof clipPath !== "undefined" && clipPath);
|
|
|
1231 |
if (hasClipPath) {
|
|
|
1232 |
var _clip = new paper.Path(),
|
|
|
1233 |
instructions = clipPath.match(/[a-z][^a-z]+/gi) || [],
|
|
|
1234 |
lastCoords = [0,0],
|
|
|
1235 |
minX = Infinity,
|
|
|
1236 |
minY = Infinity,
|
|
|
1237 |
maxX = -Infinity,
|
|
|
1238 |
maxY = -Infinity;
|
|
|
1239 |
|
|
|
1240 |
function transformCoords(tabc, relative) {
|
|
|
1241 |
var newCoords = tabc.slice(1).map(function(v, k) {
|
|
|
1242 |
var res = parseFloat(v),
|
|
|
1243 |
isY = k % 2;
|
|
|
1244 |
if (isY) {
|
|
|
1245 |
res = ( res - .5 ) * height;
|
|
|
1246 |
} else {
|
|
|
1247 |
res = ( res - .5 ) * width;
|
|
|
1248 |
}
|
|
|
1249 |
if (relative) {
|
|
|
1250 |
res += lastCoords[isY];
|
|
|
1251 |
}
|
|
|
1252 |
if (isY) {
|
|
|
1253 |
minY = Math.min(minY, res);
|
|
|
1254 |
maxY = Math.max(maxY, res);
|
|
|
1255 |
} else {
|
|
|
1256 |
minX = Math.min(minX, res);
|
|
|
1257 |
maxX = Math.max(maxX, res);
|
|
|
1258 |
}
|
|
|
1259 |
return res;
|
|
|
1260 |
});
|
|
|
1261 |
lastCoords = newCoords.slice(-2);
|
|
|
1262 |
return newCoords;
|
|
|
1263 |
}
|
|
|
1264 |
|
|
|
1265 |
instructions.forEach(function(instr) {
|
|
|
1266 |
var coords = instr.match(/([a-z]|[0-9.-]+)/ig) || [""];
|
|
|
1267 |
switch(coords[0]) {
|
|
|
1268 |
case "M":
|
|
|
1269 |
_clip.moveTo(transformCoords(coords));
|
|
|
1270 |
break;
|
|
|
1271 |
case "m":
|
|
|
1272 |
_clip.moveTo(transformCoords(coords, true));
|
|
|
1273 |
break;
|
|
|
1274 |
case "L":
|
|
|
1275 |
_clip.lineTo(transformCoords(coords));
|
|
|
1276 |
break;
|
|
|
1277 |
case "l":
|
|
|
1278 |
_clip.lineTo(transformCoords(coords, true));
|
|
|
1279 |
break;
|
|
|
1280 |
case "C":
|
|
|
1281 |
_clip.cubicCurveTo(transformCoords(coords));
|
|
|
1282 |
break;
|
|
|
1283 |
case "c":
|
|
|
1284 |
_clip.cubicCurveTo(transformCoords(coords, true));
|
|
|
1285 |
break;
|
|
|
1286 |
case "Q":
|
|
|
1287 |
_clip.quadraticCurveTo(transformCoords(coords));
|
|
|
1288 |
break;
|
|
|
1289 |
case "q":
|
|
|
1290 |
_clip.quadraticCurveTo(transformCoords(coords, true));
|
|
|
1291 |
break;
|
|
|
1292 |
}
|
|
|
1293 |
});
|
|
|
1294 |
|
|
|
1295 |
var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](maxX - minX, maxY - minY) / 2,
|
|
|
1296 |
centerPoint = new paper.Point((maxX + minX) / 2, (maxY + minY) / 2);
|
|
|
1297 |
if (!this.options.show_node_circles) {
|
|
|
1298 |
this.h_ratio = (maxY - minY) / (2 * baseRadius);
|
|
|
1299 |
}
|
|
|
1300 |
} else {
|
|
|
1301 |
var baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](width, height) / 2,
|
|
|
1302 |
centerPoint = new paper.Point(0,0);
|
|
|
1303 |
if (!this.options.show_node_circles) {
|
|
|
1304 |
this.h_ratio = height / (2 * baseRadius);
|
|
|
1305 |
}
|
|
|
1306 |
}
|
|
|
1307 |
var _raster = new paper.Raster(_image);
|
|
|
1308 |
if (hasClipPath) {
|
|
|
1309 |
_raster = new paper.Group(_clip, _raster);
|
|
|
1310 |
_raster.opacity = .99;
|
|
|
1311 |
/* This is a workaround to allow clipping at group level
|
|
|
1312 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug).
|
|
|
1313 |
*/
|
|
|
1314 |
_raster.clipped = true;
|
|
|
1315 |
_clip.__representation = this;
|
|
|
1316 |
}
|
|
|
1317 |
if (this.options.clip_node_images) {
|
|
|
1318 |
var _circleClip = new paper.Path.Circle(centerPoint, baseRadius);
|
|
|
1319 |
_raster = new paper.Group(_circleClip, _raster);
|
|
|
1320 |
_raster.opacity = .99;
|
|
|
1321 |
_raster.clipped = true;
|
|
|
1322 |
_circleClip.__representation = this;
|
|
|
1323 |
}
|
|
|
1324 |
this.image_delta = centerPoint.divide(baseRadius);
|
|
|
1325 |
this.node_image = _raster;
|
|
|
1326 |
this.node_image.__representation = _this;
|
|
|
1327 |
this.node_image.scale(this.circle_radius / baseRadius);
|
|
|
1328 |
this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius));
|
|
|
1329 |
this.redraw();
|
|
|
1330 |
this.renderer.throttledPaperDraw();
|
|
|
1331 |
} else {
|
|
|
1332 |
var _this = this;
|
|
|
1333 |
Rkns.$(_image).on("load", function() {
|
|
|
1334 |
_this.showImage();
|
|
|
1335 |
});
|
|
|
1336 |
}
|
|
|
1337 |
}
|
|
|
1338 |
|
|
|
1339 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) {
|
|
|
1340 |
if (this.options.editor_mode) {
|
|
|
1341 |
if (!this.renkan.read_only) {
|
|
|
1342 |
this.is_dragging = true;
|
|
|
1343 |
this.paper_coords = this.paper_coords.add(_delta);
|
|
|
1344 |
this.redraw();
|
|
|
1345 |
}
|
|
|
1346 |
} else {
|
|
|
1347 |
this.renderer.paperShift(_delta);
|
|
|
1348 |
}
|
|
|
1349 |
};
|
|
|
1350 |
|
|
|
1351 |
Rkns.Renderer.Node.prototype.openEditor = function() {
|
|
|
1352 |
this.renderer.removeRepresentationsOfType("editor");
|
|
|
1353 |
var _editor = this.renderer.addRepresentation("NodeEditor",null);
|
|
|
1354 |
_editor.source_representation = this;
|
|
|
1355 |
_editor.draw();
|
|
|
1356 |
};
|
|
|
1357 |
|
|
|
1358 |
Rkns.Renderer.Node.prototype.select = function() {
|
|
|
1359 |
this.selected = true;
|
|
|
1360 |
this.circle.strokeWidth = this.options.selected_node_stroke_width;
|
|
|
1361 |
if (this.renderer.isEditable()) {
|
|
|
1362 |
this.active_buttons.forEach(function(b) {
|
|
|
1363 |
b.show();
|
|
|
1364 |
});
|
|
|
1365 |
}
|
|
|
1366 |
var _uri = this.model.get("uri");
|
|
|
1367 |
if (_uri) {
|
|
|
1368 |
Rkns.$('.Rk-Bin-Item').each(function() {
|
|
|
1369 |
var _el = Rkns.$(this);
|
|
|
1370 |
if (_el.attr("data-uri") == _uri) {
|
|
|
1371 |
_el.addClass("selected");
|
|
|
1372 |
}
|
|
|
1373 |
});
|
|
|
1374 |
}
|
|
|
1375 |
if (!this.options.editor_mode) {
|
|
|
1376 |
this.openEditor();
|
|
|
1377 |
}
|
|
|
1378 |
|
|
|
1379 |
if (this.renderer.minimap) {
|
|
|
1380 |
this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight;
|
|
|
1381 |
this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
|
|
|
1382 |
}
|
|
|
1383 |
this.super("select");
|
|
|
1384 |
};
|
|
|
1385 |
|
|
|
1386 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
|
|
|
1387 |
if (!_newTarget || _newTarget.source_representation !== this) {
|
|
|
1388 |
this.selected = false;
|
|
|
1389 |
this.all_buttons.forEach(function(b) {
|
|
|
1390 |
b.hide();
|
|
|
1391 |
});
|
|
|
1392 |
this.circle.strokeWidth = this.options.node_stroke_width;
|
|
|
1393 |
Rkns.$('.Rk-Bin-Item').removeClass("selected");
|
|
|
1394 |
if (this.renderer.minimap) {
|
|
|
1395 |
this.minimap_circle.strokeColor = undefined;
|
|
|
1396 |
}
|
|
|
1397 |
this.super("unselect");
|
|
|
1398 |
}
|
|
|
1399 |
};
|
|
|
1400 |
|
|
|
1401 |
Rkns.Renderer.Node.prototype.highlight = function() {
|
|
|
1402 |
if (this.highlighted) {
|
|
|
1403 |
return;
|
|
|
1404 |
}
|
|
|
1405 |
this.highlighted = true;
|
|
|
1406 |
this.redraw();
|
|
|
1407 |
this.renderer.throttledPaperDraw();
|
|
|
1408 |
};
|
|
|
1409 |
|
|
|
1410 |
Rkns.Renderer.Node.prototype.unhighlight = function() {
|
|
|
1411 |
if (!this.highlighted) {
|
|
|
1412 |
return;
|
|
|
1413 |
}
|
|
|
1414 |
this.highlighted = false;
|
|
|
1415 |
this.redraw();
|
|
|
1416 |
this.renderer.throttledPaperDraw();
|
|
|
1417 |
};
|
|
|
1418 |
|
|
|
1419 |
Rkns.Renderer.Node.prototype.saveCoords = function() {
|
|
|
1420 |
var _coords = this.renderer.toModelCoords(this.paper_coords),
|
|
|
1421 |
_data = {
|
|
|
1422 |
position: {
|
|
|
1423 |
x: _coords.x,
|
|
|
1424 |
y: _coords.y
|
|
|
1425 |
}
|
|
|
1426 |
};
|
|
|
1427 |
if (this.renderer.isEditable()) {
|
|
|
1428 |
this.model.set(_data);
|
|
|
1429 |
}
|
|
|
1430 |
};
|
|
|
1431 |
|
|
|
1432 |
Rkns.Renderer.Node.prototype.mousedown = function(_event, _isTouch) {
|
|
|
1433 |
if (_isTouch) {
|
|
|
1434 |
this.renderer.unselectAll();
|
|
|
1435 |
this.select();
|
|
|
1436 |
}
|
|
|
1437 |
};
|
|
|
1438 |
|
|
|
1439 |
Rkns.Renderer.Node.prototype.mouseup = function(_event, _isTouch) {
|
|
|
1440 |
if (this.renderer.is_dragging && this.renderer.isEditable()) {
|
|
|
1441 |
this.saveCoords();
|
|
|
1442 |
} else {
|
|
|
1443 |
if (!_isTouch && !this.model.get("delete_scheduled")) {
|
|
|
1444 |
this.openEditor();
|
|
|
1445 |
}
|
|
|
1446 |
this.model.trigger("clicked");
|
|
|
1447 |
}
|
|
|
1448 |
this.renderer.click_target = null;
|
|
|
1449 |
this.renderer.is_dragging = false;
|
|
|
1450 |
this.is_dragging = false;
|
|
|
1451 |
};
|
|
|
1452 |
|
|
|
1453 |
Rkns.Renderer.Node.prototype.destroy = function(_event) {
|
|
|
1454 |
this.super("destroy");
|
|
|
1455 |
this.all_buttons.forEach(function(b) {
|
|
|
1456 |
b.destroy();
|
|
|
1457 |
});
|
|
|
1458 |
this.circle.remove();
|
|
|
1459 |
this.title.remove();
|
|
|
1460 |
if (this.renderer.minimap) {
|
|
|
1461 |
this.minimap_circle.remove();
|
|
|
1462 |
}
|
|
|
1463 |
if (this.node_image) {
|
|
|
1464 |
this.node_image.remove();
|
|
|
1465 |
}
|
|
|
1466 |
};
|
|
|
1467 |
|
|
|
1468 |
/* */
|
|
|
1469 |
|
|
|
1470 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
1471 |
|
|
|
1472 |
Rkns.Renderer.Edge.prototype._init = function() {
|
|
|
1473 |
this.renderer.edge_layer.activate();
|
|
|
1474 |
this.type = "Edge";
|
|
|
1475 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from"));
|
|
|
1476 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to"));
|
|
|
1477 |
this.bundle = this.renderer.addToBundles(this);
|
|
|
1478 |
this.line = new paper.Path();
|
|
|
1479 |
this.line.add([0,0],[0,0],[0,0]);
|
|
|
1480 |
this.line.__representation = this;
|
|
|
1481 |
this.line.strokeWidth = this.options.edge_stroke_width;
|
|
|
1482 |
this.arrow = new paper.Path();
|
|
|
1483 |
this.arrow.add(
|
|
|
1484 |
[ 0, 0 ],
|
|
|
1485 |
[ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
|
|
|
1486 |
[ 0, this.options.edge_arrow_width ]
|
|
|
1487 |
);
|
|
|
1488 |
this.arrow.__representation = this;
|
|
|
1489 |
this.text = Rkns.$('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$);
|
|
|
1490 |
this.arrow_angle = 0;
|
|
|
1491 |
if (this.options.editor_mode) {
|
|
|
1492 |
this.normal_buttons = [
|
|
|
1493 |
new Rkns.Renderer.EdgeEditButton(this.renderer, null),
|
|
|
1494 |
new Rkns.Renderer.EdgeRemoveButton(this.renderer, null),
|
|
|
1495 |
];
|
|
|
1496 |
this.pending_delete_buttons = [
|
|
|
1497 |
new Rkns.Renderer.EdgeRevertButton(this.renderer, null)
|
|
|
1498 |
];
|
|
|
1499 |
this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons);
|
|
|
1500 |
for (var i = 0; i < this.all_buttons.length; i++) {
|
|
|
1501 |
this.all_buttons[i].source_representation = this;
|
|
|
1502 |
}
|
|
|
1503 |
this.active_buttons = [];
|
|
|
1504 |
} else {
|
|
|
1505 |
this.active_buttons = this.all_buttons = [];
|
|
|
1506 |
}
|
|
|
1507 |
|
|
|
1508 |
if (this.renderer.minimap) {
|
|
|
1509 |
this.renderer.minimap.edge_layer.activate();
|
|
|
1510 |
this.minimap_line = new paper.Path();
|
|
|
1511 |
this.minimap_line.add([0,0],[0,0]);
|
|
|
1512 |
this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation;
|
|
|
1513 |
this.minimap_line.strokeWidth = 1;
|
|
|
1514 |
}
|
|
|
1515 |
};
|
|
|
1516 |
|
|
|
1517 |
Rkns.Renderer.Edge.prototype.redraw = function() {
|
|
|
1518 |
var from = this.model.get("from"),
|
|
|
1519 |
to = this.model.get("to");
|
|
|
1520 |
if (!from || !to) {
|
|
|
1521 |
return;
|
|
|
1522 |
}
|
|
|
1523 |
this.from_representation = this.renderer.getRepresentationByModel(from);
|
|
|
1524 |
this.to_representation = this.renderer.getRepresentationByModel(to);
|
|
|
1525 |
if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined") {
|
|
|
1526 |
return;
|
|
|
1527 |
}
|
|
|
1528 |
var _p0a = this.from_representation.paper_coords,
|
|
|
1529 |
_p1a = this.to_representation.paper_coords,
|
|
|
1530 |
_v = _p1a.subtract(_p0a),
|
|
|
1531 |
_r = _v.length,
|
|
|
1532 |
_u = _v.divide(_r),
|
|
|
1533 |
_ortho = new paper.Point([- _u.y, _u.x]),
|
|
|
1534 |
_group_pos = this.bundle.getPosition(this),
|
|
|
1535 |
_delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ),
|
|
|
1536 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */
|
|
|
1537 |
_p1b = _p1a.add(_delta), /* to differentiate bundled links */
|
|
|
1538 |
_a = _v.angle,
|
|
|
1539 |
_textdelta = _ortho.multiply(this.options.edge_label_distance),
|
|
|
1540 |
_handle = _v.divide(3),
|
|
|
1541 |
_color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
|
|
|
1542 |
|
|
|
1543 |
if (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) {
|
|
|
1544 |
var opacity = .5;
|
|
|
1545 |
this.line.dashArray = [2, 2];
|
|
|
1546 |
} else {
|
|
|
1547 |
var opacity = 1;
|
|
|
1548 |
this.line.dashArray = null;
|
|
|
1549 |
}
|
|
|
1550 |
|
|
|
1551 |
var old_act_btn = this.active_buttons;
|
|
|
1552 |
|
|
|
1553 |
this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
|
|
|
1554 |
|
|
|
1555 |
if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) {
|
|
|
1556 |
old_act_btn.forEach(function(b) {
|
|
|
1557 |
b.hide();
|
|
|
1558 |
});
|
|
|
1559 |
this.active_buttons.forEach(function(b) {
|
|
|
1560 |
b.show();
|
|
|
1561 |
});
|
|
|
1562 |
}
|
|
|
1563 |
|
|
|
1564 |
this.paper_coords = _p0b.add(_p1b).divide(2);
|
|
|
1565 |
this.line.strokeColor = _color;
|
|
|
1566 |
this.line.opacity = opacity;
|
|
|
1567 |
this.line.segments[0].point = _p0a;
|
|
|
1568 |
this.line.segments[1].point = this.paper_coords;
|
|
|
1569 |
this.line.segments[1].handleIn = _handle.multiply(-1);
|
|
|
1570 |
this.line.segments[1].handleOut = _handle;
|
|
|
1571 |
this.line.segments[2].point = _p1a;
|
|
|
1572 |
this.arrow.rotate(_a - this.arrow_angle);
|
|
|
1573 |
this.arrow.fillColor = _color;
|
|
|
1574 |
this.arrow.opacity = opacity;
|
|
|
1575 |
this.arrow.position = this.paper_coords;
|
|
|
1576 |
this.arrow_angle = _a;
|
|
|
1577 |
if (_a > 90) {
|
|
|
1578 |
_a -= 180;
|
|
|
1579 |
_textdelta = _textdelta.multiply(-1);
|
|
|
1580 |
}
|
|
|
1581 |
if (_a < -90) {
|
|
|
1582 |
_a += 180;
|
|
|
1583 |
_textdelta = _textdelta.multiply(-1);
|
|
|
1584 |
}
|
|
|
1585 |
var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_edges) || "";
|
|
|
1586 |
_text = Rkns.Renderer.shortenText(_text, this.options.node_label_max_length);
|
|
|
1587 |
this.text.text(_text);
|
|
|
1588 |
var _textpos = this.paper_coords.add(_textdelta);
|
|
|
1589 |
this.text.css({
|
|
|
1590 |
left: _textpos.x,
|
|
|
1591 |
top: _textpos.y,
|
|
|
1592 |
transform: "rotate(" + _a + "deg)",
|
|
|
1593 |
"-moz-transform": "rotate(" + _a + "deg)",
|
|
|
1594 |
"-webkit-transform": "rotate(" + _a + "deg)",
|
|
|
1595 |
opacity: opacity
|
|
|
1596 |
});
|
|
|
1597 |
this.text_angle = _a;
|
|
|
1598 |
|
|
|
1599 |
var _pc = this.paper_coords;
|
|
|
1600 |
this.all_buttons.forEach(function(b) {
|
|
|
1601 |
b.moveTo(_pc);
|
|
|
1602 |
});
|
|
|
1603 |
|
|
|
1604 |
if (this.renderer.minimap) {
|
|
|
1605 |
this.minimap_line.strokeColor = _color;
|
|
|
1606 |
this.minimap_line.segments[0].point = this.renderer.toMinimapCoords(new paper.Point(this.from_representation.model.get("position")));
|
|
|
1607 |
this.minimap_line.segments[1].point = this.renderer.toMinimapCoords(new paper.Point(this.to_representation.model.get("position")));
|
|
|
1608 |
}
|
|
|
1609 |
};
|
|
|
1610 |
|
|
|
1611 |
Rkns.Renderer.Edge.prototype.openEditor = function() {
|
|
|
1612 |
this.renderer.removeRepresentationsOfType("editor");
|
|
|
1613 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null);
|
|
|
1614 |
_editor.source_representation = this;
|
|
|
1615 |
_editor.draw();
|
|
|
1616 |
};
|
|
|
1617 |
|
|
|
1618 |
Rkns.Renderer.Edge.prototype.select = function() {
|
|
|
1619 |
this.selected = true;
|
|
|
1620 |
this.line.strokeWidth = this.options.selected_edge_stroke_width;
|
|
|
1621 |
if (this.renderer.isEditable()) {
|
|
|
1622 |
this.active_buttons.forEach(function(b) {
|
|
|
1623 |
b.show();
|
|
|
1624 |
});
|
|
|
1625 |
}
|
|
|
1626 |
if (!this.options.editor_mode) {
|
|
|
1627 |
this.openEditor();
|
|
|
1628 |
}
|
|
|
1629 |
this.super("select");
|
|
|
1630 |
};
|
|
|
1631 |
|
|
|
1632 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
|
|
|
1633 |
if (!_newTarget || _newTarget.source_representation !== this) {
|
|
|
1634 |
this.selected = false;
|
|
|
1635 |
if (this.options.editor_mode) {
|
|
|
1636 |
this.all_buttons.forEach(function(b) {
|
|
|
1637 |
b.hide();
|
|
|
1638 |
});
|
|
|
1639 |
}
|
|
|
1640 |
this.line.strokeWidth = this.options.edge_stroke_width;
|
|
|
1641 |
this.super("unselect");
|
|
|
1642 |
}
|
|
|
1643 |
};
|
|
|
1644 |
|
|
|
1645 |
Rkns.Renderer.Edge.prototype.mousedown = function(_event, _isTouch) {
|
|
|
1646 |
if (_isTouch) {
|
|
|
1647 |
this.renderer.unselectAll();
|
|
|
1648 |
this.select();
|
|
|
1649 |
}
|
|
|
1650 |
};
|
|
|
1651 |
|
|
|
1652 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event, _isTouch) {
|
|
|
1653 |
if (!this.renkan.read_only && this.renderer.is_dragging) {
|
|
|
1654 |
this.from_representation.saveCoords();
|
|
|
1655 |
this.to_representation.saveCoords();
|
|
|
1656 |
this.from_representation.is_dragging = false;
|
|
|
1657 |
this.to_representation.is_dragging = false;
|
|
|
1658 |
} else {
|
|
|
1659 |
if (!_isTouch) {
|
|
|
1660 |
this.openEditor();
|
|
|
1661 |
}
|
|
|
1662 |
this.model.trigger("clicked");
|
|
|
1663 |
}
|
|
|
1664 |
this.renderer.click_target = null;
|
|
|
1665 |
this.renderer.is_dragging = false;
|
|
|
1666 |
};
|
|
|
1667 |
|
|
|
1668 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) {
|
|
|
1669 |
if (this.options.editor_mode) {
|
|
|
1670 |
if (!this.options.read_only) {
|
|
|
1671 |
this.from_representation.paperShift(_delta);
|
|
|
1672 |
this.to_representation.paperShift(_delta);
|
|
|
1673 |
}
|
|
|
1674 |
} else {
|
|
|
1675 |
this.renderer.paperShift(_delta);
|
|
|
1676 |
}
|
|
|
1677 |
};
|
|
|
1678 |
|
|
|
1679 |
Rkns.Renderer.Edge.prototype.destroy = function() {
|
|
|
1680 |
this.super("destroy");
|
|
|
1681 |
this.line.remove();
|
|
|
1682 |
this.arrow.remove();
|
|
|
1683 |
this.text.remove();
|
|
|
1684 |
if (this.renderer.minimap) {
|
|
|
1685 |
this.minimap_line.remove();
|
|
|
1686 |
}
|
|
|
1687 |
this.all_buttons.forEach(function(b) {
|
|
|
1688 |
b.destroy();
|
|
|
1689 |
});
|
|
|
1690 |
var _this = this;
|
|
|
1691 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) {
|
|
|
1692 |
return _edge === _this;
|
|
|
1693 |
});
|
|
|
1694 |
};
|
|
|
1695 |
|
|
|
1696 |
/* */
|
|
|
1697 |
|
|
|
1698 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
1699 |
|
|
|
1700 |
Rkns.Renderer.TempEdge.prototype._init = function() {
|
|
|
1701 |
this.renderer.edge_layer.activate();
|
|
|
1702 |
this.type = "Temp-edge";
|
|
|
1703 |
|
|
|
1704 |
var _color = (this.project.get("users").get(this.renkan.current_user) || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
|
|
|
1705 |
this.line = new paper.Path();
|
|
|
1706 |
this.line.strokeColor = _color;
|
|
|
1707 |
this.line.dashArray = [4, 2];
|
|
|
1708 |
this.line.strokeWidth = this.options.selected_edge_stroke_width;
|
|
|
1709 |
this.line.add([0,0],[0,0]);
|
|
|
1710 |
this.line.__representation = this;
|
|
|
1711 |
this.arrow = new paper.Path();
|
|
|
1712 |
this.arrow.fillColor = _color;
|
|
|
1713 |
this.arrow.add(
|
|
|
1714 |
[ 0, 0 ],
|
|
|
1715 |
[ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
|
|
|
1716 |
[ 0, this.options.edge_arrow_width ]
|
|
|
1717 |
);
|
|
|
1718 |
this.arrow.__representation = this;
|
|
|
1719 |
this.arrow_angle = 0;
|
|
|
1720 |
};
|
|
|
1721 |
|
|
|
1722 |
Rkns.Renderer.TempEdge.prototype.redraw = function() {
|
|
|
1723 |
var _p0 = this.from_representation.paper_coords,
|
|
|
1724 |
_p1 = this.end_pos,
|
|
|
1725 |
_a = _p1.subtract(_p0).angle,
|
|
|
1726 |
_c = _p0.add(_p1).divide(2);
|
|
|
1727 |
this.line.segments[0].point = _p0;
|
|
|
1728 |
this.line.segments[1].point = _p1;
|
|
|
1729 |
this.arrow.rotate(_a - this.arrow_angle);
|
|
|
1730 |
this.arrow.position = _c;
|
|
|
1731 |
this.arrow_angle = _a;
|
|
|
1732 |
};
|
|
|
1733 |
|
|
|
1734 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) {
|
|
|
1735 |
if (!this.renderer.isEditable()) {
|
|
|
1736 |
this.renderer.removeRepresentation(_this);
|
|
|
1737 |
paper.view.draw();
|
|
|
1738 |
return;
|
|
|
1739 |
}
|
|
|
1740 |
this.end_pos = this.end_pos.add(_delta);
|
|
|
1741 |
var _hitResult = paper.project.hitTest(this.end_pos);
|
|
|
1742 |
this.renderer.findTarget(_hitResult);
|
|
|
1743 |
this.redraw();
|
|
|
1744 |
};
|
|
|
1745 |
|
|
|
1746 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event, _isTouch) {
|
|
|
1747 |
var _hitResult = paper.project.hitTest(_event.point),
|
|
|
1748 |
_model = this.from_representation.model,
|
|
|
1749 |
_endDrag = true;
|
|
|
1750 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
|
|
|
1751 |
var _target = _hitResult.item.__representation;
|
|
|
1752 |
if (_target.type.substr(0,4) === "Node") {
|
|
|
1753 |
var _destmodel = _target.model || _target.source_representation.model;
|
|
|
1754 |
if (_model !== _destmodel) {
|
|
|
1755 |
var _data = {
|
|
|
1756 |
id: Rkns.Utils.getUID('edge'),
|
|
|
1757 |
created_by: this.renkan.current_user,
|
|
|
1758 |
from: _model,
|
|
|
1759 |
to: _destmodel
|
|
|
1760 |
};
|
|
|
1761 |
if (this.renderer.isEditable()) {
|
|
|
1762 |
this.project.addEdge(_data);
|
|
|
1763 |
}
|
|
|
1764 |
}
|
|
|
1765 |
}
|
|
|
1766 |
|
|
|
1767 |
if (_model === _target.model || (_target.source_representation && _target.source_representation.model === _model)) {
|
|
|
1768 |
_endDrag = false;
|
|
|
1769 |
this.renderer.is_dragging = true;
|
|
|
1770 |
}
|
|
|
1771 |
}
|
|
|
1772 |
if (_endDrag) {
|
|
|
1773 |
this.renderer.click_target = null;
|
|
|
1774 |
this.renderer.is_dragging = false;
|
|
|
1775 |
this.renderer.removeRepresentation(this);
|
|
|
1776 |
paper.view.draw();
|
|
|
1777 |
}
|
|
|
1778 |
};
|
|
|
1779 |
|
|
|
1780 |
Rkns.Renderer.TempEdge.prototype.destroy = function() {
|
|
|
1781 |
this.arrow.remove();
|
|
|
1782 |
this.line.remove();
|
|
|
1783 |
};
|
|
|
1784 |
|
|
|
1785 |
/* */
|
|
|
1786 |
|
|
|
1787 |
Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
1788 |
|
|
|
1789 |
Rkns.Renderer._BaseEditor.prototype._init = function() {
|
|
|
1790 |
this.renderer.buttons_layer.activate();
|
|
|
1791 |
this.type = "editor";
|
|
|
1792 |
this.editor_block = new paper.Path();
|
|
|
1793 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0];});
|
|
|
1794 |
this.editor_block.add.apply(this.editor_block, _pts);
|
|
|
1795 |
this.editor_block.strokeWidth = this.options.tooltip_border_width;
|
|
|
1796 |
this.editor_block.strokeColor = this.options.tooltip_border_color;
|
|
|
1797 |
this.editor_block.opacity = .8;
|
|
|
1798 |
this.editor_$ = Rkns.$('<div>')
|
|
|
1799 |
.appendTo(this.renderer.editor_$)
|
|
|
1800 |
.css({
|
|
|
1801 |
position: "absolute",
|
|
|
1802 |
opacity: .8
|
|
|
1803 |
})
|
|
|
1804 |
.hide();
|
|
|
1805 |
};
|
|
|
1806 |
|
|
|
1807 |
Rkns.Renderer._BaseEditor.prototype.destroy = function() {
|
|
|
1808 |
this.editor_block.remove();
|
|
|
1809 |
this.editor_$.remove();
|
|
|
1810 |
};
|
|
|
1811 |
|
|
|
1812 |
/* */
|
|
|
1813 |
|
|
|
1814 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
|
|
|
1815 |
|
|
|
1816 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template(
|
|
|
1817 |
'<h2><span class="Rk-CloseX">×</span><%-renkan.translate("Edit Node")%></span></h2>'
|
|
|
1818 |
+ '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>'
|
|
|
1819 |
+ '<% if (options.show_node_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p><% } %>'
|
|
|
1820 |
+ '<% if (options.show_node_editor_description) { %><p><label><%-renkan.translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p><% } %>'
|
|
|
1821 |
+ '<% if (options.show_node_editor_size) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p><% } %>'
|
|
|
1822 |
+ '<% if (options.show_node_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
|
|
|
1823 |
+ '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
|
|
|
1824 |
+ '<% if (options.show_node_editor_image) { %><div class="Rk-Edit-ImgWrap"><div class="Rk-Edit-ImgPreview"><img src="<%-node.image || node.image_placeholder%>" />'
|
|
|
1825 |
+ '<% if (node.clip_path) { %><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 1 1" preserveAspectRatio="none"><path style="stroke-width: .02; stroke:red; fill-opacity:.3; fill:red;" d="<%- node.clip_path %>"/></svg><% }%>'
|
|
|
1826 |
+ '</div></div><p><label><%-renkan.translate("Image URL:")%></label><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></p>'
|
|
|
1827 |
+ '<p><label><%-renkan.translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p><% } %>'
|
|
|
1828 |
+ '<% if (options.show_node_editor_creator && node.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.shortenText(node.created_by_title, 25) %></p><% } %>'
|
|
|
1829 |
);
|
|
|
1830 |
|
|
|
1831 |
Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
|
|
|
1832 |
'<h2><span class="Rk-CloseX">×</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>'
|
|
|
1833 |
+ '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
|
|
|
1834 |
+ '<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
|
|
|
1835 |
+ '<% if (options.show_node_tooltip_description) { %><p><%-node.description%></p><% } %>'
|
|
|
1836 |
+ '<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
|
|
|
1837 |
+ '<% if (node.has_creator && options.show_node_tooltip_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.shortenText(node.created_by_title, 25) %></p><% } %>'
|
|
|
1838 |
);
|
|
|
1839 |
|
|
|
1840 |
Rkns.Renderer.NodeEditor.prototype.draw = function() {
|
|
|
1841 |
var _model = this.source_representation.model,
|
|
|
1842 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan),
|
|
|
1843 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ),
|
|
|
1844 |
_image_placeholder = this.options.static_url + "img/image-placeholder.png",
|
|
|
1845 |
_size = (_model.get("size") || 0);
|
|
|
1846 |
this.editor_$
|
|
|
1847 |
.html(_template({
|
|
|
1848 |
node: {
|
|
|
1849 |
has_creator: !!_model.get("created_by"),
|
|
|
1850 |
title: _model.get("title"),
|
|
|
1851 |
uri: _model.get("uri"),
|
|
|
1852 |
short_uri: Rkns.Renderer.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
|
|
|
1853 |
description: _model.get("description"),
|
|
|
1854 |
image: _model.get("image") || "",
|
|
|
1855 |
image_placeholder: _image_placeholder,
|
|
|
1856 |
color: _model.get("color") || _created_by.get("color"),
|
|
|
1857 |
clip_path: _model.get("clip-path") || false,
|
|
|
1858 |
created_by_color: _created_by.get("color"),
|
|
|
1859 |
created_by_title: _created_by.get("title"),
|
|
|
1860 |
size: (_size > 0 ? "+" : "") + _size
|
|
|
1861 |
},
|
|
|
1862 |
renkan: this.renkan,
|
|
|
1863 |
options: this.options
|
|
|
1864 |
}));
|
|
|
1865 |
this.redraw();
|
|
|
1866 |
var _this = this,
|
|
|
1867 |
closeEditor = function() {
|
|
|
1868 |
_this.renderer.removeRepresentation(_this);
|
|
|
1869 |
paper.view.draw();
|
|
|
1870 |
};
|
|
|
1871 |
|
|
|
1872 |
this.editor_$.find(".Rk-CloseX").click(closeEditor);
|
|
|
1873 |
|
|
|
1874 |
if (this.renderer.isEditable()) {
|
|
|
1875 |
|
|
|
1876 |
var onFieldChange = Rkns._(function() {
|
|
|
1877 |
Rkns._(function() {
|
|
|
1878 |
if (_this.renderer.isEditable()) {
|
|
|
1879 |
var _data = {
|
|
|
1880 |
title: _this.editor_$.find(".Rk-Edit-Title").val()
|
|
|
1881 |
};
|
|
|
1882 |
if (_this.options.show_node_editor_uri) {
|
|
|
1883 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
|
|
|
1884 |
}
|
|
|
1885 |
if (_this.options.show_node_editor_image) {
|
|
|
1886 |
_data.image = _this.editor_$.find(".Rk-Edit-Image").val();
|
|
|
1887 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder);
|
|
|
1888 |
}
|
|
|
1889 |
if (_this.options.show_node_editor_description) {
|
|
|
1890 |
_data.description = _this.editor_$.find(".Rk-Edit-Description").val();
|
|
|
1891 |
}
|
|
|
1892 |
_model.set(_data);
|
|
|
1893 |
_this.redraw();
|
|
|
1894 |
} else {
|
|
|
1895 |
closeEditor();
|
|
|
1896 |
}
|
|
|
1897 |
|
|
|
1898 |
}).defer();
|
|
|
1899 |
}).throttle(500);
|
|
|
1900 |
|
|
|
1901 |
this.editor_$.on("keyup", function(_e) {
|
|
|
1902 |
if (_e.keyCode === 27) {
|
|
|
1903 |
closeEditor();
|
|
|
1904 |
}
|
|
|
1905 |
});
|
|
|
1906 |
|
|
|
1907 |
this.editor_$.find("input, textarea").on("change keyup paste", onFieldChange);
|
|
|
1908 |
|
|
|
1909 |
this.editor_$.find(".Rk-Edit-Image-File").change(function() {
|
|
|
1910 |
if (this.files.length) {
|
|
|
1911 |
var f = this.files[0],
|
|
|
1912 |
fr = new FileReader();
|
|
|
1913 |
if (f.type.substr(0,5) !== "image") {
|
|
|
1914 |
alert(_this.renkan.translate("This file is not an image"));
|
|
|
1915 |
return;
|
|
|
1916 |
}
|
|
|
1917 |
if (f.size > (Rkns.Renderer._IMAGE_MAX_KB * 1024)) {
|
|
|
1918 |
alert(_this.renkan.translate("Image size must be under ")+Rkns.Renderer._IMAGE_MAX_KB+_this.renkan.translate("KB"));
|
|
|
1919 |
return;
|
|
|
1920 |
}
|
|
|
1921 |
fr.onload = function(e) {
|
|
|
1922 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result);
|
|
|
1923 |
onFieldChange();
|
|
|
1924 |
};
|
|
|
1925 |
fr.readAsDataURL(f);
|
|
|
1926 |
}
|
|
|
1927 |
});
|
|
|
1928 |
this.editor_$.find(".Rk-Edit-Title")[0].focus();
|
|
|
1929 |
|
|
|
1930 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
|
|
|
1931 |
|
|
|
1932 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
|
|
|
1933 |
function(_e) {
|
|
|
1934 |
_e.preventDefault();
|
|
|
1935 |
_picker.show();
|
|
|
1936 |
},
|
|
|
1937 |
function(_e) {
|
|
|
1938 |
_e.preventDefault();
|
|
|
1939 |
_picker.hide();
|
|
|
1940 |
}
|
|
|
1941 |
);
|
|
|
1942 |
|
|
|
1943 |
_picker.find("li").hover(
|
|
|
1944 |
function(_e) {
|
|
|
1945 |
_e.preventDefault();
|
|
|
1946 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
|
|
|
1947 |
},
|
|
|
1948 |
function(_e) {
|
|
|
1949 |
_e.preventDefault();
|
|
|
1950 |
_this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(_this.renkan)).get("color"));
|
|
|
1951 |
}
|
|
|
1952 |
).click(function(_e) {
|
|
|
1953 |
_e.preventDefault();
|
|
|
1954 |
if (_this.renderer.isEditable()) {
|
|
|
1955 |
_model.set("color", $(this).attr("data-color"));
|
|
|
1956 |
_picker.hide();
|
|
|
1957 |
paper.view.draw();
|
|
|
1958 |
} else {
|
|
|
1959 |
closeEditor();
|
|
|
1960 |
}
|
|
|
1961 |
});
|
|
|
1962 |
|
|
|
1963 |
function shiftSize(n) {
|
|
|
1964 |
if (_this.renderer.isEditable()) {
|
|
|
1965 |
var _newsize = n+(_model.get("size") || 0);
|
|
|
1966 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize);
|
|
|
1967 |
_model.set("size", _newsize);
|
|
|
1968 |
paper.view.draw();
|
|
|
1969 |
} else {
|
|
|
1970 |
closeEditor();
|
|
|
1971 |
}
|
|
|
1972 |
}
|
|
|
1973 |
|
|
|
1974 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() {
|
|
|
1975 |
shiftSize(-1);
|
|
|
1976 |
return false;
|
|
|
1977 |
});
|
|
|
1978 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() {
|
|
|
1979 |
shiftSize(1);
|
|
|
1980 |
return false;
|
|
|
1981 |
});
|
|
|
1982 |
}
|
|
|
1983 |
this.editor_$.find("img").load(function() {
|
|
|
1984 |
_this.redraw();
|
|
|
1985 |
});
|
|
|
1986 |
};
|
|
|
1987 |
|
|
|
1988 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() {
|
|
|
1989 |
var _coords = this.source_representation.paper_coords;
|
|
|
1990 |
Rkns.Renderer.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * .75, this.editor_$);
|
|
|
1991 |
this.editor_$.show();
|
|
|
1992 |
paper.view.draw();
|
|
|
1993 |
};
|
|
|
1994 |
|
|
|
1995 |
/* */
|
|
|
1996 |
|
|
|
1997 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
|
|
|
1998 |
|
|
|
1999 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
|
|
|
2000 |
'<h2><span class="Rk-CloseX">×</span><%-renkan.translate("Edit Edge")%></span></h2>'
|
|
|
2001 |
+ '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>'
|
|
|
2002 |
+ '<% if (options.show_edge_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>'
|
|
|
2003 |
+ '<% if (options.properties.length) { %><p><label><%-renkan.translate("Choose from vocabulary:")%></label><select class="Rk-Edit-Vocabulary">'
|
|
|
2004 |
+ '<% _(options.properties).each(function(ontology) { %><option class="Rk-Edit-Vocabulary-Class" value=""><%- renkan.translate(ontology.label) %></option>'
|
|
|
2005 |
+ '<% _(ontology.properties).each(function(property) { var uri = ontology["base-uri"] + property.uri; %><option class="Rk-Edit-Vocabulary-Property" value="<%- uri %>'
|
|
|
2006 |
+ '"<% if (uri === edge.uri) { %> selected<% } %>><%- renkan.translate(property.label) %></option>'
|
|
|
2007 |
+ '<% }) %><% }) %></select></p><% } } %>'
|
|
|
2008 |
+ '<% if (options.show_edge_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Edge color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-edge.color%>;"><span class="Rk-Edit-ColorTip"></span></span><ul class="Rk-Edit-ColorPicker">'
|
|
|
2009 |
+ '<% _(Rkns.pickerColors).each(function(c) { %><li data-color="<%=c%>" style="background: <%=c%>"></li><% }); %></ul><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>'
|
|
|
2010 |
+ '<% if (options.show_edge_editor_direction) { %><p><span class="Rk-Edit-Direction"><%- renkan.translate("Change edge direction") %></span></p><% } %>'
|
|
|
2011 |
+ '<% if (options.show_edge_editor_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- Rkns.Renderer.shortenText(edge.from_title, 25) %></p>'
|
|
|
2012 |
+ '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- Rkns.Renderer.shortenText(edge.to_title, 25) %></p><% } %>'
|
|
|
2013 |
+ '<% if (options.show_edge_editor_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- Rkns.Renderer.shortenText(edge.created_by_title, 25) %></p><% } %>'
|
|
|
2014 |
);
|
|
|
2015 |
|
|
|
2016 |
Rkns.Renderer.EdgeEditor.prototype.readOnlyTemplate = Rkns._.template(
|
|
|
2017 |
'<h2><span class="Rk-CloseX">×</span><% if (options.show_edge_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-edge.color%>;"></span><% } %>'
|
|
|
2018 |
+ '<span class="Rk-Display-Title"><% if (edge.uri) { %><a href="<%-edge.uri%>" target="_blank"><% } %><%-edge.title%><% if (edge.uri) { %></a><% } %></span></h2>'
|
|
|
2019 |
+ '<% if (options.show_edge_tooltip_uri && edge.uri) { %><p class="Rk-Display-URI"><a href="<%-edge.uri%>" target="_blank"><%-edge.short_uri%></a></p><% } %>'
|
|
|
2020 |
+ '<p><%-edge.description%></p>'
|
|
|
2021 |
+ '<% if (options.show_edge_tooltip_nodes) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("From:")%></span><span class="Rk-UserColor" style="background:<%-edge.from_color%>;"></span><%- Rkns.Renderer.shortenText(edge.from_title, 25) %></p>'
|
|
|
2022 |
+ '<p><span class="Rk-Editor-Label"><%-renkan.translate("To:")%></span><span class="Rk-UserColor" style="background:<%-edge.to_color%>;"></span><%- Rkns.Renderer.shortenText(edge.to_title, 25) %></p><% } %>'
|
|
|
2023 |
+ '<% if (options.show_edge_tooltip_creator && edge.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-edge.created_by_color%>;"></span><%- Rkns.Renderer.shortenText(edge.created_by_title, 25) %></p><% } %>'
|
|
|
2024 |
);
|
|
|
2025 |
|
|
|
2026 |
Rkns.Renderer.EdgeEditor.prototype.draw = function() {
|
|
|
2027 |
var _model = this.source_representation.model,
|
|
|
2028 |
_from_model = _model.get("from"),
|
|
|
2029 |
_to_model = _model.get("to"),
|
|
|
2030 |
_created_by = _model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan),
|
|
|
2031 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate);
|
|
|
2032 |
this.editor_$
|
|
|
2033 |
.html(_template({
|
|
|
2034 |
edge: {
|
|
|
2035 |
has_creator: !!_model.get("created_by"),
|
|
|
2036 |
title: _model.get("title"),
|
|
|
2037 |
uri: _model.get("uri"),
|
|
|
2038 |
short_uri: Rkns.Renderer.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40),
|
|
|
2039 |
description: _model.get("description"),
|
|
|
2040 |
color: _model.get("color") || _created_by.get("color"),
|
|
|
2041 |
from_title: _from_model.get("title"),
|
|
|
2042 |
to_title: _to_model.get("title"),
|
|
|
2043 |
from_color: _from_model.get("color") || (_from_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color"),
|
|
|
2044 |
to_color: _to_model.get("color") || (_to_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color"),
|
|
|
2045 |
created_by_color: _created_by.get("color"),
|
|
|
2046 |
created_by_title: _created_by.get("title")
|
|
|
2047 |
},
|
|
|
2048 |
renkan: this.renkan,
|
|
|
2049 |
options: this.options,
|
|
|
2050 |
}));
|
|
|
2051 |
this.redraw();
|
|
|
2052 |
var _this = this,
|
|
|
2053 |
closeEditor = function() {
|
|
|
2054 |
_this.renderer.removeRepresentation(_this);
|
|
|
2055 |
paper.view.draw();
|
|
|
2056 |
};
|
|
|
2057 |
this.editor_$.find(".Rk-CloseX").click(closeEditor);
|
|
|
2058 |
|
|
|
2059 |
if (this.renderer.isEditable()) {
|
|
|
2060 |
|
|
|
2061 |
var onFieldChange = Rkns._(function() {
|
|
|
2062 |
Rkns._(function() {
|
|
|
2063 |
if (_this.renderer.isEditable()) {
|
|
|
2064 |
var _data = {
|
|
|
2065 |
title: _this.editor_$.find(".Rk-Edit-Title").val()
|
|
|
2066 |
};
|
|
|
2067 |
if (_this.options.show_edge_editor_uri) {
|
|
|
2068 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val();
|
|
|
2069 |
}
|
|
|
2070 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri);
|
|
|
2071 |
_model.set(_data);
|
|
|
2072 |
paper.view.draw();
|
|
|
2073 |
} else {
|
|
|
2074 |
closeEditor();
|
|
|
2075 |
}
|
|
|
2076 |
}).defer();
|
|
|
2077 |
}).throttle(500);
|
|
|
2078 |
|
|
|
2079 |
this.editor_$.on("keyup", function(_e) {
|
|
|
2080 |
if (_e.keyCode === 27) {
|
|
|
2081 |
closeEditor();
|
|
|
2082 |
}
|
|
|
2083 |
});
|
|
|
2084 |
|
|
|
2085 |
this.editor_$.find("input").on("keyup change paste", onFieldChange);
|
|
|
2086 |
|
|
|
2087 |
this.editor_$.find(".Rk-Edit-Vocabulary").change(function() {
|
|
|
2088 |
var e = $(this),
|
|
|
2089 |
v = e.val();
|
|
|
2090 |
if (v) {
|
|
|
2091 |
_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text());
|
|
|
2092 |
_this.editor_$.find(".Rk-Edit-URI").val(v);
|
|
|
2093 |
onFieldChange();
|
|
|
2094 |
}
|
|
|
2095 |
});
|
|
|
2096 |
this.editor_$.find(".Rk-Edit-Direction").click(function() {
|
|
|
2097 |
if (_this.renderer.isEditable()) {
|
|
|
2098 |
_model.set({
|
|
|
2099 |
from: _model.get("to"),
|
|
|
2100 |
to: _model.get("from")
|
|
|
2101 |
});
|
|
|
2102 |
_this.draw();
|
|
|
2103 |
} else {
|
|
|
2104 |
closeEditor();
|
|
|
2105 |
}
|
|
|
2106 |
});
|
|
|
2107 |
|
|
|
2108 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker");
|
|
|
2109 |
|
|
|
2110 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover(
|
|
|
2111 |
function(_e) {
|
|
|
2112 |
_e.preventDefault();
|
|
|
2113 |
_picker.show();
|
|
|
2114 |
},
|
|
|
2115 |
function(_e) {
|
|
|
2116 |
_e.preventDefault();
|
|
|
2117 |
_picker.hide();
|
|
|
2118 |
}
|
|
|
2119 |
);
|
|
|
2120 |
|
|
|
2121 |
_picker.find("li").hover(
|
|
|
2122 |
function(_e) {
|
|
|
2123 |
_e.preventDefault();
|
|
|
2124 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color"));
|
|
|
2125 |
},
|
|
|
2126 |
function(_e) {
|
|
|
2127 |
_e.preventDefault();
|
|
|
2128 |
_this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(_this.renkan)).get("color"));
|
|
|
2129 |
}
|
|
|
2130 |
).click(function(_e) {
|
|
|
2131 |
_e.preventDefault();
|
|
|
2132 |
if (_this.renderer.isEditable()) {
|
|
|
2133 |
_model.set("color", $(this).attr("data-color"));
|
|
|
2134 |
_picker.hide();
|
|
|
2135 |
paper.view.draw();
|
|
|
2136 |
} else {
|
|
|
2137 |
closeEditor();
|
|
|
2138 |
}
|
|
|
2139 |
});
|
|
|
2140 |
}
|
|
|
2141 |
};
|
|
|
2142 |
|
|
|
2143 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() {
|
|
|
2144 |
var _coords = this.source_representation.paper_coords;
|
|
|
2145 |
Rkns.Renderer.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
|
|
|
2146 |
this.editor_$.show();
|
|
|
2147 |
paper.view.draw();
|
|
|
2148 |
};
|
|
|
2149 |
|
|
|
2150 |
/* */
|
|
|
2151 |
|
|
|
2152 |
Rkns.Renderer._NodeButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
|
|
|
2153 |
|
|
|
2154 |
Rkns.Renderer._NodeButton.prototype.setSectorSize = function() {
|
|
|
2155 |
var sectorInner = this.source_representation.circle_radius;
|
|
|
2156 |
if (sectorInner !== this.lastSectorInner) {
|
|
|
2157 |
if (this.sector) {
|
|
|
2158 |
this.sector.destroy();
|
|
|
2159 |
}
|
|
|
2160 |
this.sector = this.renderer.drawSector(
|
|
|
2161 |
this, 1 + sectorInner,
|
|
|
2162 |
Rkns.Renderer._NODE_BUTTON_WIDTH + sectorInner,
|
|
|
2163 |
this.startAngle,
|
|
|
2164 |
this.endAngle,
|
|
|
2165 |
1,
|
|
|
2166 |
this.imageName,
|
|
|
2167 |
this.renkan.translate(this.text)
|
|
|
2168 |
);
|
|
|
2169 |
this.lastSectorInner = sectorInner;
|
|
|
2170 |
}
|
|
|
2171 |
};
|
|
|
2172 |
|
|
|
2173 |
/* */
|
|
|
2174 |
|
|
|
2175 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2176 |
|
|
|
2177 |
Rkns.Renderer.NodeEditButton.prototype._init = function() {
|
|
|
2178 |
this.type = "Node-edit-button";
|
|
|
2179 |
this.lastSectorInner = 0;
|
|
|
2180 |
this.startAngle = -135;
|
|
|
2181 |
this.endAngle = -45;
|
|
|
2182 |
this.imageName = "edit";
|
|
|
2183 |
this.text = "Edit";
|
|
|
2184 |
};
|
|
|
2185 |
|
|
|
2186 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() {
|
|
|
2187 |
if (!this.renderer.is_dragging) {
|
|
|
2188 |
this.source_representation.openEditor();
|
|
|
2189 |
}
|
|
|
2190 |
};
|
|
|
2191 |
|
|
|
2192 |
/* */
|
|
|
2193 |
|
|
|
2194 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2195 |
|
|
|
2196 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() {
|
|
|
2197 |
this.type = "Node-remove-button";
|
|
|
2198 |
this.lastSectorInner = 0;
|
|
|
2199 |
this.startAngle = 0;
|
|
|
2200 |
this.endAngle = 90;
|
|
|
2201 |
this.imageName = "remove";
|
|
|
2202 |
this.text = "Remove";
|
|
|
2203 |
};
|
|
|
2204 |
|
|
|
2205 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() {
|
|
|
2206 |
this.renderer.click_target = null;
|
|
|
2207 |
this.renderer.is_dragging = false;
|
|
|
2208 |
this.renderer.removeRepresentationsOfType("editor");
|
|
|
2209 |
if (this.renderer.isEditable()) {
|
|
|
2210 |
if (this.options.element_delete_delay) {
|
|
|
2211 |
var delid = Rkns.Utils.getUID("delete");
|
|
|
2212 |
this.renderer.delete_list.push({
|
|
|
2213 |
id: delid,
|
|
|
2214 |
time: new Date().valueOf() + this.options.element_delete_delay
|
|
|
2215 |
});
|
|
|
2216 |
this.source_representation.model.set("delete_scheduled", delid);
|
|
|
2217 |
} else {
|
|
|
2218 |
if (confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
|
|
|
2219 |
this.project.removeNode(this.source_representation.model);
|
|
|
2220 |
}
|
|
|
2221 |
}
|
|
|
2222 |
}
|
|
|
2223 |
};
|
|
|
2224 |
|
|
|
2225 |
/* */
|
|
|
2226 |
|
|
|
2227 |
Rkns.Renderer.NodeRevertButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2228 |
|
|
|
2229 |
Rkns.Renderer.NodeRevertButton.prototype._init = function() {
|
|
|
2230 |
this.type = "Node-revert-button";
|
|
|
2231 |
this.lastSectorInner = 0;
|
|
|
2232 |
this.startAngle = -135;
|
|
|
2233 |
this.endAngle = 135;
|
|
|
2234 |
this.imageName = "revert";
|
|
|
2235 |
this.text = "Cancel deletion";
|
|
|
2236 |
};
|
|
|
2237 |
|
|
|
2238 |
Rkns.Renderer.NodeRevertButton.prototype.mouseup = function() {
|
|
|
2239 |
this.renderer.click_target = null;
|
|
|
2240 |
this.renderer.is_dragging = false;
|
|
|
2241 |
if (this.renderer.isEditable()) {
|
|
|
2242 |
this.source_representation.model.unset("delete_scheduled");
|
|
|
2243 |
}
|
|
|
2244 |
};
|
|
|
2245 |
|
|
|
2246 |
/* */
|
|
|
2247 |
|
|
|
2248 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2249 |
|
|
|
2250 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() {
|
|
|
2251 |
this.type = "Node-link-button";
|
|
|
2252 |
this.lastSectorInner = 0;
|
|
|
2253 |
this.startAngle = 90;
|
|
|
2254 |
this.endAngle = 180;
|
|
|
2255 |
this.imageName = "link";
|
|
|
2256 |
this.text = "Link to another node";
|
|
|
2257 |
};
|
|
|
2258 |
|
|
|
2259 |
Rkns.Renderer.NodeLinkButton.prototype.mousedown = function(_event, _isTouch) {
|
|
|
2260 |
if (this.renderer.isEditable()) {
|
|
|
2261 |
var _off = this.renderer.canvas_$.offset(),
|
|
|
2262 |
_point = new paper.Point([
|
|
|
2263 |
_event.pageX - _off.left,
|
|
|
2264 |
_event.pageY - _off.top
|
|
|
2265 |
]);
|
|
|
2266 |
this.renderer.click_target = null;
|
|
|
2267 |
this.renderer.removeRepresentationsOfType("editor");
|
|
|
2268 |
this.renderer.addTempEdge(this.source_representation, _point);
|
|
|
2269 |
}
|
|
|
2270 |
};
|
|
|
2271 |
|
|
|
2272 |
/* */
|
|
|
2273 |
|
|
|
2274 |
Rkns.Renderer.NodeEnlargeButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2275 |
|
|
|
2276 |
Rkns.Renderer.NodeEnlargeButton.prototype._init = function() {
|
|
|
2277 |
this.type = "Node-enlarge-button";
|
|
|
2278 |
this.lastSectorInner = 0;
|
|
|
2279 |
this.startAngle = -45;
|
|
|
2280 |
this.endAngle = 0;
|
|
|
2281 |
this.imageName = "enlarge";
|
|
|
2282 |
this.text = "Enlarge";
|
|
|
2283 |
};
|
|
|
2284 |
|
|
|
2285 |
Rkns.Renderer.NodeEnlargeButton.prototype.mouseup = function() {
|
|
|
2286 |
var _newsize = 1 + (this.source_representation.model.get("size") || 0);
|
|
|
2287 |
this.source_representation.model.set("size", _newsize);
|
|
|
2288 |
this.source_representation.select();
|
|
|
2289 |
this.select();
|
|
|
2290 |
paper.view.draw();
|
|
|
2291 |
};
|
|
|
2292 |
|
|
|
2293 |
/* */
|
|
|
2294 |
|
|
|
2295 |
Rkns.Renderer.NodeShrinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
|
|
|
2296 |
|
|
|
2297 |
Rkns.Renderer.NodeShrinkButton.prototype._init = function() {
|
|
|
2298 |
this.type = "Node-shrink-button";
|
|
|
2299 |
this.lastSectorInner = 0;
|
|
|
2300 |
this.startAngle = -180;
|
|
|
2301 |
this.endAngle = -135;
|
|
|
2302 |
this.imageName = "shrink";
|
|
|
2303 |
this.text = "Shrink";
|
|
|
2304 |
};
|
|
|
2305 |
|
|
|
2306 |
Rkns.Renderer.NodeShrinkButton.prototype.mouseup = function() {
|
|
|
2307 |
var _newsize = -1 + (this.source_representation.model.get("size") || 0);
|
|
|
2308 |
this.source_representation.model.set("size", _newsize);
|
|
|
2309 |
this.source_representation.select();
|
|
|
2310 |
this.select();
|
|
|
2311 |
paper.view.draw();
|
|
|
2312 |
};
|
|
|
2313 |
|
|
|
2314 |
/* */
|
|
|
2315 |
|
|
|
2316 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
|
|
|
2317 |
|
|
|
2318 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() {
|
|
|
2319 |
this.type = "Edge-edit-button";
|
|
|
2320 |
this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -270, -90, 1, "edit", this.renkan.translate("Edit"));
|
|
|
2321 |
};
|
|
|
2322 |
|
|
|
2323 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() {
|
|
|
2324 |
if (!this.renderer.is_dragging) {
|
|
|
2325 |
this.source_representation.openEditor();
|
|
|
2326 |
}
|
|
|
2327 |
};
|
|
|
2328 |
|
|
|
2329 |
/* */
|
|
|
2330 |
|
|
|
2331 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
|
|
|
2332 |
|
|
|
2333 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() {
|
|
|
2334 |
this.type = "Edge-remove-button";
|
|
|
2335 |
this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -90, 90, 1, "remove", this.renkan.translate("Remove"));
|
|
|
2336 |
};
|
|
|
2337 |
|
|
|
2338 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() {
|
|
|
2339 |
this.renderer.click_target = null;
|
|
|
2340 |
this.renderer.is_dragging = false;
|
|
|
2341 |
this.renderer.removeRepresentationsOfType("editor");
|
|
|
2342 |
if (this.renderer.isEditable()) {
|
|
|
2343 |
if (this.options.element_delete_delay) {
|
|
|
2344 |
var delid = Rkns.Utils.getUID("delete");
|
|
|
2345 |
this.renderer.delete_list.push({
|
|
|
2346 |
id: delid,
|
|
|
2347 |
time: new Date().valueOf() + this.options.element_delete_delay
|
|
|
2348 |
});
|
|
|
2349 |
this.source_representation.model.set("delete_scheduled", delid);
|
|
|
2350 |
} else {
|
|
|
2351 |
if (confirm(this.renkan.translate('Do you really wish to remove edge ') + '"' + this.source_representation.model.get("title") + '"?')) {
|
|
|
2352 |
this.project.removeEdge(this.source_representation.model);
|
|
|
2353 |
}
|
|
|
2354 |
}
|
|
|
2355 |
}
|
|
|
2356 |
};
|
|
|
2357 |
|
|
|
2358 |
/* */
|
|
|
2359 |
|
|
|
2360 |
Rkns.Renderer.EdgeRevertButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
|
|
|
2361 |
|
|
|
2362 |
Rkns.Renderer.EdgeRevertButton.prototype._init = function() {
|
|
|
2363 |
this.type = "Edge-revert-button";
|
|
|
2364 |
this.sector = this.renderer.drawSector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, -135, 135, 1, "revert", this.renkan.translate("Cancel deletion"));
|
|
|
2365 |
};
|
|
|
2366 |
|
|
|
2367 |
Rkns.Renderer.EdgeRevertButton.prototype.mouseup = function() {
|
|
|
2368 |
this.renderer.click_target = null;
|
|
|
2369 |
this.renderer.is_dragging = false;
|
|
|
2370 |
if (this.renderer.isEditable()) {
|
|
|
2371 |
this.source_representation.model.unset("delete_scheduled");
|
|
|
2372 |
}
|
|
|
2373 |
};
|
|
|
2374 |
|
|
|
2375 |
/* */
|
|
|
2376 |
|
|
|
2377 |
Rkns.Renderer.MiniFrame = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
|
|
|
2378 |
|
|
|
2379 |
Rkns.Renderer.MiniFrame.prototype.paperShift = function(_delta) {
|
|
|
2380 |
this.renderer.offset = this.renderer.offset.subtract(_delta.divide(this.renderer.minimap.scale).multiply(this.renderer.scale));
|
|
|
2381 |
this.renderer.redraw();
|
|
|
2382 |
};
|
|
|
2383 |
|
|
|
2384 |
Rkns.Renderer.MiniFrame.prototype.mouseup = function(_delta) {
|
|
|
2385 |
this.renderer.click_target = null;
|
|
|
2386 |
this.renderer.is_dragging = false;
|
|
|
2387 |
};
|
|
|
2388 |
|
|
|
2389 |
/* */
|
|
|
2390 |
|
|
|
2391 |
Rkns.Renderer.Scene = function(_renkan) {
|
|
|
2392 |
this.renkan = _renkan;
|
|
|
2393 |
this.$ = Rkns.$(".Rk-Render");
|
|
|
2394 |
this.representations = [];
|
|
|
2395 |
this.$.html(this.template(_renkan));
|
|
|
2396 |
this.onStatusChange();
|
|
|
2397 |
this.canvas_$ = this.$.find(".Rk-Canvas");
|
|
|
2398 |
this.labels_$ = this.$.find(".Rk-Labels");
|
|
|
2399 |
this.editor_$ = this.$.find(".Rk-Editor");
|
|
|
2400 |
this.notif_$ = this.$.find(".Rk-Notifications");
|
|
|
2401 |
paper.setup(this.canvas_$[0]);
|
|
|
2402 |
this.scale = 1;
|
|
|
2403 |
this.offset = paper.view.center;
|
|
|
2404 |
this.totalScroll = 0;
|
|
|
2405 |
this.mouse_down = false;
|
|
|
2406 |
this.click_target = null;
|
|
|
2407 |
this.selected_target = null;
|
|
|
2408 |
this.edge_layer = new paper.Layer();
|
|
|
2409 |
this.node_layer = new paper.Layer();
|
|
|
2410 |
this.buttons_layer = new paper.Layer();
|
|
|
2411 |
this.delete_list = [];
|
|
|
2412 |
|
|
|
2413 |
if (_renkan.options.show_minimap) {
|
|
|
2414 |
this.minimap = {
|
|
|
2415 |
background_layer: new paper.Layer(),
|
|
|
2416 |
edge_layer: new paper.Layer(),
|
|
|
2417 |
node_layer: new paper.Layer(),
|
|
|
2418 |
node_group: new paper.Group(),
|
|
|
2419 |
size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height )
|
|
|
2420 |
};
|
|
|
2421 |
|
|
|
2422 |
this.minimap.background_layer.activate();
|
|
|
2423 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size);
|
|
|
2424 |
this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4]));
|
|
|
2425 |
this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color;
|
|
|
2426 |
this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color;
|
|
|
2427 |
this.minimap.rectangle.strokeWidth = 4;
|
|
|
2428 |
this.minimap.offset = new paper.Point(this.minimap.size.divide(2));
|
|
|
2429 |
this.minimap.scale = .1;
|
|
|
2430 |
|
|
|
2431 |
this.minimap.node_layer.activate();
|
|
|
2432 |
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
|
|
|
2433 |
this.minimap.node_group.addChild(this.minimap.cliprectangle);
|
|
|
2434 |
this.minimap.node_group.clipped = true;
|
|
|
2435 |
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
|
|
|
2436 |
this.minimap.node_group.addChild(this.minimap.miniframe);
|
|
|
2437 |
this.minimap.miniframe.fillColor = '#c0c0ff';
|
|
|
2438 |
this.minimap.miniframe.opacity = .3;
|
|
|
2439 |
this.minimap.miniframe.strokeColor = '#000080';
|
|
|
2440 |
this.minimap.miniframe.strokeWidth = 3;
|
|
|
2441 |
this.minimap.miniframe.__representation = new Rkns.Renderer.MiniFrame(this, null);
|
|
|
2442 |
}
|
|
|
2443 |
|
|
|
2444 |
this.throttledPaperDraw = Rkns._(function() {
|
|
|
2445 |
paper.view.draw();
|
|
|
2446 |
}).throttle(100);
|
|
|
2447 |
|
|
|
2448 |
this.bundles = [];
|
|
|
2449 |
this.click_mode = false;
|
|
|
2450 |
|
|
|
2451 |
var _this = this,
|
|
|
2452 |
_allowScroll = true,
|
|
|
2453 |
_originalScale,
|
|
|
2454 |
_zooming = false,
|
|
|
2455 |
_lastTapDate,
|
|
|
2456 |
_lastTapX,
|
|
|
2457 |
_lastTapY;
|
|
|
2458 |
|
|
|
2459 |
this.image_cache = {};
|
|
|
2460 |
this.icon_cache = {};
|
|
|
2461 |
|
|
|
2462 |
['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
|
|
|
2463 |
var img = new Image();
|
|
|
2464 |
img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
|
|
|
2465 |
_this.icon_cache[imgname] = img;
|
|
|
2466 |
});
|
|
|
2467 |
|
|
|
2468 |
var throttledMouseMove = _.throttle(function(_event, _isTouch) {
|
|
|
2469 |
_this.onMouseMove(_event, _isTouch);
|
|
|
2470 |
}, Rkns.Renderer._MOUSEMOVE_RATE);
|
|
|
2471 |
|
|
|
2472 |
this.canvas_$.on({
|
|
|
2473 |
mousedown: function(_event) {
|
|
|
2474 |
_event.preventDefault();
|
|
|
2475 |
_this.onMouseDown(_event, false);
|
|
|
2476 |
},
|
|
|
2477 |
mousemove: function(_event) {
|
|
|
2478 |
_event.preventDefault();
|
|
|
2479 |
throttledMouseMove(_event, false);
|
|
|
2480 |
},
|
|
|
2481 |
mouseup: function(_event) {
|
|
|
2482 |
_event.preventDefault();
|
|
|
2483 |
_this.onMouseUp(_event, false);
|
|
|
2484 |
},
|
|
|
2485 |
mousewheel: function(_event, _delta) {
|
|
|
2486 |
_event.preventDefault();
|
|
|
2487 |
if (_allowScroll) {
|
|
|
2488 |
_this.onScroll(_event, _delta);
|
|
|
2489 |
}
|
|
|
2490 |
},
|
|
|
2491 |
touchstart: function(_event) {
|
|
|
2492 |
_event.preventDefault();
|
|
|
2493 |
var _touches = _event.originalEvent.touches[0];
|
|
|
2494 |
if (
|
|
|
2495 |
_renkan.options.allow_double_click
|
|
|
2496 |
&& new Date() - _lastTap < Rkns.Renderer._DOUBLETAP_DELAY
|
|
|
2497 |
&& ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Rkns.Renderer._DOUBLETAP_DISTANCE )
|
|
|
2498 |
) {
|
|
|
2499 |
_lastTap = 0;
|
|
|
2500 |
_this.onDoubleClick(_touches);
|
|
|
2501 |
} else {
|
|
|
2502 |
_lastTap = new Date();
|
|
|
2503 |
_lastTapX = _touches.pageX;
|
|
|
2504 |
_lastTapY = _touches.pageY;
|
|
|
2505 |
_originalScale = _this.scale;
|
|
|
2506 |
_zooming = false;
|
|
|
2507 |
_this.onMouseDown(_touches, true);
|
|
|
2508 |
}
|
|
|
2509 |
},
|
|
|
2510 |
touchmove: function(_event) {
|
|
|
2511 |
_event.preventDefault();
|
|
|
2512 |
_lastTap = 0;
|
|
|
2513 |
if (_event.originalEvent.touches.length == 1) {
|
|
|
2514 |
_this.onMouseMove(_event.originalEvent.touches[0], true);
|
|
|
2515 |
} else {
|
|
|
2516 |
if (!_zooming) {
|
|
|
2517 |
_this.onMouseUp(_event.originalEvent.touches[0], true);
|
|
|
2518 |
_this.click_target = null;
|
|
|
2519 |
_this.is_dragging = false;
|
|
|
2520 |
_zooming = true;
|
|
|
2521 |
}
|
|
|
2522 |
if (_event.originalEvent.scale === "undefined") {
|
|
|
2523 |
return;
|
|
|
2524 |
}
|
|
|
2525 |
var _newScale = _event.originalEvent.scale * _originalScale,
|
|
|
2526 |
_scaleRatio = _newScale / _this.scale,
|
|
|
2527 |
_newOffset = new paper.Point([
|
|
|
2528 |
_this.canvas_$.width(),
|
|
|
2529 |
_this.canvas_$.height()
|
|
|
2530 |
]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
|
|
|
2531 |
_this.setScale(_newScale, _this.offset);
|
|
|
2532 |
}
|
|
|
2533 |
},
|
|
|
2534 |
touchend: function(_event) {
|
|
|
2535 |
_event.preventDefault();
|
|
|
2536 |
_this.onMouseUp(_event.originalEvent.changedTouches[0], true);
|
|
|
2537 |
},
|
|
|
2538 |
dblclick: function(_event) {
|
|
|
2539 |
_event.preventDefault();
|
|
|
2540 |
if (_renkan.options.allow_double_click) {
|
|
|
2541 |
_this.onDoubleClick(_event);
|
|
|
2542 |
}
|
|
|
2543 |
},
|
|
|
2544 |
mouseleave: function(_event) {
|
|
|
2545 |
_event.preventDefault();
|
|
|
2546 |
_this.onMouseUp(_event, false);
|
|
|
2547 |
_this.click_target = null;
|
|
|
2548 |
_this.is_dragging = false;
|
|
|
2549 |
},
|
|
|
2550 |
dragover: function(_event) {
|
|
|
2551 |
_event.preventDefault();
|
|
|
2552 |
},
|
|
|
2553 |
dragenter: function(_event) {
|
|
|
2554 |
_event.preventDefault();
|
|
|
2555 |
_allowScroll = false;
|
|
|
2556 |
},
|
|
|
2557 |
dragleave: function(_event) {
|
|
|
2558 |
_event.preventDefault();
|
|
|
2559 |
_allowScroll = true;
|
|
|
2560 |
},
|
|
|
2561 |
drop: function(_event) {
|
|
|
2562 |
_event.preventDefault();
|
|
|
2563 |
_allowScroll = true;
|
|
|
2564 |
var res = {};
|
|
|
2565 |
Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) {
|
|
|
2566 |
try {
|
|
|
2567 |
res[t] = _event.originalEvent.dataTransfer.getData(t);
|
|
|
2568 |
} catch(e) {}
|
|
|
2569 |
});
|
|
|
2570 |
var text = _event.originalEvent.dataTransfer.getData("Text");
|
|
|
2571 |
if (typeof text === "string") {
|
|
|
2572 |
switch(text[0]) {
|
|
|
2573 |
case "{":
|
|
|
2574 |
case "[":
|
|
|
2575 |
try {
|
|
|
2576 |
var data = JSON.parse(text);
|
|
|
2577 |
_(res).extend(data);
|
|
|
2578 |
}
|
|
|
2579 |
catch(e) {
|
|
|
2580 |
if (!res["text/plain"]) {
|
|
|
2581 |
res["text/plain"] = text;
|
|
|
2582 |
}
|
|
|
2583 |
}
|
|
|
2584 |
break;
|
|
|
2585 |
case "<":
|
|
|
2586 |
if (!res["text/html"]) {
|
|
|
2587 |
res["text/html"] = text;
|
|
|
2588 |
}
|
|
|
2589 |
break;
|
|
|
2590 |
default:
|
|
|
2591 |
if (!res["text/plain"]) {
|
|
|
2592 |
res["text/plain"] = text;
|
|
|
2593 |
}
|
|
|
2594 |
}
|
|
|
2595 |
}
|
|
|
2596 |
var url = _event.originalEvent.dataTransfer.getData("URL");
|
|
|
2597 |
if (url && !res["text/uri-list"]) {
|
|
|
2598 |
res["text/uri-list"] = url;
|
|
|
2599 |
}
|
|
|
2600 |
_this.dropData(res, _event.originalEvent);
|
|
|
2601 |
}
|
|
|
2602 |
});
|
|
|
2603 |
this.editor_$.find(".Rk-ZoomOut").click(function() {
|
|
|
2604 |
var _newScale = _this.scale * Math.SQRT1_2,
|
|
|
2605 |
_offset = new paper.Point([
|
|
|
2606 |
_this.canvas_$.width(),
|
|
|
2607 |
_this.canvas_$.height()
|
|
|
2608 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 ));
|
|
|
2609 |
_this.setScale( _newScale, _offset );
|
|
|
2610 |
});
|
|
|
2611 |
this.editor_$.find(".Rk-ZoomIn").click(function() {
|
|
|
2612 |
var _newScale = _this.scale * Math.SQRT2,
|
|
|
2613 |
_offset = new paper.Point([
|
|
|
2614 |
_this.canvas_$.width(),
|
|
|
2615 |
_this.canvas_$.height()
|
|
|
2616 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 ));
|
|
|
2617 |
_this.setScale( _newScale, _offset );
|
|
|
2618 |
});
|
|
|
2619 |
this.$.find(".Rk-CurrentUser").mouseenter(
|
|
|
2620 |
function() { _this.$.find(".Rk-UserList").slideDown(); }
|
|
|
2621 |
);
|
|
|
2622 |
this.$.find(".Rk-Users").mouseleave(
|
|
|
2623 |
function() { _this.$.find(".Rk-UserList").slideUp(); }
|
|
|
2624 |
);
|
|
|
2625 |
this.$.find(".Rk-FullScreen-Button").click(function() {
|
|
|
2626 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
|
|
|
2627 |
_el = _this.renkan.$[0],
|
|
|
2628 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
|
|
|
2629 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"];
|
|
|
2630 |
if (_isFull) {
|
|
|
2631 |
for (var i = 0; i < _cancelMethods.length; i++) {
|
|
|
2632 |
if (typeof document[_cancelMethods[i]] === "function") {
|
|
|
2633 |
document[_cancelMethods[i]]();
|
|
|
2634 |
break;
|
|
|
2635 |
}
|
|
|
2636 |
}
|
|
|
2637 |
} else {
|
|
|
2638 |
for (var i = 0; i < _requestMethods.length; i++) {
|
|
|
2639 |
if (typeof _el[_requestMethods[i]] === "function") {
|
|
|
2640 |
_el[_requestMethods[i]]();
|
|
|
2641 |
break;
|
|
|
2642 |
}
|
|
|
2643 |
}
|
|
|
2644 |
}
|
|
|
2645 |
});
|
|
|
2646 |
this.$.find(".Rk-AddNode-Button").click(function() {
|
|
|
2647 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) {
|
|
|
2648 |
_this.click_mode = false;
|
|
|
2649 |
_this.notif_$.hide();
|
|
|
2650 |
} else {
|
|
|
2651 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE;
|
|
|
2652 |
_this.notif_$.text(_renkan.translate("Click on the background canvas to add a node")).fadeIn();
|
|
|
2653 |
}
|
|
|
2654 |
});
|
|
|
2655 |
this.$.find(".Rk-AddEdge-Button").click(function() {
|
|
|
2656 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE || _this.click_mode === Rkns.Renderer._CLICKMODE_ENDEDGE) {
|
|
|
2657 |
_this.click_mode = false;
|
|
|
2658 |
_this.notif_$.hide();
|
|
|
2659 |
} else {
|
|
|
2660 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE;
|
|
|
2661 |
_this.notif_$.text(_renkan.translate("Click on a first node to start the edge")).fadeIn();
|
|
|
2662 |
}
|
|
|
2663 |
});
|
|
|
2664 |
this.$.find(".Rk-Bookmarklet-Button")
|
|
|
2665 |
.attr("href","javascript:" + Rkns.Renderer._BOOKMARKLET_CODE(_renkan))
|
|
|
2666 |
.click(function(){
|
|
|
2667 |
_this.notif_$
|
|
|
2668 |
.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."))
|
|
|
2669 |
.fadeIn()
|
|
|
2670 |
.delay(5000)
|
|
|
2671 |
.fadeOut();
|
|
|
2672 |
return false;
|
|
|
2673 |
});
|
|
|
2674 |
this.$.find(".Rk-TopBar-Button").mouseover(function() {
|
|
|
2675 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show();
|
|
|
2676 |
}).mouseout(function() {
|
|
|
2677 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide();
|
|
|
2678 |
});
|
|
|
2679 |
this.$.find(".Rk-Fold-Bins").click(function() {
|
|
|
2680 |
var bins = _renkan.$.find(".Rk-Bins");
|
|
|
2681 |
if (bins.offset().left < 0) {
|
|
|
2682 |
bins.animate({left: 0},250);
|
|
|
2683 |
_this.$.animate({left: 300},250,function() {
|
|
|
2684 |
var w = _this.$.width();
|
|
|
2685 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
|
|
|
2686 |
});
|
|
|
2687 |
$(this).html("«");
|
|
|
2688 |
} else {
|
|
|
2689 |
bins.animate({left: -300},250);
|
|
|
2690 |
_this.$.animate({left: 0},250,function() {
|
|
|
2691 |
var w = _this.$.width();
|
|
|
2692 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
|
|
|
2693 |
});
|
|
|
2694 |
$(this).html("»");
|
|
|
2695 |
}
|
|
|
2696 |
});
|
|
|
2697 |
|
|
|
2698 |
paper.view.onResize = function(_event) {
|
|
|
2699 |
_this.offset = _this.offset.add(_event.delta.divide(2));
|
|
|
2700 |
if (_this.minimap) {
|
|
|
2701 |
_this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size);
|
|
|
2702 |
_this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4]));
|
|
|
2703 |
_this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size);
|
|
|
2704 |
}
|
|
|
2705 |
_this.redraw();
|
|
|
2706 |
};
|
|
|
2707 |
|
|
|
2708 |
var _thRedraw = Rkns._.throttle(function() {
|
|
|
2709 |
_this.redraw();
|
|
|
2710 |
},50);
|
|
|
2711 |
|
|
|
2712 |
this.addRepresentations("Node", this.renkan.project.get("nodes"));
|
|
|
2713 |
this.addRepresentations("Edge", this.renkan.project.get("edges"));
|
|
|
2714 |
this.renkan.project.on("change:title", function() {
|
|
|
2715 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
|
|
|
2716 |
});
|
|
|
2717 |
|
|
|
2718 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() {
|
|
|
2719 |
_renkan.project.set({"title": $(this).val()});
|
|
|
2720 |
});
|
|
|
2721 |
|
|
|
2722 |
this.renkan.project.get("users").each(function(_user) {
|
|
|
2723 |
_this.addUser(_user);
|
|
|
2724 |
});
|
|
|
2725 |
|
|
|
2726 |
this.renkan.project.on("add:users", function(_user) {
|
|
|
2727 |
_this.addUser(_user);
|
|
|
2728 |
});
|
|
|
2729 |
this.renkan.project.on("add:nodes", function(_node) {
|
|
|
2730 |
_this.addRepresentation("Node", _node);
|
|
|
2731 |
_thRedraw();
|
|
|
2732 |
});
|
|
|
2733 |
this.renkan.project.on("add:edges", function(_edge) {
|
|
|
2734 |
_this.addRepresentation("Edge", _edge);
|
|
|
2735 |
_thRedraw();
|
|
|
2736 |
});
|
|
|
2737 |
this.renkan.project.on("change:title", function(_model, _title) {
|
|
|
2738 |
var el = _this.$.find(".Rk-PadTitle");
|
|
|
2739 |
if (el.is("input")) {
|
|
|
2740 |
if (el.val() !== _title) {
|
|
|
2741 |
el.val(_title);
|
|
|
2742 |
}
|
|
|
2743 |
} else {
|
|
|
2744 |
el.text(_title);
|
|
|
2745 |
}
|
|
|
2746 |
});
|
|
|
2747 |
|
|
|
2748 |
if (_renkan.options.size_bug_fix) {
|
|
|
2749 |
var _delay = (
|
|
|
2750 |
typeof _renkan.options.size_bug_fix === "number"
|
|
|
2751 |
? _renkan.options.size_bug_fix
|
|
|
2752 |
: 500
|
|
|
2753 |
);
|
|
|
2754 |
window.setTimeout(
|
|
|
2755 |
function() {
|
|
|
2756 |
_this.fixSize(true);
|
|
|
2757 |
},
|
|
|
2758 |
_delay
|
|
|
2759 |
);
|
|
|
2760 |
}
|
|
|
2761 |
|
|
|
2762 |
if (_renkan.options.force_resize) {
|
|
|
2763 |
$(window).resize(function() {
|
|
|
2764 |
_this.fixSize(false);
|
|
|
2765 |
});
|
|
|
2766 |
}
|
|
|
2767 |
|
|
|
2768 |
this.redraw();
|
|
|
2769 |
|
|
|
2770 |
window.setInterval(function() {
|
|
|
2771 |
var _now = new Date().valueOf();
|
|
|
2772 |
_this.delete_list.forEach(function(d) {
|
|
|
2773 |
if (_now >= d.time) {
|
|
|
2774 |
var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id});
|
|
|
2775 |
if (el) {
|
|
|
2776 |
project.removeNode(el);
|
|
|
2777 |
}
|
|
|
2778 |
el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
|
|
|
2779 |
if (el) {
|
|
|
2780 |
project.removeEdge(el);
|
|
|
2781 |
}
|
|
|
2782 |
}
|
|
|
2783 |
});
|
|
|
2784 |
_this.delete_list = _this.delete_list.filter(function(d) {
|
|
|
2785 |
return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id});
|
|
|
2786 |
});
|
|
|
2787 |
}, 500);
|
|
|
2788 |
|
|
|
2789 |
if (this.minimap) {
|
|
|
2790 |
window.setInterval(function() {
|
|
|
2791 |
_this.rescaleMinimap();
|
|
|
2792 |
}, 2000);
|
|
|
2793 |
}
|
|
|
2794 |
|
|
|
2795 |
};
|
|
|
2796 |
|
|
|
2797 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template(
|
|
|
2798 |
'<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>'
|
|
|
2799 |
+ '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>'
|
|
|
2800 |
+ '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>'
|
|
|
2801 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Full Screen")%></div></div></div>'
|
|
|
2802 |
+ '<% if (options.editor_mode) { %>'
|
|
|
2803 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Node")%></div></div></div>'
|
|
|
2804 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%-translate("Add Edge")%></div></div></div>'
|
|
|
2805 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div>'
|
|
|
2806 |
+ '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">'
|
|
|
2807 |
+ '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a>'
|
|
|
2808 |
+ '<div class="Rk-TopBar-Separator"></div>'
|
|
|
2809 |
+ '<% } %></div><% } %>'
|
|
|
2810 |
+ '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
|
|
|
2811 |
+ '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
|
|
|
2812 |
+ '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">«</div><% } %>'
|
|
|
2813 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
|
|
|
2814 |
+ '</div></div>'
|
|
|
2815 |
);
|
|
|
2816 |
|
|
|
2817 |
Rkns.Renderer.Scene.prototype.fixSize = function(_autoscale) {
|
|
|
2818 |
var w = this.$.width(),
|
|
|
2819 |
h = this.$.height();
|
|
|
2820 |
if (this.renkan.options.show_top_bar) {
|
|
|
2821 |
h -= this.$.find(".Rk-TopBar").height();
|
|
|
2822 |
}
|
|
|
2823 |
this.canvas_$.attr({
|
|
|
2824 |
width: w,
|
|
|
2825 |
height: h
|
|
|
2826 |
});
|
|
|
2827 |
|
|
|
2828 |
paper.view.viewSize = new paper.Size([w, h]);
|
|
|
2829 |
|
|
|
2830 |
if (_autoscale) {
|
|
|
2831 |
this.autoScale();
|
|
|
2832 |
}
|
|
|
2833 |
};
|
|
|
2834 |
|
|
|
2835 |
Rkns.Renderer.Scene.prototype.drawSector = function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
|
|
|
2836 |
var _options = this.renkan.options,
|
|
|
2837 |
_startRads = _startAngle * Math.PI / 180,
|
|
|
2838 |
_endRads = _endAngle * Math.PI / 180,
|
|
|
2839 |
_img = this.icon_cache[_imgname],
|
|
|
2840 |
_span = _endRads - _startRads,
|
|
|
2841 |
_startdx = - Math.sin(_startRads),
|
|
|
2842 |
_startdy = Math.cos(_startRads),
|
|
|
2843 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx,
|
|
|
2844 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy,
|
|
|
2845 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx,
|
|
|
2846 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy,
|
|
|
2847 |
_enddx = - Math.sin(_endRads),
|
|
|
2848 |
_enddy = Math.cos(_endRads),
|
|
|
2849 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx,
|
|
|
2850 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
|
|
|
2851 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
|
|
|
2852 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
|
|
|
2853 |
_centerR = (_inR + _outR)/2,
|
|
|
2854 |
_centerRads = (_startRads + _endRads) / 2,
|
|
|
2855 |
_centerX = Math.cos(_centerRads) * _centerR,
|
|
|
2856 |
_centerY = Math.sin(_centerRads) * _centerR,
|
|
|
2857 |
_centerXIn = Math.cos(_centerRads) * _inR,
|
|
|
2858 |
_centerXOut = Math.cos(_centerRads) * _outR,
|
|
|
2859 |
_centerYIn = Math.sin(_centerRads) * _inR,
|
|
|
2860 |
_centerYOut = Math.sin(_centerRads) * _outR,
|
|
|
2861 |
_textX = Math.cos(_centerRads) * (_outR + 3),
|
|
|
2862 |
_textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2,
|
|
|
2863 |
_segments = [];
|
|
|
2864 |
this.buttons_layer.activate();
|
|
|
2865 |
var _path = new paper.Path();
|
|
|
2866 |
_path.add([_startXIn, _startYIn]);
|
|
|
2867 |
_path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]);
|
|
|
2868 |
_path.lineTo([_endXOut, _endYOut]);
|
|
|
2869 |
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
|
|
|
2870 |
_path.fillColor = _options.buttons_background;
|
|
|
2871 |
_path.opacity = .5;
|
|
|
2872 |
_path.closed = true;
|
|
|
2873 |
_path.__representation = _repr;
|
|
|
2874 |
var _text = new paper.PointText(_textX,_textY);
|
|
|
2875 |
_text.characterStyle = {
|
|
|
2876 |
fontSize: _options.buttons_label_font_size,
|
|
|
2877 |
fillColor: _options.buttons_label_color
|
|
|
2878 |
};
|
|
|
2879 |
if (_textX > 2) {
|
|
|
2880 |
_text.paragraphStyle.justification = 'left';
|
|
|
2881 |
} else if (_textX < -2) {
|
|
|
2882 |
_text.paragraphStyle.justification = 'right';
|
|
|
2883 |
} else {
|
|
|
2884 |
_text.paragraphStyle.justification = 'center';
|
|
|
2885 |
}
|
|
|
2886 |
_text.visible = false;
|
|
|
2887 |
var _visible = false,
|
|
|
2888 |
_restPos = new paper.Point(-200, -200),
|
|
|
2889 |
_grp = new paper.Group([_path, _text]),
|
|
|
2890 |
_delta = _grp.position,
|
|
|
2891 |
_imgdelta = new paper.Point([_centerX, _centerY]),
|
|
|
2892 |
_currentPos = new paper.Point(0,0);
|
|
|
2893 |
_text.content = _caption;
|
|
|
2894 |
_grp.visible = false;
|
|
|
2895 |
_grp.position = _restPos;
|
|
|
2896 |
var _res = {
|
|
|
2897 |
show: function() {
|
|
|
2898 |
_visible = true;
|
|
|
2899 |
_grp.position = _currentPos.add(_delta);
|
|
|
2900 |
_grp.visible = true;
|
|
|
2901 |
},
|
|
|
2902 |
moveTo: function(_point) {
|
|
|
2903 |
_currentPos = _point;
|
|
|
2904 |
if (_visible) {
|
|
|
2905 |
_grp.position = _point.add(_delta);
|
|
|
2906 |
}
|
|
|
2907 |
},
|
|
|
2908 |
hide: function() {
|
|
|
2909 |
_visible = false;
|
|
|
2910 |
_grp.visible = false;
|
|
|
2911 |
_grp.position = _restPos;
|
|
|
2912 |
},
|
|
|
2913 |
select: function() {
|
|
|
2914 |
_path.opacity = .8;
|
|
|
2915 |
_text.visible = true;
|
|
|
2916 |
},
|
|
|
2917 |
unselect: function() {
|
|
|
2918 |
_path.opacity = .5;
|
|
|
2919 |
_text.visible = false;
|
|
|
2920 |
},
|
|
|
2921 |
destroy: function() {
|
|
|
2922 |
_grp.remove();
|
|
|
2923 |
}
|
|
|
2924 |
};
|
|
|
2925 |
function showImage() {
|
|
|
2926 |
var _raster = new paper.Raster(_img);
|
|
|
2927 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta);
|
|
|
2928 |
_grp.addChild(_raster);
|
|
|
2929 |
}
|
|
|
2930 |
if (_img.width) {
|
|
|
2931 |
showImage();
|
|
|
2932 |
} else {
|
|
|
2933 |
Rkns.$(_img).on("load",showImage);
|
|
|
2934 |
}
|
|
|
2935 |
|
|
|
2936 |
return _res;
|
|
|
2937 |
};
|
|
|
2938 |
|
|
|
2939 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) {
|
|
|
2940 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) {
|
|
|
2941 |
return (
|
|
|
2942 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation )
|
|
|
2943 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
|
|
|
2944 |
);
|
|
|
2945 |
});
|
|
|
2946 |
if (typeof _bundle !== "undefined") {
|
|
|
2947 |
_bundle.edges.push(_edgeRepr);
|
|
|
2948 |
} else {
|
|
|
2949 |
_bundle = {
|
|
|
2950 |
from: _edgeRepr.from_representation,
|
|
|
2951 |
to: _edgeRepr.to_representation,
|
|
|
2952 |
edges: [ _edgeRepr ],
|
|
|
2953 |
getPosition: function(_er) {
|
|
|
2954 |
var _dir = (_er.from_representation === this.from) ? 1 : -1;
|
|
|
2955 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 );
|
|
|
2956 |
}
|
|
|
2957 |
};
|
|
|
2958 |
this.bundles.push(_bundle);
|
|
|
2959 |
}
|
|
|
2960 |
return _bundle;
|
|
|
2961 |
};
|
|
|
2962 |
|
|
|
2963 |
Rkns.Renderer.Scene.prototype.isEditable = function() {
|
|
|
2964 |
return (this.renkan.options.editor_mode && !this.renkan.read_only);
|
|
|
2965 |
};
|
|
|
2966 |
|
|
|
2967 |
Rkns.Renderer.Scene.prototype.onStatusChange = function() {
|
|
|
2968 |
var savebtn = this.$.find(".Rk-Save-Button"),
|
|
|
2969 |
tip = savebtn.find(".Rk-TopBar-Tooltip-Contents");
|
|
|
2970 |
if (this.renkan.read_only) {
|
|
|
2971 |
savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly");
|
|
|
2972 |
tip.text(this.renkan.translate("Connection lost"));
|
|
|
2973 |
} else {
|
|
|
2974 |
if (this.renkan.options.snapshot_mode) {
|
|
|
2975 |
savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online");
|
|
|
2976 |
tip.text(this.renkan.translate("Archive Project"));
|
|
|
2977 |
} else {
|
|
|
2978 |
savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online");
|
|
|
2979 |
tip.text(this.renkan.translate("Auto-save enabled"));
|
|
|
2980 |
}
|
|
|
2981 |
}
|
|
|
2982 |
};
|
|
|
2983 |
|
|
|
2984 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale, _offset) {
|
|
|
2985 |
if (_newScale > Rkns.Renderer._MIN_SCALE && _newScale < Rkns.Renderer._MAX_SCALE) {
|
|
|
2986 |
this.scale = _newScale;
|
|
|
2987 |
if (_offset) {
|
|
|
2988 |
this.offset = _offset;
|
|
|
2989 |
}
|
|
|
2990 |
this.redraw();
|
|
|
2991 |
}
|
|
|
2992 |
};
|
|
|
2993 |
|
|
|
2994 |
Rkns.Renderer.Scene.prototype.autoScale = function() {
|
|
|
2995 |
var nodes = this.renkan.project.get("nodes");
|
|
|
2996 |
if (nodes.length > 1) {
|
|
|
2997 |
var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
|
|
|
2998 |
_yy = nodes.map(function(_node) { return _node.get("position").y; }),
|
|
|
2999 |
_minx = Math.min.apply(Math, _xx),
|
|
|
3000 |
_miny = Math.min.apply(Math, _yy),
|
|
|
3001 |
_maxx = Math.max.apply(Math, _xx),
|
|
|
3002 |
_maxy = Math.max.apply(Math, _yy);
|
|
|
3003 |
var _scale = Math.max(Rkns.Renderer._MIN_SCALE, Math.min(Rkns.Renderer._MAX_SCALE, (paper.view.size.width - 2 * this.renkan.options.autoscale_padding) / (_maxx - _minx), (paper.view.size.height - 2 * this.renkan.options.autoscale_padding) / (_maxy - _miny)));
|
|
|
3004 |
this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
|
|
|
3005 |
}
|
|
|
3006 |
if (nodes.length === 1) {
|
|
|
3007 |
this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
|
|
|
3008 |
}
|
|
|
3009 |
};
|
|
|
3010 |
|
|
|
3011 |
Rkns.Renderer.Scene.prototype.redrawMiniframe = function() {
|
|
|
3012 |
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
|
|
|
3013 |
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
|
|
|
3014 |
this.minimap.miniframe.fitBounds(topleft, bottomright);
|
|
|
3015 |
};
|
|
|
3016 |
|
|
|
3017 |
Rkns.Renderer.Scene.prototype.rescaleMinimap = function() {
|
|
|
3018 |
var nodes = this.renkan.project.get("nodes");
|
|
|
3019 |
if (nodes.length > 1) {
|
|
|
3020 |
var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
|
|
|
3021 |
_yy = nodes.map(function(_node) { return _node.get("position").y; }),
|
|
|
3022 |
_minx = Math.min.apply(Math, _xx),
|
|
|
3023 |
_miny = Math.min.apply(Math, _yy),
|
|
|
3024 |
_maxx = Math.max.apply(Math, _xx),
|
|
|
3025 |
_maxy = Math.max.apply(Math, _yy);
|
|
|
3026 |
var _scale = Math.min(
|
|
|
3027 |
this.scale * .8 * this.renkan.options.minimap_width / paper.view.bounds.width,
|
|
|
3028 |
this.scale * .8 * this.renkan.options.minimap_height / paper.view.bounds.height,
|
|
|
3029 |
( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
|
|
|
3030 |
( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
|
|
|
3031 |
);
|
|
|
3032 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
|
|
|
3033 |
this.minimap.scale = _scale;
|
|
|
3034 |
}
|
|
|
3035 |
if (nodes.length === 1) {
|
|
|
3036 |
this.minimap.scale = .1;
|
|
|
3037 |
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));
|
|
|
3038 |
}
|
|
|
3039 |
this.redraw();
|
|
|
3040 |
};
|
|
|
3041 |
|
|
|
3042 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) {
|
|
|
3043 |
return _point.multiply(this.scale).add(this.offset);
|
|
|
3044 |
};
|
|
|
3045 |
|
|
|
3046 |
Rkns.Renderer.Scene.prototype.toMinimapCoords = function(_point) {
|
|
|
3047 |
return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
|
|
|
3048 |
};
|
|
|
3049 |
|
|
|
3050 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) {
|
|
|
3051 |
return _point.subtract(this.offset).divide(this.scale);
|
|
|
3052 |
};
|
|
|
3053 |
|
|
|
3054 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) {
|
|
|
3055 |
var _repr = new Rkns.Renderer[_type](this, _model);
|
|
|
3056 |
this.representations.push(_repr);
|
|
|
3057 |
return _repr;
|
|
|
3058 |
};
|
|
|
3059 |
|
|
|
3060 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) {
|
|
|
3061 |
var _this = this;
|
|
|
3062 |
_collection.forEach(function(_model) {
|
|
|
3063 |
_this.addRepresentation(_type, _model);
|
|
|
3064 |
});
|
|
|
3065 |
};
|
|
|
3066 |
|
|
|
3067 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template(
|
|
|
3068 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>'
|
|
|
3069 |
);
|
|
|
3070 |
|
|
|
3071 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) {
|
|
|
3072 |
if (_user.get("_id") === this.renkan.current_user) {
|
|
|
3073 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title"));
|
|
|
3074 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color"));
|
|
|
3075 |
} else {
|
|
|
3076 |
this.$.find(".Rk-UserList").append(
|
|
|
3077 |
Rkns.$(
|
|
|
3078 |
this.userTemplate({
|
|
|
3079 |
name: _user.get("title"),
|
|
|
3080 |
background: _user.get("color")
|
|
|
3081 |
})
|
|
|
3082 |
)
|
|
|
3083 |
);
|
|
|
3084 |
}
|
|
|
3085 |
};
|
|
|
3086 |
|
|
|
3087 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) {
|
|
|
3088 |
_representation.destroy();
|
|
|
3089 |
this.representations = Rkns._(this.representations).reject(
|
|
|
3090 |
function(_repr) {
|
|
|
3091 |
return _repr == _representation;
|
|
|
3092 |
}
|
|
|
3093 |
);
|
|
|
3094 |
};
|
|
|
3095 |
|
|
|
3096 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) {
|
|
|
3097 |
if (!_model) {
|
|
|
3098 |
return undefined;
|
|
|
3099 |
}
|
|
|
3100 |
return Rkns._(this.representations).find(function(_repr) {
|
|
|
3101 |
return _repr.model === _model;
|
|
|
3102 |
});
|
|
|
3103 |
};
|
|
|
3104 |
|
|
|
3105 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) {
|
|
|
3106 |
var _representations = Rkns._(this.representations).filter(function(_repr) {
|
|
|
3107 |
return _repr.type == _type;
|
|
|
3108 |
}),
|
|
|
3109 |
_this = this;
|
|
|
3110 |
Rkns._(_representations).each(function(_repr) {
|
|
|
3111 |
_this.removeRepresentation(_repr);
|
|
|
3112 |
});
|
|
|
3113 |
};
|
|
|
3114 |
|
|
|
3115 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) {
|
|
|
3116 |
var _repr = this.getRepresentationByModel(_model);
|
|
|
3117 |
if (_repr) {
|
|
|
3118 |
_repr.highlight();
|
|
|
3119 |
}
|
|
|
3120 |
};
|
|
|
3121 |
|
|
|
3122 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) {
|
|
|
3123 |
Rkns._(this.representations).each(function(_repr) {
|
|
|
3124 |
_repr.unhighlight();
|
|
|
3125 |
});
|
|
|
3126 |
};
|
|
|
3127 |
|
|
|
3128 |
Rkns.Renderer.Scene.prototype.unselectAll = function(_model) {
|
|
|
3129 |
Rkns._(this.representations).each(function(_repr) {
|
|
|
3130 |
_repr.unselect();
|
|
|
3131 |
});
|
|
|
3132 |
};
|
|
|
3133 |
|
|
|
3134 |
Rkns.Renderer.Scene.prototype.redraw = function() {
|
|
|
3135 |
Rkns._(this.representations).each(function(_representation) {
|
|
|
3136 |
_representation.redraw(true);
|
|
|
3137 |
});
|
|
|
3138 |
if (this.minimap) {
|
|
|
3139 |
this.redrawMiniframe();
|
|
|
3140 |
}
|
|
|
3141 |
paper.view.draw();
|
|
|
3142 |
};
|
|
|
3143 |
|
|
|
3144 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) {
|
|
|
3145 |
var _tmpEdge = this.addRepresentation("TempEdge",null);
|
|
|
3146 |
_tmpEdge.end_pos = _point;
|
|
|
3147 |
_tmpEdge.from_representation = _from;
|
|
|
3148 |
_tmpEdge.redraw();
|
|
|
3149 |
this.click_target = _tmpEdge;
|
|
|
3150 |
};
|
|
|
3151 |
|
|
|
3152 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) {
|
|
|
3153 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
|
|
|
3154 |
var _newTarget = _hitResult.item.__representation;
|
|
|
3155 |
if (this.selected_target !== _hitResult.item.__representation) {
|
|
|
3156 |
if (this.selected_target) {
|
|
|
3157 |
this.selected_target.unselect(_newTarget);
|
|
|
3158 |
}
|
|
|
3159 |
_newTarget.select(this.selected_target);
|
|
|
3160 |
this.selected_target = _newTarget;
|
|
|
3161 |
}
|
|
|
3162 |
} else {
|
|
|
3163 |
if (this.selected_target) {
|
|
|
3164 |
this.selected_target.unselect();
|
|
|
3165 |
}
|
|
|
3166 |
this.selected_target = null;
|
|
|
3167 |
}
|
|
|
3168 |
};
|
|
|
3169 |
|
|
|
3170 |
Rkns.Renderer.Scene.prototype.paperShift = function(_delta) {
|
|
|
3171 |
this.offset = this.offset.add(_delta);
|
|
|
3172 |
this.redraw();
|
|
|
3173 |
};
|
|
|
3174 |
|
|
|
3175 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) {
|
|
|
3176 |
var _off = this.canvas_$.offset(),
|
|
|
3177 |
_point = new paper.Point([
|
|
|
3178 |
_event.pageX - _off.left,
|
|
|
3179 |
_event.pageY - _off.top
|
|
|
3180 |
]),
|
|
|
3181 |
_delta = _point.subtract(this.last_point);
|
|
|
3182 |
this.last_point = _point;
|
|
|
3183 |
if (!this.is_dragging && this.mouse_down && _delta.length > Rkns.Renderer._MIN_DRAG_DISTANCE) {
|
|
|
3184 |
this.is_dragging = true;
|
|
|
3185 |
}
|
|
|
3186 |
var _hitResult = paper.project.hitTest(_point);
|
|
|
3187 |
if (this.is_dragging) {
|
|
|
3188 |
if (this.click_target && typeof this.click_target.paperShift === "function") {
|
|
|
3189 |
this.click_target.paperShift(_delta);
|
|
|
3190 |
} else {
|
|
|
3191 |
this.paperShift(_delta);
|
|
|
3192 |
}
|
|
|
3193 |
} else {
|
|
|
3194 |
this.findTarget(_hitResult);
|
|
|
3195 |
}
|
|
|
3196 |
paper.view.draw();
|
|
|
3197 |
};
|
|
|
3198 |
|
|
|
3199 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event, _isTouch) {
|
|
|
3200 |
var _off = this.canvas_$.offset(),
|
|
|
3201 |
_point = new paper.Point([
|
|
|
3202 |
_event.pageX - _off.left,
|
|
|
3203 |
_event.pageY - _off.top
|
|
|
3204 |
]);
|
|
|
3205 |
this.last_point = _point;
|
|
|
3206 |
this.mouse_down = true;
|
|
|
3207 |
if (!this.click_target || this.click_target.type !== "Temp-edge") {
|
|
|
3208 |
this.removeRepresentationsOfType("editor");
|
|
|
3209 |
this.is_dragging = false;
|
|
|
3210 |
var _hitResult = paper.project.hitTest(_point);
|
|
|
3211 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
|
|
|
3212 |
this.click_target = _hitResult.item.__representation;
|
|
|
3213 |
this.click_target.mousedown(_event, _isTouch);
|
|
|
3214 |
} else {
|
|
|
3215 |
this.click_target = null;
|
|
|
3216 |
if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) {
|
|
|
3217 |
var _coords = this.toModelCoords(_point),
|
|
|
3218 |
_data = {
|
|
|
3219 |
id: Rkns.Utils.getUID('node'),
|
|
|
3220 |
created_by: this.renkan.current_user,
|
|
|
3221 |
position: {
|
|
|
3222 |
x: _coords.x,
|
|
|
3223 |
y: _coords.y
|
|
|
3224 |
}
|
|
|
3225 |
};
|
|
|
3226 |
_node = this.renkan.project.addNode(_data);
|
|
|
3227 |
this.getRepresentationByModel(_node).openEditor();
|
|
|
3228 |
}
|
|
|
3229 |
}
|
|
|
3230 |
}
|
|
|
3231 |
if (this.click_mode) {
|
|
|
3232 |
if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
|
|
|
3233 |
this.removeRepresentationsOfType("editor");
|
|
|
3234 |
this.addTempEdge(this.click_target, _point);
|
|
|
3235 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE;
|
|
|
3236 |
this.notif_$.fadeOut(function() {
|
|
|
3237 |
Rkns.$(this).html(_renkan.translate("Click on a second node to complete the edge")).fadeIn();
|
|
|
3238 |
});
|
|
|
3239 |
} else {
|
|
|
3240 |
this.notif_$.hide();
|
|
|
3241 |
this.click_mode = false;
|
|
|
3242 |
}
|
|
|
3243 |
}
|
|
|
3244 |
paper.view.draw();
|
|
|
3245 |
};
|
|
|
3246 |
|
|
|
3247 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event, _isTouch) {
|
|
|
3248 |
this.mouse_down = false;
|
|
|
3249 |
if (this.click_target) {
|
|
|
3250 |
var _off = this.canvas_$.offset();
|
|
|
3251 |
this.click_target.mouseup(
|
|
|
3252 |
{
|
|
|
3253 |
point: new paper.Point([
|
|
|
3254 |
_event.pageX - _off.left,
|
|
|
3255 |
_event.pageY - _off.top
|
|
|
3256 |
])
|
|
|
3257 |
},
|
|
|
3258 |
_isTouch
|
|
|
3259 |
);
|
|
|
3260 |
} else {
|
|
|
3261 |
this.click_target = null;
|
|
|
3262 |
this.is_dragging = false;
|
|
|
3263 |
if (_isTouch) {
|
|
|
3264 |
this.unselectAll();
|
|
|
3265 |
}
|
|
|
3266 |
}
|
|
|
3267 |
paper.view.draw();
|
|
|
3268 |
};
|
|
|
3269 |
|
|
|
3270 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) {
|
|
|
3271 |
this.totalScroll += _scrolldelta;
|
|
|
3272 |
if (Math.abs(this.totalScroll) >= 1) {
|
|
|
3273 |
var _off = this.canvas_$.offset(),
|
|
|
3274 |
_delta = new paper.Point([
|
|
|
3275 |
_event.pageX - _off.left,
|
|
|
3276 |
_event.pageY - _off.top
|
|
|
3277 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 );
|
|
|
3278 |
if (this.totalScroll > 0) {
|
|
|
3279 |
this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) );
|
|
|
3280 |
} else {
|
|
|
3281 |
this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2)));
|
|
|
3282 |
}
|
|
|
3283 |
this.totalScroll = 0;
|
|
|
3284 |
}
|
|
|
3285 |
};
|
|
|
3286 |
|
|
|
3287 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) {
|
|
|
3288 |
if (!this.isEditable()) {
|
|
|
3289 |
return;
|
|
|
3290 |
}
|
|
|
3291 |
var _off = this.canvas_$.offset(),
|
|
|
3292 |
_point = new paper.Point([
|
|
|
3293 |
_event.pageX - _off.left,
|
|
|
3294 |
_event.pageY - _off.top
|
|
|
3295 |
]);
|
|
|
3296 |
var _hitResult = paper.project.hitTest(_point);
|
|
|
3297 |
if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) {
|
|
|
3298 |
var _coords = this.toModelCoords(_point),
|
|
|
3299 |
_data = {
|
|
|
3300 |
id: Rkns.Utils.getUID('node'),
|
|
|
3301 |
created_by: this.renkan.current_user,
|
|
|
3302 |
position: {
|
|
|
3303 |
x: _coords.x,
|
|
|
3304 |
y: _coords.y
|
|
|
3305 |
}
|
|
|
3306 |
};
|
|
|
3307 |
_node = this.renkan.project.addNode(_data);
|
|
|
3308 |
this.getRepresentationByModel(_node).openEditor();
|
|
|
3309 |
}
|
|
|
3310 |
paper.view.draw();
|
|
|
3311 |
};
|
|
|
3312 |
|
|
|
3313 |
Rkns.Renderer.Scene.prototype.dropData = function(_data, _event) {
|
|
|
3314 |
if (!this.isEditable()) {
|
|
|
3315 |
return;
|
|
|
3316 |
}
|
|
|
3317 |
if (_data["text/json"] || _data["application/json"]) {
|
|
|
3318 |
try {
|
|
|
3319 |
var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]);
|
|
|
3320 |
_(_data).extend(jsondata);
|
|
|
3321 |
}
|
|
|
3322 |
catch(e) {}
|
|
|
3323 |
}
|
|
|
3324 |
var newNode = {};
|
|
|
3325 |
switch(_data["text/x-iri-specific-site"]) {
|
|
|
3326 |
case "twitter":
|
|
|
3327 |
var snippet = Rkns.$('<div>').html(_data["text/x-iri-selected-html"]),
|
|
|
3328 |
tweetdiv = snippet.find(".tweet");
|
|
|
3329 |
newNode.title = _renkan.translate("Tweet by ") + tweetdiv.attr("data-name");
|
|
|
3330 |
newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id");
|
|
|
3331 |
newNode.image = tweetdiv.find(".avatar").attr("src");
|
|
|
3332 |
newNode.description = tweetdiv.find(".js-tweet-text:first").text();
|
|
|
3333 |
break;
|
|
|
3334 |
case "google":
|
|
|
3335 |
var snippet = Rkns.$('<div>').html(_data["text/x-iri-selected-html"]);
|
|
|
3336 |
newNode.title = snippet.find("h3:first").text().trim();
|
|
|
3337 |
newNode.uri = snippet.find("h3 a").attr("href");
|
|
|
3338 |
newNode.description = snippet.find(".st:first").text().trim();
|
|
|
3339 |
break;
|
|
|
3340 |
case undefined:
|
|
|
3341 |
default:
|
|
|
3342 |
if (_data["text/x-iri-source-uri"]) {
|
|
|
3343 |
newNode.uri = _data["text/x-iri-source-uri"];
|
|
|
3344 |
}
|
|
|
3345 |
if (_data["text/plain"] || _data["text/x-iri-selected-text"]) {
|
|
|
3346 |
newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
|
|
|
3347 |
}
|
|
|
3348 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
|
|
|
3349 |
var snippet = Rkns.$('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
|
|
|
3350 |
var _svgimgs = snippet.find("image");
|
|
|
3351 |
if (_svgimgs.length) {
|
|
|
3352 |
newNode.image = _svgimgs.attr("xlink:href");
|
|
|
3353 |
}
|
|
|
3354 |
var _svgpaths = snippet.find("path");
|
|
|
3355 |
if (_svgpaths.length) {
|
|
|
3356 |
newNode.clipPath = _svgpaths.attr("d");
|
|
|
3357 |
}
|
|
|
3358 |
var _imgs = snippet.find("img");
|
|
|
3359 |
if (_imgs.length) {
|
|
|
3360 |
newNode.image = _imgs[0].src;
|
|
|
3361 |
}
|
|
|
3362 |
var _as = snippet.find("a");
|
|
|
3363 |
if (_as.length) {
|
|
|
3364 |
newNode.uri = _as[0].href;
|
|
|
3365 |
}
|
|
|
3366 |
newNode.title = snippet.find("[title]").attr("title") || newNode.title;
|
|
|
3367 |
newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
|
|
|
3368 |
}
|
|
|
3369 |
if (_data["text/uri-list"]) {
|
|
|
3370 |
newNode.uri = _data["text/uri-list"];
|
|
|
3371 |
}
|
|
|
3372 |
if (_data["text/x-moz-url"] && !newNode.title) {
|
|
|
3373 |
newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim();
|
|
|
3374 |
if (newNode.title === newNode.uri) {
|
|
|
3375 |
newNode.title = false;
|
|
|
3376 |
}
|
|
|
3377 |
}
|
|
|
3378 |
if (_data["text/x-iri-source-title"] && !newNode.title) {
|
|
|
3379 |
newNode.title = _data["text/x-iri-source-title"];
|
|
|
3380 |
}
|
|
|
3381 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
|
|
|
3382 |
newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image;
|
|
|
3383 |
newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri;
|
|
|
3384 |
newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title;
|
|
|
3385 |
newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
|
|
|
3386 |
newNode.description = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.description;
|
|
|
3387 |
}
|
|
|
3388 |
}
|
|
|
3389 |
if (!newNode.title) {
|
|
|
3390 |
newNode.title = this.renkan.translate("Dragged resource");
|
|
|
3391 |
}
|
|
|
3392 |
var fields = ["title", "description", "uri", "image"];
|
|
|
3393 |
for (var i = 0; i < fields.length; i++) {
|
|
|
3394 |
var f = fields[i];
|
|
|
3395 |
if (_data["text/x-iri-" + f] || _data[f]) {
|
|
|
3396 |
newNode[f] = _data["text/x-iri-" + f] || _data[f];
|
|
|
3397 |
}
|
|
|
3398 |
if (newNode[f] === "none" || newNode[f] === "null") {
|
|
|
3399 |
newNode[f] = undefined;
|
|
|
3400 |
}
|
|
|
3401 |
}
|
|
|
3402 |
var _off = this.canvas_$.offset(),
|
|
|
3403 |
_point = new paper.Point([
|
|
|
3404 |
_event.pageX - _off.left,
|
|
|
3405 |
_event.pageY - _off.top
|
|
|
3406 |
]),
|
|
|
3407 |
_coords = this.toModelCoords(_point),
|
|
|
3408 |
_nodedata = {
|
|
|
3409 |
id: Rkns.Utils.getUID('node'),
|
|
|
3410 |
created_by: this.renkan.current_user,
|
|
|
3411 |
uri: newNode.uri || "",
|
|
|
3412 |
title: newNode.title || "",
|
|
|
3413 |
description: newNode.description || "",
|
|
|
3414 |
image: newNode.image || "",
|
|
|
3415 |
color: newNode.color || undefined,
|
|
|
3416 |
"clip-path": newNode.clipPath || undefined,
|
|
|
3417 |
position: {
|
|
|
3418 |
x: _coords.x,
|
|
|
3419 |
y: _coords.y
|
|
|
3420 |
}
|
|
|
3421 |
};
|
|
|
3422 |
var _node = this.renkan.project.addNode(_nodedata),
|
|
|
3423 |
_repr = this.getRepresentationByModel(_node);
|
|
|
3424 |
if (_event.type === "drop") {
|
|
|
3425 |
_repr.openEditor();
|
|
|
3426 |
}
|
|
|
3427 |
};
|
|
|
3428 |
|
|
|
3429 |
/* *********************************************************
|
|
|
3430 |
end of paper-renderer.js
|
|
|
3431 |
************************************************************
|
|
|
3432 |
************************************************************
|
|
|
3433 |
start of full-json.js
|
|
|
3434 |
********************************************************* */
|
|
|
3435 |
|
|
|
3436 |
/* Saves the Full JSON at each modification */
|
|
|
3437 |
|
|
|
3438 |
Rkns.jsonIO = function(_renkan, _opts) {
|
|
|
3439 |
var _proj = _renkan.project;
|
|
|
3440 |
if (typeof _opts.http_method == "undefined") {
|
|
|
3441 |
_opts.http_method = 'PUT';
|
|
|
3442 |
}
|
|
|
3443 |
var _load = function() {
|
|
|
3444 |
Rkns.$.getJSON(_opts.url, function(_data) {
|
|
|
3445 |
_proj.set(_data, {validate: true});
|
|
|
3446 |
_renkan.renderer.autoScale();
|
|
|
3447 |
});
|
|
|
3448 |
};
|
|
|
3449 |
var _save = function() {
|
|
|
3450 |
var _data = _proj.toJSON();
|
|
|
3451 |
if (!_renkan.read_only) {
|
|
|
3452 |
Rkns.$.ajax({
|
|
|
3453 |
type: _opts.http_method,
|
|
|
3454 |
url: _opts.url,
|
|
|
3455 |
contentType: "application/json",
|
|
|
3456 |
data: JSON.stringify(_data),
|
|
|
3457 |
success: function(data, textStatus, jqXHR) {
|
|
|
3458 |
}
|
|
|
3459 |
});
|
|
|
3460 |
}
|
|
|
3461 |
|
|
|
3462 |
};
|
|
|
3463 |
var _thrSave = Rkns._.throttle(
|
|
|
3464 |
function() {
|
|
|
3465 |
setTimeout(_save, 100);
|
|
|
3466 |
}, 1000);
|
|
|
3467 |
_proj.on("add:nodes add:edges add:users", function(_model) {
|
|
|
3468 |
_model.on("change remove", function(_model) {
|
|
|
3469 |
_thrSave();
|
|
|
3470 |
});
|
|
|
3471 |
_thrSave();
|
|
|
3472 |
});
|
|
|
3473 |
_proj.on("change", function() {
|
|
|
3474 |
_thrSave();
|
|
|
3475 |
});
|
|
|
3476 |
|
|
|
3477 |
_load();
|
|
|
3478 |
};
|
|
|
3479 |
|
|
|
3480 |
/* *********************************************************
|
|
|
3481 |
end of full-json.js
|
|
|
3482 |
************************************************************
|
|
|
3483 |
*/
|