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