| author | veltr |
| Tue, 26 Feb 2013 17:04:24 +0100 | |
| changeset 66 | 9b459e41e2df |
| parent 64 | 3a5a9421687b |
| child 68 | 803dbeb7c919 |
| permissions | -rw-r--r-- |
| 1 | 1 |
/* |
2 |
* Copyright 2012 Institut de recherche et d'innovation |
|
| 28 | 3 |
* contributor(s) : Yves-Marie Haussonne, Raphael Velt, Samuel Huron |
| 1 | 4 |
* |
5 |
* contact@iri.centrepompidou.fr |
|
6 |
* http://www.iri.centrepompidou.fr |
|
7 |
* |
|
8 |
* This software is a computer program whose purpose is to show and add annotations on a video . |
|
9 |
* This software is governed by the CeCILL-C license under French law and |
|
10 |
* abiding by the rules of distribution of free software. You can use, |
|
11 |
* modify and/ or redistribute the software under the terms of the CeCILL-C |
|
12 |
* license as circulated by CEA, CNRS and INRIA at the following URL |
|
13 |
* "http://www.cecill.info". |
|
14 |
* |
|
15 |
* The fact that you are presently reading this means that you have had |
|
16 |
* knowledge of the CeCILL-C license and that you accept its terms. |
|
17 |
*/ |
|
18 |
||
| 5 | 19 |
/* Declaring the Renkan Namespace Rkns and Default values */ |
| 1 | 20 |
|
| 28 | 21 |
if (typeof Rkns !== "object") { |
22 |
Rkns = {} |
|
| 3 | 23 |
} |
| 1 | 24 |
|
25 |
Rkns.$ = jQuery; |
|
26 |
||
27 |
Rkns._ = _; |
|
28 |
||
| 53 | 29 |
Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", "#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", "#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", "#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", "#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", "#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", "#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", "#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"]; |
| 52 | 30 |
|
| 34 | 31 |
Rkns._BaseBin = function(_renkan, _opts) { |
| 21 | 32 |
if (typeof _renkan !== "undefined") { |
33 |
this.renkan = _renkan; |
|
34 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
35 |
this.$ = Rkns.$('<li>') |
|
36 |
.addClass("Rk-Bin") |
|
37 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
| 34 | 38 |
this.title_icon_$ = Rkns.$('<span>') |
39 |
.addClass("Rk-Bin-Title-Icon") |
|
40 |
.appendTo(this.$); |
|
| 42 | 41 |
|
| 34 | 42 |
var _this = this; |
| 42 | 43 |
|
44 |
Rkns.$('<a>') |
|
45 |
.attr("href","#") |
|
| 34 | 46 |
.addClass("Rk-Bin-Close") |
47 |
.html('×') |
|
48 |
.appendTo(this.$) |
|
49 |
.click(function() { |
|
50 |
_this.destroy(); |
|
| 42 | 51 |
return false; |
52 |
}); |
|
53 |
Rkns.$('<a>') |
|
54 |
.attr("href","#") |
|
55 |
.addClass("Rk-Bin-Refresh") |
|
56 |
.appendTo(this.$) |
|
57 |
.click(function() { |
|
58 |
_this.refresh(); |
|
59 |
return false; |
|
| 34 | 60 |
}); |
| 44 | 61 |
this.count_$ = Rkns.$('<div>') |
62 |
.addClass("Rk-Bin-Count") |
|
63 |
.appendTo(this.$); |
|
| 21 | 64 |
this.title_$ = Rkns.$('<h2>') |
65 |
.addClass("Rk-Bin-Title") |
|
66 |
.appendTo(this.$); |
|
67 |
this.main_$ = Rkns.$('<div>') |
|
68 |
.addClass("Rk-Bin-Main") |
|
| 64 | 69 |
.appendTo(this.$) |
| 66 | 70 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>'); |
| 26 | 71 |
this.title_$.html(_opts.title || '(new bin)'); |
| 21 | 72 |
this.renkan.resizeBins(); |
| 42 | 73 |
|
74 |
if (_opts.auto_refresh) { |
|
75 |
window.setInterval(function() { |
|
76 |
_this.refresh(); |
|
77 |
},_opts.auto_refresh) |
|
78 |
} |
|
| 20 | 79 |
} |
80 |
} |
|
| 34 | 81 |
|
82 |
Rkns._BaseBin.prototype.destroy = function() { |
|
83 |
this.$.detach(); |
|
84 |
this.renkan.resizeBins(); |
|
85 |
} |
|
86 |
||
| 20 | 87 |
/* Point of entry */ |
88 |
||
89 |
Rkns.Renkan = function(_opts) { |
|
| 21 | 90 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
| 5 | 91 |
_opts.language = "en"; |
92 |
} |
|
| 21 | 93 |
if (typeof _opts.container !== "string") { |
| 20 | 94 |
_opts.container = "renkan"; |
95 |
} |
|
| 21 | 96 |
if (typeof _opts.search !== "object" || !_opts.search) { |
97 |
_opts.search = []; |
|
98 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
99 |
if (typeof _opts.bins !== "object" || !_opts.bins) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
100 |
_opts.bins = []; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
101 |
} |
| 56 | 102 |
if (typeof _opts.static_url !== "string") { |
103 |
_opts.static_url = ""; |
|
104 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
105 |
if (typeof _opts.show_bins !== "boolean") { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
106 |
_opts.show_bins = !!_opts.search.length || !!_opts.bins.length; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
107 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
108 |
if (typeof _opts.read_only !== "boolean") { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
109 |
_opts.read_only = false; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
110 |
} |
| 23 | 111 |
this.project = new Rkns.Models.Project(); |
| 34 | 112 |
this.language = _opts.language; |
| 56 | 113 |
this.static_url = _opts.static_url; |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
114 |
this.read_only = _opts.read_only; |
| 66 | 115 |
this.translate = function(_text) { |
116 |
return (Rkns.i18n[_opts.language] || Rkns.i18n[_opts.language.substr(0,2)] || {})[_text] || _text; |
|
117 |
} |
|
| 23 | 118 |
if (typeof _opts.user_id !== "undefined") { |
119 |
this.current_user = _opts.user_id; |
|
| 4 | 120 |
} |
| 21 | 121 |
this.$ = Rkns.$("#" + _opts.container); |
| 34 | 122 |
this.$ |
123 |
.addClass("Rk-Main") |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
124 |
.html(this.template(_opts)); |
| 23 | 125 |
this.renderer = new Rkns.Renderer.Scene(this); |
| 21 | 126 |
this.tabs = []; |
| 34 | 127 |
this.search_engines = []; |
| 21 | 128 |
this.selected_bin_item = undefined; |
| 56 | 129 |
|
130 |
this.current_user_list = new Rkns.Models.UsersList(); |
|
131 |
|
|
| 1 | 132 |
var _this = this; |
| 21 | 133 |
this.$.mouseup(function() { |
134 |
_this.selected_bin_item = undefined; |
|
| 26 | 135 |
_this.$.find(".Rk-Bin-Item.dragging").removeClass("dragging"); |
| 21 | 136 |
}); |
137 |
if (!_opts.search.length) { |
|
| 44 | 138 |
this.$.find(".Rk-Web-Search-Form").detach(); |
| 21 | 139 |
} else { |
| 34 | 140 |
var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
141 |
_select = this.$.find(".Rk-Search-List"), |
|
| 44 | 142 |
_input = this.$.find(".Rk-Web-Search-Input") |
143 |
_form = this.$.find(".Rk-Web-Search-Form"); |
|
| 34 | 144 |
Rkns._(_opts.search).each(function(_search, _key) { |
145 |
var _searchObj = new _search.type(_this, _search); |
|
146 |
_this.search_engines.push(_searchObj); |
|
147 |
}); |
|
| 24 | 148 |
_select.html( |
| 34 | 149 |
Rkns._(this.search_engines).map(function(_search, _key) { |
| 24 | 150 |
return _tmpl({ |
151 |
key: _key, |
|
| 34 | 152 |
title: _search.getSearchTitle(), |
153 |
className: _search.getBgClass() |
|
| 24 | 154 |
}); |
| 21 | 155 |
}).join("") |
| 34 | 156 |
); |
157 |
_select.find("li").click(function() { |
|
158 |
var _el = Rkns.$(this); |
|
159 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 160 |
_form.submit(); |
161 |
}); |
|
162 |
_form.submit(function() { |
|
163 |
if (_input.val()) { |
|
| 34 | 164 |
var _search = _this.search_engine; |
165 |
_search.search(_input.val()); |
|
| 24 | 166 |
} |
167 |
return false; |
|
168 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
169 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
170 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
171 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
172 |
this.$.find(".Rk-Search-Select").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
173 |
function() { _select.slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
174 |
); |
| 34 | 175 |
this.setSearchEngine(0); |
| 21 | 176 |
} |
| 26 | 177 |
Rkns._(_opts.bins).each(function(_bin) { |
178 |
_this.tabs.push(new _bin.bin(_this, _bin)); |
|
| 42 | 179 |
}); |
| 24 | 180 |
|
| 21 | 181 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
182 |
.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
|
183 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
184 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
185 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
186 |
_mainDiv.slideDown(); |
| 21 | 187 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
188 |
}).on("mousedown", ".Rk-Bin-Item", function() { |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
189 |
if (_this.read_only) { |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
190 |
return false; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
191 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
192 |
var _t = Rkns.$(this); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
193 |
_t.addClass("dragging"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
194 |
_this.selected_bin_item = { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
195 |
uri : $(_t).attr("data-uri"), |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
196 |
title : $(_t).attr("data-title"), |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
197 |
description : $(_t).attr("data-description"), |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
198 |
image: $(_t).attr("data-image") |
| 21 | 199 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
200 |
return false; |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
201 |
}).on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
202 |
var _t = Rkns.$(this); |
| 26 | 203 |
if (_t && $(_t).attr("data-uri")) { |
204 |
var _models = _this.project.get("nodes").where({ |
|
205 |
uri: $(_t).attr("data-uri") |
|
206 |
}); |
|
207 |
Rkns._(_models).each(function(_model) { |
|
208 |
_this.renderer.highlightModel(_model); |
|
209 |
}); |
|
210 |
} |
|
211 |
}).mouseout(function() { |
|
212 |
_this.renderer.unhighlightAll(); |
|
| 20 | 213 |
}); |
| 21 | 214 |
Rkns.$(window).resize(function() { |
215 |
_this.resizeBins(); |
|
| 2 | 216 |
}); |
| 44 | 217 |
|
218 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
|
219 |
var val = Rkns.$(this).val(); |
|
220 |
Rkns._(_this.tabs).each(function(tab) { |
|
221 |
tab.render(val); |
|
222 |
}); |
|
223 |
}); |
|
224 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
225 |
return false |
|
226 |
}); |
|
| 1 | 227 |
} |
228 |
||
| 20 | 229 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
230 |
'<% if (show_bins) { %><div class="Rk-Title"><h1>Hyper Plateau</h1></div><div class="Rk-Bins">' |
| 44 | 231 |
+ '<form class="Rk-Web-Search-Form Rk-Search-Form"><input class="Rk-Web-Search-Input Rk-Search-Input" type="search" placeholder="Search the Web" />' |
| 34 | 232 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
| 44 | 233 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>' |
234 |
+ '<form class="Rk-Bins-Search-Form Rk-Search-Form"><input class="Rk-Bins-Search-Input Rk-Search-Input" type="search" placeholder="Search in Bins" />' |
|
235 |
+ '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form>' |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
236 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
| 20 | 237 |
); |
| 18 | 238 |
|
| 21 | 239 |
|
| 34 | 240 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
241 |
this.search_engine = this.search_engines[_key]; |
|
242 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
243 |
} |
|
244 |
||
| 21 | 245 |
Rkns.Renkan.prototype.resizeBins = function() { |
| 44 | 246 |
var _d = + this.$.find(".Rk-Web-Search-Form").outerHeight() + this.$.find(".Rk-Bins-Search-Form").outerHeight(); |
247 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
|
| 26 | 248 |
_d += Rkns.$(this).outerHeight(); |
249 |
}); |
|
| 21 | 250 |
this.$.find(".Rk-Bin-Main").css({ |
251 |
height: this.$.find(".Rk-Bins").height() - _d |
|
252 |
}); |
|
253 |
} |
|
254 |
||
| 1 | 255 |
/* Utility functions */ |
256 |
||
257 |
Rkns.Utils = { |
|
258 |
_ID_AUTO_INCREMENT : 0, |
|
259 |
_ID_BASE : (function(_d) { |
|
260 |
function pad(n){return n<10 ? '0'+n : n} |
|
261 |
function fillrand(n) { |
|
262 |
var _res = '' |
|
263 |
for (var i=0; i<n; i++) { |
|
264 |
_res += Math.floor(16*Math.random()).toString(16); |
|
265 |
} |
|
266 |
return _res; |
|
267 |
} |
|
268 |
return _d.getUTCFullYear() + '-' |
|
269 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
270 |
+ pad(_d.getUTCDate()) + '-' |
|
271 |
+ fillrand(16); |
|
272 |
})(new Date()), |
|
273 |
getUID : function(_base) { |
|
274 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
275 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
276 |
while (_n.length < 4) { |
|
277 |
_n = '0' + _n |
|
278 |
} |
|
279 |
return _base + this._ID_BASE + '-' + _n; |
|
280 |
}, |
|
281 |
inherit : function(_baseClass, _callbefore) { |
|
282 |
var _class = function() { |
|
283 |
if (typeof _callbefore === "function") { |
|
284 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
285 |
} |
|
| 28 | 286 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
287 |
if (typeof this._init == "function") { |
|
288 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
| 1 | 289 |
} |
290 |
} |
|
291 |
_class.prototype = new _baseClass(); |
|
292 |
return _class; |
|
293 |
} |
|
294 |
} |