| author | veltr |
| Thu, 14 Mar 2013 11:29:33 +0100 | |
| changeset 78 | af9e716b01bc |
| parent 75 | 7adef9ce92aa |
| child 79 | f33771f3c510 |
| 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 |
||
| 68 | 29 |
Rkns.VERSION = '0.2'; |
30 |
||
| 69 | 31 |
Rkns.pickerColors = ["#8f1919", "#a80000", "#d82626", "#ff0000", "#e87c7c", "#ff6565", "#f7d3d3", "#fecccc", |
32 |
"#8f5419", "#a85400", "#d87f26", "#ff7f00", "#e8b27c", "#ffb265", "#f7e5d3", "#fee5cc", |
|
33 |
"#8f8f19", "#a8a800", "#d8d826", "#feff00", "#e8e87c", "#feff65", "#f7f7d3", "#fefecc", |
|
34 |
"#198f19", "#00a800", "#26d826", "#00ff00", "#7ce87c", "#65ff65", "#d3f7d3", "#ccfecc", |
|
35 |
"#198f8f", "#00a8a8", "#26d8d8", "#00feff", "#7ce8e8", "#65feff", "#d3f7f7", "#ccfefe", |
|
36 |
"#19198f", "#0000a8", "#2626d8", "#0000ff", "#7c7ce8", "#6565ff", "#d3d3f7", "#ccccfe", |
|
37 |
"#8f198f", "#a800a8", "#d826d8", "#ff00fe", "#e87ce8", "#ff65fe", "#f7d3f7", "#feccfe", |
|
38 |
"#000000", "#242424", "#484848", "#6d6d6d", "#919191", "#b6b6b6", "#dadada", "#ffffff"]; |
|
| 52 | 39 |
|
| 34 | 40 |
Rkns._BaseBin = function(_renkan, _opts) { |
| 21 | 41 |
if (typeof _renkan !== "undefined") { |
42 |
this.renkan = _renkan; |
|
43 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
44 |
this.$ = Rkns.$('<li>') |
|
45 |
.addClass("Rk-Bin") |
|
46 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
| 34 | 47 |
this.title_icon_$ = Rkns.$('<span>') |
48 |
.addClass("Rk-Bin-Title-Icon") |
|
49 |
.appendTo(this.$); |
|
| 42 | 50 |
|
| 34 | 51 |
var _this = this; |
| 42 | 52 |
|
53 |
Rkns.$('<a>') |
|
54 |
.attr("href","#") |
|
| 34 | 55 |
.addClass("Rk-Bin-Close") |
56 |
.html('×') |
|
57 |
.appendTo(this.$) |
|
58 |
.click(function() { |
|
59 |
_this.destroy(); |
|
| 42 | 60 |
return false; |
61 |
}); |
|
62 |
Rkns.$('<a>') |
|
63 |
.attr("href","#") |
|
64 |
.addClass("Rk-Bin-Refresh") |
|
65 |
.appendTo(this.$) |
|
66 |
.click(function() { |
|
67 |
_this.refresh(); |
|
68 |
return false; |
|
| 34 | 69 |
}); |
| 44 | 70 |
this.count_$ = Rkns.$('<div>') |
71 |
.addClass("Rk-Bin-Count") |
|
72 |
.appendTo(this.$); |
|
| 21 | 73 |
this.title_$ = Rkns.$('<h2>') |
74 |
.addClass("Rk-Bin-Title") |
|
75 |
.appendTo(this.$); |
|
76 |
this.main_$ = Rkns.$('<div>') |
|
77 |
.addClass("Rk-Bin-Main") |
|
| 64 | 78 |
.appendTo(this.$) |
| 66 | 79 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>'); |
| 26 | 80 |
this.title_$.html(_opts.title || '(new bin)'); |
| 21 | 81 |
this.renkan.resizeBins(); |
| 42 | 82 |
|
83 |
if (_opts.auto_refresh) { |
|
84 |
window.setInterval(function() { |
|
85 |
_this.refresh(); |
|
86 |
},_opts.auto_refresh) |
|
87 |
} |
|
| 20 | 88 |
} |
89 |
} |
|
| 34 | 90 |
|
91 |
Rkns._BaseBin.prototype.destroy = function() { |
|
92 |
this.$.detach(); |
|
93 |
this.renkan.resizeBins(); |
|
94 |
} |
|
95 |
||
| 20 | 96 |
/* Point of entry */ |
97 |
||
98 |
Rkns.Renkan = function(_opts) { |
|
| 68 | 99 |
var _this = this; |
100 |
|
|
| 21 | 101 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
| 5 | 102 |
_opts.language = "en"; |
103 |
} |
|
| 21 | 104 |
if (typeof _opts.container !== "string") { |
| 20 | 105 |
_opts.container = "renkan"; |
106 |
} |
|
| 21 | 107 |
if (typeof _opts.search !== "object" || !_opts.search) { |
108 |
_opts.search = []; |
|
109 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
110 |
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
|
111 |
_opts.bins = []; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
112 |
} |
| 56 | 113 |
if (typeof _opts.static_url !== "string") { |
114 |
_opts.static_url = ""; |
|
115 |
} |
|
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
116 |
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
|
117 |
_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
|
118 |
} |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
119 |
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
|
120 |
_opts.read_only = false; |
|
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
121 |
} |
| 68 | 122 |
if (typeof _opts.properties !== "object") { |
123 |
_opts.properties = []; |
|
124 |
} |
|
125 |
if (typeof _opts.property_files === "object") { |
|
126 |
Rkns._(_opts.property_files).each(function(f) { |
|
127 |
Rkns.$.getJSON(f, function(data) { |
|
128 |
_this.properties = _this.properties.concat(data); |
|
129 |
}); |
|
130 |
}); |
|
131 |
} |
|
| 73 | 132 |
if (typeof _opts.clip_images === "undefined") { |
133 |
_opts.clip_images = true; |
|
134 |
} |
|
| 23 | 135 |
this.project = new Rkns.Models.Project(); |
| 34 | 136 |
this.language = _opts.language; |
| 56 | 137 |
this.static_url = _opts.static_url; |
| 68 | 138 |
this.show_bins = _opts.show_bins; |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
139 |
this.read_only = _opts.read_only; |
| 68 | 140 |
this.properties = _opts.properties; |
| 73 | 141 |
this.clip_images = _opts.clip_images; |
| 69 | 142 |
|
| 66 | 143 |
this.translate = function(_text) { |
144 |
return (Rkns.i18n[_opts.language] || Rkns.i18n[_opts.language.substr(0,2)] || {})[_text] || _text; |
|
145 |
} |
|
| 23 | 146 |
if (typeof _opts.user_id !== "undefined") { |
147 |
this.current_user = _opts.user_id; |
|
| 4 | 148 |
} |
| 21 | 149 |
this.$ = Rkns.$("#" + _opts.container); |
| 34 | 150 |
this.$ |
151 |
.addClass("Rk-Main") |
|
| 68 | 152 |
.html(this.template(this)); |
| 23 | 153 |
this.renderer = new Rkns.Renderer.Scene(this); |
| 21 | 154 |
this.tabs = []; |
| 34 | 155 |
this.search_engines = []; |
| 56 | 156 |
|
157 |
this.current_user_list = new Rkns.Models.UsersList(); |
|
158 |
|
|
| 21 | 159 |
if (!_opts.search.length) { |
| 44 | 160 |
this.$.find(".Rk-Web-Search-Form").detach(); |
| 21 | 161 |
} else { |
| 34 | 162 |
var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
163 |
_select = this.$.find(".Rk-Search-List"), |
|
| 44 | 164 |
_input = this.$.find(".Rk-Web-Search-Input") |
165 |
_form = this.$.find(".Rk-Web-Search-Form"); |
|
| 34 | 166 |
Rkns._(_opts.search).each(function(_search, _key) { |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
167 |
console.log(_search, Rkns[_search.type]); |
|
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
168 |
if (Rkns[_search.type] && Rkns[_search.type].Search) { |
|
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
169 |
_this.search_engines.push(new Rkns[_search.type].Search(_this, _search)); |
|
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
170 |
} |
| 34 | 171 |
}); |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
172 |
console.log(_this.search_engines); |
| 24 | 173 |
_select.html( |
| 34 | 174 |
Rkns._(this.search_engines).map(function(_search, _key) { |
| 24 | 175 |
return _tmpl({ |
176 |
key: _key, |
|
| 34 | 177 |
title: _search.getSearchTitle(), |
178 |
className: _search.getBgClass() |
|
| 24 | 179 |
}); |
| 21 | 180 |
}).join("") |
| 34 | 181 |
); |
182 |
_select.find("li").click(function() { |
|
183 |
var _el = Rkns.$(this); |
|
184 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 185 |
_form.submit(); |
186 |
}); |
|
187 |
_form.submit(function() { |
|
188 |
if (_input.val()) { |
|
| 34 | 189 |
var _search = _this.search_engine; |
190 |
_search.search(_input.val()); |
|
| 24 | 191 |
} |
192 |
return false; |
|
193 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
194 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
195 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
196 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
197 |
this.$.find(".Rk-Search-Select").mouseleave( |
| 70 | 198 |
function() { _select.hide(); } |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
199 |
); |
| 34 | 200 |
this.setSearchEngine(0); |
| 21 | 201 |
} |
| 26 | 202 |
Rkns._(_opts.bins).each(function(_bin) { |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
203 |
if (Rkns[_bin.type] && Rkns[_bin.type].Bin) { |
|
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
204 |
_this.tabs.push(new Rkns[_bin.type].Bin(_this, _bin)); |
|
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
205 |
} |
| 42 | 206 |
}); |
| 24 | 207 |
|
| 21 | 208 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
209 |
.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
|
210 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
211 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
212 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
213 |
_mainDiv.slideDown(); |
| 21 | 214 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
215 |
}).on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
216 |
var _t = Rkns.$(this); |
| 26 | 217 |
if (_t && $(_t).attr("data-uri")) { |
218 |
var _models = _this.project.get("nodes").where({ |
|
219 |
uri: $(_t).attr("data-uri") |
|
220 |
}); |
|
221 |
Rkns._(_models).each(function(_model) { |
|
222 |
_this.renderer.highlightModel(_model); |
|
223 |
}); |
|
224 |
} |
|
225 |
}).mouseout(function() { |
|
226 |
_this.renderer.unhighlightAll(); |
|
| 68 | 227 |
}).on("dragstart", ".Rk-Bin-Item", function(e) { |
228 |
var _t = Rkns.$(this); |
|
229 |
e.originalEvent.dataTransfer.setData("text/x-iri-title",$(_t).attr("data-title")); |
|
230 |
e.originalEvent.dataTransfer.setData("text/x-iri-description",$(_t).attr("data-description")); |
|
231 |
e.originalEvent.dataTransfer.setData("text/x-iri-uri",$(_t).attr("data-uri")); |
|
232 |
e.originalEvent.dataTransfer.setData("text/x-iri-image",$(_t).attr("data-image")); |
|
| 20 | 233 |
}); |
| 21 | 234 |
Rkns.$(window).resize(function() { |
235 |
_this.resizeBins(); |
|
| 2 | 236 |
}); |
| 44 | 237 |
|
238 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
|
239 |
var val = Rkns.$(this).val(); |
|
240 |
Rkns._(_this.tabs).each(function(tab) { |
|
241 |
tab.render(val); |
|
242 |
}); |
|
243 |
}); |
|
244 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
245 |
return false |
|
246 |
}); |
|
| 1 | 247 |
} |
248 |
||
| 20 | 249 |
Rkns.Renkan.prototype.template = Rkns._.template( |
| 75 | 250 |
'<% if (show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
| 68 | 251 |
+ '<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") %>" />' |
| 34 | 252 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
| 44 | 253 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>' |
| 68 | 254 |
+ '<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") %>" />' |
| 75 | 255 |
+ '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" /></form></div>' |
|
62
f9019462465a
Publishing code is now same as Editing code with renkan.read_only = true
veltr
parents:
56
diff
changeset
|
256 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
| 20 | 257 |
); |
| 18 | 258 |
|
| 21 | 259 |
|
| 34 | 260 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
261 |
this.search_engine = this.search_engines[_key]; |
|
262 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
263 |
} |
|
264 |
||
| 21 | 265 |
Rkns.Renkan.prototype.resizeBins = function() { |
| 75 | 266 |
var _d = + this.$.find(".Rk-Bins-Head").outerHeight(); |
| 44 | 267 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
| 26 | 268 |
_d += Rkns.$(this).outerHeight(); |
269 |
}); |
|
| 21 | 270 |
this.$.find(".Rk-Bin-Main").css({ |
271 |
height: this.$.find(".Rk-Bins").height() - _d |
|
272 |
}); |
|
273 |
} |
|
274 |
||
| 1 | 275 |
/* Utility functions */ |
276 |
||
277 |
Rkns.Utils = { |
|
278 |
_ID_AUTO_INCREMENT : 0, |
|
279 |
_ID_BASE : (function(_d) { |
|
280 |
function pad(n){return n<10 ? '0'+n : n} |
|
281 |
function fillrand(n) { |
|
282 |
var _res = '' |
|
283 |
for (var i=0; i<n; i++) { |
|
284 |
_res += Math.floor(16*Math.random()).toString(16); |
|
285 |
} |
|
286 |
return _res; |
|
287 |
} |
|
288 |
return _d.getUTCFullYear() + '-' |
|
289 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
290 |
+ pad(_d.getUTCDate()) + '-' |
|
291 |
+ fillrand(16); |
|
292 |
})(new Date()), |
|
293 |
getUID : function(_base) { |
|
294 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
295 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
296 |
while (_n.length < 4) { |
|
297 |
_n = '0' + _n |
|
298 |
} |
|
299 |
return _base + this._ID_BASE + '-' + _n; |
|
300 |
}, |
|
301 |
inherit : function(_baseClass, _callbefore) { |
|
302 |
var _class = function() { |
|
303 |
if (typeof _callbefore === "function") { |
|
304 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
305 |
} |
|
| 28 | 306 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
307 |
if (typeof this._init == "function") { |
|
308 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
| 1 | 309 |
} |
310 |
} |
|
311 |
_class.prototype = new _baseClass(); |
|
312 |
return _class; |
|
313 |
} |
|
314 |
} |