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