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