|
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.RemoteModels = {}; |
|
1
|
37 |
|
|
20
|
38 |
Rkns.RemoteModels._Base = function(_project, _opts) { |
|
1
|
39 |
if (typeof _project !== "undefined") { |
|
|
40 |
this._project = _project; |
|
|
41 |
this._callbackQueue = []; |
|
|
42 |
this._loaded = false; |
|
|
43 |
} |
|
|
44 |
} |
|
|
45 |
|
|
20
|
46 |
Rkns.RemoteModels._Base.prototype.fullSave |
|
|
47 |
= Rkns.RemoteModels._Base.prototype.addUser |
|
|
48 |
= Rkns.RemoteModels._Base.prototype.addNode |
|
|
49 |
= Rkns.RemoteModels._Base.prototype.addEdge |
|
|
50 |
= Rkns.RemoteModels._Base.prototype.updateNode |
|
|
51 |
= Rkns.RemoteModels._Base.prototype.updateEdge |
|
|
52 |
= Rkns.RemoteModels._Base.prototype.removeNode |
|
|
53 |
= Rkns.RemoteModels._Base.prototype.removeEdge |
|
|
54 |
= function() {} |
|
1
|
55 |
|
|
20
|
56 |
Rkns.RemoteModels._Base.prototype.deferCallback = function(_callback) { |
|
1
|
57 |
var _this = this; |
|
|
58 |
Rkns._.defer(function() { |
|
|
59 |
_callback.call(_this); |
|
|
60 |
}); |
|
|
61 |
} |
|
|
62 |
|
|
20
|
63 |
Rkns.RemoteModels._Base.prototype.handleCallbacks = function() { |
|
1
|
64 |
this._loaded = true; |
|
|
65 |
while (this._callbackQueue.length) { |
|
|
66 |
this.deferCallback(this._callbackQueue.splice(0,1)[0]); |
|
|
67 |
} |
|
|
68 |
} |
|
|
69 |
|
|
20
|
70 |
Rkns.RemoteModels._Base.prototype.onLoad = function(_callback) { |
|
1
|
71 |
if (this._loaded) { |
|
|
72 |
this.deferCallback(_callback); |
|
|
73 |
} else { |
|
|
74 |
this._callbackQueue.push(_callback); |
|
|
75 |
} |
|
|
76 |
} |
|
|
77 |
|
|
20
|
78 |
Rkns.RemoteModels._Base.prototype.save = function() {} |
|
|
79 |
|
|
|
80 |
Rkns.Bins = {} |
|
|
81 |
|
|
|
82 |
Rkns.Bins._Base = function(_project) { |
|
|
83 |
if (typeof _project !== "undefined") { |
|
|
84 |
this._project = _project; |
|
|
85 |
} |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
Rkns.Bins._Base.prototype.baseTemplate = ''; |
|
4
|
89 |
|
|
20
|
90 |
Rkns.Bins._Base.prototype.addTab = function(_title) { |
|
|
91 |
var _tabDiv = Rkns.$('<div>'); |
|
|
92 |
_tabDiv.addClass('Rk-TabDiv') |
|
|
93 |
.css("display","none") |
|
|
94 |
.appendTo('.Rk-TabDivs'); |
|
|
95 |
var _tabButton = Rkns.$('<li>'); |
|
|
96 |
_tabButton.addClass('Rk-TabButton') |
|
|
97 |
.html(_title) |
|
|
98 |
.click(function() { |
|
|
99 |
Rkns.$('.Rk-TabButton').removeClass("active"); |
|
|
100 |
Rkns.$(this).addClass("active"); |
|
|
101 |
Rkns.$('.Rk-TabDiv').hide(); |
|
|
102 |
_tabDiv.show(); |
|
|
103 |
}) |
|
|
104 |
.appendTo('.Rk-TabButtons'); |
|
|
105 |
return { |
|
|
106 |
button: _tabButton, |
|
|
107 |
contents: _tabDiv |
|
|
108 |
} |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
/* Point of entry */ |
|
|
112 |
|
|
|
113 |
Rkns.Renkan = function(_opts) { |
|
|
114 |
if (typeof _opts.remotemodel == "undefined") { |
|
|
115 |
_opts.remotemodel = "BasicJson"; |
|
1
|
116 |
} |
|
5
|
117 |
if (typeof _opts.language == "undefined" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
|
118 |
_opts.language = "en"; |
|
|
119 |
} |
|
20
|
120 |
if (typeof _opts.container == "undefined") { |
|
|
121 |
_opts.container = "renkan"; |
|
|
122 |
} |
|
|
123 |
this.project = new Rkns.ViewModel.Project(); |
|
|
124 |
this.project.l10n = Rkns.i18n[_opts.language]; |
|
|
125 |
if (typeof _opts.user === "object") { |
|
|
126 |
this.current_user = this.project.addUser(_opts.user) |
|
4
|
127 |
} |
|
20
|
128 |
Rkns.$("#" + _opts.container).html(this.template()); |
|
|
129 |
this.project.remotemodel = new Rkns.RemoteModels[_opts.remotemodel](this.project, _opts); |
|
|
130 |
this.project.renderer = new Rkns.Renderer.Scene(this.project, _opts); |
|
1
|
131 |
var _this = this; |
|
20
|
132 |
/* if (typeof _opts.bins === "object") { |
|
|
133 |
this.bins = Rkns._(_opts.bins).map(function(_type) { |
|
|
134 |
return new Rkns.Bins[_type](_this); |
|
|
135 |
}); |
|
|
136 |
Rkns.$('.Rk-TabButton:last').addClass("active"); |
|
|
137 |
Rkns.$('.Rk-TabDiv:last').show(); |
|
|
138 |
} */ |
|
|
139 |
this.project.remotemodel.onLoad(function() { |
|
|
140 |
if (typeof _this.project.current_user === "undefined") { |
|
|
141 |
_this.project.current_user = _this.project.users[0]; |
|
4
|
142 |
} |
|
20
|
143 |
_this.project.renderer.draw(); |
|
2
|
144 |
}); |
|
1
|
145 |
} |
|
|
146 |
|
|
20
|
147 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
|
148 |
'<div class="Rk-Bins"></div><div class="Rk-Render"></div>' |
|
|
149 |
); |
|
18
|
150 |
|
|
1
|
151 |
/* Utility functions */ |
|
|
152 |
|
|
|
153 |
Rkns.Utils = { |
|
|
154 |
_ID_AUTO_INCREMENT : 0, |
|
|
155 |
_ID_BASE : (function(_d) { |
|
|
156 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
157 |
function fillrand(n) { |
|
|
158 |
var _res = '' |
|
|
159 |
for (var i=0; i<n; i++) { |
|
|
160 |
_res += Math.floor(16*Math.random()).toString(16); |
|
|
161 |
} |
|
|
162 |
return _res; |
|
|
163 |
} |
|
|
164 |
return _d.getUTCFullYear() + '-' |
|
|
165 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
|
166 |
+ pad(_d.getUTCDate()) + '-' |
|
|
167 |
+ fillrand(16); |
|
|
168 |
})(new Date()), |
|
|
169 |
getUID : function(_base) { |
|
|
170 |
var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
|
171 |
_base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
|
172 |
while (_n.length < 4) { |
|
|
173 |
_n = '0' + _n |
|
|
174 |
} |
|
|
175 |
return _base + this._ID_BASE + '-' + _n; |
|
|
176 |
}, |
|
|
177 |
inherit : function(_baseClass, _callbefore) { |
|
|
178 |
var _class = function() { |
|
|
179 |
if (typeof _callbefore === "function") { |
|
|
180 |
_callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
181 |
} |
|
|
182 |
if (typeof _baseClass.prototype._init !== "function") { |
|
|
183 |
_baseClass.prototype._init = function() {} |
|
|
184 |
} |
|
|
185 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
186 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
187 |
} |
|
|
188 |
_class.prototype = new _baseClass(); |
|
|
189 |
return _class; |
|
|
190 |
} |
|
|
191 |
} |