| author | veltr |
| Wed, 13 Mar 2013 10:24:23 +0100 | |
| changeset 74 | c059efca2d7a |
| parent 73 | cc9deb3b3e13 |
| child 75 | 7adef9ce92aa |
| 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) { |
167 |
var _searchObj = new _search.type(_this, _search); |
|
168 |
_this.search_engines.push(_searchObj); |
|
169 |
}); |
|
| 24 | 170 |
_select.html( |
| 34 | 171 |
Rkns._(this.search_engines).map(function(_search, _key) { |
| 24 | 172 |
return _tmpl({ |
173 |
key: _key, |
|
| 34 | 174 |
title: _search.getSearchTitle(), |
175 |
className: _search.getBgClass() |
|
| 24 | 176 |
}); |
| 21 | 177 |
}).join("") |
| 34 | 178 |
); |
179 |
_select.find("li").click(function() { |
|
180 |
var _el = Rkns.$(this); |
|
181 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 182 |
_form.submit(); |
183 |
}); |
|
184 |
_form.submit(function() { |
|
185 |
if (_input.val()) { |
|
| 34 | 186 |
var _search = _this.search_engine; |
187 |
_search.search(_input.val()); |
|
| 24 | 188 |
} |
189 |
return false; |
|
190 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
191 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
192 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
193 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
194 |
this.$.find(".Rk-Search-Select").mouseleave( |
| 70 | 195 |
function() { _select.hide(); } |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
196 |
); |
| 34 | 197 |
this.setSearchEngine(0); |
| 21 | 198 |
} |
| 26 | 199 |
Rkns._(_opts.bins).each(function(_bin) { |
200 |
_this.tabs.push(new _bin.bin(_this, _bin)); |
|
| 42 | 201 |
}); |
| 24 | 202 |
|
| 21 | 203 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
204 |
.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
|
205 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
206 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
207 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
208 |
_mainDiv.slideDown(); |
| 21 | 209 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
210 |
}).on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
211 |
var _t = Rkns.$(this); |
| 26 | 212 |
if (_t && $(_t).attr("data-uri")) { |
213 |
var _models = _this.project.get("nodes").where({ |
|
214 |
uri: $(_t).attr("data-uri") |
|
215 |
}); |
|
216 |
Rkns._(_models).each(function(_model) { |
|
217 |
_this.renderer.highlightModel(_model); |
|
218 |
}); |
|
219 |
} |
|
220 |
}).mouseout(function() { |
|
221 |
_this.renderer.unhighlightAll(); |
|
| 68 | 222 |
}).on("dragstart", ".Rk-Bin-Item", function(e) { |
223 |
var _t = Rkns.$(this); |
|
224 |
e.originalEvent.dataTransfer.setData("text/x-iri-title",$(_t).attr("data-title")); |
|
225 |
e.originalEvent.dataTransfer.setData("text/x-iri-description",$(_t).attr("data-description")); |
|
226 |
e.originalEvent.dataTransfer.setData("text/x-iri-uri",$(_t).attr("data-uri")); |
|
227 |
e.originalEvent.dataTransfer.setData("text/x-iri-image",$(_t).attr("data-image")); |
|
| 20 | 228 |
}); |
| 21 | 229 |
Rkns.$(window).resize(function() { |
230 |
_this.resizeBins(); |
|
| 2 | 231 |
}); |
| 44 | 232 |
|
233 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
|
234 |
var val = Rkns.$(this).val(); |
|
235 |
Rkns._(_this.tabs).each(function(tab) { |
|
236 |
tab.render(val); |
|
237 |
}); |
|
238 |
}); |
|
239 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
240 |
return false |
|
241 |
}); |
|
| 1 | 242 |
} |
243 |
||
| 20 | 244 |
Rkns.Renkan.prototype.template = Rkns._.template( |
| 69 | 245 |
'<% if (show_bins) { %><div class="Rk-Bins"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
| 68 | 246 |
+ '<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 | 247 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
| 44 | 248 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" /></form>' |
| 68 | 249 |
+ '<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") %>" />' |
| 44 | 250 |
+ '<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
|
251 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
| 20 | 252 |
); |
| 18 | 253 |
|
| 21 | 254 |
|
| 34 | 255 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
256 |
this.search_engine = this.search_engines[_key]; |
|
257 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
258 |
} |
|
259 |
||
| 21 | 260 |
Rkns.Renkan.prototype.resizeBins = function() { |
| 44 | 261 |
var _d = + this.$.find(".Rk-Web-Search-Form").outerHeight() + this.$.find(".Rk-Bins-Search-Form").outerHeight(); |
262 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
|
| 26 | 263 |
_d += Rkns.$(this).outerHeight(); |
264 |
}); |
|
| 21 | 265 |
this.$.find(".Rk-Bin-Main").css({ |
266 |
height: this.$.find(".Rk-Bins").height() - _d |
|
267 |
}); |
|
268 |
} |
|
269 |
||
| 1 | 270 |
/* Utility functions */ |
271 |
||
272 |
Rkns.Utils = { |
|
273 |
_ID_AUTO_INCREMENT : 0, |
|
274 |
_ID_BASE : (function(_d) { |
|
275 |
function pad(n){return n<10 ? '0'+n : n} |
|
276 |
function fillrand(n) { |
|
277 |
var _res = '' |
|
278 |
for (var i=0; i<n; i++) { |
|
279 |
_res += Math.floor(16*Math.random()).toString(16); |
|
280 |
} |
|
281 |
return _res; |
|
282 |
} |
|
283 |
return _d.getUTCFullYear() + '-' |
|
284 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
285 |
+ pad(_d.getUTCDate()) + '-' |
|
286 |
+ fillrand(16); |
|
287 |
})(new Date()), |
|
288 |
getUID : function(_base) { |
|
289 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
290 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
291 |
while (_n.length < 4) { |
|
292 |
_n = '0' + _n |
|
293 |
} |
|
294 |
return _base + this._ID_BASE + '-' + _n; |
|
295 |
}, |
|
296 |
inherit : function(_baseClass, _callbefore) { |
|
297 |
var _class = function() { |
|
298 |
if (typeof _callbefore === "function") { |
|
299 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
300 |
} |
|
| 28 | 301 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
302 |
if (typeof this._init == "function") { |
|
303 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
| 1 | 304 |
} |
305 |
} |
|
306 |
_class.prototype = new _baseClass(); |
|
307 |
return _class; |
|
308 |
} |
|
309 |
} |