|
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 |
|
|
34
|
29 |
Rkns._BaseBin = function(_renkan, _opts) { |
|
21
|
30 |
if (typeof _renkan !== "undefined") { |
|
|
31 |
this.renkan = _renkan; |
|
|
32 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
|
33 |
this.$ = Rkns.$('<li>') |
|
|
34 |
.addClass("Rk-Bin") |
|
|
35 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
34
|
36 |
this.title_icon_$ = Rkns.$('<span>') |
|
|
37 |
.addClass("Rk-Bin-Title-Icon") |
|
|
38 |
.appendTo(this.$); |
|
|
39 |
var _this = this; |
|
|
40 |
Rkns.$('<span>') |
|
|
41 |
.addClass("Rk-Bin-Close") |
|
|
42 |
.html('×') |
|
|
43 |
.appendTo(this.$) |
|
|
44 |
.click(function() { |
|
|
45 |
_this.destroy(); |
|
|
46 |
}); |
|
21
|
47 |
this.title_$ = Rkns.$('<h2>') |
|
|
48 |
.addClass("Rk-Bin-Title") |
|
|
49 |
.appendTo(this.$); |
|
|
50 |
this.main_$ = Rkns.$('<div>') |
|
|
51 |
.addClass("Rk-Bin-Main") |
|
|
52 |
.appendTo(this.$); |
|
26
|
53 |
this.title_$.html(_opts.title || '(new bin)'); |
|
21
|
54 |
this.renkan.resizeBins(); |
|
20
|
55 |
} |
|
|
56 |
} |
|
34
|
57 |
|
|
|
58 |
Rkns._BaseBin.prototype.destroy = function() { |
|
|
59 |
this.$.detach(); |
|
|
60 |
this.renkan.resizeBins(); |
|
|
61 |
} |
|
|
62 |
|
|
20
|
63 |
/* Point of entry */ |
|
|
64 |
|
|
|
65 |
Rkns.Renkan = function(_opts) { |
|
21
|
66 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
5
|
67 |
_opts.language = "en"; |
|
|
68 |
} |
|
21
|
69 |
if (typeof _opts.container !== "string") { |
|
20
|
70 |
_opts.container = "renkan"; |
|
|
71 |
} |
|
21
|
72 |
if (typeof _opts.search !== "object" || !_opts.search) { |
|
|
73 |
_opts.search = []; |
|
|
74 |
} |
|
23
|
75 |
this.project = new Rkns.Models.Project(); |
|
34
|
76 |
this.language = _opts.language; |
|
23
|
77 |
this.l10n = Rkns.i18n[_opts.language]; |
|
|
78 |
if (typeof _opts.user_id !== "undefined") { |
|
|
79 |
this.current_user = _opts.user_id; |
|
4
|
80 |
} |
|
21
|
81 |
this.$ = Rkns.$("#" + _opts.container); |
|
34
|
82 |
this.$ |
|
|
83 |
.addClass("Rk-Main") |
|
|
84 |
.html(this.template()); |
|
23
|
85 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
21
|
86 |
this.tabs = []; |
|
34
|
87 |
this.search_engines = []; |
|
21
|
88 |
this.selected_bin_item = undefined; |
|
1
|
89 |
var _this = this; |
|
21
|
90 |
this.$.mouseup(function() { |
|
|
91 |
_this.selected_bin_item = undefined; |
|
26
|
92 |
_this.$.find(".Rk-Bin-Item.dragging").removeClass("dragging"); |
|
21
|
93 |
}); |
|
|
94 |
if (!_opts.search.length) { |
|
|
95 |
this.$.find(".Rk-Search-Form").detach(); |
|
|
96 |
} else { |
|
34
|
97 |
var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
|
|
98 |
_select = this.$.find(".Rk-Search-List"), |
|
24
|
99 |
_input = this.$.find(".Rk-Search-Input") |
|
|
100 |
_form = this.$.find(".Rk-Search-Form"); |
|
34
|
101 |
Rkns._(_opts.search).each(function(_search, _key) { |
|
|
102 |
var _searchObj = new _search.type(_this, _search); |
|
|
103 |
_this.search_engines.push(_searchObj); |
|
|
104 |
}); |
|
24
|
105 |
_select.html( |
|
34
|
106 |
Rkns._(this.search_engines).map(function(_search, _key) { |
|
24
|
107 |
return _tmpl({ |
|
|
108 |
key: _key, |
|
34
|
109 |
title: _search.getSearchTitle(), |
|
|
110 |
className: _search.getBgClass() |
|
24
|
111 |
}); |
|
21
|
112 |
}).join("") |
|
34
|
113 |
); |
|
|
114 |
_select.find("li").click(function() { |
|
|
115 |
var _el = Rkns.$(this); |
|
|
116 |
_this.setSearchEngine(_el.attr("data-key")); |
|
24
|
117 |
_form.submit(); |
|
|
118 |
}); |
|
|
119 |
_form.submit(function() { |
|
|
120 |
if (_input.val()) { |
|
34
|
121 |
var _search = _this.search_engine; |
|
|
122 |
_search.search(_input.val()); |
|
24
|
123 |
} |
|
|
124 |
return false; |
|
|
125 |
}); |
|
34
|
126 |
this.$.find(".Rk-Search-Select").mouseenter(function() { |
|
|
127 |
_select.slideDown(); |
|
|
128 |
}).mouseleave(function() { |
|
|
129 |
_select.slideUp(); |
|
|
130 |
}) |
|
|
131 |
this.setSearchEngine(0); |
|
21
|
132 |
} |
|
26
|
133 |
Rkns._(_opts.bins).each(function(_bin) { |
|
|
134 |
_this.tabs.push(new _bin.bin(_this, _bin)); |
|
|
135 |
}) |
|
|
136 |
|
|
|
137 |
/* The bins are not yet populated, but we want to bind dragging functions |
|
|
138 |
* here, as it will be easier than in the bins. Therefore, we bind to Rk-Bins |
|
|
139 |
* and look where the click was. */ |
|
|
140 |
function findItem(_event) { |
|
|
141 |
var _t = Rkns.$(_event.target); |
|
|
142 |
while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) { |
|
|
143 |
_t = _t.parent(); |
|
|
144 |
} |
|
|
145 |
if (_t.is(".Rk-Bin-Item")) { |
|
|
146 |
return _t |
|
|
147 |
} else { |
|
|
148 |
return null; |
|
|
149 |
} |
|
|
150 |
} |
|
24
|
151 |
|
|
21
|
152 |
this.$.find(".Rk-Bins") |
|
|
153 |
.click(function(_e) { |
|
34
|
154 |
if (Rkns.$(_e.target).is(".Rk-Bin-Title,.Rk-Bin-Title-Icon")) { |
|
21
|
155 |
var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main"); |
|
|
156 |
if (_mainDiv.is(":hidden")) { |
|
|
157 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
|
158 |
_mainDiv.slideDown(); |
|
|
159 |
} |
|
|
160 |
} |
|
|
161 |
}).mousedown(function(_e) { |
|
26
|
162 |
var _t = findItem(_e); |
|
|
163 |
if (_t) { |
|
|
164 |
_t.addClass("dragging"); |
|
21
|
165 |
_this.selected_bin_item = { |
|
|
166 |
uri : $(_t).attr("data-uri"), |
|
|
167 |
title : $(_t).attr("data-title"), |
|
|
168 |
description : $(_t).attr("data-description") |
|
|
169 |
} |
|
|
170 |
return false; |
|
|
171 |
} |
|
26
|
172 |
}).mouseover(function(_e) { |
|
|
173 |
var _t = findItem(_e); |
|
|
174 |
if (_t && $(_t).attr("data-uri")) { |
|
|
175 |
var _models = _this.project.get("nodes").where({ |
|
|
176 |
uri: $(_t).attr("data-uri") |
|
|
177 |
}); |
|
|
178 |
Rkns._(_models).each(function(_model) { |
|
|
179 |
_this.renderer.highlightModel(_model); |
|
|
180 |
}); |
|
|
181 |
} |
|
|
182 |
}).mouseout(function() { |
|
|
183 |
_this.renderer.unhighlightAll(); |
|
20
|
184 |
}); |
|
21
|
185 |
Rkns.$(window).resize(function() { |
|
|
186 |
_this.resizeBins(); |
|
2
|
187 |
}); |
|
1
|
188 |
} |
|
|
189 |
|
|
20
|
190 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
34
|
191 |
'<div class="Rk-Title"><h1>Hyper Plateau</h1></div><div class="Rk-Bins">' |
|
|
192 |
+ '<form class="Rk-Search-Form"><input class="Rk-Search-Input" type="text" placeholder="Search" />' |
|
|
193 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
|
|
194 |
+ '<input type="submit" value="" class="Rk-Search-Submit" /></form>' |
|
28
|
195 |
+ '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render Rk-Render-Panel"></div>' |
|
20
|
196 |
); |
|
18
|
197 |
|
|
21
|
198 |
|
|
34
|
199 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
|
|
200 |
this.search_engine = this.search_engines[_key]; |
|
|
201 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
|
202 |
} |
|
|
203 |
|
|
21
|
204 |
Rkns.Renkan.prototype.resizeBins = function() { |
|
26
|
205 |
var _d = + this.$.find(".Rk-Search-Form").outerHeight(); |
|
|
206 |
this.$.find(".Rk-Bin-Title").each(function() { |
|
|
207 |
_d += Rkns.$(this).outerHeight(); |
|
|
208 |
}); |
|
21
|
209 |
this.$.find(".Rk-Bin-Main").css({ |
|
|
210 |
height: this.$.find(".Rk-Bins").height() - _d |
|
|
211 |
}); |
|
|
212 |
} |
|
|
213 |
|
|
1
|
214 |
/* Utility functions */ |
|
|
215 |
|
|
|
216 |
Rkns.Utils = { |
|
|
217 |
_ID_AUTO_INCREMENT : 0, |
|
|
218 |
_ID_BASE : (function(_d) { |
|
|
219 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
220 |
function fillrand(n) { |
|
|
221 |
var _res = '' |
|
|
222 |
for (var i=0; i<n; i++) { |
|
|
223 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
224 |
} |
|
|
225 |
return _res; |
|
|
226 |
} |
|
|
227 |
return _d.getUTCFullYear() + '-' |
|
|
228 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
229 |
+ pad(_d.getUTCDate()) + '-' |
|
|
230 |
+ fillrand(16); |
|
|
231 |
})(new Date()), |
|
|
232 |
getUID : function(_base) { |
|
|
233 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
234 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
235 |
while (_n.length < 4) { |
|
|
236 |
_n = '0' + _n |
|
|
237 |
} |
|
|
238 |
return _base + this._ID_BASE + '-' + _n; |
|
|
239 |
}, |
|
|
240 |
inherit : function(_baseClass, _callbefore) { |
|
|
241 |
var _class = function() { |
|
|
242 |
if (typeof _callbefore === "function") { |
|
|
243 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
244 |
} |
|
28
|
245 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
246 |
if (typeof this._init == "function") { |
|
|
247 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
1
|
248 |
} |
|
|
249 |
} |
|
|
250 |
_class.prototype = new _baseClass(); |
|
|
251 |
return _class; |
|
|
252 |
} |
|
|
253 |
} |