| author | ymh <ymh.work@gmail.com> |
| Thu, 31 Dec 2015 15:51:09 +0100 | |
| changeset 1070 | 36517cb225fe |
| parent 1068 | 7623f9af9272 |
| child 1072 | ac1eacb3aa33 |
| 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; |
|
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
579 |
this.timeRange = false; |
| 987 | 580 |
this.loadedMetadata = false; |
| 970 | 581 |
var _this = this; |
582 |
this.on("play", function() { |
|
583 |
_this.paused = false; |
|
584 |
}); |
|
585 |
this.on("pause", function() { |
|
586 |
_this.paused = true; |
|
587 |
}); |
|
588 |
this.on("timeupdate", function(_time) { |
|
589 |
_this.currentTime = _time; |
|
| 983 | 590 |
_this.getAnnotations().filter(function(_a) { |
| 1013 | 591 |
return (_a.end <= _time || _a.begin > _time) && _a.playing; |
| 983 | 592 |
}).forEach(function(_a) { |
593 |
_a.playing = false; |
|
594 |
_a.trigger("leave"); |
|
595 |
_this.trigger("leave-annotation",_a); |
|
596 |
}); |
|
597 |
_this.getAnnotations().filter(function(_a) { |
|
| 1013 | 598 |
return _a.begin <= _time && _a.end > _time && !_a.playing; |
| 983 | 599 |
}).forEach(function(_a) { |
600 |
_a.playing = true; |
|
601 |
_a.trigger("enter"); |
|
602 |
_this.trigger("enter-annotation",_a); |
|
603 |
}); |
|
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
604 |
|
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
605 |
if (_this.getTimeRange()){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
606 |
if (_this.getTimeRange()[0] > _time) { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
607 |
_this.pause(); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
608 |
_this.setCurrentTime(_this.getTimeRange()[0]); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
609 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
610 |
if (_this.getTimeRange()[1] < _time){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
611 |
_this.pause(); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
612 |
_this.setCurrentTime(_this.getTimeRange()[1]); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
613 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
614 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
615 |
|
| 970 | 616 |
}); |
| 987 | 617 |
this.on("loadedmetadata", function() { |
618 |
_this.loadedMetadata = true; |
|
| 998 | 619 |
}); |
620 |
}; |
|
| 970 | 621 |
|
| 998 | 622 |
extendPrototype(Playable, BaseElement); |
| 970 | 623 |
|
| 998 | 624 |
Playable.prototype.getCurrentTime = function() { |
| 970 | 625 |
return this.currentTime; |
| 998 | 626 |
}; |
| 970 | 627 |
|
| 998 | 628 |
Playable.prototype.getVolume = function() { |
| 970 | 629 |
return this.volume; |
| 998 | 630 |
}; |
| 970 | 631 |
|
| 998 | 632 |
Playable.prototype.getPaused = function() { |
| 970 | 633 |
return this.paused; |
| 998 | 634 |
}; |
| 970 | 635 |
|
| 998 | 636 |
Playable.prototype.getMuted = function() { |
| 970 | 637 |
return this.muted; |
| 998 | 638 |
}; |
| 970 | 639 |
|
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
640 |
Playable.prototype.getTimeRange = function() { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
641 |
return this.timeRange; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
642 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
643 |
|
| 998 | 644 |
Playable.prototype.setCurrentTime = function(_time) { |
| 970 | 645 |
this.trigger("setcurrenttime",_time); |
| 998 | 646 |
}; |
| 970 | 647 |
|
| 998 | 648 |
Playable.prototype.setVolume = function(_vol) { |
| 970 | 649 |
this.trigger("setvolume",_vol); |
| 998 | 650 |
}; |
| 970 | 651 |
|
| 998 | 652 |
Playable.prototype.setMuted = function(_muted) { |
| 970 | 653 |
this.trigger("setmuted",_muted); |
| 998 | 654 |
}; |
| 970 | 655 |
|
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
656 |
Playable.prototype.setTimeRange = function(_timeBegin, _timeEnd) { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
657 |
if ((_timeBegin < _timeEnd)&&(_timeBegin >= 0)&&(_timeEnd>0)){ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
658 |
return this.trigger("settimerange", [_timeBegin, _timeEnd]); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
659 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
660 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
661 |
|
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
662 |
Playable.prototype.resetTimeRange = function() { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
663 |
return this.trigger("resettimerange"); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
664 |
} |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
665 |
|
| 998 | 666 |
Playable.prototype.play = function() { |
| 970 | 667 |
this.trigger("setplay"); |
| 998 | 668 |
}; |
| 970 | 669 |
|
| 998 | 670 |
Playable.prototype.pause = function() { |
| 970 | 671 |
this.trigger("setpause"); |
| 998 | 672 |
}; |
| 970 | 673 |
|
| 998 | 674 |
Playable.prototype.show = function() {}; |
| 983 | 675 |
|
| 998 | 676 |
Playable.prototype.hide = function() {}; |
| 970 | 677 |
|
678 |
/* */ |
|
679 |
||
| 998 | 680 |
var Media = Model.Media = function(_id, _source) { |
681 |
Playable.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
682 |
this.elementType = 'media'; |
| 998 | 683 |
this.duration = new Time(); |
| 866 | 684 |
this.video = ''; |
| 965 | 685 |
var _this = this; |
| 998 | 686 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
687 |
|
| 998 | 688 |
extendPrototype(Media, Playable); |
|
1044
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
689 |
/* */ |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
690 |
|
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
691 |
var Media = Model.Media = function(_id, _source) { |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
692 |
Playable.call(this, _id, _source); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
693 |
this.elementType = 'media'; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
694 |
this.duration = new Time(); |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
695 |
this.video = ''; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
696 |
var _this = this; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
697 |
}; |
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
698 |
|
|
d8339b45edc4
Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents:
1026
diff
changeset
|
699 |
extendPrototype(Media, Playable); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
700 |
|
| 957 | 701 |
/* Default functions to be overriden by players */ |
702 |
|
|
| 998 | 703 |
Media.prototype.setDuration = function(_durationMs) { |
| 900 | 704 |
this.duration.setMilliseconds(_durationMs); |
| 998 | 705 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
706 |
|
| 998 | 707 |
Media.prototype.getAnnotations = function() { |
| 864 | 708 |
return this.getRelated("annotation"); |
| 998 | 709 |
}; |
| 864 | 710 |
|
| 998 | 711 |
Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 712 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
713 |
if (_annTypes.length) { |
|
714 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 715 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 716 |
}); |
717 |
} else { |
|
| 1013 | 718 |
return new List(this.source.directory); |
| 900 | 719 |
} |
| 998 | 720 |
}; |
| 900 | 721 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
722 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
723 |
|
| 998 | 724 |
var Tag = Model.Tag = function(_id, _source) { |
725 |
BaseElement.call(this, _id, _source); |
|
| 858 | 726 |
this.elementType = 'tag'; |
| 998 | 727 |
}; |
| 858 | 728 |
|
| 998 | 729 |
extendPrototype(Tag, BaseElement); |
| 858 | 730 |
|
| 998 | 731 |
Tag.prototype.getAnnotations = function() { |
| 864 | 732 |
return this.getRelated("annotation"); |
| 998 | 733 |
}; |
| 864 | 734 |
|
| 858 | 735 |
/* */ |
| 998 | 736 |
var AnnotationType = Model.AnnotationType = function(_id, _source) { |
737 |
BaseElement.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
738 |
this.elementType = 'annotationType'; |
| 998 | 739 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
740 |
|
| 998 | 741 |
extendPrototype(AnnotationType, BaseElement); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
742 |
|
| 998 | 743 |
AnnotationType.prototype.getAnnotations = function() { |
| 864 | 744 |
return this.getRelated("annotation"); |
| 998 | 745 |
}; |
| 864 | 746 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
747 |
/* Annotation |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
748 |
* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
749 |
|
| 998 | 750 |
var Annotation = Model.Annotation = function(_id, _source) { |
751 |
BaseElement.call(this, _id, _source); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
752 |
this.elementType = 'annotation'; |
| 998 | 753 |
this.begin = new Time(); |
754 |
this.end = new Time(); |
|
755 |
this.tag = new Reference(_source, []); |
|
| 965 | 756 |
this.playing = false; |
| 964 | 757 |
var _this = this; |
758 |
this.on("click", function() { |
|
759 |
_this.getMedia().setCurrentTime(_this.begin); |
|
| 965 | 760 |
}); |
| 998 | 761 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
762 |
|
| 998 | 763 |
extendPrototype(Annotation, BaseElement); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
764 |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
765 |
/* Set begin and end in one go, to avoid undesired side-effects in |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
766 |
* setBegin/setEnd interaction */ |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
767 |
Annotation.prototype.setBeginEnd = function(_beginMs, _endMs) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
768 |
_beginMs = Math.max(0,_beginMs); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
769 |
_endMs = Math.max(0,_endMs); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
770 |
if (_endMs < _beginMs) |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
771 |
_endMs = _beginMs; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
772 |
this.begin.setMilliseconds(_beginMs); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
773 |
this.end.setMilliseconds(_endMs); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
774 |
this.trigger("change-begin"); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
775 |
this.trigger("change-end"); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
776 |
}; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1044
diff
changeset
|
777 |
|
| 998 | 778 |
Annotation.prototype.setBegin = function(_beginMs) { |
| 976 | 779 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
780 |
this.trigger("change-begin"); |
|
| 983 | 781 |
if (this.end < this.begin) { |
782 |
this.setEnd(this.begin); |
|
783 |
} |
|
| 998 | 784 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
785 |
|
| 998 | 786 |
Annotation.prototype.setEnd = function(_endMs) { |
| 983 | 787 |
this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
| 976 | 788 |
this.trigger("change-end"); |
| 983 | 789 |
if (this.end < this.begin) { |
790 |
this.setBegin(this.end); |
|
791 |
} |
|
| 998 | 792 |
}; |
| 976 | 793 |
|
| 998 | 794 |
Annotation.prototype.setDuration = function(_durMs) { |
| 976 | 795 |
this.setEnd(_durMs + this.begin.milliseconds); |
| 998 | 796 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
797 |
|
| 998 | 798 |
Annotation.prototype.setMedia = function(_idRef) { |
| 858 | 799 |
this.setReference("media", _idRef); |
| 998 | 800 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
801 |
|
| 998 | 802 |
Annotation.prototype.getMedia = function() { |
| 858 | 803 |
return this.getReference("media"); |
| 998 | 804 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
805 |
|
| 998 | 806 |
Annotation.prototype.setAnnotationType = function(_idRef) { |
| 858 | 807 |
this.setReference("annotationType", _idRef); |
| 998 | 808 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
809 |
|
| 998 | 810 |
Annotation.prototype.getAnnotationType = function() { |
| 858 | 811 |
return this.getReference("annotationType"); |
| 998 | 812 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
813 |
|
| 998 | 814 |
Annotation.prototype.setTags = function(_idRefs) { |
| 858 | 815 |
this.setReference("tag", _idRefs); |
| 998 | 816 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
817 |
|
| 998 | 818 |
Annotation.prototype.getTags = function() { |
| 858 | 819 |
return this.getReference("tag"); |
| 998 | 820 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
821 |
|
| 998 | 822 |
Annotation.prototype.getTagTexts = function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
823 |
return this.getTags().getTitles(); |
| 998 | 824 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
825 |
|
| 998 | 826 |
Annotation.prototype.getDuration = function() { |
| 1013 | 827 |
return new Time(this.end.milliseconds - this.begin.milliseconds); |
| 998 | 828 |
}; |
| 900 | 829 |
|
| 858 | 830 |
/* */ |
831 |
||
| 998 | 832 |
var MashedAnnotation = Model.MashedAnnotation = function(_mashup, _annotation) { |
833 |
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
|
834 |
this.elementType = 'mashedAnnotation'; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
835 |
this.annotation = _annotation; |
| 998 | 836 |
this.begin = new Time(); |
837 |
this.end = new Time(); |
|
838 |
this.duration = new Time(); |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
839 |
this.title = this.annotation.title; |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
840 |
this.description = this.annotation.description; |
| 900 | 841 |
this.color = this.annotation.color; |
| 965 | 842 |
var _this = this; |
843 |
this.on("click", function() { |
|
844 |
_mashup.setCurrentTime(_this.begin); |
|
845 |
}); |
|
| 983 | 846 |
this.on("enter", function() { |
847 |
_this.annotation.trigger("enter"); |
|
848 |
}); |
|
849 |
this.on("leave", function() { |
|
850 |
_this.annotation.trigger("leave"); |
|
851 |
}); |
|
| 998 | 852 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
853 |
|
| 998 | 854 |
extendPrototype(MashedAnnotation, BaseElement); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
855 |
|
| 998 | 856 |
MashedAnnotation.prototype.getMedia = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
857 |
return this.annotation.getReference("media"); |
| 998 | 858 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
859 |
|
| 998 | 860 |
MashedAnnotation.prototype.getAnnotationType = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
861 |
return this.annotation.getReference("annotationType"); |
| 998 | 862 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
863 |
|
| 998 | 864 |
MashedAnnotation.prototype.getTags = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
865 |
return this.annotation.getReference("tag"); |
| 998 | 866 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
867 |
|
| 998 | 868 |
MashedAnnotation.prototype.getTagTexts = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
869 |
return this.annotation.getTags().getTitles(); |
| 998 | 870 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
871 |
|
| 998 | 872 |
MashedAnnotation.prototype.getDuration = function() { |
| 940 | 873 |
return this.annotation.getDuration(); |
| 998 | 874 |
}; |
| 940 | 875 |
|
| 998 | 876 |
MashedAnnotation.prototype.setBegin = function(_begin) { |
| 983 | 877 |
this.begin.setMilliseconds(_begin); |
878 |
this.duration.setMilliseconds(this.annotation.getDuration()); |
|
879 |
this.end.setMilliseconds(_begin + this.duration); |
|
| 998 | 880 |
}; |
| 983 | 881 |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
882 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
883 |
|
| 998 | 884 |
var Mashup = Model.Mashup = function(_id, _source) { |
885 |
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
|
886 |
this.elementType = 'mashup'; |
| 998 | 887 |
this.duration = new Time(); |
888 |
this.segments = new List(_source.directory); |
|
| 983 | 889 |
this.loaded = false; |
| 965 | 890 |
var _this = this; |
| 983 | 891 |
this._updateTimes = function() { |
892 |
_this.updateTimes(); |
|
893 |
_this.trigger("change"); |
|
| 1013 | 894 |
}; |
| 983 | 895 |
this.on("add", this._updateTimes); |
896 |
this.on("remove", this._updateTimes); |
|
| 998 | 897 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
898 |
|
| 998 | 899 |
extendPrototype(Mashup, Playable); |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
900 |
|
| 998 | 901 |
Mashup.prototype.updateTimes = function() { |
| 983 | 902 |
var _time = 0; |
903 |
this.segments.forEach(function(_segment) { |
|
904 |
_segment.setBegin(_time); |
|
905 |
_time = _segment.end; |
|
906 |
}); |
|
907 |
this.duration.setMilliseconds(_time); |
|
| 998 | 908 |
}; |
| 983 | 909 |
|
| 998 | 910 |
Mashup.prototype.addAnnotation = function(_annotation, _defer) { |
911 |
var _mashedAnnotation = new MashedAnnotation(this, _annotation), |
|
| 983 | 912 |
_defer = _defer || false; |
| 900 | 913 |
this.segments.push(_mashedAnnotation); |
| 983 | 914 |
_annotation.on("change-begin", this._updateTimes); |
915 |
_annotation.on("change-end", this._updateTimes); |
|
916 |
if (!_defer) { |
|
917 |
this.trigger("add"); |
|
918 |
} |
|
| 998 | 919 |
}; |
| 983 | 920 |
|
| 998 | 921 |
Mashup.prototype.addAnnotationById = function(_elId, _defer) { |
| 983 | 922 |
var _annotation = this.source.getElement(_elId), |
923 |
_defer = _defer || false; |
|
924 |
if (typeof _annotation !== "undefined") { |
|
925 |
this.addAnnotation(_annotation, _defer); |
|
926 |
} |
|
| 998 | 927 |
}; |
| 983 | 928 |
|
| 998 | 929 |
Mashup.prototype.addAnnotations = function(_segments) { |
| 983 | 930 |
var _this = this; |
931 |
ns._(_segments).forEach(function(_segment) { |
|
932 |
_this.addAnnotation(_segment, true); |
|
933 |
}); |
|
934 |
this.trigger("add"); |
|
| 998 | 935 |
}; |
| 900 | 936 |
|
| 998 | 937 |
Mashup.prototype.addAnnotationsById = function(_segments) { |
| 983 | 938 |
var _this = this; |
939 |
ns._(_segments).forEach(function(_segment) { |
|
940 |
_this.addAnnotationById(_segment, true); |
|
941 |
}); |
|
942 |
this.trigger("add"); |
|
| 998 | 943 |
}; |
| 983 | 944 |
|
| 998 | 945 |
Mashup.prototype.removeAnnotation = function(_annotation, _defer) { |
| 983 | 946 |
var _defer = _defer || false; |
947 |
_annotation.off("change-begin", this._updateTimes); |
|
948 |
_annotation.off("change-end", this._updateTimes); |
|
949 |
this.segments.removeId(this.id + "_" + _annotation.id); |
|
950 |
if (!_defer) { |
|
951 |
this.trigger("remove"); |
|
952 |
} |
|
| 998 | 953 |
}; |
| 983 | 954 |
|
| 998 | 955 |
Mashup.prototype.removeAnnotationById = function(_annId, _defer) { |
| 983 | 956 |
var _defer = _defer || false; |
957 |
var _annotation = this.source.getElement(_annId); |
|
958 |
||
959 |
if (_annotation) { |
|
960 |
this.removeAnnotation(_annotation, _defer); |
|
961 |
} |
|
962 |
if (!_defer) { |
|
963 |
this.trigger("remove"); |
|
| 900 | 964 |
} |
| 998 | 965 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
966 |
|
| 998 | 967 |
Mashup.prototype.setAnnotations = function(_segments) { |
| 983 | 968 |
while (this.segments.length) { |
969 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
970 |
} |
|
971 |
this.addAnnotations(_segments); |
|
| 998 | 972 |
}; |
| 983 | 973 |
|
| 998 | 974 |
Mashup.prototype.setAnnotationsById = function(_segments) { |
| 983 | 975 |
while (this.segments.length) { |
976 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
977 |
} |
|
978 |
this.addAnnotationsById(_segments); |
|
| 998 | 979 |
}; |
| 983 | 980 |
|
| 998 | 981 |
Mashup.prototype.hasAnnotation = function(_annotation) { |
| 983 | 982 |
return !!ns._(this.segments).find(function(_s) { |
| 1013 | 983 |
return _s.annotation === _annotation; |
| 983 | 984 |
}); |
| 998 | 985 |
}; |
| 983 | 986 |
|
| 998 | 987 |
Mashup.prototype.getAnnotation = function(_annotation) { |
| 983 | 988 |
return ns._(this.segments).find(function(_s) { |
| 1013 | 989 |
return _s.annotation === _annotation; |
| 983 | 990 |
}); |
| 998 | 991 |
}; |
| 983 | 992 |
|
| 998 | 993 |
Mashup.prototype.getAnnotationById = function(_id) { |
| 983 | 994 |
return ns._(this.segments).find(function(_s) { |
| 1013 | 995 |
return _s.annotation.id === _id; |
| 983 | 996 |
}); |
| 998 | 997 |
}; |
| 983 | 998 |
|
| 998 | 999 |
Mashup.prototype.getAnnotations = function() { |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
1000 |
return this.segments; |
| 998 | 1001 |
}; |
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
1002 |
|
| 998 | 1003 |
Mashup.prototype.getOriginalAnnotations = function() { |
1004 |
var annotations = new List(this.source.directory); |
|
| 983 | 1005 |
this.segments.forEach(function(_s) { |
1006 |
annotations.push(_s.annotation); |
|
1007 |
}); |
|
1008 |
return annotations; |
|
| 998 | 1009 |
}; |
| 983 | 1010 |
|
| 998 | 1011 |
Mashup.prototype.getMedias = function() { |
1012 |
var medias = new List(this.source.directory); |
|
| 983 | 1013 |
this.segments.forEach(function(_annotation) { |
| 1013 | 1014 |
medias.push(_annotation.getMedia()); |
1015 |
}); |
|
| 983 | 1016 |
return medias; |
| 998 | 1017 |
}; |
| 900 | 1018 |
|
| 998 | 1019 |
Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 900 | 1020 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
1021 |
if (_annTypes.length) { |
|
1022 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 970 | 1023 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 900 | 1024 |
}); |
1025 |
} else { |
|
| 1013 | 1026 |
return new List(this.source.directory); |
| 900 | 1027 |
} |
| 998 | 1028 |
}; |
| 900 | 1029 |
|
| 998 | 1030 |
Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 903 | 1031 |
var _list = this.segments.filter(function(_annotation) { |
1032 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
1033 |
}); |
|
1034 |
if (_list.length) { |
|
1035 |
return _list[0]; |
|
1036 |
} else { |
|
1037 |
return undefined; |
|
1038 |
} |
|
| 998 | 1039 |
}; |
| 903 | 1040 |
|
| 998 | 1041 |
Mashup.prototype.getMediaAtTime = function(_time) { |
| 903 | 1042 |
var _annotation = this.getAnnotationAtTime(_time); |
1043 |
if (typeof _annotation !== "undefined") { |
|
1044 |
return _annotation.getMedia(); |
|
1045 |
} else { |
|
1046 |
return undefined; |
|
1047 |
} |
|
| 998 | 1048 |
}; |
| 903 | 1049 |
|
|
887
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
1050 |
/* */ |
|
6a04bd37da0a
Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents:
881
diff
changeset
|
1051 |
|
| 998 | 1052 |
var Source = Model.Source = function(_config) { |
1053 |
BaseElement.call(this, false, this); |
|
1054 |
this.status = _SOURCE_STATUS_EMPTY; |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1055 |
this.elementType = "source"; |
| 860 | 1056 |
if (typeof _config !== "undefined") { |
1057 |
var _this = this; |
|
| 970 | 1058 |
ns._(_config).forEach(function(_v, _k) { |
| 860 | 1059 |
_this[_k] = _v; |
| 1013 | 1060 |
}); |
| 860 | 1061 |
this.callbackQueue = []; |
1062 |
this.contents = {}; |
|
1063 |
this.get(); |
|
1064 |
} |
|
| 998 | 1065 |
}; |
| 860 | 1066 |
|
| 998 | 1067 |
extendPrototype(Source, BaseElement); |
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1068 |
|
| 998 | 1069 |
Source.prototype.addList = function(_listId, _contents) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1070 |
if (typeof this.contents[_listId] === "undefined") { |
| 998 | 1071 |
this.contents[_listId] = new List(this.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1072 |
} |
| 866 | 1073 |
this.contents[_listId].addElements(_contents); |
| 998 | 1074 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1075 |
|
| 998 | 1076 |
Source.prototype.getList = function(_listId, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1077 |
_global = (typeof _global !== "undefined" && _global); |
| 986 | 1078 |
if (_global) { |
| 860 | 1079 |
return this.directory.getGlobalList().filter(function(_e) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1080 |
return (_e.elementType === _listId); |
| 858 | 1081 |
}); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1082 |
} else { |
| 1002 | 1083 |
if (typeof this.contents[_listId] === "undefined") { |
| 1010 | 1084 |
this.contents[_listId] = new List(this.directory); |
| 1002 | 1085 |
} |
1086 |
return this.contents[_listId]; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1087 |
} |
| 998 | 1088 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1089 |
|
| 998 | 1090 |
Source.prototype.forEach = function(_callback) { |
| 860 | 1091 |
var _this = this; |
| 970 | 1092 |
ns._(this.contents).forEach(function(_value, _key) { |
| 860 | 1093 |
_callback.call(_this, _value, _key); |
| 1013 | 1094 |
}); |
| 998 | 1095 |
}; |
| 860 | 1096 |
|
| 998 | 1097 |
Source.prototype.getElement = function(_elId) { |
| 916 | 1098 |
return this.directory.getElement(_elId); |
| 998 | 1099 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1100 |
|
| 998 | 1101 |
Source.prototype.get = function() { |
1102 |
this.status = _SOURCE_STATUS_WAITING; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1103 |
this.handleCallbacks(); |
| 998 | 1104 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1105 |
|
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1106 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
| 998 | 1107 |
Source.prototype.deferCallback = function(_callback) { |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1108 |
var _this = this; |
| 970 | 1109 |
ns._.defer(function() { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1110 |
_callback.call(_this); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1111 |
}); |
| 998 | 1112 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1113 |
|
| 998 | 1114 |
Source.prototype.handleCallbacks = function() { |
1115 |
this.status = _SOURCE_STATUS_READY; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1116 |
while (this.callbackQueue.length) { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1117 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
| 858 | 1118 |
} |
| 998 | 1119 |
}; |
1120 |
Source.prototype.onLoad = function(_callback) { |
|
1121 |
if (this.status === _SOURCE_STATUS_READY) { |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1122 |
this.deferCallback(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1123 |
} else { |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1124 |
this.callbackQueue.push(_callback); |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1125 |
} |
| 998 | 1126 |
}; |
| 854 | 1127 |
|
| 998 | 1128 |
Source.prototype.serialize = function() { |
| 860 | 1129 |
return this.serializer.serialize(this); |
| 998 | 1130 |
}; |
| 860 | 1131 |
|
| 998 | 1132 |
Source.prototype.deSerialize = function(_data) { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1133 |
this.serializer.deSerialize(_data, this); |
| 998 | 1134 |
}; |
| 854 | 1135 |
|
| 998 | 1136 |
Source.prototype.getAnnotations = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1137 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1138 |
return this.getList("annotation", _global); |
| 998 | 1139 |
}; |
| 854 | 1140 |
|
| 998 | 1141 |
Source.prototype.getMedias = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1142 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1143 |
return this.getList("media", _global); |
| 998 | 1144 |
}; |
| 864 | 1145 |
|
| 998 | 1146 |
Source.prototype.getTags = function(_global) { |
| 904 | 1147 |
_global = (typeof _global !== "undefined" && _global); |
1148 |
return this.getList("tag", _global); |
|
| 998 | 1149 |
}; |
| 904 | 1150 |
|
| 998 | 1151 |
Source.prototype.getMashups = function(_global) { |
| 900 | 1152 |
_global = (typeof _global !== "undefined" && _global); |
1153 |
return this.getList("mashup", _global); |
|
| 998 | 1154 |
}; |
| 900 | 1155 |
|
| 998 | 1156 |
Source.prototype.getAnnotationTypes = function(_global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1157 |
_global = (typeof _global !== "undefined" && _global); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1158 |
return this.getList("annotationType", _global); |
| 998 | 1159 |
}; |
| 864 | 1160 |
|
| 998 | 1161 |
Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1162 |
_global = (typeof _global !== "undefined" && _global); |
| 998 | 1163 |
var _res = new List(this.directory), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1164 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1165 |
_annTypes.forEach(function(_annType) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1166 |
_res.addElements(_annType.getAnnotations(_global)); |
| 1013 | 1167 |
}); |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1168 |
return _res; |
| 998 | 1169 |
}; |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
868
diff
changeset
|
1170 |
|
| 998 | 1171 |
Source.prototype.getDuration = function() { |
| 866 | 1172 |
var _m = this.currentMedia; |
1173 |
if (typeof _m !== "undefined") { |
|
1174 |
return this.currentMedia.duration; |
|
1175 |
} |
|
| 998 | 1176 |
}; |
| 858 | 1177 |
|
| 998 | 1178 |
Source.prototype.getCurrentMedia = function(_opts) { |
| 959 | 1179 |
if (typeof this.currentMedia === "undefined") { |
1180 |
if (_opts.is_mashup) { |
|
| 957 | 1181 |
var _mashups = this.getMashups(); |
1182 |
if (_mashups.length) { |
|
1183 |
this.currentMedia = _mashups[0]; |
|
1184 |
} |
|
1185 |
} else { |
|
1186 |
var _medias = this.getMedias(); |
|
1187 |
if (_medias.length) { |
|
|
969
353b0881a0b9
Added On-the-fly (file-less) metadata generation test
veltr
parents:
965
diff
changeset
|
1188 |
this.currentMedia = _medias[0]; |
| 957 | 1189 |
} |
1190 |
} |
|
1191 |
} |
|
1192 |
return this.currentMedia; |
|
| 998 | 1193 |
}; |
| 957 | 1194 |
|
| 998 | 1195 |
Source.prototype.merge = function(_source) { |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1196 |
var _this = this; |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1197 |
_source.forEach(function(_value, _key) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1198 |
_this.getList(_key).addElements(_value); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1199 |
}); |
| 998 | 1200 |
}; |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
1201 |
|
| 858 | 1202 |
/* */ |
1203 |
||
| 998 | 1204 |
var RemoteSource = Model.RemoteSource = function(_config) { |
1205 |
Source.call(this, _config); |
|
1206 |
}; |
|
| 858 | 1207 |
|
| 998 | 1208 |
extendPrototype(RemoteSource, Source); |
| 858 | 1209 |
|
| 998 | 1210 |
RemoteSource.prototype.get = function() { |
1211 |
this.status = _SOURCE_STATUS_WAITING; |
|
| 983 | 1212 |
var _this = this, |
1213 |
urlparams = this.url_params || {}, |
|
| 998 | 1214 |
dataType = (isLocalURL(this.url) ? "json" : "jsonp"); |
| 983 | 1215 |
urlparams.format = dataType; |
1216 |
ns.jQuery.ajax({ |
|
1217 |
url: this.url, |
|
1218 |
dataType: dataType, |
|
1219 |
data: urlparams, |
|
| 986 | 1220 |
traditional: true, |
| 983 | 1221 |
success: function(_result) { |
1222 |
_this.deSerialize(_result); |
|
1223 |
_this.handleCallbacks(); |
|
1224 |
} |
|
| 858 | 1225 |
}); |
| 998 | 1226 |
}; |
| 854 | 1227 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1228 |
/* */ |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1229 |
|
| 998 | 1230 |
var Directory = Model.Directory = function() { |
| 858 | 1231 |
this.remoteSources = {}; |
1232 |
this.elements = {}; |
|
| 998 | 1233 |
}; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
870
diff
changeset
|
1234 |
|
| 998 | 1235 |
Directory.prototype.remoteSource = function(_properties) { |
| 917 | 1236 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 998 | 1237 |
throw "Error : Directory.remoteSource(configuration): configuration.url is undefined"; |
| 917 | 1238 |
} |
| 970 | 1239 |
var _config = ns._({ directory: this }).extend(_properties); |
| 983 | 1240 |
_config.url_params = _config.url_params || {}; |
1241 |
var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); |
|
1242 |
if (typeof this.remoteSources[_hash] === "undefined") { |
|
| 998 | 1243 |
this.remoteSources[_hash] = new RemoteSource(_config); |
| 858 | 1244 |
} |
| 983 | 1245 |
return this.remoteSources[_hash]; |
| 998 | 1246 |
}; |
| 854 | 1247 |
|
| 998 | 1248 |
Directory.prototype.newLocalSource = function(_properties) { |
| 970 | 1249 |
var _config = ns._({ directory: this }).extend(_properties), |
| 998 | 1250 |
_res = new Source(_config); |
| 860 | 1251 |
return _res; |
| 998 | 1252 |
}; |
| 860 | 1253 |
|
| 998 | 1254 |
Directory.prototype.getElement = function(_id) { |
| 900 | 1255 |
return this.elements[_id]; |
| 998 | 1256 |
}; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
854
diff
changeset
|
1257 |
|
| 998 | 1258 |
Directory.prototype.addElement = function(_element) { |
| 858 | 1259 |
this.elements[_element.id] = _element; |
| 998 | 1260 |
}; |
| 858 | 1261 |
|
| 998 | 1262 |
Directory.prototype.getGlobalList = function() { |
1263 |
var _res = new List(this); |
|
| 970 | 1264 |
_res.addIds(ns._(this.elements).keys()); |
| 858 | 1265 |
return _res; |
| 998 | 1266 |
}; |
| 972 | 1267 |
return Model; |
| 970 | 1268 |
|
1269 |
})(IriSP); |
|
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
1270 |
|
| 998 | 1271 |
/* END js */ |
|
988
eefd336335f9
Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents:
987
diff
changeset
|
1272 |