| author | veltr |
| Wed, 05 Sep 2012 14:49:33 +0200 | |
| changeset 36 | d249d36ecc37 |
| parent 34 | 08a366a35143 |
| child 37 | db991a757015 |
| 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 |
||
| 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 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
126 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
127 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
128 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
129 |
this.$.find(".Rk-Search-Select").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
130 |
function() { _select.slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
131 |
); |
| 34 | 132 |
this.setSearchEngine(0); |
| 21 | 133 |
} |
| 26 | 134 |
Rkns._(_opts.bins).each(function(_bin) { |
135 |
_this.tabs.push(new _bin.bin(_this, _bin)); |
|
136 |
}) |
|
137 |
|
|
138 |
/* The bins are not yet populated, but we want to bind dragging functions |
|
139 |
* here, as it will be easier than in the bins. Therefore, we bind to Rk-Bins |
|
140 |
* and look where the click was. */ |
|
141 |
function findItem(_event) { |
|
142 |
var _t = Rkns.$(_event.target); |
|
143 |
while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) { |
|
144 |
_t = _t.parent(); |
|
145 |
} |
|
146 |
if (_t.is(".Rk-Bin-Item")) { |
|
147 |
return _t |
|
148 |
} else { |
|
149 |
return null; |
|
150 |
} |
|
151 |
} |
|
| 24 | 152 |
|
| 21 | 153 |
this.$.find(".Rk-Bins") |
154 |
.click(function(_e) { |
|
| 34 | 155 |
if (Rkns.$(_e.target).is(".Rk-Bin-Title,.Rk-Bin-Title-Icon")) { |
| 21 | 156 |
var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main"); |
157 |
if (_mainDiv.is(":hidden")) { |
|
158 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
159 |
_mainDiv.slideDown(); |
|
160 |
} |
|
161 |
} |
|
162 |
}).mousedown(function(_e) { |
|
| 26 | 163 |
var _t = findItem(_e); |
164 |
if (_t) { |
|
165 |
_t.addClass("dragging"); |
|
| 21 | 166 |
_this.selected_bin_item = { |
167 |
uri : $(_t).attr("data-uri"), |
|
168 |
title : $(_t).attr("data-title"), |
|
169 |
description : $(_t).attr("data-description") |
|
170 |
} |
|
171 |
return false; |
|
172 |
} |
|
| 26 | 173 |
}).mouseover(function(_e) { |
174 |
var _t = findItem(_e); |
|
175 |
if (_t && $(_t).attr("data-uri")) { |
|
176 |
var _models = _this.project.get("nodes").where({ |
|
177 |
uri: $(_t).attr("data-uri") |
|
178 |
}); |
|
179 |
Rkns._(_models).each(function(_model) { |
|
180 |
_this.renderer.highlightModel(_model); |
|
181 |
}); |
|
182 |
} |
|
183 |
}).mouseout(function() { |
|
184 |
_this.renderer.unhighlightAll(); |
|
| 20 | 185 |
}); |
| 21 | 186 |
Rkns.$(window).resize(function() { |
187 |
_this.resizeBins(); |
|
| 2 | 188 |
}); |
| 1 | 189 |
} |
190 |
||
| 20 | 191 |
Rkns.Renkan.prototype.template = Rkns._.template( |
| 34 | 192 |
'<div class="Rk-Title"><h1>Hyper Plateau</h1></div><div class="Rk-Bins">' |
193 |
+ '<form class="Rk-Search-Form"><input class="Rk-Search-Input" type="text" placeholder="Search" />' |
|
194 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
|
195 |
+ '<input type="submit" value="" class="Rk-Search-Submit" /></form>' |
|
| 28 | 196 |
+ '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render Rk-Render-Panel"></div>' |
| 20 | 197 |
); |
| 18 | 198 |
|
| 21 | 199 |
|
| 34 | 200 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
201 |
this.search_engine = this.search_engines[_key]; |
|
202 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
203 |
} |
|
204 |
||
| 21 | 205 |
Rkns.Renkan.prototype.resizeBins = function() { |
| 26 | 206 |
var _d = + this.$.find(".Rk-Search-Form").outerHeight(); |
207 |
this.$.find(".Rk-Bin-Title").each(function() { |
|
208 |
_d += Rkns.$(this).outerHeight(); |
|
209 |
}); |
|
| 21 | 210 |
this.$.find(".Rk-Bin-Main").css({ |
211 |
height: this.$.find(".Rk-Bins").height() - _d |
|
212 |
}); |
|
213 |
} |
|
214 |
||
| 1 | 215 |
/* Utility functions */ |
216 |
||
217 |
Rkns.Utils = { |
|
218 |
_ID_AUTO_INCREMENT : 0, |
|
219 |
_ID_BASE : (function(_d) { |
|
220 |
function pad(n){return n<10 ? '0'+n : n} |
|
221 |
function fillrand(n) { |
|
222 |
var _res = '' |
|
223 |
for (var i=0; i<n; i++) { |
|
224 |
_res += Math.floor(16*Math.random()).toString(16); |
|
225 |
} |
|
226 |
return _res; |
|
227 |
} |
|
228 |
return _d.getUTCFullYear() + '-' |
|
229 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
230 |
+ pad(_d.getUTCDate()) + '-' |
|
231 |
+ fillrand(16); |
|
232 |
})(new Date()), |
|
233 |
getUID : function(_base) { |
|
234 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
235 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
236 |
while (_n.length < 4) { |
|
237 |
_n = '0' + _n |
|
238 |
} |
|
239 |
return _base + this._ID_BASE + '-' + _n; |
|
240 |
}, |
|
241 |
inherit : function(_baseClass, _callbefore) { |
|
242 |
var _class = function() { |
|
243 |
if (typeof _callbefore === "function") { |
|
244 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
245 |
} |
|
| 28 | 246 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
247 |
if (typeof this._init == "function") { |
|
248 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
| 1 | 249 |
} |
250 |
} |
|
251 |
_class.prototype = new _baseClass(); |
|
252 |
return _class; |
|
253 |
} |
|
254 |
} |