| author | veltr |
| Thu, 17 Jan 2013 17:25:46 +0100 | |
| changeset 987 | 7b65bf78873a |
| parent 986 | f9d51dd4a3fe |
| child 988 | eefd336335f9 |
| 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) { |
| 986 | 244 |
var keywords = (_element.keywords || _element.getTagTexts() || []).join(", "); |
245 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title) || _rgxp.test(keywords); |
|
| 858 | 246 |
}); |
247 |
} |
|
248 |
||
| 983 | 249 |
Model.List.prototype.search = function(_text) { |
250 |
if (!_text) { |
|
251 |
this.trigger("clear-search"); |
|
252 |
return this; |
|
253 |
} |
|
254 |
this.searching = true; |
|
255 |
this.trigger("search", _text); |
|
256 |
var rxsource = Model.fullTextRegexps(_text) |
|
257 |
rgxp = new RegExp(rxsource,"im"), |
|
258 |
this.regexp = new RegExp(rxsource,"gim"); |
|
259 |
var res = this.filter(function(_element, _k) { |
|
260 |
var titlematch = rgxp.test(_element.title), |
|
261 |
descmatch = rgxp.test(_element.description), |
|
262 |
_isfound = !!(titlematch || descmatch); |
|
263 |
_element.found = _isfound; |
|
264 |
_element.trigger(_isfound ? "found" : "not-found"); |
|
265 |
return _isfound; |
|
266 |
}); |
|
267 |
this.trigger(res.length ? "found" : "not-found",res); |
|
268 |
return res; |
|
269 |
} |
|
270 |
||
| 970 | 271 |
Model.List.prototype.getTitles = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
272 |
return this.map(function(_el) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
273 |
return _el.title; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
274 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
275 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
276 |
|
| 970 | 277 |
Model.List.prototype.addId = function(_id) { |
| 866 | 278 |
var _el = this.directory.getElement(_id) |
279 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
280 |
this.idIndex.push(_id); |
|
281 |
Array.prototype.push.call(this, _el); |
|
|
856
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
284 |
|
| 970 | 285 |
Model.List.prototype.push = function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
286 |
if (typeof _el === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
287 |
return; |
| 866 | 288 |
} |
| 970 | 289 |
var _index = (ns._(this.idIndex).indexOf(_el.id)); |
| 868 | 290 |
if (_index === -1) { |
291 |
this.idIndex.push(_el.id); |
|
292 |
Array.prototype.push.call(this, _el); |
|
293 |
} else { |
|
294 |
this[_index] = _el; |
|
295 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
296 |
} |
| 858 | 297 |
|
| 970 | 298 |
Model.List.prototype.addIds = function(_array) { |
| 866 | 299 |
var _l = _array.length, |
300 |
_this = this; |
|
| 970 | 301 |
ns._(_array).forEach(function(_id) { |
| 866 | 302 |
_this.addId(_id); |
303 |
}); |
|
| 858 | 304 |
} |
305 |
||
| 970 | 306 |
Model.List.prototype.addElements = function(_array) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
307 |
var _this = this; |
| 970 | 308 |
ns._(_array).forEach(function(_el) { |
| 866 | 309 |
_this.push(_el); |
310 |
}); |
|
| 858 | 311 |
} |
312 |
||
| 970 | 313 |
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
|
314 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
| 970 | 315 |
_index = (ns._(this.idIndex).indexOf(_id)); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
316 |
if (_index !== -1) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
317 |
this.splice(_index,1); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
318 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
319 |
if (_deleteFromDirectory) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
320 |
delete this.directory.elements[_id]; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
321 |
} |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
322 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
323 |
|
| 970 | 324 |
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
|
325 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
326 |
this.removeId(_el.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
327 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
328 |
|
| 970 | 329 |
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
|
330 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
331 |
_this = this; |
| 970 | 332 |
ns._(_list).forEach(function(_id) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
333 |
_this.removeId(_id); |
|
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 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
336 |
|
| 970 | 337 |
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
|
338 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
339 |
_this = this; |
| 970 | 340 |
ns._(_list).forEach(function(_el) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
341 |
_this.removeElement(_el); |
|
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 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
344 |
|
| 970 | 345 |
Model.List.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
346 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
347 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
348 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
349 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
350 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
351 |
|
| 970 | 352 |
Model.List.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
353 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 354 |
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
|
355 |
return _fn === _callback; |
|
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 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
359 |
|
| 970 | 360 |
Model.List.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
361 |
var _list = this; |
| 970 | 362 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
363 |
_callback.call(_list, _data); |
|
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 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
366 |
|
| 868 | 367 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
368 |
* without the clumsiness of the original Date object. |
|
369 |
*/ |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
370 |
|
| 970 | 371 |
Model.Time = function(_milliseconds) { |
| 900 | 372 |
this.milliseconds = 0; |
373 |
this.setMilliseconds(_milliseconds); |
|
374 |
} |
|
375 |
||
| 970 | 376 |
Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
| 983 | 377 |
var _ante = this.milliseconds; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
378 |
switch(typeof _milliseconds) { |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
379 |
case "string": |
| 983 | 380 |
this.milliseconds = parseInt(_milliseconds); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
381 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
382 |
case "number": |
| 983 | 383 |
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
|
384 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
385 |
case "object": |
| 983 | 386 |
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
|
387 |
break; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
388 |
default: |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
389 |
this.milliseconds = 0; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
390 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
391 |
if (this.milliseconds === NaN) { |
| 900 | 392 |
this.milliseconds = _ante; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
393 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
394 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
395 |
|
| 970 | 396 |
Model.Time.prototype.setSeconds = function(_seconds) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
397 |
this.milliseconds = 1000 * _seconds; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
398 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
399 |
|
| 970 | 400 |
Model.Time.prototype.getSeconds = function() { |
| 917 | 401 |
return this.milliseconds / 1000; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
402 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
403 |
|
| 970 | 404 |
Model.Time.prototype.getHMS = function() { |
| 917 | 405 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
406 |
return { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
407 |
hours : Math.floor(_totalSeconds / 3600), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
408 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
| 983 | 409 |
seconds : _totalSeconds % 60, |
410 |
milliseconds: this.milliseconds % 1000 |
|
|
856
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
413 |
|
| 970 | 414 |
Model.Time.prototype.add = function(_milliseconds) { |
415 |
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
|
416 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
417 |
|
| 970 | 418 |
Model.Time.prototype.valueOf = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
419 |
return this.milliseconds; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
420 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
421 |
|
| 983 | 422 |
Model.Time.prototype.toString = function(showCs) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
423 |
var _hms = this.getHMS(), |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
424 |
_res = ''; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
425 |
if (_hms.hours) { |
| 976 | 426 |
_res += _hms.hours + ':' |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
427 |
} |
| 980 | 428 |
_res += pad(2, _hms.minutes) + ':' + pad(2, _hms.seconds); |
| 983 | 429 |
if (showCs) { |
| 986 | 430 |
_res += "." + Math.floor(_hms.milliseconds / 100) |
| 983 | 431 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
432 |
return _res; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
433 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
434 |
|
| 970 | 435 |
/* Model.Reference handles references between elements |
| 868 | 436 |
*/ |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
437 |
|
| 970 | 438 |
Model.Reference = function(_source, _idRef) { |
| 860 | 439 |
this.source = _source; |
| 916 | 440 |
this.id = _idRef; |
| 858 | 441 |
if (typeof _idRef === "object") { |
442 |
this.isList = true; |
|
443 |
} else { |
|
444 |
this.isList = false; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
445 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
446 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
447 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
448 |
|
| 970 | 449 |
Model.Reference.prototype.refresh = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
450 |
if (this.isList) { |
| 970 | 451 |
this.contents = new Model.List(this.source.directory); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
452 |
this.contents.addIds(this.id); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
453 |
} else { |
| 957 | 454 |
this.contents = this.source.getElement(this.id); |
|
872
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 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
458 |
|
| 970 | 459 |
Model.Reference.prototype.getContents = function() { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
460 |
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
|
461 |
this.refresh(); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
462 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
463 |
return this.contents; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
464 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
465 |
|
| 970 | 466 |
Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
467 |
if (this.isList) { |
| 970 | 468 |
return (ns._(this.id).indexOf(_idRef) !== -1) |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
469 |
} else { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
470 |
return (this.id == _idRef); |
| 858 | 471 |
} |
|
856
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 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
475 |
|
| 970 | 476 |
Model.Element = function(_id, _source) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
477 |
this.elementType = 'element'; |
| 983 | 478 |
this.title = ""; |
479 |
this.description = ""; |
|
480 |
this.__events = {} |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
481 |
if (typeof _source === "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
482 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
483 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
484 |
if (typeof _id === "undefined" || !_id) { |
| 970 | 485 |
_id = Model.getUID(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
486 |
} |
| 983 | 487 |
this.id = _id; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
488 |
this.source = _source; |
| 983 | 489 |
if (_source !== this) { |
490 |
this.source.directory.addElement(this); |
|
491 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
492 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
493 |
|
| 970 | 494 |
Model.Element.prototype.toString = function() { |
| 858 | 495 |
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
|
496 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
497 |
|
| 970 | 498 |
Model.Element.prototype.setReference = function(_elementType, _idRef) { |
499 |
this[_elementType] = new Model.Reference(this.source, _idRef); |
|
| 854 | 500 |
} |
501 |
||
| 970 | 502 |
Model.Element.prototype.getReference = function(_elementType) { |
| 858 | 503 |
if (typeof this[_elementType] !== "undefined") { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
504 |
return this[_elementType].getContents(); |
|
856
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 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
507 |
|
| 970 | 508 |
Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
509 |
_global = (typeof _global !== "undefined" && _global); |
| 864 | 510 |
var _this = this; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
511 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
| 864 | 512 |
var _ref = _el[_this.elementType]; |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
513 |
return _ref && _ref.isOrHasId(_this.id); |
| 864 | 514 |
}); |
515 |
} |
|
516 |
||
| 970 | 517 |
Model.Element.prototype.on = function(_event, _callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
518 |
if (typeof this.__events[_event] === "undefined") { |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
519 |
this.__events[_event] = []; |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
520 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
521 |
this.__events[_event].push(_callback); |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
522 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
523 |
|
| 970 | 524 |
Model.Element.prototype.off = function(_event, _callback) { |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
525 |
if (typeof this.__events[_event] !== "undefined") { |
| 970 | 526 |
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
|
527 |
return _fn === _callback; |
|
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 |
} |
|
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
531 |
|
| 970 | 532 |
Model.Element.prototype.trigger = function(_event, _data) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
533 |
var _element = this; |
| 970 | 534 |
ns._(this.__events[_event]).each(function(_callback) { |
|
937
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
535 |
_callback.call(_element, _data); |
|
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 |
} |
|
eb3c442cec50
Added events on annotation for inter widget communication
veltr
parents:
930
diff
changeset
|
538 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
539 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
540 |
|
| 970 | 541 |
Model.Playable = function(_id, _source) { |
542 |
Model.Element.call(this, _id, _source); |
|
543 |
if (typeof _source === "undefined") { |
|
544 |
return; |
|
545 |
} |
|
546 |
this.elementType = 'playable'; |
|
547 |
this.currentTime = new Model.Time(); |
|
548 |
this.volume = .5; |
|
549 |
this.paused = true; |
|
550 |
this.muted = false; |
|
| 987 | 551 |
this.loadedMetadata = false; |
| 970 | 552 |
var _this = this; |
553 |
this.on("play", function() { |
|
554 |
_this.paused = false; |
|
555 |
}); |
|
556 |
this.on("pause", function() { |
|
557 |
_this.paused = true; |
|
558 |
}); |
|
559 |
this.on("timeupdate", function(_time) { |
|
560 |
_this.currentTime = _time; |
|
| 983 | 561 |
_this.getAnnotations().filter(function(_a) { |
562 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
563 |
}).forEach(function(_a) { |
|
564 |
_a.playing = false; |
|
565 |
_a.trigger("leave"); |
|
566 |
_this.trigger("leave-annotation",_a); |
|
567 |
}); |
|
568 |
_this.getAnnotations().filter(function(_a) { |
|
569 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
570 |
}).forEach(function(_a) { |
|
571 |
_a.playing = true; |
|
572 |
_a.trigger("enter"); |
|
573 |
_this.trigger("enter-annotation",_a); |
|
574 |
}); |
|
| 970 | 575 |
}); |
| 987 | 576 |
this.on("loadedmetadata", function() { |
577 |
_this.loadedMetadata = true; |
|
578 |
}) |
|
| 970 | 579 |
} |
580 |
||
581 |
Model.Playable.prototype = new Model.Element(); |
|
582 |
||
583 |
Model.Playable.prototype.getCurrentTime = function() { |
|
584 |
return this.currentTime; |
|
585 |
} |
|
586 |
||
587 |
Model.Playable.prototype.getVolume = function() { |
|
588 |
return this.volume; |
|
589 |
} |
|
590 |
||
591 |
Model.Playable.prototype.getPaused = function() { |
|
592 |
return this.paused; |
|
593 |
} |
|
594 |
||
595 |
Model.Playable.prototype.getMuted = function() { |
|
596 |
return this.muted; |
|
597 |
} |
|
598 |
||
599 |
Model.Playable.prototype.setCurrentTime = function(_time) { |
|
600 |
this.trigger("setcurrenttime",_time); |
|
601 |
} |
|
602 |
||
603 |
Model.Playable.prototype.setVolume = function(_vol) { |
|
604 |
this.trigger("setvolume",_vol); |
|
605 |
} |
|
606 |
||
607 |
Model.Playable.prototype.setMuted = function(_muted) { |
|
608 |
this.trigger("setmuted",_muted); |
|
609 |
} |
|
610 |
||
611 |
Model.Playable.prototype.play = function() { |
|
612 |
this.trigger("setplay"); |
|
613 |
} |
|
614 |
||
615 |
Model.Playable.prototype.pause = function() { |
|
616 |
this.trigger("setpause"); |
|
617 |
} |
|
618 |
||
| 983 | 619 |
Model.Playable.prototype.show = function() {} |
620 |
||
621 |
Model.Playable.prototype.hide = function() {} |
|
| 970 | 622 |
|
623 |
/* */ |
|
624 |
||
625 |
Model.Media = function(_id, _source) { |
|
626 |
Model.Playable.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
627 |
this.elementType = 'media'; |
| 970 | 628 |
this.duration = new Model.Time(); |
| 866 | 629 |
this.video = ''; |
| 965 | 630 |
var _this = this; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
631 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
632 |
|
| 970 | 633 |
Model.Media.prototype = new Model.Playable(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
634 |
|
| 957 | 635 |
/* Default functions to be overriden by players */ |
636 |
|
|
| 970 | 637 |
Model.Media.prototype.setDuration = function(_durationMs) { |
| 900 | 638 |
this.duration.setMilliseconds(_durationMs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
639 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
640 |
|
| 970 | 641 |
Model.Media.prototype.getAnnotations = function() { |
| 864 | 642 |
return this.getRelated("annotation"); |
643 |
} |
|
644 |
||
| 970 | 645 |
Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 646 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
647 |
if (_annTypes.length) { |
|
648 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 649 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 650 |
}); |
651 |
} else { |
|
| 970 | 652 |
return new Model.List(this.source.directory) |
| 900 | 653 |
} |
654 |
} |
|
655 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
656 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
657 |
|
| 970 | 658 |
Model.Tag = function(_id, _source) { |
659 |
Model.Element.call(this, _id, _source); |
|
| 858 | 660 |
this.elementType = 'tag'; |
661 |
} |
|
662 |
||
| 970 | 663 |
Model.Tag.prototype = new Model.Element(); |
| 858 | 664 |
|
| 970 | 665 |
Model.Tag.prototype.getAnnotations = function() { |
| 864 | 666 |
return this.getRelated("annotation"); |
667 |
} |
|
668 |
||
| 858 | 669 |
/* */ |
| 970 | 670 |
Model.AnnotationType = function(_id, _source) { |
671 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
672 |
this.elementType = 'annotationType'; |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
673 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
674 |
|
| 970 | 675 |
Model.AnnotationType.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
676 |
|
| 970 | 677 |
Model.AnnotationType.prototype.getAnnotations = function() { |
| 864 | 678 |
return this.getRelated("annotation"); |
679 |
} |
|
680 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
681 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
682 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
683 |
|
| 970 | 684 |
Model.Annotation = function(_id, _source) { |
685 |
Model.Element.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
686 |
this.elementType = 'annotation'; |
| 970 | 687 |
this.begin = new Model.Time(); |
688 |
this.end = new Model.Time(); |
|
689 |
this.tag = new Model.Reference(_source, []); |
|
| 965 | 690 |
this.playing = false; |
| 964 | 691 |
var _this = this; |
692 |
this.on("click", function() { |
|
693 |
_this.getMedia().setCurrentTime(_this.begin); |
|
| 965 | 694 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
695 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
696 |
|
| 970 | 697 |
Model.Annotation.prototype = new Model.Element(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
698 |
|
| 970 | 699 |
Model.Annotation.prototype.setBegin = function(_beginMs) { |
| 976 | 700 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
701 |
this.trigger("change-begin"); |
|
| 983 | 702 |
if (this.end < this.begin) { |
703 |
this.setEnd(this.begin); |
|
704 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
705 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
706 |
|
| 976 | 707 |
Model.Annotation.prototype.setEnd = function(_endMs) { |
| 983 | 708 |
this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
| 976 | 709 |
this.trigger("change-end"); |
| 983 | 710 |
if (this.end < this.begin) { |
711 |
this.setBegin(this.end); |
|
712 |
} |
|
| 976 | 713 |
} |
714 |
||
715 |
Model.Annotation.prototype.setDuration = function(_durMs) { |
|
716 |
this.setEnd(_durMs + this.begin.milliseconds); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
717 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
718 |
|
| 970 | 719 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
| 858 | 720 |
this.setReference("media", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
721 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
722 |
|
| 970 | 723 |
Model.Annotation.prototype.getMedia = function() { |
| 858 | 724 |
return this.getReference("media"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
725 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
726 |
|
| 970 | 727 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
| 858 | 728 |
this.setReference("annotationType", _idRef); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
729 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
730 |
|
| 970 | 731 |
Model.Annotation.prototype.getAnnotationType = function() { |
| 858 | 732 |
return this.getReference("annotationType"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
733 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
734 |
|
| 970 | 735 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
| 858 | 736 |
this.setReference("tag", _idRefs); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
737 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
738 |
|
| 970 | 739 |
Model.Annotation.prototype.getTags = function() { |
| 858 | 740 |
return this.getReference("tag"); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
741 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
742 |
|
| 970 | 743 |
Model.Annotation.prototype.getTagTexts = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
744 |
return this.getTags().getTitles(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
745 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
746 |
|
| 970 | 747 |
Model.Annotation.prototype.getDuration = function() { |
748 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
| 900 | 749 |
} |
750 |
||
| 858 | 751 |
/* */ |
752 |
||
| 970 | 753 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
754 |
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
|
755 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
756 |
this.annotation = _annotation; |
| 983 | 757 |
this.begin = new Model.Time(); |
758 |
this.end = new Model.Time(); |
|
759 |
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
|
760 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
761 |
this.description = this.annotation.description; |
| 900 | 762 |
this.color = this.annotation.color; |
| 965 | 763 |
var _this = this; |
764 |
this.on("click", function() { |
|
765 |
_mashup.setCurrentTime(_this.begin); |
|
766 |
}); |
|
| 983 | 767 |
this.on("enter", function() { |
768 |
_this.annotation.trigger("enter"); |
|
769 |
}); |
|
770 |
this.on("leave", function() { |
|
771 |
_this.annotation.trigger("leave"); |
|
772 |
}); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
773 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
774 |
|
| 970 | 775 |
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
|
776 |
|
| 970 | 777 |
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
|
778 |
return this.annotation.getReference("media"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
779 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
780 |
|
| 970 | 781 |
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
|
782 |
return this.annotation.getReference("annotationType"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
783 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
784 |
|
| 970 | 785 |
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
|
786 |
return this.annotation.getReference("tag"); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
787 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
788 |
|
| 970 | 789 |
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
|
790 |
return this.annotation.getTags().getTitles(); |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
791 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
792 |
|
| 970 | 793 |
Model.MashedAnnotation.prototype.getDuration = function() { |
| 940 | 794 |
return this.annotation.getDuration(); |
795 |
} |
|
796 |
||
| 983 | 797 |
Model.MashedAnnotation.prototype.setBegin = function(_begin) { |
798 |
this.begin.setMilliseconds(_begin); |
|
799 |
this.duration.setMilliseconds(this.annotation.getDuration()); |
|
800 |
this.end.setMilliseconds(_begin + this.duration); |
|
801 |
} |
|
802 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
803 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
804 |
|
| 970 | 805 |
Model.Mashup = function(_id, _source) { |
806 |
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
|
807 |
this.elementType = 'mashup'; |
| 970 | 808 |
this.duration = new Model.Time(); |
809 |
this.segments = new Model.List(_source.directory); |
|
| 983 | 810 |
this.loaded = false; |
| 965 | 811 |
var _this = this; |
| 983 | 812 |
this._updateTimes = function() { |
813 |
_this.updateTimes(); |
|
814 |
_this.trigger("change"); |
|
815 |
} |
|
816 |
this.on("add", this._updateTimes); |
|
817 |
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
|
818 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
819 |
|
| 970 | 820 |
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
|
821 |
|
| 983 | 822 |
Model.Mashup.prototype.checkLoaded = function() { |
823 |
var loaded = !!this.segments.length; |
|
824 |
this.getMedias().forEach(function(_m) { |
|
825 |
loaded = loaded && _m.loaded; |
|
826 |
}); |
|
827 |
this.loaded = loaded; |
|
828 |
if (loaded) { |
|
829 |
this.trigger("loadedmetadata"); |
|
830 |
} |
|
831 |
} |
|
832 |
||
833 |
Model.Mashup.prototype.updateTimes = function() { |
|
834 |
var _time = 0; |
|
835 |
this.segments.forEach(function(_segment) { |
|
836 |
_segment.setBegin(_time); |
|
837 |
_time = _segment.end; |
|
838 |
}); |
|
839 |
this.duration.setMilliseconds(_time); |
|
840 |
} |
|
841 |
||
842 |
Model.Mashup.prototype.addAnnotation = function(_annotation, _defer) { |
|
843 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), |
|
844 |
_defer = _defer || false; |
|
| 900 | 845 |
this.segments.push(_mashedAnnotation); |
| 983 | 846 |
_annotation.on("change-begin", this._updateTimes); |
847 |
_annotation.on("change-end", this._updateTimes); |
|
848 |
if (!_defer) { |
|
849 |
this.trigger("add"); |
|
850 |
} |
|
851 |
} |
|
852 |
||
853 |
Model.Mashup.prototype.addAnnotationById = function(_elId, _defer) { |
|
854 |
var _annotation = this.source.getElement(_elId), |
|
855 |
_defer = _defer || false; |
|
856 |
if (typeof _annotation !== "undefined") { |
|
857 |
this.addAnnotation(_annotation, _defer); |
|
858 |
} |
|
859 |
} |
|
860 |
||
861 |
Model.Mashup.prototype.addAnnotations = function(_segments) { |
|
862 |
var _this = this; |
|
863 |
ns._(_segments).forEach(function(_segment) { |
|
864 |
_this.addAnnotation(_segment, true); |
|
865 |
}); |
|
866 |
this.trigger("add"); |
|
| 900 | 867 |
} |
868 |
||
| 983 | 869 |
Model.Mashup.prototype.addAnnotationsById = function(_segments) { |
870 |
var _this = this; |
|
871 |
ns._(_segments).forEach(function(_segment) { |
|
872 |
_this.addAnnotationById(_segment, true); |
|
873 |
}); |
|
874 |
this.trigger("add"); |
|
875 |
} |
|
876 |
||
877 |
Model.Mashup.prototype.removeAnnotation = function(_annotation, _defer) { |
|
878 |
var _defer = _defer || false; |
|
879 |
_annotation.off("change-begin", this._updateTimes); |
|
880 |
_annotation.off("change-end", this._updateTimes); |
|
881 |
this.segments.removeId(this.id + "_" + _annotation.id); |
|
882 |
if (!_defer) { |
|
883 |
this.trigger("remove"); |
|
884 |
} |
|
885 |
} |
|
886 |
||
887 |
Model.Mashup.prototype.removeAnnotationById = function(_annId, _defer) { |
|
888 |
var _defer = _defer || false; |
|
889 |
var _annotation = this.source.getElement(_annId); |
|
890 |
||
891 |
if (_annotation) { |
|
892 |
this.removeAnnotation(_annotation, _defer); |
|
893 |
} |
|
894 |
if (!_defer) { |
|
895 |
this.trigger("remove"); |
|
| 900 | 896 |
} |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
897 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
898 |
|
| 983 | 899 |
Model.Mashup.prototype.setAnnotations = function(_segments) { |
900 |
while (this.segments.length) { |
|
901 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
902 |
} |
|
903 |
this.addAnnotations(_segments); |
|
904 |
} |
|
905 |
||
906 |
Model.Mashup.prototype.setAnnotationsById = function(_segments) { |
|
907 |
while (this.segments.length) { |
|
908 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
909 |
} |
|
910 |
this.addAnnotationsById(_segments); |
|
911 |
} |
|
912 |
||
913 |
Model.Mashup.prototype.hasAnnotation = function(_annotation) { |
|
914 |
return !!ns._(this.segments).find(function(_s) { |
|
915 |
return _s.annotation === _annotation |
|
916 |
}); |
|
917 |
} |
|
918 |
||
919 |
Model.Mashup.prototype.getAnnotation = function(_annotation) { |
|
920 |
return ns._(this.segments).find(function(_s) { |
|
921 |
return _s.annotation === _annotation |
|
922 |
}); |
|
923 |
} |
|
924 |
||
925 |
Model.Mashup.prototype.getAnnotationById = function(_id) { |
|
926 |
return ns._(this.segments).find(function(_s) { |
|
927 |
return _s.annotation.id === _id |
|
928 |
}); |
|
929 |
} |
|
930 |
||
| 970 | 931 |
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
|
932 |
return this.segments; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
933 |
} |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
934 |
|
| 983 | 935 |
Model.Mashup.prototype.getOriginalAnnotations = function() { |
936 |
var annotations = new Model.List(this.source.directory); |
|
937 |
this.segments.forEach(function(_s) { |
|
938 |
annotations.push(_s.annotation); |
|
939 |
}); |
|
940 |
return annotations; |
|
941 |
} |
|
942 |
||
| 970 | 943 |
Model.Mashup.prototype.getMedias = function() { |
| 983 | 944 |
var medias = new Model.List(this.source.directory); |
945 |
this.segments.forEach(function(_annotation) { |
|
946 |
medias.push(_annotation.getMedia()) |
|
947 |
}) |
|
948 |
return medias; |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
949 |
} |
| 900 | 950 |
|
| 970 | 951 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 952 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
953 |
if (_annTypes.length) { |
|
954 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 955 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 956 |
}); |
957 |
} else { |
|
| 970 | 958 |
return new Model.List(this.source.directory) |
| 900 | 959 |
} |
960 |
} |
|
961 |
||
| 970 | 962 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 903 | 963 |
var _list = this.segments.filter(function(_annotation) { |
964 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
965 |
}); |
|
966 |
if (_list.length) { |
|
967 |
return _list[0]; |
|
968 |
} else { |
|
969 |
return undefined; |
|
970 |
} |
|
971 |
} |
|
972 |
||
| 970 | 973 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
| 903 | 974 |
var _annotation = this.getAnnotationAtTime(_time); |
975 |
if (typeof _annotation !== "undefined") { |
|
976 |
return _annotation.getMedia(); |
|
977 |
} else { |
|
978 |
return undefined; |
|
979 |
} |
|
980 |
} |
|
981 |
||
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
982 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
983 |
|
| 970 | 984 |
Model.Source = function(_config) { |
| 983 | 985 |
Model.Element.call(this, false, this); |
| 970 | 986 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
987 |
this.elementType = "source"; |
| 860 | 988 |
if (typeof _config !== "undefined") { |
989 |
var _this = this; |
|
| 970 | 990 |
ns._(_config).forEach(function(_v, _k) { |
| 860 | 991 |
_this[_k] = _v; |
992 |
}) |
|
993 |
this.callbackQueue = []; |
|
994 |
this.contents = {}; |
|
995 |
this.get(); |
|
996 |
} |
|
997 |
} |
|
998 |
||
| 970 | 999 |
Model.Source.prototype = new Model.Element(); |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1000 |
|
| 970 | 1001 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1002 |
if (typeof this.contents[_listId] === "undefined") { |
| 970 | 1003 |
this.contents[_listId] = new Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1004 |
} |
| 866 | 1005 |
this.contents[_listId].addElements(_contents); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1006 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1007 |
|
| 970 | 1008 |
Model.Source.prototype.getList = function(_listId, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1009 |
_global = (typeof _global !== "undefined" && _global); |
| 986 | 1010 |
if (_global) { |
| 860 | 1011 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1012 |
return (_e.elementType === _listId); |
| 858 | 1013 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1014 |
} else { |
| 986 | 1015 |
return this.contents[_listId] || new IriSP.Model.List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1016 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1017 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1018 |
|
| 970 | 1019 |
Model.Source.prototype.forEach = function(_callback) { |
| 860 | 1020 |
var _this = this; |
| 970 | 1021 |
ns._(this.contents).forEach(function(_value, _key) { |
| 860 | 1022 |
_callback.call(_this, _value, _key); |
1023 |
}) |
|
1024 |
} |
|
1025 |
||
| 970 | 1026 |
Model.Source.prototype.getElement = function(_elId) { |
| 916 | 1027 |
return this.directory.getElement(_elId); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1028 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1029 |
|
| 970 | 1030 |
Model.Source.prototype.get = function() { |
1031 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1032 |
this.handleCallbacks(); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1033 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1034 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1035 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
| 970 | 1036 |
Model.Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1037 |
var _this = this; |
| 970 | 1038 |
ns._.defer(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1039 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1040 |
}); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1041 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1042 |
|
| 970 | 1043 |
Model.Source.prototype.handleCallbacks = function() { |
1044 |
this.status = Model._SOURCE_STATUS_READY; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1045 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1046 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 1047 |
} |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1048 |
} |
| 970 | 1049 |
Model.Source.prototype.onLoad = function(_callback) { |
1050 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1051 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1052 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1053 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1054 |
} |
| 854 | 1055 |
} |
1056 |
||
| 970 | 1057 |
Model.Source.prototype.serialize = function() { |
| 860 | 1058 |
return this.serializer.serialize(this); |
1059 |
} |
|
1060 |
||
| 970 | 1061 |
Model.Source.prototype.deSerialize = function(_data) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1062 |
this.serializer.deSerialize(_data, this); |
| 854 | 1063 |
} |
1064 |
||
| 970 | 1065 |
Model.Source.prototype.getAnnotations = 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("annotation", _global); |
| 854 | 1068 |
} |
1069 |
||
| 970 | 1070 |
Model.Source.prototype.getMedias = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1071 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1072 |
return this.getList("media", _global); |
| 864 | 1073 |
} |
1074 |
||
| 970 | 1075 |
Model.Source.prototype.getTags = function(_global) { |
| 904 | 1076 |
_global = (typeof _global !== "undefined" && _global); |
1077 |
return this.getList("tag", _global); |
|
1078 |
} |
|
1079 |
||
| 970 | 1080 |
Model.Source.prototype.getMashups = function(_global) { |
| 900 | 1081 |
_global = (typeof _global !== "undefined" && _global); |
1082 |
return this.getList("mashup", _global); |
|
1083 |
} |
|
1084 |
||
| 970 | 1085 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1086 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1087 |
return this.getList("annotationType", _global); |
| 864 | 1088 |
} |
1089 |
||
| 970 | 1090 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1091 |
_global = (typeof _global !== "undefined" && _global); |
| 970 | 1092 |
var _res = new Model.List(this.directory), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1093 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1094 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1095 |
_res.addElements(_annType.getAnnotations(_global)); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1096 |
}) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1097 |
return _res; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1098 |
} |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1099 |
|
| 970 | 1100 |
Model.Source.prototype.getDuration = function() { |
| 866 | 1101 |
var _m = this.currentMedia; |
1102 |
if (typeof _m !== "undefined") { |
|
1103 |
return this.currentMedia.duration; |
|
1104 |
} |
|
| 858 | 1105 |
} |
1106 |
||
| 970 | 1107 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
| 959 | 1108 |
if (typeof this.currentMedia === "undefined") { |
1109 |
if (_opts.is_mashup) { |
|
| 957 | 1110 |
var _mashups = this.getMashups(); |
1111 |
if (_mashups.length) { |
|
1112 |
this.currentMedia = _mashups[0]; |
|
1113 |
} |
|
1114 |
} else { |
|
1115 |
var _medias = this.getMedias(); |
|
1116 |
if (_medias.length) { |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1117 |
this.currentMedia = _medias[0]; |
| 957 | 1118 |
} |
1119 |
} |
|
1120 |
} |
|
1121 |
return this.currentMedia; |
|
1122 |
} |
|
1123 |
||
| 970 | 1124 |
Model.Source.prototype.merge = function(_source) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1125 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1126 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1127 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1128 |
}); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1129 |
} |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1130 |
|
| 858 | 1131 |
/* */ |
1132 |
||
| 970 | 1133 |
Model.RemoteSource = function(_config) { |
1134 |
Model.Source.call(this, _config); |
|
| 858 | 1135 |
} |
1136 |
||
| 970 | 1137 |
Model.RemoteSource.prototype = new Model.Source(); |
| 858 | 1138 |
|
| 970 | 1139 |
Model.RemoteSource.prototype.get = function() { |
1140 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
| 983 | 1141 |
var _this = this, |
1142 |
urlparams = this.url_params || {}, |
|
1143 |
dataType = (Model.isLocalURL(this.url) ? "json" : "jsonp"); |
|
1144 |
urlparams.format = dataType; |
|
1145 |
ns.jQuery.ajax({ |
|
1146 |
url: this.url, |
|
1147 |
dataType: dataType, |
|
1148 |
data: urlparams, |
|
| 986 | 1149 |
traditional: true, |
| 983 | 1150 |
success: function(_result) { |
1151 |
_this.deSerialize(_result); |
|
1152 |
_this.handleCallbacks(); |
|
1153 |
} |
|
| 858 | 1154 |
}); |
| 854 | 1155 |
} |
1156 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1157 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1158 |
|
| 970 | 1159 |
Model.Directory = function() { |
| 858 | 1160 |
this.remoteSources = {}; |
1161 |
this.elements = {}; |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1162 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1163 |
|
| 970 | 1164 |
Model.Directory.prototype.remoteSource = function(_properties) { |
| 917 | 1165 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 970 | 1166 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
| 917 | 1167 |
} |
| 970 | 1168 |
var _config = ns._({ directory: this }).extend(_properties); |
| 983 | 1169 |
_config.url_params = _config.url_params || {}; |
1170 |
var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); |
|
1171 |
if (typeof this.remoteSources[_hash] === "undefined") { |
|
1172 |
this.remoteSources[_hash] = new Model.RemoteSource(_config); |
|
| 858 | 1173 |
} |
| 983 | 1174 |
return this.remoteSources[_hash]; |
| 854 | 1175 |
} |
1176 |
||
| 970 | 1177 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
1178 |
var _config = ns._({ directory: this }).extend(_properties), |
|
1179 |
_res = new Model.Source(_config); |
|
| 860 | 1180 |
return _res; |
1181 |
} |
|
1182 |
||
| 970 | 1183 |
Model.Directory.prototype.getElement = function(_id) { |
| 900 | 1184 |
return this.elements[_id]; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1185 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1186 |
|
| 970 | 1187 |
Model.Directory.prototype.addElement = function(_element) { |
| 858 | 1188 |
this.elements[_element.id] = _element; |
1189 |
} |
|
1190 |
||
| 970 | 1191 |
Model.Directory.prototype.getGlobalList = function() { |
1192 |
var _res = new Model.List(this); |
|
1193 |
_res.addIds(ns._(this.elements).keys()); |
|
| 858 | 1194 |
return _res; |
| 854 | 1195 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1196 |
|
| 972 | 1197 |
return Model; |
| 970 | 1198 |
|
1199 |
})(IriSP); |