|
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.$); |
|
|
51 |
this.renkan.resizeBins(); |
|
20
|
52 |
} |
|
|
53 |
} |
|
|
54 |
/* Point of entry */ |
|
|
55 |
|
|
|
56 |
Rkns.Renkan = function(_opts) { |
|
21
|
57 |
if (typeof _opts.remotemodel !== "string") { |
|
|
58 |
_opts.remotemodel = "FullJson"; |
|
1
|
59 |
} |
|
21
|
60 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
5
|
61 |
_opts.language = "en"; |
|
|
62 |
} |
|
21
|
63 |
if (typeof _opts.container !== "string") { |
|
20
|
64 |
_opts.container = "renkan"; |
|
|
65 |
} |
|
21
|
66 |
if (typeof _opts.search !== "object" || !_opts.search) { |
|
|
67 |
_opts.search = []; |
|
|
68 |
} |
|
23
|
69 |
this.project = new Rkns.Models.Project(); |
|
|
70 |
this.l10n = Rkns.i18n[_opts.language]; |
|
|
71 |
if (typeof _opts.user_id !== "undefined") { |
|
|
72 |
this.current_user = _opts.user_id; |
|
4
|
73 |
} |
|
21
|
74 |
this.$ = Rkns.$("#" + _opts.container); |
|
|
75 |
this.$.html(this.template()); |
|
23
|
76 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
21
|
77 |
this.tabs = []; |
|
|
78 |
this.selected_bin_item = undefined; |
|
|
79 |
this.mousedown = false; |
|
1
|
80 |
var _this = this; |
|
21
|
81 |
this.$.mouseup(function() { |
|
|
82 |
_this.selected_bin_item = undefined; |
|
|
83 |
}); |
|
|
84 |
if (!_opts.search.length) { |
|
|
85 |
this.$.find(".Rk-Search-Form").detach(); |
|
|
86 |
} else { |
|
|
87 |
var _tmpl = Rkns._.template('<option value="<%= name %>"><%= name %></option>'); |
|
|
88 |
this.$.find(".Rk-Search-Select").html( |
|
|
89 |
Rkns._(_opts.search).map(function(_name) { |
|
|
90 |
return _tmpl({name:_name}); |
|
|
91 |
}).join("") |
|
|
92 |
); |
|
|
93 |
} |
|
|
94 |
this.$.find(".Rk-Search-Form").submit(function() { |
|
|
95 |
_this.tabs.push( |
|
|
96 |
new Rkns.Bins[_this.$.find(".Rk-Search-Select").val()]( |
|
|
97 |
_this, |
|
|
98 |
{ |
|
|
99 |
search: _this.$.find(".Rk-Search-Input").val() |
|
|
100 |
} |
|
|
101 |
) |
|
|
102 |
); |
|
|
103 |
return false; |
|
|
104 |
}); |
|
|
105 |
this.$.find(".Rk-Bins") |
|
|
106 |
.click(function(_e) { |
|
|
107 |
if (_e.target.className == "Rk-Bin-Title") { |
|
|
108 |
var _mainDiv = Rkns.$(_e.target).siblings(".Rk-Bin-Main"); |
|
|
109 |
if (_mainDiv.is(":hidden")) { |
|
|
110 |
_this.$.find(".Rk-Bin-Main").slideUp(); |
|
|
111 |
_mainDiv.slideDown(); |
|
|
112 |
} |
|
|
113 |
} |
|
|
114 |
}).mousedown(function(_e) { |
|
|
115 |
var _t = Rkns.$(_e.target); |
|
|
116 |
while (!_t.is(".Rk-Bins,.Rk-Bin-Item")) { |
|
|
117 |
_t = _t.parent(); |
|
|
118 |
} |
|
|
119 |
if (_t.is(".Rk-Bin-Item")) { |
|
|
120 |
_this.selected_bin_item = { |
|
|
121 |
uri : $(_t).attr("data-uri"), |
|
|
122 |
title : $(_t).attr("data-title"), |
|
|
123 |
description : $(_t).attr("data-description") |
|
|
124 |
} |
|
|
125 |
return false; |
|
|
126 |
} |
|
20
|
127 |
}); |
|
21
|
128 |
Rkns.$(window).resize(function() { |
|
|
129 |
_this.resizeBins(); |
|
2
|
130 |
}); |
|
1
|
131 |
} |
|
|
132 |
|
|
20
|
133 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
21
|
134 |
'<div class="Rk-Bins">' |
|
|
135 |
+ '<form class="Rk-Search-Form"><input class="Rk-Search-Input" type="search" placeholder="Search" /><select class="Rk-Search-Select"></select></form>' |
|
|
136 |
+ '<ul class="Rk-Bin-List"></ul></div><div class="Rk-Render"></div>' |
|
20
|
137 |
); |
|
18
|
138 |
|
|
21
|
139 |
|
|
|
140 |
Rkns.Renkan.prototype.resizeBins = function() { |
|
|
141 |
var _titles = this.$.find(".Rk-Bin-Title"), |
|
|
142 |
_d = _titles.length * _titles.outerHeight() + this.$.find(".Rk-Search-Form").outerHeight(); |
|
|
143 |
this.$.find(".Rk-Bin-Main").css({ |
|
|
144 |
height: this.$.find(".Rk-Bins").height() - _d |
|
|
145 |
}); |
|
|
146 |
} |
|
|
147 |
|
|
1
|
148 |
/* Utility functions */ |
|
|
149 |
|
|
|
150 |
Rkns.Utils = { |
|
|
151 |
_ID_AUTO_INCREMENT : 0, |
|
|
152 |
_ID_BASE : (function(_d) { |
|
|
153 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
154 |
function fillrand(n) { |
|
|
155 |
var _res = '' |
|
|
156 |
for (var i=0; i<n; i++) { |
|
|
157 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
158 |
} |
|
|
159 |
return _res; |
|
|
160 |
} |
|
|
161 |
return _d.getUTCFullYear() + '-' |
|
|
162 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
163 |
+ pad(_d.getUTCDate()) + '-' |
|
|
164 |
+ fillrand(16); |
|
|
165 |
})(new Date()), |
|
|
166 |
getUID : function(_base) { |
|
|
167 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
168 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
169 |
while (_n.length < 4) { |
|
|
170 |
_n = '0' + _n |
|
|
171 |
} |
|
|
172 |
return _base + this._ID_BASE + '-' + _n; |
|
|
173 |
}, |
|
|
174 |
inherit : function(_baseClass, _callbefore) { |
|
|
175 |
var _class = function() { |
|
|
176 |
if (typeof _callbefore === "function") { |
|
|
177 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
178 |
} |
|
|
179 |
if (typeof _baseClass.prototype._init !== "function") { |
|
|
180 |
_baseClass.prototype._init = function() {} |
|
|
181 |
} |
|
|
182 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
183 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
184 |
} |
|
|
185 |
_class.prototype = new _baseClass(); |
|
|
186 |
return _class; |
|
|
187 |
} |
|
|
188 |
} |