| author | veltr |
| Fri, 29 Mar 2013 18:19:47 +0100 | |
| changeset 119 | 0f7d2275a88f |
| parent 114 | 110f99eb417e |
| child 132 | 860340d4c645 |
| 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>') |
|
| 119 | 54 |
.attr({ |
55 |
href: "#", |
|
56 |
title: _renkan.translate("Close bin") |
|
57 |
}) |
|
| 34 | 58 |
.addClass("Rk-Bin-Close") |
59 |
.html('×') |
|
60 |
.appendTo(this.$) |
|
61 |
.click(function() { |
|
62 |
_this.destroy(); |
|
| 119 | 63 |
if (!_renkan.$.find(".Rk-Bin-Main:visible").length) { |
64 |
_renkan.$.find(".Rk-Bin-Main:last").slideDown(); |
|
65 |
} |
|
66 |
_renkan.resizeBins(); |
|
| 42 | 67 |
return false; |
68 |
}); |
|
69 |
Rkns.$('<a>') |
|
| 119 | 70 |
.attr({ |
71 |
href: "#", |
|
72 |
title: _renkan.translate("Refresh bin") |
|
73 |
}) |
|
| 42 | 74 |
.addClass("Rk-Bin-Refresh") |
75 |
.appendTo(this.$) |
|
76 |
.click(function() { |
|
77 |
_this.refresh(); |
|
78 |
return false; |
|
| 34 | 79 |
}); |
| 44 | 80 |
this.count_$ = Rkns.$('<div>') |
81 |
.addClass("Rk-Bin-Count") |
|
82 |
.appendTo(this.$); |
|
| 21 | 83 |
this.title_$ = Rkns.$('<h2>') |
84 |
.addClass("Rk-Bin-Title") |
|
85 |
.appendTo(this.$); |
|
86 |
this.main_$ = Rkns.$('<div>') |
|
87 |
.addClass("Rk-Bin-Main") |
|
| 64 | 88 |
.appendTo(this.$) |
| 66 | 89 |
.html('<h4 class="Rk-Bin-Loading">' + _renkan.translate("Loading, please wait") + '</h4>'); |
| 26 | 90 |
this.title_$.html(_opts.title || '(new bin)'); |
| 21 | 91 |
this.renkan.resizeBins(); |
| 42 | 92 |
|
93 |
if (_opts.auto_refresh) { |
|
94 |
window.setInterval(function() { |
|
95 |
_this.refresh(); |
|
96 |
},_opts.auto_refresh) |
|
97 |
} |
|
| 20 | 98 |
} |
99 |
} |
|
| 34 | 100 |
|
101 |
Rkns._BaseBin.prototype.destroy = function() { |
|
102 |
this.$.detach(); |
|
103 |
this.renkan.resizeBins(); |
|
104 |
} |
|
105 |
||
| 20 | 106 |
/* Point of entry */ |
107 |
||
108 |
Rkns.Renkan = function(_opts) { |
|
| 68 | 109 |
var _this = this; |
110 |
|
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
111 |
this.options = _.defaults(_opts, Rkns.defaults); |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
112 |
|
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
113 |
Rkns._(this.options.property_files).each(function(f) { |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
114 |
Rkns.$.getJSON(f, function(data) { |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
115 |
_this.options.properties = _this.options.properties.concat(data); |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
116 |
}); |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
117 |
}); |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
118 |
|
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
119 |
this.read_only = this.options.read_only || !this.options.editor_mode; |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
120 |
|
| 23 | 121 |
this.project = new Rkns.Models.Project(); |
| 69 | 122 |
|
| 66 | 123 |
this.translate = function(_text) { |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
124 |
return (Rkns.i18n[_this.options.language] || Rkns.i18n[_this.options.language.substr(0,2)] || {})[_text] || _text; |
| 66 | 125 |
} |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
126 |
if (typeof this.options.user_id !== "undefined") { |
|
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
127 |
this.current_user = this.options.user_id; |
| 4 | 128 |
} |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
129 |
this.$ = Rkns.$("#" + this.options.container); |
| 34 | 130 |
this.$ |
131 |
.addClass("Rk-Main") |
|
| 68 | 132 |
.html(this.template(this)); |
| 23 | 133 |
this.renderer = new Rkns.Renderer.Scene(this); |
| 21 | 134 |
this.tabs = []; |
| 34 | 135 |
this.search_engines = []; |
| 56 | 136 |
|
137 |
this.current_user_list = new Rkns.Models.UsersList(); |
|
138 |
|
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
139 |
if (!this.options.search.length) { |
| 44 | 140 |
this.$.find(".Rk-Web-Search-Form").detach(); |
| 21 | 141 |
} else { |
| 34 | 142 |
var _tmpl = Rkns._.template('<li class="<%= className %>" data-key="<%= key %>"><%= title %></li>'), |
143 |
_select = this.$.find(".Rk-Search-List"), |
|
| 44 | 144 |
_input = this.$.find(".Rk-Web-Search-Input") |
145 |
_form = this.$.find(".Rk-Web-Search-Form"); |
|
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
146 |
Rkns._(this.options.search).each(function(_search, _key) { |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
147 |
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
|
148 |
_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
|
149 |
} |
| 34 | 150 |
}); |
| 24 | 151 |
_select.html( |
| 34 | 152 |
Rkns._(this.search_engines).map(function(_search, _key) { |
| 24 | 153 |
return _tmpl({ |
154 |
key: _key, |
|
| 34 | 155 |
title: _search.getSearchTitle(), |
156 |
className: _search.getBgClass() |
|
| 24 | 157 |
}); |
| 21 | 158 |
}).join("") |
| 34 | 159 |
); |
160 |
_select.find("li").click(function() { |
|
161 |
var _el = Rkns.$(this); |
|
162 |
_this.setSearchEngine(_el.attr("data-key")); |
|
| 24 | 163 |
_form.submit(); |
164 |
}); |
|
165 |
_form.submit(function() { |
|
166 |
if (_input.val()) { |
|
| 34 | 167 |
var _search = _this.search_engine; |
168 |
_search.search(_input.val()); |
|
| 24 | 169 |
} |
170 |
return false; |
|
171 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
172 |
this.$.find(".Rk-Search-Current").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
173 |
function() { _select.slideDown(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
174 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
175 |
this.$.find(".Rk-Search-Select").mouseleave( |
| 70 | 176 |
function() { _select.hide(); } |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
177 |
); |
| 34 | 178 |
this.setSearchEngine(0); |
| 21 | 179 |
} |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
180 |
Rkns._(this.options.bins).each(function(_bin) { |
|
78
af9e716b01bc
Renkan bin configuration now with class names instead of classes themselves
veltr
parents:
75
diff
changeset
|
181 |
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
|
182 |
_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
|
183 |
} |
| 42 | 184 |
}); |
| 24 | 185 |
|
| 21 | 186 |
this.$.find(".Rk-Bins") |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
187 |
.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
|
188 |
var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main"); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
189 |
if (_mainDiv.is(":hidden")) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
190 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
191 |
_mainDiv.slideDown(); |
| 21 | 192 |
} |
|
41
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
193 |
}).on("mouseover", ".Rk-Bin-Item", function(_e) { |
|
9b9aabbb83bb
Today, I learned about the delegate function in jQuery
veltr
parents:
37
diff
changeset
|
194 |
var _t = Rkns.$(this); |
| 26 | 195 |
if (_t && $(_t).attr("data-uri")) { |
196 |
var _models = _this.project.get("nodes").where({ |
|
197 |
uri: $(_t).attr("data-uri") |
|
198 |
}); |
|
199 |
Rkns._(_models).each(function(_model) { |
|
200 |
_this.renderer.highlightModel(_model); |
|
201 |
}); |
|
202 |
} |
|
203 |
}).mouseout(function() { |
|
204 |
_this.renderer.unhighlightAll(); |
|
| 113 | 205 |
}).on("mousemove", ".Rk-Bin-Item", function(e) { |
206 |
try { |
|
207 |
this.dragDrop(); |
|
208 |
} |
|
209 |
catch(err) {} |
|
| 68 | 210 |
}).on("dragstart", ".Rk-Bin-Item", function(e) { |
| 113 | 211 |
var div = document.createElement('div'); |
212 |
div.appendChild(this.cloneNode(true)); |
|
213 |
try { |
|
214 |
e.originalEvent.dataTransfer.setData("text/html",div.innerHTML); |
|
215 |
} |
|
216 |
catch(err) { |
|
217 |
e.originalEvent.dataTransfer.setData("text",div.innerHTML); |
|
218 |
} |
|
| 20 | 219 |
}); |
| 21 | 220 |
Rkns.$(window).resize(function() { |
221 |
_this.resizeBins(); |
|
| 2 | 222 |
}); |
| 44 | 223 |
|
224 |
this.$.find(".Rk-Bins-Search-Input").on("change keyup paste input", function() { |
|
225 |
var val = Rkns.$(this).val(); |
|
226 |
Rkns._(_this.tabs).each(function(tab) { |
|
227 |
tab.render(val); |
|
228 |
}); |
|
229 |
}); |
|
230 |
this.$.find(".Rk-Bins-Search-Form").submit(function() { |
|
231 |
return false |
|
232 |
}); |
|
| 1 | 233 |
} |
234 |
||
| 20 | 235 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
236 |
'<% if (options.show_bins) { %><div class="Rk-Bins"><div class="Rk-Bins-Head"><h2 class="Rk-Bins-Title"><%- translate("Select contents:")%></h2>' |
| 68 | 237 |
+ '<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 | 238 |
+ '<div class="Rk-Search-Select"><div class="Rk-Search-Current"></div><ul class="Rk-Search-List"></ul></div>' |
| 119 | 239 |
+ '<input type="submit" value="" class="Rk-Web-Search-Submit Rk-Search-Submit" title="<%- translate("Search the Web") %>" /></form>' |
| 68 | 240 |
+ '<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") %>" />' |
| 119 | 241 |
+ '<input type="submit" value="" class="Rk-Bins-Search-Submit Rk-Search-Submit" title="<%- translate("Search in Bins") %>" /></form></div>' |
|
114
110f99eb417e
moved options to defaults.js and improved read-only switching
veltr
parents:
113
diff
changeset
|
242 |
+ '<ul class="Rk-Bin-List"></ul></div><% } %><div class="Rk-Render Rk-Render-<% if (options.show_bins) { %>Panel<% } else { %>Full<% } %>"></div>' |
| 20 | 243 |
); |
| 18 | 244 |
|
| 111 | 245 |
Rkns.Renkan.prototype.onStatusChange = function() { |
246 |
this.renderer.onStatusChange(); |
|
247 |
} |
|
248 |
||
| 21 | 249 |
|
| 34 | 250 |
Rkns.Renkan.prototype.setSearchEngine = function(_key) { |
251 |
this.search_engine = this.search_engines[_key]; |
|
252 |
this.$.find(".Rk-Search-Current").attr("class","Rk-Search-Current " + this.search_engine.getBgClass()); |
|
253 |
} |
|
254 |
||
| 21 | 255 |
Rkns.Renkan.prototype.resizeBins = function() { |
| 75 | 256 |
var _d = + this.$.find(".Rk-Bins-Head").outerHeight(); |
| 44 | 257 |
this.$.find(".Rk-Bin-Title:visible").each(function() { |
| 26 | 258 |
_d += Rkns.$(this).outerHeight(); |
259 |
}); |
|
| 21 | 260 |
this.$.find(".Rk-Bin-Main").css({ |
261 |
height: this.$.find(".Rk-Bins").height() - _d |
|
262 |
}); |
|
263 |
} |
|
264 |
||
| 1 | 265 |
/* Utility functions */ |
266 |
||
267 |
Rkns.Utils = { |
|
268 |
_ID_AUTO_INCREMENT : 0, |
|
269 |
_ID_BASE : (function(_d) { |
|
270 |
function pad(n){return n<10 ? '0'+n : n} |
|
271 |
function fillrand(n) { |
|
272 |
var _res = '' |
|
273 |
for (var i=0; i<n; i++) { |
|
274 |
_res += Math.floor(16*Math.random()).toString(16); |
|
275 |
} |
|
276 |
return _res; |
|
277 |
} |
|
278 |
return _d.getUTCFullYear() + '-' |
|
279 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
280 |
+ pad(_d.getUTCDate()) + '-' |
|
281 |
+ fillrand(16); |
|
282 |
})(new Date()), |
|
283 |
getUID : function(_base) { |
|
284 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
285 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
286 |
while (_n.length < 4) { |
|
287 |
_n = '0' + _n |
|
288 |
} |
|
289 |
return _base + this._ID_BASE + '-' + _n; |
|
290 |
}, |
|
291 |
inherit : function(_baseClass, _callbefore) { |
|
292 |
var _class = function() { |
|
293 |
if (typeof _callbefore === "function") { |
|
294 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
295 |
} |
|
| 28 | 296 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
297 |
if (typeof this._init == "function") { |
|
298 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
| 1 | 299 |
} |
300 |
} |
|
301 |
_class.prototype = new _baseClass(); |
|
302 |
return _class; |
|
303 |
} |
|
304 |
} |