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