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