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