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