| author | veltr |
| Wed, 21 Nov 2012 16:33:51 +0100 | |
| changeset 983 | 97fef7a4b189 |
| parent 980 | 9ee8c00ae5b7 |
| child 986 | f9d51dd4a3fe |
| permissions | -rw-r--r-- |
| 917 | 1 |
/* TODO: Separate Project-specific data from Source */ |
2 |
||
| 854 | 3 |
/* model.js is where data is stored in a standard form, whatever the serializer */ |
| 972 | 4 |
IriSP.Model = (function (ns) { |
| 980 | 5 |
|
6 |
function pad(n, x, b) { |
|
7 |
b = b || 10; |
|
8 |
var s = (x).toString(b); |
|
9 |
while (s.length < n) { |
|
10 |
s = "0" + s; |
|
11 |
} |
|
12 |
return s; |
|
13 |
} |
|
14 |
|
|
15 |
function rand16(n) { |
|
16 |
return pad(n, Math.floor(Math.random()*Math.pow(16,n)), 16); |
|
17 |
} |
|
18 |
|
|
19 |
var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000); |
|
| 983 | 20 |
|
21 |
var charsub = [ |
|
22 |
[ 'a', 'á', 'à', 'â', 'ä' ], |
|
23 |
[ 'c', 'ç' ], |
|
24 |
[ 'e', 'é', 'è', 'ê', 'ë' ], |
|
25 |
[ 'i', 'í', 'ì', 'î', 'ï' ], |
|
26 |
[ 'o', 'ó', 'ò', 'ô', 'ö' ] |
|
27 |
]; |
|
28 |
|
|
29 |
var removeChars = [ |
|
30 |
String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), |
|
31 |
"{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", |
|
32 |
",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" |
|
33 |
] |
|
34 |
|
|
| 970 | 35 |
var Model = { |
| 868 | 36 |
_SOURCE_STATUS_EMPTY : 0, |
37 |
_SOURCE_STATUS_WAITING : 1, |
|
38 |
_SOURCE_STATUS_READY : 2, |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
39 |
getUID : function() { |
| 980 | 40 |
return uidbase + pad(4, (++uidincrement % 0x10000), 16) + "-" + rand16(4) + "-" + rand16(6) + rand16(6); |
| 860 | 41 |
}, |
| 983 | 42 |
isLocalURL : function(url) { |
43 |
var matches = url.match(/^(\w+:)\/\/([^/]+)/); |
|
44 |
if (matches) { |
|
45 |
return(matches[1] === document.location.protocol && matches[2] === document.location.host) |
|
46 |
} |
|
47 |
return true; |
|
48 |
}, |
|
| 973 | 49 |
regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
50 |
var _testOnly = _testOnly || false, |
|
51 |
_iexact = _iexact || false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
52 |
function escapeText(_text) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
53 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
54 |
} |
| 925 | 55 |
var _source = |
56 |
typeof _textOrArray === "string" |
|
57 |
? escapeText(_textOrArray) |
|
| 973 | 58 |
: ns._(_textOrArray).map(escapeText).join("|"), |
59 |
_flags = 'im'; |
|
60 |
if (!_testOnly) { |
|
61 |
_source = '(' + _source + ')'; |
|
62 |
_flags += 'g'; |
|
| 925 | 63 |
} |
| 973 | 64 |
if (_iexact) { |
65 |
_source = '^' + _source + '$'; |
|
66 |
} |
|
67 |
return new RegExp( _source, _flags); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
68 |
}, |
| 983 | 69 |
fullTextRegexps: function(_text) { |
70 |
var remsrc = "[\\" + removeChars.join("\\") + "]", |
|
71 |
remrx = new RegExp(remsrc,"gm"), |
|
72 |
txt = _text.toLowerCase().replace(remrx,"") |
|
73 |
res = [], |
|
74 |
charsrc = ns._(charsub).map(function(c) { |
|
75 |
return "(" + c.join("|") + ")"; |
|
76 |
}), |
|
77 |
charsrx = ns._(charsrc).map(function(c) { |
|
78 |
return new RegExp(c); |
|
79 |
}), |
|
80 |
src = ""; |
|
81 |
for (var j = 0; j < txt.length; j++) { |
|
82 |
if (j) { |
|
83 |
src += remsrc + "*"; |
|
84 |
} |
|
85 |
var l = txt[j]; |
|
86 |
ns._(charsrc).each(function(v, k) { |
|
87 |
l = l.replace(charsrx[k], v); |
|
88 |
}); |
|
89 |
src += l; |
|
90 |
} |
|
91 |
return "(" + src + ")"; |
|
92 |
}, |
|
| 860 | 93 |
isoToDate : function(_str) { |
94 |
// http://delete.me.uk/2005/03/iso8601.html |
|
95 |
var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?"; |
|
96 |
var d = _str.match(new RegExp(regexp)); |
|
97 |
|
|
98 |
var offset = 0; |
|
99 |
var date = new Date(d[1], 0, 1); |
|
100 |
|
|
101 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
102 |
if (d[5]) { date.setDate(d[5]); } |
|
103 |
if (d[7]) { date.setHours(d[7]); } |
|
104 |
if (d[8]) { date.setMinutes(d[8]); } |
|
105 |
if (d[10]) { date.setSeconds(d[10]); } |
|
106 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
107 |
if (d[14]) { |
|
108 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
109 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
110 |
} |
|
111 |
|
|
112 |
offset -= date.getTimezoneOffset(); |
|
113 |
time = (Number(date) + (offset * 60 * 1000)); |
|
114 |
var _res = new Date(); |
|
115 |
_res.setTime(Number(time)); |
|
116 |
return _res; |
|
117 |
}, |
|
| 983 | 118 |
dateToIso : function(_d) { |
119 |
var d = _d ? new Date(_d) : new Date(); |
|
| 860 | 120 |
return d.getUTCFullYear()+'-' |
| 980 | 121 |
+ pad(2, d.getUTCMonth()+1)+'-' |
122 |
+ pad(2, d.getUTCDate())+'T' |
|
123 |
+ pad(2, d.getUTCHours())+':' |
|
124 |
+ pad(2, d.getUTCMinutes())+':' |
|
125 |
+ pad(2, d.getUTCSeconds())+'Z' |
|
| 860 | 126 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
127 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
128 |
|
| 868 | 129 |
/* |
| 970 | 130 |
* Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
| 868 | 131 |
*/ |
| 970 | 132 |
Model.List = function(_directory) { |
| 866 | 133 |
Array.call(this); |
| 858 | 134 |
this.directory = _directory; |
| 866 | 135 |
this.idIndex = []; |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
136 |
this.__events = {}; |
| 860 | 137 |
if (typeof _directory == "undefined") { |
| 900 | 138 |
console.trace(); |
| 970 | 139 |
throw "Error : new Model.List(directory): directory is undefined"; |
| 860 | 140 |
} |
| 983 | 141 |
var _this = this; |
142 |
this.on("clear-search", function() { |
|
143 |
_this.searching = false; |
|
144 |
_this.regexp = undefined; |
|
145 |
_this.forEach(function(_element) { |
|
146 |
_element.found = undefined; |
|
147 |
}); |
|
148 |
_this.trigger("search-cleared"); |
|
149 |
}) |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
150 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
151 |
|
| 970 | 152 |
Model.List.prototype = new Array(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
153 |
|
| 970 | 154 |
Model.List.prototype.hasId = function(_id) { |
155 |
return ns._(this.idIndex).include(_id); |
|
| 864 | 156 |
} |
157 |
||
| 868 | 158 |
/* On recent browsers, forEach and map are defined and do what we want. |
159 |
* Otherwise, we'll use the Underscore.js functions |
|
160 |
*/ |
|
| 866 | 161 |
if (typeof Array.prototype.forEach === "undefined") { |
| 970 | 162 |
Model.List.prototype.forEach = function(_callback) { |
| 866 | 163 |
var _this = this; |
| 970 | 164 |
ns._(this).forEach(function(_value, _key) { |
| 866 | 165 |
_callback(_value, _key, _this); |
166 |
}); |
|
167 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
168 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
169 |
|
| 866 | 170 |
if (typeof Array.prototype.map === "undefined") { |
| 970 | 171 |
Model.List.prototype.map = function(_callback) { |
| 866 | 172 |
var _this = this; |
| 970 | 173 |
return ns._(this).map(function(_value, _key) { |
| 866 | 174 |
return _callback(_value, _key, _this); |
175 |
}); |
|
176 |
} |
|
| 858 | 177 |
} |
178 |
||
| 970 | 179 |
Model.List.prototype.pluck = function(_key) { |
| 900 | 180 |
return this.map(function(_value) { |
181 |
return _value[_key]; |
|
182 |
}); |
|
183 |
} |
|
184 |
||
| 970 | 185 |
/* We override Array's filter function because it doesn't return an Model.List |
| 868 | 186 |
*/ |
| 970 | 187 |
Model.List.prototype.filter = function(_callback) { |
| 858 | 188 |
var _this = this, |
| 970 | 189 |
_res = new Model.List(this.directory); |
190 |
_res.addElements(ns._(this).filter(function(_value, _key) { |
|
| 866 | 191 |
return _callback(_value, _key, _this); |
192 |
})); |
|
| 858 | 193 |
return _res; |
194 |
} |
|
195 |
||
| 970 | 196 |
Model.List.prototype.slice = function(_start, _end) { |
197 |
var _res = new Model.List(this.directory); |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
198 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
199 |
return _res; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
200 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
201 |
|
| 970 | 202 |
Model.List.prototype.splice = function(_start, _end) { |
203 |
var _res = new Model.List(this.directory); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
204 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
205 |
this.idIndex.splice(_start, _end); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
206 |
return _res; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
207 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
208 |
|
| 868 | 209 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
| 970 | 210 |
* and won't return a new Model.List |
| 868 | 211 |
*/ |
| 970 | 212 |
Model.List.prototype.sortBy = function(_callback) { |
| 864 | 213 |
var _this = this, |
| 970 | 214 |
_res = new Model.List(this.directory); |
215 |
_res.addElements(ns._(this).sortBy(function(_value, _key) { |
|
| 866 | 216 |
return _callback(_value, _key, _this); |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
217 |
})); |
| 864 | 218 |
return _res; |
219 |
} |
|
220 |
||
| 868 | 221 |
/* Title and Description are basic information for (almost) all element types, |
222 |
* here we can search by these criteria |
|
223 |
*/ |
|
| 973 | 224 |
Model.List.prototype.searchByTitle = function(_text, _iexact) { |
225 |
var _iexact = _iexact || false, |
|
226 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 227 |
return this.filter(function(_element) { |
| 864 | 228 |
return _rgxp.test(_element.title); |
| 858 | 229 |
}); |
230 |
} |
|
231 |
||
| 973 | 232 |
Model.List.prototype.searchByDescription = function(_text, _iexact) { |
233 |
var _iexact = _iexact || false, |
|
234 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 235 |
return this.filter(function(_element) { |
236 |
return _rgxp.test(_element.description); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
237 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
238 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
239 |
|
| 973 | 240 |
Model.List.prototype.searchByTextFields = function(_text, _iexact) { |
241 |
var _iexact = _iexact || false, |
|
242 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 858 | 243 |
return this.filter(function(_element) { |
| 864 | 244 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
| 858 | 245 |
}); |
246 |
} |
|
247 |
||
| 983 | 248 |
Model.List.prototype.search = function(_text) { |
249 |
if (!_text) { |
|
250 |
this.trigger("clear-search"); |
|
251 |
return this; |
|
252 |
} |
|
253 |
this.searching = true; |
|
254 |
this.trigger("search", _text); |
|
255 |
var rxsource = Model.fullTextRegexps(_text) |
|
256 |
rgxp = new RegExp(rxsource,"im"), |
|
257 |
this.regexp = new RegExp(rxsource,"gim"); |
|
258 |
var res = this.filter(function(_element, _k) { |
|
259 |
var titlematch = rgxp.test(_element.title), |
|
260 |
descmatch = rgxp.test(_element.description), |
|
261 |
_isfound = !!(titlematch || descmatch); |
|
262 |
_element.found = _isfound; |
|
263 |
_element.trigger(_isfound ? "found" : "not-found"); |
|
264 |
return _isfound; |
|
265 |
}); |
|
266 |
this.trigger(res.length ? "found" : "not-found",res); |
|
267 |
return res; |
|
268 |
} |
|
269 |
||
| 970 | 270 |
Model.List.prototype.getTitles = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
271 |
return this.map(function(_el) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
272 |
return _el.title; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
273 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
274 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
275 |
|
| 970 | 276 |
Model.List.prototype.addId = function(_id) { |
| 866 | 277 |
var _el = this.directory.getElement(_id) |
278 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
279 |
this.idIndex.push(_id); |
|
280 |
Array.prototype.push.call(this, _el); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
281 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
282 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
283 |
|
| 970 | 284 |
Model.List.prototype.push = function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
285 |
if (typeof _el === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
286 |
return; |
| 866 | 287 |
} |
| 970 | 288 |
var _index = (ns._(this.idIndex).indexOf(_el.id)); |
| 868 | 289 |
if (_index === -1) { |
290 |
this.idIndex.push(_el.id); |
|
291 |
Array.prototype.push.call(this, _el); |
|
292 |
} else { |
|
293 |
this[_index] = _el; |
|
294 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
295 |
} |
| 858 | 296 |
|
| 970 | 297 |
Model.List.prototype.addIds = function(_array) { |
| 866 | 298 |
var _l = _array.length, |
299 |
_this = this; |
|
| 970 | 300 |
ns._(_array).forEach(function(_id) { |
| 866 | 301 |
_this.addId(_id); |
302 |
}); |
|
| 858 | 303 |
} |
304 |
||
| 970 | 305 |
Model.List.prototype.addElements = function(_array) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
306 |
var _this = this; |
| 970 | 307 |
ns._(_array).forEach(function(_el) { |
| 866 | 308 |
_this.push(_el); |
309 |
}); |
|
| 858 | 310 |
} |
311 |
||
| 970 | 312 |
Model.List.prototype.removeId = function(_id, _deleteFromDirectory) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
313 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
| 970 | 314 |
_index = (ns._(this.idIndex).indexOf(_id)); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
315 |
if (_index !== -1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
316 |
this.splice(_index,1); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
317 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
318 |
if (_deleteFromDirectory) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
319 |
delete this.directory.elements[_id]; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
320 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
321 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
322 |
|
| 970 | 323 |
Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
324 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
325 |
this.removeId(_el.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
326 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
327 |
|
| 970 | 328 |
Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
329 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
330 |
_this = this; |
| 970 | 331 |
ns._(_list).forEach(function(_id) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
332 |
_this.removeId(_id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
333 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
334 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
335 |
|
| 970 | 336 |
Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
337 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
338 |
_this = this; |
| 970 | 339 |
ns._(_list).forEach(function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
340 |
_this.removeElement(_el); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
341 |
}); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
342 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
343 |
|
| 970 | 344 |
Model.List.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
345 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
346 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
347 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
348 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
349 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
350 |
|
| 970 | 351 |
Model.List.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
352 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 353 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
354 |
return _fn === _callback; |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
355 |
}); |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
356 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
357 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
358 |
|
| 970 | 359 |
Model.List.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
360 |
var _list = this; |
| 970 | 361 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
362 |
_callback.call(_list, _data); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
363 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
364 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
365 |
|
| 868 | 366 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
367 |
* without the clumsiness of the original Date object. |
|
368 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
369 |
|
| 970 | 370 |
Model.Time = function(_milliseconds) { |
| 900 | 371 |
this.milliseconds = 0; |
372 |
this.setMilliseconds(_milliseconds); |
|
373 |
} |
|
374 |
||
| 970 | 375 |
Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
| 983 | 376 |
var _ante = this.milliseconds; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
377 |
switch(typeof _milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
378 |
case "string": |
| 983 | 379 |
this.milliseconds = parseInt(_milliseconds); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
380 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
381 |
case "number": |
| 983 | 382 |
this.milliseconds = Math.floor(_milliseconds); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
383 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
384 |
case "object": |
| 983 | 385 |
this.milliseconds = parseInt(_milliseconds.valueOf()); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
386 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
387 |
default: |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
388 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
389 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
390 |
if (this.milliseconds === NaN) { |
| 900 | 391 |
this.milliseconds = _ante; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
392 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
393 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
394 |
|
| 970 | 395 |
Model.Time.prototype.setSeconds = function(_seconds) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
396 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
397 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
398 |
|
| 970 | 399 |
Model.Time.prototype.getSeconds = function() { |
| 917 | 400 |
return this.milliseconds / 1000; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
401 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
402 |
|
| 970 | 403 |
Model.Time.prototype.getHMS = function() { |
| 917 | 404 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
405 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
406 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
407 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
| 983 | 408 |
seconds : _totalSeconds % 60, |
409 |
milliseconds: this.milliseconds % 1000 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
410 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
411 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
412 |
|
| 970 | 413 |
Model.Time.prototype.add = function(_milliseconds) { |
414 |
this.milliseconds += new Model.Time(_milliseconds).milliseconds; |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
415 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
416 |
|
| 970 | 417 |
Model.Time.prototype.valueOf = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
418 |
return this.milliseconds; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
419 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
420 |
|
| 983 | 421 |
Model.Time.prototype.toString = function(showCs) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
422 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
423 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
424 |
if (_hms.hours) { |
| 976 | 425 |
_res += _hms.hours + ':' |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
426 |
} |
| 980 | 427 |
_res += pad(2, _hms.minutes) + ':' + pad(2, _hms.seconds); |
| 983 | 428 |
if (showCs) { |
429 |
_res += "." + Math.round(_hms.milliseconds / 100) |
|
430 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
431 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
432 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
433 |
|
| 970 | 434 |
/* Model.Reference handles references between elements |
| 868 | 435 |
*/ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
436 |
|
| 970 | 437 |
Model.Reference = function(_source, _idRef) { |
| 860 | 438 |
this.source = _source; |
| 916 | 439 |
this.id = _idRef; |
| 858 | 440 |
if (typeof _idRef === "object") { |
441 |
this.isList = true; |
|
442 |
} else { |
|
443 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
444 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
445 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
446 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
447 |
|
| 970 | 448 |
Model.Reference.prototype.refresh = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
449 |
if (this.isList) { |
| 970 | 450 |
this.contents = new Model.List(this.source.directory); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
451 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
452 |
} else { |
| 957 | 453 |
this.contents = this.source.getElement(this.id); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
454 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
455 |
|
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
456 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
457 |
|
| 970 | 458 |
Model.Reference.prototype.getContents = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
459 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
460 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
461 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
462 |
return this.contents; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
463 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
464 |
|
| 970 | 465 |
Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
466 |
if (this.isList) { |
| 970 | 467 |
return (ns._(this.id).indexOf(_idRef) !== -1) |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
468 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
469 |
return (this.id == _idRef); |
| 858 | 470 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
471 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
472 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
473 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
474 |
|
| 970 | 475 |
Model.Element = function(_id, _source) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
476 |
this.elementType = 'element'; |
| 983 | 477 |
this.title = ""; |
478 |
this.description = ""; |
|
479 |
this.__events = {} |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
480 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
481 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
482 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
483 |
if (typeof _id === "undefined" || !_id) { |
| 970 | 484 |
_id = Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
485 |
} |
| 983 | 486 |
this.id = _id; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
487 |
this.source = _source; |
| 983 | 488 |
if (_source !== this) { |
489 |
this.source.directory.addElement(this); |
|
490 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
491 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
492 |
|
| 970 | 493 |
Model.Element.prototype.toString = function() { |
| 858 | 494 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
495 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
496 |
|
| 970 | 497 |
Model.Element.prototype.setReference = function(_elementType, _idRef) { |
498 |
this[_elementType] = new Model.Reference(this.source, _idRef); |
|
| 854 | 499 |
} |
500 |
||
| 970 | 501 |
Model.Element.prototype.getReference = function(_elementType) { |
| 858 | 502 |
if (typeof this[_elementType] !== "undefined") { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
503 |
return this[_elementType].getContents(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
504 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
505 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
506 |
|
| 970 | 507 |
Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
508 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 509 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
510 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 511 |
var _ref = _el[_this.elementType]; |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
512 |
return _ref && _ref.isOrHasId(_this.id); |
| 864 | 513 |
}); |
514 |
} |
|
515 |
||
| 970 | 516 |
Model.Element.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
517 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
518 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
519 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
520 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
521 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
522 |
|
| 970 | 523 |
Model.Element.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
524 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 525 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
526 |
return _fn === _callback; |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
527 |
}); |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
528 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
529 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
530 |
|
| 970 | 531 |
Model.Element.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
532 |
var _element = this; |
| 970 | 533 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
534 |
_callback.call(_element, _data); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
535 |
}); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
536 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
537 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
538 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
539 |
|
| 970 | 540 |
Model.Playable = function(_id, _source) { |
541 |
Model.Element.call(this, _id, _source); |
|
542 |
if (typeof _source === "undefined") { |
|
543 |
return; |
|
544 |
} |
|
545 |
this.elementType = 'playable'; |
|
546 |
this.currentTime = new Model.Time(); |
|
547 |
this.volume = .5; |
|
548 |
this.paused = true; |
|
549 |
this.muted = false; |
|
550 |
var _this = this; |
|
551 |
this.on("play", function() { |
|
552 |
_this.paused = false; |
|
553 |
}); |
|
554 |
this.on("pause", function() { |
|
555 |
_this.paused = true; |
|
556 |
}); |
|
557 |
this.on("timeupdate", function(_time) { |
|
558 |
_this.currentTime = _time; |
|
| 983 | 559 |
_this.getAnnotations().filter(function(_a) { |
560 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
561 |
}).forEach(function(_a) { |
|
562 |
_a.playing = false; |
|
563 |
_a.trigger("leave"); |
|
564 |
_this.trigger("leave-annotation",_a); |
|
565 |
}); |
|
566 |
_this.getAnnotations().filter(function(_a) { |
|
567 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
568 |
}).forEach(function(_a) { |
|
569 |
_a.playing = true; |
|
570 |
_a.trigger("enter"); |
|
571 |
_this.trigger("enter-annotation",_a); |
|
572 |
}); |
|
| 970 | 573 |
}); |
574 |
} |
|
575 |
||
576 |
Model.Playable.prototype = new Model.Element(); |
|
577 |
||
578 |
Model.Playable.prototype.getCurrentTime = function() { |
|
579 |
return this.currentTime; |
|
580 |
} |
|
581 |
||
582 |
Model.Playable.prototype.getVolume = function() { |
|
583 |
return this.volume; |
|
584 |
} |
|
585 |
||
586 |
Model.Playable.prototype.getPaused = function() { |
|
587 |
return this.paused; |
|
588 |
} |
|
589 |
||
590 |
Model.Playable.prototype.getMuted = function() { |
|
591 |
return this.muted; |
|
592 |
} |
|
593 |
||
594 |
Model.Playable.prototype.setCurrentTime = function(_time) { |
|
595 |
this.trigger("setcurrenttime",_time); |
|
596 |
} |
|
597 |
||
598 |
Model.Playable.prototype.setVolume = function(_vol) { |
|
599 |
this.trigger("setvolume",_vol); |
|
600 |
} |
|
601 |
||
602 |
Model.Playable.prototype.setMuted = function(_muted) { |
|
603 |
this.trigger("setmuted",_muted); |
|
604 |
} |
|
605 |
||
606 |
Model.Playable.prototype.play = function() { |
|
607 |
this.trigger("setplay"); |
|
608 |
} |
|
609 |
||
610 |
Model.Playable.prototype.pause = function() { |
|
611 |
this.trigger("setpause"); |
|
612 |
} |
|
613 |
||
| 983 | 614 |
Model.Playable.prototype.show = function() {} |
615 |
||
616 |
Model.Playable.prototype.hide = function() {} |
|
| 970 | 617 |
|
618 |
/* */ |
|
619 |
||
620 |
Model.Media = function(_id, _source) { |
|
621 |
Model.Playable.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
622 |
this.elementType = 'media'; |
| 970 | 623 |
this.duration = new Model.Time(); |
| 866 | 624 |
this.video = ''; |
| 965 | 625 |
var _this = this; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
626 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
627 |
|
| 970 | 628 |
Model.Media.prototype = new Model.Playable(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
629 |
|
| 957 | 630 |
/* Default functions to be overriden by players */ |
631 |
|
|
| 970 | 632 |
Model.Media.prototype.setDuration = function(_durationMs) { |
| 900 | 633 |
this.duration.setMilliseconds(_durationMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
634 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
635 |
|
| 970 | 636 |
Model.Media.prototype.getAnnotations = function() { |
| 864 | 637 |
return this.getRelated("annotation"); |
638 |
} |
|
639 |
||
| 970 | 640 |
Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 641 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
642 |
if (_annTypes.length) { |
|
643 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 644 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 645 |
}); |
646 |
} else { |
|
| 970 | 647 |
return new Model.List(this.source.directory) |
| 900 | 648 |
} |
649 |
} |
|
650 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
651 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
652 |
|
| 970 | 653 |
Model.Tag = function(_id, _source) { |
654 |
Model.Element.call(this, _id, _source); |
|
| 858 | 655 |
this.elementType = 'tag'; |
656 |
} |
|
657 |
||
| 970 | 658 |
Model.Tag.prototype = new Model.Element(); |
| 858 | 659 |
|
| 970 | 660 |
Model.Tag.prototype.getAnnotations = function() { |
| 864 | 661 |
return this.getRelated("annotation"); |
662 |
} |
|
663 |
||
| 858 | 664 |
/* */ |
| 970 | 665 |
Model.AnnotationType = function(_id, _source) { |
666 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
667 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
668 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
669 |
|
| 970 | 670 |
Model.AnnotationType.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
671 |
|
| 970 | 672 |
Model.AnnotationType.prototype.getAnnotations = function() { |
| 864 | 673 |
return this.getRelated("annotation"); |
674 |
} |
|
675 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
676 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
677 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
678 |
|
| 970 | 679 |
Model.Annotation = function(_id, _source) { |
680 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
681 |
this.elementType = 'annotation'; |
| 970 | 682 |
this.begin = new Model.Time(); |
683 |
this.end = new Model.Time(); |
|
684 |
this.tag = new Model.Reference(_source, []); |
|
| 965 | 685 |
this.playing = false; |
| 964 | 686 |
var _this = this; |
687 |
this.on("click", function() { |
|
688 |
_this.getMedia().setCurrentTime(_this.begin); |
|
| 965 | 689 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
690 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
691 |
|
| 970 | 692 |
Model.Annotation.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
693 |
|
| 970 | 694 |
Model.Annotation.prototype.setBegin = function(_beginMs) { |
| 976 | 695 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
696 |
this.trigger("change-begin"); |
|
| 983 | 697 |
if (this.end < this.begin) { |
698 |
this.setEnd(this.begin); |
|
699 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
700 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
701 |
|
| 976 | 702 |
Model.Annotation.prototype.setEnd = function(_endMs) { |
| 983 | 703 |
this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
| 976 | 704 |
this.trigger("change-end"); |
| 983 | 705 |
if (this.end < this.begin) { |
706 |
this.setBegin(this.end); |
|
707 |
} |
|
| 976 | 708 |
} |
709 |
||
710 |
Model.Annotation.prototype.setDuration = function(_durMs) { |
|
711 |
this.setEnd(_durMs + this.begin.milliseconds); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
712 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
713 |
|
| 970 | 714 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
| 858 | 715 |
this.setReference("media", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
716 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
717 |
|
| 970 | 718 |
Model.Annotation.prototype.getMedia = function() { |
| 858 | 719 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
720 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
721 |
|
| 970 | 722 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
| 858 | 723 |
this.setReference("annotationType", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
724 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
725 |
|
| 970 | 726 |
Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 727 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
728 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
729 |
|
| 970 | 730 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
| 858 | 731 |
this.setReference("tag", _idRefs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
732 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
733 |
|
| 970 | 734 |
Model.Annotation.prototype.getTags = function() { |
| 858 | 735 |
return this.getReference("tag"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
736 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
737 |
|
| 970 | 738 |
Model.Annotation.prototype.getTagTexts = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
739 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
740 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
741 |
|
| 970 | 742 |
Model.Annotation.prototype.getDuration = function() { |
743 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
| 900 | 744 |
} |
745 |
||
| 858 | 746 |
/* */ |
747 |
||
| 970 | 748 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
749 |
Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
750 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
751 |
this.annotation = _annotation; |
| 983 | 752 |
this.begin = new Model.Time(); |
753 |
this.end = new Model.Time(); |
|
754 |
this.duration = new Model.Time(); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
755 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
756 |
this.description = this.annotation.description; |
| 900 | 757 |
this.color = this.annotation.color; |
| 965 | 758 |
var _this = this; |
759 |
this.on("click", function() { |
|
760 |
_mashup.setCurrentTime(_this.begin); |
|
761 |
}); |
|
| 983 | 762 |
this.on("enter", function() { |
763 |
_this.annotation.trigger("enter"); |
|
764 |
}); |
|
765 |
this.on("leave", function() { |
|
766 |
_this.annotation.trigger("leave"); |
|
767 |
}); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
768 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
769 |
|
| 970 | 770 |
Model.MashedAnnotation.prototype = new Model.Element(null); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
771 |
|
| 970 | 772 |
Model.MashedAnnotation.prototype.getMedia = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
773 |
return this.annotation.getReference("media"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
774 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
775 |
|
| 970 | 776 |
Model.MashedAnnotation.prototype.getAnnotationType = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
777 |
return this.annotation.getReference("annotationType"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
778 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
779 |
|
| 970 | 780 |
Model.MashedAnnotation.prototype.getTags = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
781 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
782 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
783 |
|
| 970 | 784 |
Model.MashedAnnotation.prototype.getTagTexts = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
785 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
786 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
787 |
|
| 970 | 788 |
Model.MashedAnnotation.prototype.getDuration = function() { |
| 940 | 789 |
return this.annotation.getDuration(); |
790 |
} |
|
791 |
||
| 983 | 792 |
Model.MashedAnnotation.prototype.setBegin = function(_begin) { |
793 |
this.begin.setMilliseconds(_begin); |
|
794 |
this.duration.setMilliseconds(this.annotation.getDuration()); |
|
795 |
this.end.setMilliseconds(_begin + this.duration); |
|
796 |
} |
|
797 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
798 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
799 |
|
| 970 | 800 |
Model.Mashup = function(_id, _source) { |
801 |
Model.Playable.call(this, _id, _source); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
802 |
this.elementType = 'mashup'; |
| 970 | 803 |
this.duration = new Model.Time(); |
804 |
this.segments = new Model.List(_source.directory); |
|
| 983 | 805 |
this.loaded = false; |
| 965 | 806 |
var _this = this; |
| 983 | 807 |
this._updateTimes = function() { |
808 |
_this.updateTimes(); |
|
809 |
_this.trigger("change"); |
|
810 |
} |
|
811 |
this.on("add", this._updateTimes); |
|
812 |
this.on("remove", this._updateTimes); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
813 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
814 |
|
| 970 | 815 |
Model.Mashup.prototype = new Model.Playable(); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
816 |
|
| 983 | 817 |
Model.Mashup.prototype.checkLoaded = function() { |
818 |
var loaded = !!this.segments.length; |
|
819 |
this.getMedias().forEach(function(_m) { |
|
820 |
loaded = loaded && _m.loaded; |
|
821 |
}); |
|
822 |
this.loaded = loaded; |
|
823 |
if (loaded) { |
|
824 |
this.trigger("loadedmetadata"); |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
Model.Mashup.prototype.updateTimes = function() { |
|
829 |
var _time = 0; |
|
830 |
this.segments.forEach(function(_segment) { |
|
831 |
_segment.setBegin(_time); |
|
832 |
_time = _segment.end; |
|
833 |
}); |
|
834 |
this.duration.setMilliseconds(_time); |
|
835 |
} |
|
836 |
||
837 |
Model.Mashup.prototype.addAnnotation = function(_annotation, _defer) { |
|
838 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), |
|
839 |
_defer = _defer || false; |
|
| 900 | 840 |
this.segments.push(_mashedAnnotation); |
| 983 | 841 |
_annotation.on("change-begin", this._updateTimes); |
842 |
_annotation.on("change-end", this._updateTimes); |
|
843 |
if (!_defer) { |
|
844 |
this.trigger("add"); |
|
845 |
} |
|
846 |
} |
|
847 |
||
848 |
Model.Mashup.prototype.addAnnotationById = function(_elId, _defer) { |
|
849 |
var _annotation = this.source.getElement(_elId), |
|
850 |
_defer = _defer || false; |
|
851 |
if (typeof _annotation !== "undefined") { |
|
852 |
this.addAnnotation(_annotation, _defer); |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
Model.Mashup.prototype.addAnnotations = function(_segments) { |
|
857 |
var _this = this; |
|
858 |
ns._(_segments).forEach(function(_segment) { |
|
859 |
_this.addAnnotation(_segment, true); |
|
860 |
}); |
|
861 |
this.trigger("add"); |
|
| 900 | 862 |
} |
863 |
||
| 983 | 864 |
Model.Mashup.prototype.addAnnotationsById = function(_segments) { |
865 |
var _this = this; |
|
866 |
ns._(_segments).forEach(function(_segment) { |
|
867 |
_this.addAnnotationById(_segment, true); |
|
868 |
}); |
|
869 |
this.trigger("add"); |
|
870 |
} |
|
871 |
||
872 |
Model.Mashup.prototype.removeAnnotation = function(_annotation, _defer) { |
|
873 |
var _defer = _defer || false; |
|
874 |
_annotation.off("change-begin", this._updateTimes); |
|
875 |
_annotation.off("change-end", this._updateTimes); |
|
876 |
this.segments.removeId(this.id + "_" + _annotation.id); |
|
877 |
if (!_defer) { |
|
878 |
this.trigger("remove"); |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
Model.Mashup.prototype.removeAnnotationById = function(_annId, _defer) { |
|
883 |
var _defer = _defer || false; |
|
884 |
var _annotation = this.source.getElement(_annId); |
|
885 |
||
886 |
if (_annotation) { |
|
887 |
this.removeAnnotation(_annotation, _defer); |
|
888 |
} |
|
889 |
if (!_defer) { |
|
890 |
this.trigger("remove"); |
|
| 900 | 891 |
} |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
892 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
893 |
|
| 983 | 894 |
Model.Mashup.prototype.setAnnotations = function(_segments) { |
895 |
while (this.segments.length) { |
|
896 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
897 |
} |
|
898 |
this.addAnnotations(_segments); |
|
899 |
} |
|
900 |
||
901 |
Model.Mashup.prototype.setAnnotationsById = function(_segments) { |
|
902 |
while (this.segments.length) { |
|
903 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
904 |
} |
|
905 |
this.addAnnotationsById(_segments); |
|
906 |
} |
|
907 |
||
908 |
Model.Mashup.prototype.hasAnnotation = function(_annotation) { |
|
909 |
return !!ns._(this.segments).find(function(_s) { |
|
910 |
return _s.annotation === _annotation |
|
911 |
}); |
|
912 |
} |
|
913 |
||
914 |
Model.Mashup.prototype.getAnnotation = function(_annotation) { |
|
915 |
return ns._(this.segments).find(function(_s) { |
|
916 |
return _s.annotation === _annotation |
|
917 |
}); |
|
918 |
} |
|
919 |
||
920 |
Model.Mashup.prototype.getAnnotationById = function(_id) { |
|
921 |
return ns._(this.segments).find(function(_s) { |
|
922 |
return _s.annotation.id === _id |
|
923 |
}); |
|
924 |
} |
|
925 |
||
| 970 | 926 |
Model.Mashup.prototype.getAnnotations = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
927 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
928 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
929 |
|
| 983 | 930 |
Model.Mashup.prototype.getOriginalAnnotations = function() { |
931 |
var annotations = new Model.List(this.source.directory); |
|
932 |
this.segments.forEach(function(_s) { |
|
933 |
annotations.push(_s.annotation); |
|
934 |
}); |
|
935 |
return annotations; |
|
936 |
} |
|
937 |
||
| 970 | 938 |
Model.Mashup.prototype.getMedias = function() { |
| 983 | 939 |
var medias = new Model.List(this.source.directory); |
940 |
this.segments.forEach(function(_annotation) { |
|
941 |
medias.push(_annotation.getMedia()) |
|
942 |
}) |
|
943 |
return medias; |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
944 |
} |
| 900 | 945 |
|
| 970 | 946 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 947 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
948 |
if (_annTypes.length) { |
|
949 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 950 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 951 |
}); |
952 |
} else { |
|
| 970 | 953 |
return new Model.List(this.source.directory) |
| 900 | 954 |
} |
955 |
} |
|
956 |
||
| 970 | 957 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 903 | 958 |
var _list = this.segments.filter(function(_annotation) { |
959 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
960 |
}); |
|
961 |
if (_list.length) { |
|
962 |
return _list[0]; |
|
963 |
} else { |
|
964 |
return undefined; |
|
965 |
} |
|
966 |
} |
|
967 |
||
| 970 | 968 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
| 903 | 969 |
var _annotation = this.getAnnotationAtTime(_time); |
970 |
if (typeof _annotation !== "undefined") { |
|
971 |
return _annotation.getMedia(); |
|
972 |
} else { |
|
973 |
return undefined; |
|
974 |
} |
|
975 |
} |
|
976 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
977 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
978 |
|
| 970 | 979 |
Model.Source = function(_config) { |
| 983 | 980 |
Model.Element.call(this, false, this); |
| 970 | 981 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
982 |
this.elementType = "source"; |
| 860 | 983 |
if (typeof _config !== "undefined") { |
984 |
var _this = this; |
|
| 970 | 985 |
ns._(_config).forEach(function(_v, _k) { |
| 860 | 986 |
_this[_k] = _v; |
987 |
}) |
|
988 |
this.callbackQueue = []; |
|
989 |
this.contents = {}; |
|
990 |
this.get(); |
|
991 |
} |
|
992 |
} |
|
993 |
||
| 970 | 994 |
Model.Source.prototype = new Model.Element(); |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
995 |
|
| 970 | 996 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
997 |
if (typeof this.contents[_listId] === "undefined") { |
| 970 | 998 |
this.contents[_listId] = new Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
999 |
} |
| 866 | 1000 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1001 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1002 |
|
| 970 | 1003 |
Model.Source.prototype.getList = function(_listId, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1004 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1005 |
if (_global || typeof this.contents[_listId] === "undefined") { |
| 860 | 1006 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1007 |
return (_e.elementType === _listId); |
| 858 | 1008 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1009 |
} else { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1010 |
return this.contents[_listId]; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1011 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1012 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1013 |
|
| 970 | 1014 |
Model.Source.prototype.forEach = function(_callback) { |
| 860 | 1015 |
var _this = this; |
| 970 | 1016 |
ns._(this.contents).forEach(function(_value, _key) { |
| 860 | 1017 |
_callback.call(_this, _value, _key); |
1018 |
}) |
|
1019 |
} |
|
1020 |
||
| 970 | 1021 |
Model.Source.prototype.getElement = function(_elId) { |
| 916 | 1022 |
return this.directory.getElement(_elId); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1023 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1024 |
|
| 970 | 1025 |
Model.Source.prototype.get = function() { |
1026 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1027 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1028 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1029 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1030 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
| 970 | 1031 |
Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1032 |
var _this = this; |
| 970 | 1033 |
ns._.defer(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1034 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1035 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1036 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1037 |
|
| 970 | 1038 |
Model.Source.prototype.handleCallbacks = function() { |
1039 |
this.status = Model._SOURCE_STATUS_READY; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1040 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1041 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 1042 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1043 |
} |
| 970 | 1044 |
Model.Source.prototype.onLoad = function(_callback) { |
1045 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1046 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1047 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1048 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1049 |
} |
| 854 | 1050 |
} |
1051 |
||
| 970 | 1052 |
Model.Source.prototype.serialize = function() { |
| 860 | 1053 |
return this.serializer.serialize(this); |
1054 |
} |
|
1055 |
||
| 970 | 1056 |
Model.Source.prototype.deSerialize = function(_data) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1057 |
this.serializer.deSerialize(_data, this); |
| 854 | 1058 |
} |
1059 |
||
| 970 | 1060 |
Model.Source.prototype.getAnnotations = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1061 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1062 |
return this.getList("annotation", _global); |
| 854 | 1063 |
} |
1064 |
||
| 970 | 1065 |
Model.Source.prototype.getMedias = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1066 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1067 |
return this.getList("media", _global); |
| 864 | 1068 |
} |
1069 |
||
| 970 | 1070 |
Model.Source.prototype.getTags = function(_global) { |
| 904 | 1071 |
_global = (typeof _global !== "undefined" && _global); |
1072 |
return this.getList("tag", _global); |
|
1073 |
} |
|
1074 |
||
| 970 | 1075 |
Model.Source.prototype.getMashups = function(_global) { |
| 900 | 1076 |
_global = (typeof _global !== "undefined" && _global); |
1077 |
return this.getList("mashup", _global); |
|
1078 |
} |
|
1079 |
||
| 970 | 1080 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1081 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1082 |
return this.getList("annotationType", _global); |
| 864 | 1083 |
} |
1084 |
||
| 970 | 1085 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1086 |
_global = (typeof _global !== "undefined" && _global); |
| 970 | 1087 |
var _res = new Model.List(this.directory), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1088 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1089 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1090 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1091 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1092 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1093 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1094 |
|
| 970 | 1095 |
Model.Source.prototype.getDuration = function() { |
| 866 | 1096 |
var _m = this.currentMedia; |
1097 |
if (typeof _m !== "undefined") { |
|
1098 |
return this.currentMedia.duration; |
|
1099 |
} |
|
| 858 | 1100 |
} |
1101 |
||
| 970 | 1102 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
| 959 | 1103 |
if (typeof this.currentMedia === "undefined") { |
1104 |
if (_opts.is_mashup) { |
|
| 957 | 1105 |
var _mashups = this.getMashups(); |
1106 |
if (_mashups.length) { |
|
1107 |
this.currentMedia = _mashups[0]; |
|
1108 |
} |
|
1109 |
} else { |
|
1110 |
var _medias = this.getMedias(); |
|
1111 |
if (_medias.length) { |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1112 |
this.currentMedia = _medias[0]; |
| 957 | 1113 |
} |
1114 |
} |
|
1115 |
} |
|
1116 |
return this.currentMedia; |
|
1117 |
} |
|
1118 |
||
| 970 | 1119 |
Model.Source.prototype.merge = function(_source) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1120 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1121 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1122 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1123 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1124 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1125 |
|
| 858 | 1126 |
/* */ |
1127 |
||
| 970 | 1128 |
Model.RemoteSource = function(_config) { |
1129 |
Model.Source.call(this, _config); |
|
| 858 | 1130 |
} |
1131 |
||
| 970 | 1132 |
Model.RemoteSource.prototype = new Model.Source(); |
| 858 | 1133 |
|
| 970 | 1134 |
Model.RemoteSource.prototype.get = function() { |
1135 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
| 983 | 1136 |
var _this = this, |
1137 |
urlparams = this.url_params || {}, |
|
1138 |
dataType = (Model.isLocalURL(this.url) ? "json" : "jsonp"); |
|
1139 |
urlparams.format = dataType; |
|
1140 |
ns.jQuery.ajax({ |
|
1141 |
url: this.url, |
|
1142 |
dataType: dataType, |
|
1143 |
data: urlparams, |
|
1144 |
success: function(_result) { |
|
1145 |
_this.deSerialize(_result); |
|
1146 |
_this.handleCallbacks(); |
|
1147 |
} |
|
| 858 | 1148 |
}); |
| 854 | 1149 |
} |
1150 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1151 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1152 |
|
| 970 | 1153 |
Model.Directory = function() { |
| 858 | 1154 |
this.remoteSources = {}; |
1155 |
this.elements = {}; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1156 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1157 |
|
| 970 | 1158 |
Model.Directory.prototype.remoteSource = function(_properties) { |
| 917 | 1159 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 970 | 1160 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
| 917 | 1161 |
} |
| 970 | 1162 |
var _config = ns._({ directory: this }).extend(_properties); |
| 983 | 1163 |
_config.url_params = _config.url_params || {}; |
1164 |
var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); |
|
1165 |
if (typeof this.remoteSources[_hash] === "undefined") { |
|
1166 |
this.remoteSources[_hash] = new Model.RemoteSource(_config); |
|
| 858 | 1167 |
} |
| 983 | 1168 |
return this.remoteSources[_hash]; |
| 854 | 1169 |
} |
1170 |
||
| 970 | 1171 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
1172 |
var _config = ns._({ directory: this }).extend(_properties), |
|
1173 |
_res = new Model.Source(_config); |
|
| 860 | 1174 |
return _res; |
1175 |
} |
|
1176 |
||
| 970 | 1177 |
Model.Directory.prototype.getElement = function(_id) { |
| 900 | 1178 |
return this.elements[_id]; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1179 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1180 |
|
| 970 | 1181 |
Model.Directory.prototype.addElement = function(_element) { |
| 858 | 1182 |
this.elements[_element.id] = _element; |
1183 |
} |
|
1184 |
||
| 970 | 1185 |
Model.Directory.prototype.getGlobalList = function() { |
1186 |
var _res = new Model.List(this); |
|
1187 |
_res.addIds(ns._(this.elements).keys()); |
|
| 858 | 1188 |
return _res; |
| 854 | 1189 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1190 |
|
| 972 | 1191 |
return Model; |
| 970 | 1192 |
|
1193 |
})(IriSP); |