|
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 |
|
19 /* Declaring the Renkan Namespace Rkns */ |
|
20 |
|
21 Rkns = {} |
|
22 |
|
23 Rkns.$ = jQuery; |
|
24 |
|
25 Rkns._ = _; |
|
26 |
|
27 Rkns.Serializers = {}; |
|
28 |
|
29 Rkns.Serializers._Base = function(_project) { |
|
30 if (typeof _project !== "undefined") { |
|
31 this._project = _project; |
|
32 this._callbackQueue = []; |
|
33 this._loaded = false; |
|
34 } |
|
35 } |
|
36 |
|
37 Rkns.Serializers._Base.prototype.deserialize = function() {} |
|
38 |
|
39 Rkns.Serializers._Base.prototype.deferCallback = function(_callback) { |
|
40 var _this = this; |
|
41 Rkns._.defer(function() { |
|
42 _callback.call(_this); |
|
43 }); |
|
44 } |
|
45 |
|
46 Rkns.Serializers._Base.prototype.handleCallbacks = function() { |
|
47 this._loaded = true; |
|
48 while (this._callbackQueue.length) { |
|
49 this.deferCallback(this._callbackQueue.splice(0,1)[0]); |
|
50 } |
|
51 } |
|
52 |
|
53 Rkns.Serializers._Base.prototype.onLoad = function(_callback) { |
|
54 if (this._loaded) { |
|
55 this.deferCallback(_callback); |
|
56 } else { |
|
57 this._callbackQueue.push(_callback); |
|
58 } |
|
59 } |
|
60 |
|
61 Rkns.Renderers = {}; |
|
62 |
|
63 Rkns.Renderers._Base = function(_project) { |
|
64 if (typeof _project !== "undefined") { |
|
65 this._project = _project; |
|
66 } |
|
67 } |
|
68 |
|
69 Rkns.Project = function(_opts) { |
|
70 if (typeof _opts.serializer == "undefined") { |
|
71 _opts.serializer = "BasicJson"; |
|
72 } |
|
73 if (typeof _opts.renderer == "undefined") { |
|
74 _opts.renderer = "Paper"; |
|
75 } |
|
76 this._opts = _opts; |
|
77 this.users = new Rkns.Model.List(); |
|
78 this.nodes = new Rkns.Model.List(); |
|
79 this.edges = new Rkns.Model.List(); |
|
80 this.serializer = new Rkns.Serializers[_opts.serializer](this); |
|
81 this.renderer = new Rkns.Renderers[_opts.renderer](this); |
|
82 var _this = this; |
|
83 this.serializer.onLoad(function() { |
|
84 _this.renderer.draw(); |
|
85 }) |
|
86 } |
|
87 |
|
88 /* Utility functions */ |
|
89 |
|
90 Rkns.Utils = { |
|
91 _ID_AUTO_INCREMENT : 0, |
|
92 _ID_BASE : (function(_d) { |
|
93 function pad(n){return n<10 ? '0'+n : n} |
|
94 function fillrand(n) { |
|
95 var _res = '' |
|
96 for (var i=0; i<n; i++) { |
|
97 _res += Math.floor(16*Math.random()).toString(16); |
|
98 } |
|
99 return _res; |
|
100 } |
|
101 return _d.getUTCFullYear() + '-' |
|
102 + pad(_d.getUTCMonth()+1) + '-' |
|
103 + pad(_d.getUTCDate()) + '-' |
|
104 + fillrand(16); |
|
105 })(new Date()), |
|
106 getUID : function(_base) { |
|
107 var _n = (++this._ID_AUTO_INCREMENT).toString(16), |
|
108 _base = (typeof _base === "undefined" ? "" : _base + "-" ); |
|
109 while (_n.length < 4) { |
|
110 _n = '0' + _n |
|
111 } |
|
112 return _base + this._ID_BASE + '-' + _n; |
|
113 }, |
|
114 inherit : function(_baseClass, _callbefore) { |
|
115 var _class = function() { |
|
116 if (typeof _callbefore === "function") { |
|
117 _callbefore.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
118 } |
|
119 if (typeof _baseClass.prototype._init !== "function") { |
|
120 _baseClass.prototype._init = function() {} |
|
121 } |
|
122 _baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
123 this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
124 } |
|
125 _class.prototype = new _baseClass(); |
|
126 return _class; |
|
127 } |
|
128 } |