|
1
|
1 |
/* |
|
|
2 |
* Copyright 2012 Institut de recherche et d'innovation |
|
|
3 |
* contributor(s) : Samuel Huron, Raphael Velt |
|
|
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 |
|
|
3
|
21 |
Rkns = { |
|
15
|
22 |
_MIN_DRAG_DISTANCE: 2, |
|
4
|
23 |
_NODE_RADIUS: 20, |
|
|
24 |
_NODE_FONT_SIZE: 14, |
|
|
25 |
_ARROW_LENGTH: 20, |
|
|
26 |
_ARROW_WIDTH: 15, |
|
|
27 |
_RENDER: 1, |
|
|
28 |
_SAVE: 2, |
|
|
29 |
_RENDER_AND_SAVE: 3 |
|
3
|
30 |
} |
|
1
|
31 |
|
|
|
32 |
Rkns.$ = jQuery; |
|
|
33 |
|
|
|
34 |
Rkns._ = _; |
|
|
35 |
|
|
20
|
36 |
Rkns.Bins = {} |
|
|
37 |
|
|
21
|
38 |
Rkns.Bins._Base = function(_renkan, _opts) { |
|
|
39 |
if (typeof _renkan !== "undefined") { |
|
|
40 |
this.renkan = _renkan; |
|
|
41 |
this.renkan.$.find(".Rk-Bin-Main").hide(); |
|
|
42 |
this.$ = Rkns.$('<li>') |
|
|
43 |
.addClass("Rk-Bin") |
|
|
44 |
.appendTo(_renkan.$.find(".Rk-Bin-List")); |
|
|
45 |
this.title_$ = Rkns.$('<h2>') |
|
|
46 |
.addClass("Rk-Bin-Title") |
|
|
47 |
.appendTo(this.$); |
|
|
48 |
this.main_$ = Rkns.$('<div>') |
|
|
49 |
.addClass("Rk-Bin-Main") |
|
|
50 |
.appendTo(this.$); |
|
26
|
51 |
this.title_$.html(_opts.title || '(new bin)'); |
|
21
|
52 |
this.renkan.resizeBins(); |
|
20
|
53 |
} |
|
|
54 |
} |
|
|
55 |
/* Point of entry */ |
|
|
56 |
|
|
|
57 |
Rkns.Renkan = function(_opts) { |
|
21
|
58 |
if (typeof _opts.remotemodel !== "string") { |
|
|
59 |
_opts.remotemodel = "FullJson"; |
|
1
|
60 |
} |
|
21
|
61 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
5
|
62 |
_opts.language = "en"; |
|
|
63 |
} |
|
21
|
64 |
if (typeof _opts.container !== "string") { |
|
20
|
65 |
_opts.container = "renkan"; |
|
|
66 |
} |
|
21
|
67 |
if (typeof _opts.search !== "object" || !_opts.search) { |
|
|
68 |
_opts.search = []; |
|
|
69 |
} |
|
23
|
70 |
this.project = new Rkns.Models.Project(); |
|
|
71 |
this.l10n = Rkns.i18n[_opts.language]; |
|
|
72 |
if (typeof _opts.user_id !== "undefined") { |
|
|
73 |
this.current_user = _opts.user_id; |
|
4
|
74 |
} |
|
21
|
75 |
this.$ = Rkns.$("#" + _opts.container); |
|
|
76 |
this.$.html(this.template()); |
|
23
|
77 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
21
|
78 |
this.tabs = []; |
|
|
79 |
this.selected_bin_item = undefined; |
|
1
|
80 |
var _this = this; |
|
21
|
81 |
this.$.mouseup(function() { |
|
|
82 |
_this.selected_bin_item = undefined; |
|
26
|
83 |
_this.$.find(".Rk-Bin-Item.dragging").removeClass("dragging"); |
|
21
|
84 |
}); |
|
|
85 |
if (!_opts.search.length) { |
|
|
86 |
this.$.find(".Rk-Search-Form").detach(); |
|
|
87 |
} else { |
|
24
|
88 |
var _tmpl = Rkns._.template('<option value="<%= key %>"><%= value.title %></option>'), |
|
|
89 |
_select = this.$.find(".Rk-Search-Select"), |
|
|
90 |
_input = this.$.find(".Rk-Search-Input") |
|
|
91 |
_form = this.$.find(".Rk-Search-Form"); |
|
|
92 |
_select.html( |
|
|
93 |
Rkns._(_opts.search).map(function(_value, _key) { |
|
|
94 |
return _tmpl({ |
|
|
95 |
key: _key, |
|
|
96 |
value: _value |
|
|
97 |
}); |
|
21
|
98 |
}).join("") |
|
24
|
99 |
).change(function() { |
|
|
100 |
_form.submit(); |
|
|
101 |
}); |
|
|
102 |
_form.submit(function() { |
|
|
103 |
if (_input.val()) { |
|
|
104 |
var _search = _opts.search[_select.val()]; |
|
|
105 |
_this.tabs.push( |
|
|
106 |
new _search.bin( |
|
|
107 |
_this, |
|
|
108 |
Rkns._({ search: _input.val() }).defaults(_search) |
|
|
109 |
) |
|
|
110 |
); |
|
|
111 |
} |
|
|
112 |
return false; |
|
|
113 |
|
|
|
114 |
}); |
|
21
|
115 |
} |
|
26
|
116 |
Rkns._(_opts.bins).each(function(_bin) { |
|
|
117 |
_this.tabs.push(new _bin.bin(_this, _bin)); |
|
|
118 |
}) |
|
|
119 |
|
|
|
120 |
/* The bins are not yet populated, but we want to bind dragging functions |
|
|
121 |
* here, as it will be easier than in the bins. Therefore, we bind to Rk-Bins |
|
|
122 |
* and look where the click was. */ |
|
|
123 |
function findItem(_event) { |
|
|
124 |
var _t = Rkns.$(_event.target); |
|
|
125 |
while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) { |
|
|
126 |
_t = _t.parent(); |
|
|
127 |
} |
|
|
128 |
if (_t.is(".Rk-Bin-Item")) { |
|
|
129 |
return _t |
|
|
130 |
} else { |
|
|
131 |
return null; |
|
|
132 |
} |
|
|
133 |
} |
|
24
|
134 |
|
|
21
|
135 |
this.$.find(".Rk-Bins") |
|
|
136 |
.click(function(_e) { |
|
|
137 |
if (_e.target.className == "Rk-Bin-Title") { |
|
|
138 |
var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main"); |
|
|
139 |
if (_mainDiv.is(":hidden")) { |
|
|
140 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
|
141 |
_mainDiv.slideDown(); |
|
|
142 |
} |
|
|
143 |
} |
|
|
144 |
}).mousedown(function(_e) { |
|
26
|
145 |
var _t = findItem(_e); |
|
|
146 |
if (_t) { |
|
|
147 |
_t.addClass("dragging"); |
|
21
|
148 |
_this.selected_bin_item = { |
|
|
149 |
uri : $(_t).attr("data-uri"), |
|
|
150 |
title : $(_t).attr("data-title"), |
|
|
151 |
description : $(_t).attr("data-description") |
|
|
152 |
} |
|
|
153 |
return false; |
|
|
154 |
} |
|
26
|
155 |
}).mouseover(function(_e) { |
|
|
156 |
var _t = findItem(_e); |
|
|
157 |
if (_t && $(_t).attr("data-uri")) { |
|
|
158 |
var _models = _this.project.get("nodes").where({ |
|
|
159 |
uri: $(_t).attr("data-uri") |
|
|
160 |
}); |
|
|
161 |
Rkns._(_models).each(function(_model) { |
|
|
162 |
_this.renderer.highlightModel(_model); |
|
|
163 |
}); |
|
|
164 |
} |
|
|
165 |
}).mouseout(function() { |
|
|
166 |
_this.renderer.unhighlightAll(); |
|
20
|
167 |
}); |
|
21
|
168 |
Rkns.$(window).resize(function() { |
|
|
169 |
_this.resizeBins(); |
|
2
|
170 |
}); |
|
1
|
171 |
} |
|
|
172 |
|
|
20
|
173 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
21
|
174 |
'<div class="Rk-Bins">' |
|
|
175 |
+ '<form class="Rk-Search-Form"><input class="Rk-Search-Input" type="search" placeholder="Search" /><select class="Rk-Search-Select"></select></form>' |
|
|
176 |
+ '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render"></div>' |
|
20
|
177 |
); |
|
18
|
178 |
|
|
21
|
179 |
|
|
|
180 |
Rkns.Renkan.prototype.resizeBins = function() { |
|
26
|
181 |
var _d = + this.$.find(".Rk-Search-Form").outerHeight(); |
|
|
182 |
this.$.find(".Rk-Bin-Title").each(function() { |
|
|
183 |
_d += Rkns.$(this).outerHeight(); |
|
|
184 |
}); |
|
21
|
185 |
this.$.find(".Rk-Bin-Main").css({ |
|
|
186 |
height: this.$.find(".Rk-Bins").height() - _d |
|
|
187 |
}); |
|
|
188 |
} |
|
|
189 |
|
|
1
|
190 |
/* Utility functions */ |
|
|
191 |
|
|
|
192 |
Rkns.Utils = { |
|
|
193 |
_ID_AUTO_INCREMENT : 0, |
|
|
194 |
_ID_BASE : (function(_d) { |
|
|
195 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
196 |
function fillrand(n) { |
|
|
197 |
var _res = '' |
|
|
198 |
for (var i=0; i<n; i++) { |
|
|
199 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
200 |
} |
|
|
201 |
return _res; |
|
|
202 |
} |
|
|
203 |
return _d.getUTCFullYear() + '-' |
|
|
204 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
205 |
+ pad(_d.getUTCDate()) + '-' |
|
|
206 |
+ fillrand(16); |
|
|
207 |
})(new Date()), |
|
|
208 |
getUID : function(_base) { |
|
|
209 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
210 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
211 |
while (_n.length < 4) { |
|
|
212 |
_n = '0' + _n |
|
|
213 |
} |
|
|
214 |
return _base + this._ID_BASE + '-' + _n; |
|
|
215 |
}, |
|
|
216 |
inherit : function(_baseClass, _callbefore) { |
|
|
217 |
var _class = function() { |
|
|
218 |
if (typeof _callbefore === "function") { |
|
|
219 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
220 |
} |
|
|
221 |
if (typeof _baseClass.prototype._init !== "function") { |
|
|
222 |
_baseClass.prototype._init = function() {} |
|
|
223 |
} |
|
|
224 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
225 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
226 |
} |
|
|
227 |
_class.prototype = new _baseClass(); |
|
|
228 |
return _class; |
|
|
229 |
} |
|
|
230 |
} |