| author | ymh <ymh.work@gmail.com> |
| Sat, 25 Apr 2015 04:13:53 +0200 | |
| changeset 433 | e457ec945e50 |
| parent 430 | d3ae63bc18c6 |
| child 444 | 19f0b7803aed |
| child 447 | e246651b6626 |
| permissions | -rw-r--r-- |
| 1 | 1 |
|
| 5 | 2 |
/* Declaring the Renkan Namespace Rkns and Default values */ |
| 1 | 3 |
|
| 195 | 4 |
(function(root) { |
5 |
||
6 |
"use strict"; |
|
7 |
||
8 |
if (typeof root.Rkns !== "object") { |
|
9 |
root.Rkns = {}; |
|
| 3 | 10 |
} |
| 1 | 11 |
|
| 195 | 12 |
var Rkns = root.Rkns; |
13 |
var $ = Rkns.$ = root.jQuery; |
|
14 |
var _ = Rkns._ = root._; |
|
| 1 | 15 |
|
| 69 | 16 |
Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", |
17 |
"#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", |
|
18 |
"#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", |
|
19 |
"#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", |
|
20 |
"#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", |
|
21 |
"#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", |
|
22 |
"#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", |
|
23 |
"#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"]; |
|
| 52 | 24 |
|
| 195 | 25 |
Rkns.__renkans = []; |
26 |
||
27 |
var _BaseBin = Rkns._BaseBin = function(_renkan, _opts) { |
|
| 21 | 28 |
if (typeof _renkan !== "undefined") { |
29 |
this.renkan = _renkan; |
|
30 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
31 |
this.$ = Rkns.$('<li>') |
|
32 |
.addClass("Rk-Bin") |
|
33 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
| 34 | 34 |
this.title_icon_$ = Rkns.$('<span>') |
35 |
.addClass("Rk-Bin-Title-Icon") |
|
36 |
.appendTo(this.$); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
37 |
|
| 34 | 38 |
var _this = this; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
39 |
|
| 42 | 40 |
Rkns.$('<a>') |
| 119 | 41 |
.attr({ |
| 160 | 42 |
href: "#", |
43 |
title: _renkan.translate("Close bin") |
|
44 |
}) |
|
| 34 | 45 |
.addClass("Rk-Bin-Close") |
46 |
.html('×') |
|
47 |
.appendTo(this.$) |
|
48 |
.click(function() { |
|
49 |
_this.destroy(); |
|
| 119 | 50 |
if (!_renkan.$.find(".Rk-Bin-Main:visible").length) { |
| 160 | 51 |
_renkan.$.find(".Rk-Bin-Main:last").slideDown(); |
| 119 | 52 |
} |
53 |
_renkan.resizeBins(); |
|
| 42 | 54 |
return false; |
55 |
}); |
|
56 |
Rkns.$('<a>') |
|
| 119 | 57 |
.attr({ |
| 160 | 58 |
href: "#", |
59 |
title: _renkan.translate("Refresh bin") |
|
60 |
}) |
|
| 42 | 61 |
.addClass("Rk-Bin-Refresh") |
62 |
.appendTo(this.$) |
|
63 |
.click(function() { |
|
64 |
_this.refresh(); |
|
65 |
return false; |
|
| 34 | 66 |
}); |
| 44 | 67 |
this.count_$ = Rkns.$('<div>') |
68 |
.addClass("Rk-Bin-Count") |
|
69 |
.appendTo(this.$); |
|
| 21 | 70 |
this.title_$ = Rkns.$('<h2>') |
71 |
.addClass("Rk-Bin-Title") |
|
72 |
.appendTo(this.$); |
|
73 |
this.main_$ = Rkns.$('<div>') |
|
74 |
.addClass("Rk-Bin-Main") |
|
| 64 | 75 |
.appendTo(this.$) |
| 66 | 76 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>'); |
| 26 | 77 |
this.title_$.html(_opts.title || '(new bin)'); |
| 21 | 78 |
this.renkan.resizeBins(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
79 |
|
| 42 | 80 |
if (_opts.auto_refresh) { |
81 |
window.setInterval(function() { |
|
82 |
_this.refresh(); |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
83 |
},_opts.auto_refresh); |
| 42 | 84 |
} |
| 20 | 85 |
} |
| 163 | 86 |
}; |
| 34 | 87 |
|
| 195 | 88 |
_BaseBin.prototype.destroy = function() { |
| 34 | 89 |
this.$.detach(); |
90 |
this.renkan.resizeBins(); |
|
| 163 | 91 |
}; |
| 34 | 92 |
|
| 20 | 93 |
/* Point of entry */ |
94 |
||
| 195 | 95 |
var Renkan = Rkns.Renkan = function(_opts) { |
| 68 | 96 |
var _this = this; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
97 |
|
| 195 | 98 |
Rkns.__renkans.push(this); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
99 |
|
| 418 | 100 |
this.options = _.defaults(_opts, Rkns.defaults, {templates: renkanJST}); |
|
426
05ed0d95a511
split templates in main, list-bin and wikipedia-bin
rougeronj
parents:
418
diff
changeset
|
101 |
this.template = renkanJST['templates/main.html']; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
102 |
|
| 433 | 103 |
_.each(this.options.property_files,function(f) { |
| 160 | 104 |
Rkns.$.getJSON(f, function(data) { |
105 |
_this.options.properties = _this.options.properties.concat(data); |
|
106 |
}); |
|
107 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
108 |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
109 |
this.read_only = this.options.read_only || !this.options.editor_mode; |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
110 |
|
| 23 | 111 |
this.project = new Rkns.Models.Project(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
112 |
|
|
383
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
113 |
this.setCurrentUser = function (user_id, user_name) { |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
114 |
this.project.addUser({ |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
115 |
_id:user_id, |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
116 |
title: user_name |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
117 |
}); |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
118 |
this.current_user = user_id; |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
119 |
this.renderer.redrawUsers(); |
|
ba1f278841a2
close 55 - add function to set current user when someone log In
rougeronj
parents:
377
diff
changeset
|
120 |
}; |
| 433 | 121 |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
122 |
if (typeof this.options.user_id !== "undefined") { |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
123 |
this.current_user = this.options.user_id; |
| 4 | 124 |
} |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
125 |
this.$ = Rkns.$("#" + this.options.container); |
| 34 | 126 |
this.$ |
127 |
.addClass("Rk-Main") |
|
| 68 | 128 |
.html(this.template(this)); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
129 |
|
| 21 | 130 |
this.tabs = []; |
| 34 | 131 |
this.search_engines = []; |
| 56 | 132 |
|
133 |
this.current_user_list = new Rkns.Models.UsersList(); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
134 |
|
| 195 | 135 |
this.current_user_list.on("add remove", function() { |
136 |
if (this.renderer) { |
|
137 |
this.renderer.redrawUsers(); |
|
138 |
} |
|
139 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
140 |
|
| 195 | 141 |
this.colorPicker = (function() { |
|
430
d3ae63bc18c6
split the 'colorpicker' template and the 'search' template (list of possible kind of search in the bins) into separate html
rougeronj
parents:
426
diff
changeset
|
142 |
var _tmpl = renkanJST['templates/colorpicker.html']; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
143 |
return '<ul class="Rk-Edit-ColorPicker">' + Rkns.pickerColors.map(function(c) { return _tmpl({c:c});}).join("") + '</ul>'; |
| 195 | 144 |
})(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
145 |
|
| 195 | 146 |
if (this.options.show_editor) { |
147 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
148 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
149 |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
150 |
if (!this.options.search.length) { |
| 44 | 151 |
this.$.find(".Rk-Web-Search-Form").detach(); |
| 21 | 152 |
} else { |
|
430
d3ae63bc18c6
split the 'colorpicker' template and the 'search' template (list of possible kind of search in the bins) into separate html
rougeronj
parents:
426
diff
changeset
|
153 |
var _tmpl = renkanJST['templates/search.html'], |
| 34 | 154 |
_select = this.$.find(".Rk-Search-List"), |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
155 |
_input = this.$.find(".Rk-Web-Search-Input"), |
| 44 | 156 |
_form = this.$.find(".Rk-Web-Search-Form"); |
| 433 | 157 |
_.each(this.options.search, function(_search, _key) { |
| 160 | 158 |
if (Rkns[_search.type] && Rkns[_search.type].Search) { |
159 |
_this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
|
160 |
} |
|
| 34 | 161 |
}); |
| 24 | 162 |
_select.html( |
| 196 | 163 |
_(this.search_engines).map(function(_search, _key) { |
| 24 | 164 |
return _tmpl({ |
165 |
key: _key, |
|
| 34 | 166 |
title: _search.getSearchTitle(), |
167 |
className: _search.getBgClass() |
|
| 24 | 168 |
}); |
| 21 | 169 |
}).join("") |
| 34 | 170 |
); |
171 |
_select.find("li").click(function() { |
|
172 |
var _el = Rkns.$(this); |
|
173 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 174 |
_form.submit(); |
175 |
}); |
|
176 |
_form.submit(function() { |
|
177 |
if (_input.val()) { |
|
| 34 | 178 |
var _search = _this.search_engine; |
179 |
_search.search(_input.val()); |
|
| 24 | 180 |
} |
181 |
return false; |
|
182 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
183 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
184 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
185 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
186 |
this.$.find(".Rk-Search-Select").mouseleave( |
| 70 | 187 |
function() { _select.hide(); } |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
188 |
); |
| 34 | 189 |
this.setSearchEngine(0); |
| 21 | 190 |
} |
| 433 | 191 |
_.each(this.options.bins, function(_bin) { |
| 160 | 192 |
if (Rkns[_bin.type] && Rkns[_bin.type].Bin) { |
193 |
_this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin)); |
|
194 |
} |
|
| 42 | 195 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
196 |
|
| 155 | 197 |
var elementDropped = false; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
198 |
|
| 21 | 199 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
200 |
.on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
201 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
202 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
203 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
204 |
_mainDiv.slideDown(); |
| 21 | 205 |
} |
| 188 | 206 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
207 |
|
| 188 | 208 |
if (this.options.show_editor) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
209 |
|
| 188 | 210 |
this.$.find(".Rk-Bins").on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
211 |
var _t = Rkns.$(this); |
| 26 | 212 |
if (_t && $(_t).attr("data-uri")) { |
213 |
var _models = _this.project.get("nodes").where({ |
|
214 |
uri: $(_t).attr("data-uri") |
|
215 |
}); |
|
| 433 | 216 |
_.each(_models, function(_model) { |
| 26 | 217 |
_this.renderer.highlightModel(_model); |
218 |
}); |
|
219 |
} |
|
220 |
}).mouseout(function() { |
|
221 |
_this.renderer.unhighlightAll(); |
|
| 113 | 222 |
}).on("mousemove", ".Rk-Bin-Item", function(e) { |
| 160 | 223 |
try { |
224 |
this.dragDrop(); |
|
225 |
} |
|
226 |
catch(err) {} |
|
| 155 | 227 |
}).on("touchstart", ".Rk-Bin-Item", function(e) { |
| 160 | 228 |
elementDropped = false; |
| 155 | 229 |
}).on("touchmove", ".Rk-Bin-Item", function(e) { |
| 160 | 230 |
e.preventDefault(); |
231 |
var touch = e.originalEvent.changedTouches[0], |
|
232 |
off = _this.renderer.canvas_$.offset(), |
|
233 |
w = _this.renderer.canvas_$.width(), |
|
234 |
h = _this.renderer.canvas_$.height(); |
|
235 |
if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) { |
|
236 |
if (elementDropped) { |
|
237 |
_this.renderer.onMouseMove(touch, true); |
|
238 |
} else { |
|
239 |
elementDropped = true; |
|
240 |
var div = document.createElement('div'); |
|
241 |
div.appendChild(this.cloneNode(true)); |
|
242 |
_this.renderer.dropData({"text/html": div.innerHTML}, touch); |
|
243 |
_this.renderer.onMouseDown(touch, true); |
|
244 |
} |
|
245 |
} |
|
| 155 | 246 |
}).on("touchend", ".Rk-Bin-Item", function(e) { |
| 160 | 247 |
if (elementDropped) { |
248 |
_this.renderer.onMouseUp(e.originalEvent.changedTouches[0], true); |
|
249 |
} |
|
250 |
elementDropped = false; |
|
| 68 | 251 |
}).on("dragstart", ".Rk-Bin-Item", function(e) { |
| 160 | 252 |
var div = document.createElement('div'); |
253 |
div.appendChild(this.cloneNode(true)); |
|
254 |
try { |
|
255 |
e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
|
256 |
} |
|
257 |
catch(err) { |
|
258 |
e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
|
259 |
} |
|
| 20 | 260 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
261 |
|
| 188 | 262 |
} |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
263 |
|
| 21 | 264 |
Rkns.$(window).resize(function() { |
265 |
_this.resizeBins(); |
|
| 2 | 266 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
267 |
|
| 196 | 268 |
var lastsearch = false, lastval = ''; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
269 |
|
| 44 | 270 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
| 196 | 271 |
var val = Rkns.$(this).val(); |
272 |
if (val === lastval) { |
|
273 |
return; |
|
274 |
} |
|
275 |
var search = Rkns.Utils.regexpFromTextOrArray(val.length > 1 ? val: null); |
|
276 |
if (search.source === lastsearch) { |
|
277 |
return; |
|
278 |
} |
|
279 |
lastsearch = search.source; |
|
| 433 | 280 |
_.each(_this.tabs, function(tab) { |
| 196 | 281 |
tab.render(search); |
282 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
283 |
|
| 44 | 284 |
}); |
285 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
286 |
return false; |
| 44 | 287 |
}); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
288 |
|
| 163 | 289 |
}; |
| 1 | 290 |
|
| 195 | 291 |
Renkan.prototype.translate = function(_text) { |
| 160 | 292 |
if (Rkns.i18n[this.options.language] && Rkns.i18n[this.options.language][_text]) { |
293 |
return Rkns.i18n[this.options.language][_text]; |
|
294 |
} |
|
295 |
if (this.options.language.length > 2 && Rkns.i18n[this.options.language.substr(0,2)] && Rkns.i18n[this.options.language.substr(0,2)][_text]) { |
|
296 |
return Rkns.i18n[this.options.language.substr(0,2)][_text]; |
|
297 |
} |
|
298 |
return _text; |
|
| 163 | 299 |
}; |
| 159 | 300 |
|
| 195 | 301 |
Renkan.prototype.onStatusChange = function() { |
| 160 | 302 |
this.renderer.onStatusChange(); |
| 163 | 303 |
}; |
| 111 | 304 |
|
| 195 | 305 |
Renkan.prototype.setSearchEngine = function(_key) { |
| 34 | 306 |
this.search_engine = this.search_engines[_key]; |
307 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
| 374 | 308 |
var listClasses = this.search_engine.getBgClass().split(" "); |
309 |
var classes = ""; |
|
310 |
for (var i= 0; i < listClasses.length; i++) { |
|
311 |
classes += "." + listClasses[i]; |
|
312 |
} |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
374
diff
changeset
|
313 |
this.$.find(".Rk-Web-Search-Input.Rk-Search-Input").attr("placeholder", this.translate("Search in ") + this.$.find(".Rk-Search-List "+ classes).html()); |
| 163 | 314 |
}; |
| 34 | 315 |
|
| 195 | 316 |
Renkan.prototype.resizeBins = function() { |
| 75 | 317 |
var _d = + this.$.find(".Rk-Bins-Head").outerHeight(); |
| 44 | 318 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
| 26 | 319 |
_d += Rkns.$(this).outerHeight(); |
320 |
}); |
|
| 21 | 321 |
this.$.find(".Rk-Bin-Main").css({ |
322 |
height: this.$.find(".Rk-Bins").height() - _d |
|
323 |
}); |
|
| 163 | 324 |
}; |
| 21 | 325 |
|
| 1 | 326 |
/* Utility functions */ |
| 298 | 327 |
var getUUID4 = function() { |
328 |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
|
329 |
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8); |
|
330 |
return v.toString(16); |
|
331 |
}); |
|
332 |
}; |
|
| 1 | 333 |
|
334 |
Rkns.Utils = { |
|
| 298 | 335 |
getUUID4 : getUUID4, |
| 196 | 336 |
getUID : (function() { |
337 |
function pad(n){ |
|
338 |
return n<10 ? '0'+n : n; |
|
339 |
} |
|
340 |
var _d = new Date(), |
|
341 |
ID_AUTO_INCREMENT = 0, |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
342 |
ID_BASE = _d.getUTCFullYear() + '-' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
343 |
pad(_d.getUTCMonth()+1) + '-' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
344 |
pad(_d.getUTCDate()) + '-' + |
| 298 | 345 |
getUUID4(); |
| 196 | 346 |
return function(_base) { |
347 |
var _n = (++ID_AUTO_INCREMENT).toString(16), |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
348 |
_uidbase = (typeof _base === "undefined" ? "" : _base + "-" ); |
| 196 | 349 |
while (_n.length < 4) { _n = '0' + _n; } |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
350 |
return _uidbase + ID_BASE + '-' + _n; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
351 |
}; |
| 196 | 352 |
})(), |
| 132 | 353 |
getFullURL : function(url) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
354 |
|
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
355 |
if(typeof(url) === 'undefined' || url == null ) { |
| 160 | 356 |
return ""; |
357 |
} |
|
358 |
if(/https?:\/\//.test(url)) { |
|
359 |
return url; |
|
360 |
} |
|
361 |
var img = new Image(); |
|
362 |
img.src = url; |
|
363 |
var res = img.src; |
|
364 |
img.src = null; |
|
365 |
return res; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
366 |
|
| 132 | 367 |
}, |
| 1 | 368 |
inherit : function(_baseClass, _callbefore) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
369 |
|
| 163 | 370 |
var _class = function(_arg) { |
| 1 | 371 |
if (typeof _callbefore === "function") { |
372 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
373 |
} |
|
| 28 | 374 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
375 |
if (typeof this._init === "function" && !this._initialized) { |
| 28 | 376 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
| 163 | 377 |
this._initialized = true; |
| 1 | 378 |
} |
|
170
603ffa4c6fa5
correct ";" and "," in javascripts
ymh <ymh.work@gmail.com>
parents:
169
diff
changeset
|
379 |
}; |
| 433 | 380 |
_.extend(_class.prototype,_baseClass.prototype); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
381 |
|
| 1 | 382 |
return _class; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
383 |
|
| 196 | 384 |
}, |
385 |
regexpFromTextOrArray: (function() { |
|
386 |
var charsub = [ |
|
387 |
'[aáàâä]', |
|
388 |
'[cç]', |
|
389 |
'[eéèêë]', |
|
390 |
'[iíìîï]', |
|
391 |
'[oóòôö]', |
|
392 |
'[uùûü]' |
|
393 |
], |
|
394 |
removeChars = [ |
|
395 |
String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), |
|
396 |
"{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", |
|
397 |
",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" |
|
398 |
], |
|
399 |
remsrc = "[\\" + removeChars.join("\\") + "]", |
|
400 |
remrx = new RegExp(remsrc, "gm"), |
|
| 433 | 401 |
charsrx = _.map(charsub, function(c) { |
| 196 | 402 |
return new RegExp(c); |
403 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
404 |
|
| 196 | 405 |
function replaceText(_text) { |
406 |
var txt = _text.toLowerCase().replace(remrx,""), src = ""; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
407 |
function makeReplaceFunc(l) { |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
408 |
return function(k,v) { |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
409 |
l = l.replace(charsrx[k], v); |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
410 |
}; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
411 |
} |
| 196 | 412 |
for (var j = 0; j < txt.length; j++) { |
413 |
if (j) { |
|
414 |
src += remsrc + "*"; |
|
415 |
} |
|
416 |
var l = txt[j]; |
|
| 433 | 417 |
_.each(charsub, makeReplaceFunc(l)); |
| 196 | 418 |
src += l; |
419 |
} |
|
420 |
return src; |
|
421 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
422 |
|
| 196 | 423 |
function getSource(inp) { |
424 |
switch (typeof inp) { |
|
425 |
case "string": |
|
426 |
return replaceText(inp); |
|
427 |
case "object": |
|
428 |
var src = ''; |
|
| 433 | 429 |
_.each(inp, function(v) { |
| 196 | 430 |
var res = getSource(v); |
431 |
if (res) { |
|
432 |
if (src) { |
|
433 |
src += '|'; |
|
434 |
} |
|
435 |
src += res; |
|
436 |
} |
|
437 |
}); |
|
438 |
return src; |
|
439 |
} |
|
440 |
return ''; |
|
441 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
442 |
|
| 196 | 443 |
return function(_textOrArray) { |
444 |
var source = getSource(_textOrArray); |
|
445 |
if (source) { |
|
446 |
var testrx = new RegExp( source, "im"), |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
447 |
replacerx = new RegExp( '(' + source + ')', "igm"); |
| 196 | 448 |
return { |
449 |
isempty: false, |
|
450 |
source: source, |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
451 |
test: function(_t) { return testrx.test(_t); }, |
| 196 | 452 |
replace: function(_text, _replace) { return _text.replace(replacerx, _replace); } |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
453 |
}; |
| 196 | 454 |
} else { |
455 |
return { |
|
456 |
isempty: true, |
|
457 |
source: '', |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
458 |
test: function() { return true; }, |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
459 |
replace: function(_text) { return text; } |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
460 |
}; |
| 196 | 461 |
} |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
462 |
}; |
| 284 | 463 |
})(), |
464 |
/* The minimum distance (in pixels) the mouse has to move to consider an element was dragged */ |
|
465 |
_MIN_DRAG_DISTANCE: 2, |
|
466 |
/* Distance between the inner and outer radius of buttons that appear when hovering on a node */ |
|
467 |
_NODE_BUTTON_WIDTH: 40, |
|
468 |
||
469 |
_EDGE_BUTTON_INNER: 2, |
|
470 |
_EDGE_BUTTON_OUTER: 40, |
|
471 |
/* Constants used to know if a specific action is to be performed when clicking on the canvas */ |
|
472 |
_CLICKMODE_ADDNODE: 1, |
|
473 |
_CLICKMODE_STARTEDGE: 2, |
|
474 |
_CLICKMODE_ENDEDGE: 3, |
|
475 |
/* Node size step: Used to calculate the size change when clicking the +/- buttons */ |
|
476 |
_NODE_SIZE_STEP: Math.LN2/4, |
|
477 |
_MIN_SCALE: 1/20, |
|
478 |
_MAX_SCALE: 20, |
|
479 |
_MOUSEMOVE_RATE: 80, |
|
480 |
_DOUBLETAP_DELAY: 800, |
|
481 |
/* Maximum distance in pixels (squared, to reduce calculations) |
|
482 |
* between two taps when double-tapping on a touch terminal */ |
|
483 |
_DOUBLETAP_DISTANCE: 20*20, |
|
484 |
/* A placeholder so a default colour is displayed when a node has a null value for its user property */ |
|
485 |
_USER_PLACEHOLDER: function(_renkan) { |
|
486 |
return { |
|
487 |
color: _renkan.options.default_user_color, |
|
488 |
title: _renkan.translate("(unknown user)"), |
|
489 |
get: function(attr) { |
|
490 |
return this[attr] || false; |
|
491 |
} |
|
492 |
}; |
|
493 |
}, |
|
494 |
/* The code for the "Drag and Add Bookmarklet", slightly minified and with whitespaces removed, though |
|
495 |
* it doesn't seem that it's still a requirement in newer browsers (i.e. the ones compatibles with canvas drawing) |
|
496 |
*/ |
|
497 |
_BOOKMARKLET_CODE: function(_renkan) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
498 |
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;\">" + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
499 |
_renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
500 |
"</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);})();"; |
| 284 | 501 |
}, |
502 |
/* Shortens text to the required length then adds ellipsis */ |
|
503 |
shortenText: function(_text, _maxlength) { |
|
504 |
return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
|
505 |
}, |
|
506 |
/* Drawing an edit box with an arrow and positioning the edit box according to the position of the node/edge being edited |
|
507 |
* Called by Rkns.Renderer.NodeEditor and Rkns.Renderer.EdgeEditor */ |
|
508 |
drawEditBox: function(_options, _coords, _path, _xmargin, _selector) { |
|
509 |
_selector.css({ |
|
510 |
width: ( _options.tooltip_width - 2* _options.tooltip_padding ) |
|
511 |
}); |
|
512 |
var _height = _selector.outerHeight() + 2* _options.tooltip_padding, |
|
513 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
514 |
_left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ), |
|
515 |
_right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ), |
|
516 |
_top = _coords.y - _height / 2; |
|
517 |
if (_top + _height > (paper.view.size.height - _options.tooltip_margin)) { |
|
518 |
_top = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 ) - _height; |
|
519 |
} |
|
520 |
if (_top < _options.tooltip_margin) { |
|
521 |
_top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 ); |
|
522 |
} |
|
523 |
var _bottom = _top + _height; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
524 |
/* jshint laxbreak:true */ |
| 284 | 525 |
_path.segments[0].point |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
526 |
= _path.segments[7].point |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
527 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 284 | 528 |
_path.segments[1].point.x |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
529 |
= _path.segments[2].point.x |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
530 |
= _path.segments[5].point.x |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
531 |
= _path.segments[6].point.x |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
532 |
= _left; |
| 284 | 533 |
_path.segments[3].point.x |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
534 |
= _path.segments[4].point.x |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
535 |
= _right; |
| 284 | 536 |
_path.segments[2].point.y |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
537 |
= _path.segments[3].point.y |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
538 |
= _top; |
| 284 | 539 |
_path.segments[4].point.y |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
540 |
= _path.segments[5].point.y |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
290
diff
changeset
|
541 |
= _bottom; |
| 284 | 542 |
_path.segments[1].point.y = _coords.y - _options.tooltip_arrow_width / 2; |
543 |
_path.segments[6].point.y = _coords.y + _options.tooltip_arrow_width / 2; |
|
544 |
_path.closed = true; |
|
545 |
_path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]); |
|
546 |
_selector.css({ |
|
547 |
left: (_options.tooltip_padding + Math.min(_left, _right)), |
|
548 |
top: (_options.tooltip_padding + _top) |
|
549 |
}); |
|
550 |
return _path; |
|
551 |
} |
|
| 163 | 552 |
}; |
| 195 | 553 |
})(window); |
| 188 | 554 |
|
555 |
/* END main.js */ |