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