| author | Raphael Velt <raph.velt@gmail.com> |
| Wed, 28 Nov 2012 13:19:48 +0100 | |
| changeset 719 | d0d3a9369f84 |
| parent 694 | e9400c80e1e4 |
| child 726 | d82d070cf23e |
| permissions | -rw-r--r-- |
| 598 | 1 |
/* |
2 |
* |
|
3 |
* Copyright 2010-2012 Institut de recherche et d'innovation |
|
4 |
* contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie |
|
5 |
* |
|
6 |
* contact@iri.centrepompidou.fr |
|
7 |
* http://www.iri.centrepompidou.fr |
|
8 |
* |
|
9 |
* This software is a computer program whose purpose is to show and add annotations on a video . |
|
10 |
* This software is governed by the CeCILL-C license under French law and |
|
11 |
* abiding by the rules of distribution of free software. You can use, |
|
12 |
* modify and/ or redistribute the software under the terms of the CeCILL-C |
|
13 |
* license as circulated by CEA, CNRS and INRIA at the following URL |
|
14 |
* "http://www.cecill.info". |
|
15 |
* |
|
16 |
* The fact that you are presently reading this means that you have had |
|
17 |
* knowledge of the CeCILL-C license and that you accept its terms. |
|
18 |
*/ |
|
19 |
/*! LAB.js (LABjs :: Loading And Blocking JavaScript) |
|
20 |
v2.0.3 (c) Kyle Simpson |
|
21 |
MIT License |
|
22 |
*/ |
|
| 694 | 23 |
(function(o){var K=o.$LAB,y="UseLocalXHR",z="AlwaysPreserveOrder",u="AllowDuplicates",A="CacheBust",B="BasePath",C=/^[^?#]*\//.exec(location.href)[0],D=/^\w+\:\/\/\/?[^\/]+/.exec(C)[0],i=document.head||document.getElementsByTagName("head"),L=(o.opera&&Object.prototype.toString.call(o.opera)=="[object Opera]")||("MozAppearance"in document.documentElement.style),q=document.createElement("script"),E=typeof q.preload=="boolean",r=E||(q.readyState&&q.readyState=="uninitialized"),F=!r&&q.async===true,M=!r&&!F&&!L;function G(a){return Object.prototype.toString.call(a)=="[object Function]"}function H(a){return Object.prototype.toString.call(a)=="[object Array]"}function N(a,c){var b=/^\w+\:\/\//;if(/^\/\/\/?/.test(a)){a=location.protocol+a}else if(!b.test(a)&&a.charAt(0)!="/"){a=(c||"")+a}return b.test(a)?a:((a.charAt(0)=="/"?D:C)+a)}function s(a,c){for(var b in a){if(a.hasOwnProperty(b)){c[b]=a[b]}}return c}function O(a){var c=false;for(var b=0;b<a.scripts.length;b++){if(a.scripts[b].ready&&a.scripts[b].exec_trigger){c=true;a.scripts[b].exec_trigger();a.scripts[b].exec_trigger=null}}return c}function t(a,c,b,d){a.onload=a.onreadystatechange=function(){if((a.readyState&&a.readyState!="complete"&&a.readyState!="loaded")||c[b])return;a.onload=a.onreadystatechange=null;d()}}function I(a){a.ready=a.finished=true;for(var c=0;c<a.finished_listeners.length;c++){a.finished_listeners[c]()}a.ready_listeners=[];a.finished_listeners=[]}function P(d,f,e,g,h){setTimeout(function(){var a,c=f.real_src,b;if("item"in i){if(!i[0]){setTimeout(arguments.callee,25);return}i=i[0]}a=document.createElement("script");if(f.type)a.type=f.type;if(f.charset)a.charset=f.charset;if(h){if(r){e.elem=a;if(E){a.preload=true;a.onpreload=g}else{a.onreadystatechange=function(){if(a.readyState=="loaded")g()}}a.src=c}else if(h&&c.indexOf(D)==0&&d[y]){b=new XMLHttpRequest();b.onreadystatechange=function(){if(b.readyState==4){b.onreadystatechange=function(){};e.text=b.responseText+"\n//@ sourceURL="+c;g()}};b.open("GET",c);b.send()}else{a.type="text/cache-script";t(a,e,"ready",function(){i.removeChild(a);g()});a.src=c;i.insertBefore(a,i.firstChild)}}else if(F){a.async=false;t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}else{t(a,e,"finished",g);a.src=c;i.insertBefore(a,i.firstChild)}},0)}function J(){var l={},Q=r||M,n=[],p={},m;l[y]=true;l[z]=false;l[u]=false;l[A]=false;l[B]="";function R(a,c,b){var d;function f(){if(d!=null){d=null;I(b)}}if(p[c.src].finished)return;if(!a[u])p[c.src].finished=true;d=b.elem||document.createElement("script");if(c.type)d.type=c.type;if(c.charset)d.charset=c.charset;t(d,b,"finished",f);if(b.elem){b.elem=null}else if(b.text){d.onload=d.onreadystatechange=null;d.text=b.text}else{d.src=c.real_src}i.insertBefore(d,i.firstChild);if(b.text){f()}}function S(c,b,d,f){var e,g,h=function(){b.ready_cb(b,function(){R(c,b,e)})},j=function(){b.finished_cb(b,d)};b.src=N(b.src,c[B]);b.real_src=b.src+(c[A]?((/\?.*$/.test(b.src)?"&_":"?_")+~~(Math.random()*1E9)+"="):"");if(!p[b.src])p[b.src]={items:[],finished:false};g=p[b.src].items;if(c[u]||g.length==0){e=g[g.length]={ready:false,finished:false,ready_listeners:[h],finished_listeners:[j]};P(c,b,e,((f)?function(){e.ready=true;for(var a=0;a<e.ready_listeners.length;a++){e.ready_listeners[a]()}e.ready_listeners=[]}:function(){I(e)}),f)}else{e=g[0];if(e.finished){j()}else{e.finished_listeners.push(j)}}}function v(){var e,g=s(l,{}),h=[],j=0,w=false,k;function T(a,c){a.ready=true;a.exec_trigger=c;x()}function U(a,c){a.ready=a.finished=true;a.exec_trigger=null;for(var b=0;b<c.scripts.length;b++){if(!c.scripts[b].finished)return}c.finished=true;x()}function x(){while(j<h.length){if(G(h[j])){try{h[j++]()}catch(err){}continue}else if(!h[j].finished){if(O(h[j]))continue;break}j++}if(j==h.length){w=false;k=false}}function V(){if(!k||!k.scripts){h.push(k={scripts:[],finished:true})}}e={script:function(){for(var f=0;f<arguments.length;f++){(function(a,c){var b;if(!H(a)){c=[a]}for(var d=0;d<c.length;d++){V();a=c[d];if(G(a))a=a();if(!a)continue;if(H(a)){b=[].slice.call(a);b.unshift(d,1);[].splice.apply(c,b);d--;continue}if(typeof a=="string")a={src:a};a=s(a,{ready:false,ready_cb:T,finished:false,finished_cb:U});k.finished=false;k.scripts.push(a);S(g,a,k,(Q&&w));w=true;if(g[z])e.wait()}})(arguments[f],arguments[f])}return e},wait:function(){if(arguments.length>0){for(var a=0;a<arguments.length;a++){h.push(arguments[a])}k=h[h.length-1]}else k=false;x();return e}};return{script:e.script,wait:e.wait,setOptions:function(a){s(a,g);return e}}}m={setGlobalDefaults:function(a){s(a,l);return m},setOptions:function(){return v().setOptions.apply(null,arguments)},script:function(){return v().script.apply(null,arguments)},wait:function(){return v().wait.apply(null,arguments)},queueScript:function(){n[n.length]={type:"script",args:[].slice.call(arguments)};return m},queueWait:function(){n[n.length]={type:"wait",args:[].slice.call(arguments)};return m},runQueue:function(){var a=m,c=n.length,b=c,d;for(;--b>=0;){d=n.shift();a=a[d.type].apply(null,d.args)}return a},noConflict:function(){o.$LAB=K;return m},sandbox:function(){return J()}};return m}o.$LAB=J();(function(a,c,b){if(document.readyState==null&&document[a]){document.readyState="loading";document[a](c,b=function(){document.removeEventListener(c,b,false);document.readyState="complete"},false)}})("addEventListener","DOMContentLoaded")})(this);/* init.js - initialization and configuration of the widgets |
| 598 | 24 |
*/ |
25 |
||
26 |
if (typeof window.IriSP === "undefined") { |
|
| 694 | 27 |
window.IriSP = {}; |
| 598 | 28 |
} |
29 |
||
30 |
/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ |
|
31 |
||
| 638 | 32 |
IriSP.Metadataplayer = function(config) { |
| 623 | 33 |
IriSP.log("IriSP.Metadataplayer constructor"); |
| 598 | 34 |
for (var key in IriSP.guiDefaults) { |
| 694 | 35 |
if (IriSP.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) { |
36 |
config[key] = IriSP.guiDefaults[key] |
|
| 598 | 37 |
} |
38 |
} |
|
| 694 | 39 |
var _container = document.getElementById(config.container); |
| 598 | 40 |
_container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>'; |
41 |
this.sourceManager = new IriSP.Model.Directory(); |
|
42 |
this.config = config; |
|
| 694 | 43 |
this.__events = {}; |
| 598 | 44 |
this.loadLibs(); |
45 |
} |
|
46 |
||
47 |
IriSP.Metadataplayer.prototype.toString = function() { |
|
| 694 | 48 |
return 'Metadataplayer in #' + this.config.container; |
| 638 | 49 |
} |
50 |
||
| 694 | 51 |
IriSP.Metadataplayer.prototype.on = function(_event, _callback) { |
52 |
if (typeof this.__events[_event] === "undefined") { |
|
53 |
this.__events[_event] = []; |
|
| 638 | 54 |
} |
| 694 | 55 |
this.__events[_event].push(_callback); |
| 638 | 56 |
} |
57 |
||
| 694 | 58 |
IriSP.Metadataplayer.prototype.trigger = function(_event, _data) { |
59 |
var _element = this; |
|
60 |
IriSP._(this.__events[_event]).each(function(_callback) { |
|
61 |
_callback.call(_element, _data); |
|
62 |
}); |
|
| 598 | 63 |
} |
64 |
||
65 |
IriSP.Metadataplayer.prototype.loadLibs = function() { |
|
| 623 | 66 |
IriSP.log("IriSP.Metadataplayer.prototype.loadLibs"); |
67 |
var $L = $LAB |
|
68 |
.script(IriSP.getLib("underscore")) |
|
69 |
.script(IriSP.getLib("Mustache")) |
|
| 694 | 70 |
.script(IriSP.getLib("jQuery")); |
| 638 | 71 |
|
72 |
if (typeof JSON == "undefined") { |
|
73 |
$L.script(IriSP.getLib("json")); |
|
74 |
} |
|
75 |
|
|
76 |
$L.wait() |
|
| 623 | 77 |
.script(IriSP.getLib("jQueryUI")); |
| 598 | 78 |
|
79 |
/* widget specific requirements */ |
|
| 694 | 80 |
for(var _i = 0; _i < this.config.widgets.length; _i++) { |
81 |
var _t = this.config.widgets[_i].type; |
|
82 |
if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined" ) { |
|
83 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_t].requires.length; _j++) { |
|
84 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires[_j])); |
|
85 |
} |
|
| 598 | 86 |
} |
87 |
} |
|
88 |
|
|
89 |
var _this = this; |
|
| 694 | 90 |
|
| 598 | 91 |
$L.wait(function() { |
92 |
_this.onLibsLoaded(); |
|
93 |
}); |
|
94 |
} |
|
95 |
||
96 |
IriSP.Metadataplayer.prototype.onLibsLoaded = function() { |
|
| 623 | 97 |
IriSP.log("IriSP.Metadataplayer.prototype.onLibsLoaded"); |
98 |
if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { |
|
99 |
IriSP.jQuery = window.jQuery.noConflict(); |
|
100 |
} |
|
101 |
if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") { |
|
| 694 | 102 |
IriSP._ = window._; |
| 623 | 103 |
} |
104 |
IriSP.loadCss(IriSP.getLib("cssjQueryUI")); |
|
| 694 | 105 |
IriSP.loadCss(this.config.css); |
| 623 | 106 |
|
| 694 | 107 |
this.$ = IriSP.jQuery('#' + this.config.container); |
| 598 | 108 |
this.$.css({ |
| 694 | 109 |
"width": this.config.width, |
| 598 | 110 |
"clear": "both" |
111 |
}); |
|
| 694 | 112 |
if (typeof this.config.height !== "undefined") { |
113 |
this.$.css("height", this.config.height); |
|
| 598 | 114 |
} |
115 |
|
|
| 694 | 116 |
this.widgets = []; |
| 598 | 117 |
var _this = this; |
| 694 | 118 |
for(var i = 0; i < this.config.widgets.length; i++) { |
119 |
this.loadWidget(this.config.widgets[i], function(_widget) { |
|
120 |
_this.widgets.push(_widget) |
|
121 |
}); |
|
122 |
}; |
|
123 |
this.$.find('.Ldt-Loader').detach(); |
|
| 598 | 124 |
} |
125 |
||
126 |
IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { |
|
| 719 | 127 |
if (_metadataInfo.elementType === "source") { |
128 |
return _metadataInfo; |
|
129 |
} |
|
| 598 | 130 |
if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { |
131 |
_metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; |
|
132 |
} |
|
133 |
if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { |
|
134 |
return this.sourceManager.remoteSource(_metadataInfo); |
|
135 |
} else { |
|
136 |
return this.sourceManager.newLocalSource(_metadataInfo); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) { |
|
141 |
/* Creating containers if needed */ |
|
142 |
if (typeof _widgetConfig.container === "undefined") { |
|
143 |
var _divs = this.layoutDivs(_widgetConfig.type); |
|
144 |
_widgetConfig.container = _divs[0]; |
|
145 |
} |
|
146 |
|
|
147 |
var _this = this; |
|
148 |
|
|
149 |
if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") { |
|
150 |
IriSP._.defer(function() { |
|
151 |
_callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
152 |
}); |
|
153 |
} else { |
|
154 |
/* Loading Widget CSS */ |
|
155 |
if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) { |
|
156 |
IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css'); |
|
157 |
} |
|
158 |
/* Loading Widget JS */ |
|
159 |
$LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() { |
|
160 |
_callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
161 |
}); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
/** create a subdiv with an unique id, and a spacer div as well. |
|
166 |
@param widgetName the name of the widget. |
|
167 |
@return an array of the form [createdivId, spacerdivId]. |
|
168 |
*/ |
|
| 638 | 169 |
IriSP.Metadataplayer.prototype.layoutDivs = function(_name, _height) { |
| 598 | 170 |
if (typeof(_name) === "undefined") { |
171 |
_name = ""; |
|
172 |
} |
|
| 694 | 173 |
var newDiv = IriSP._.uniqueId(this.config.container + "_widget_" + _name + "_"), |
| 598 | 174 |
spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"), |
175 |
divHtml = IriSP.jQuery('<div>') |
|
176 |
.attr("id",newDiv) |
|
177 |
.css({ |
|
| 694 | 178 |
width: this.config.width + "px", |
| 598 | 179 |
position: "relative", |
180 |
clear: "both" |
|
181 |
}), |
|
182 |
spacerHtml = IriSP.jQuery('<div>') |
|
183 |
.attr("id",spacerDiv) |
|
184 |
.css({ |
|
| 694 | 185 |
width: this.config.width + "px", |
186 |
height: this.config.spacer_div_height + "px", |
|
| 598 | 187 |
position: "relative", |
188 |
clear: "both" |
|
189 |
}); |
|
| 638 | 190 |
if (typeof _height !== "undefined") { |
191 |
divHtml.css("height", _height); |
|
192 |
} |
|
| 598 | 193 |
|
194 |
this.$.append(divHtml); |
|
195 |
this.$.append(spacerHtml); |
|
196 |
||
197 |
return [newDiv, spacerDiv]; |
|
198 |
}; |
|
199 |
/* utils.js - various utils that don't belong anywhere else */ |
|
200 |
||
201 |
IriSP.jqEscape = function(_text) { |
|
| 623 | 202 |
return _text.replace(/(:|\.)/g,'\\$1'); |
| 598 | 203 |
} |
204 |
||
205 |
IriSP.getLib = function(lib) { |
|
206 |
if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { |
|
207 |
return IriSP.libFiles.cdn[lib]; |
|
208 |
} |
|
209 |
if (typeof IriSP.libFiles.locations[lib] == "string") { |
|
210 |
return IriSP.libFiles.locations[lib]; |
|
211 |
} |
|
212 |
if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { |
|
213 |
return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib]; |
|
214 |
} |
|
215 |
} |
|
216 |
||
| 623 | 217 |
IriSP._cssCache = []; |
218 |
||
| 598 | 219 |
IriSP.loadCss = function(_cssFile) { |
| 623 | 220 |
if (IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) { |
221 |
IriSP.jQuery("<link>", { |
|
222 |
rel : "stylesheet", |
|
223 |
type : "text/css", |
|
224 |
href : _cssFile |
|
225 |
}).appendTo('head'); |
|
226 |
IriSP._cssCache.push(_cssFile); |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
IriSP.log = function() { |
|
231 |
if (typeof console !== "undefined" && typeof IriSP.logging !== "undefined" && IriSP.logging) { |
|
232 |
console.log.apply(console, arguments); |
|
233 |
} |
|
234 |
} |
|
| 694 | 235 |
/* TODO: Separate Project-specific data from Source */ |
| 638 | 236 |
|
237 |
/* model.js is where data is stored in a standard form, whatever the serializer */ |
|
| 719 | 238 |
IriSP.Model = (function (ns) { |
239 |
|
|
240 |
function pad(n, x, b) { |
|
241 |
b = b || 10; |
|
242 |
var s = (x).toString(b); |
|
243 |
while (s.length < n) { |
|
244 |
s = "0" + s; |
|
245 |
} |
|
246 |
return s; |
|
247 |
} |
|
248 |
|
|
249 |
function rand16(n) { |
|
250 |
return pad(n, Math.floor(Math.random()*Math.pow(16,n)), 16); |
|
251 |
} |
|
252 |
|
|
253 |
var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000); |
|
254 |
|
|
255 |
var charsub = [ |
|
256 |
[ 'a', 'á', 'à', 'â', 'ä' ], |
|
257 |
[ 'c', 'ç' ], |
|
258 |
[ 'e', 'é', 'è', 'ê', 'ë' ], |
|
259 |
[ 'i', 'í', 'ì', 'î', 'ï' ], |
|
260 |
[ 'o', 'ó', 'ò', 'ô', 'ö' ] |
|
261 |
]; |
|
262 |
|
|
263 |
var removeChars = [ |
|
264 |
String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807), |
|
265 |
"{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ", |
|
266 |
",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/" |
|
267 |
] |
|
268 |
|
|
269 |
var Model = { |
|
| 598 | 270 |
_SOURCE_STATUS_EMPTY : 0, |
271 |
_SOURCE_STATUS_WAITING : 1, |
|
272 |
_SOURCE_STATUS_READY : 2, |
|
| 719 | 273 |
getUID : function() { |
274 |
return uidbase + pad(4, (++uidincrement % 0x10000), 16) + "-" + rand16(4) + "-" + rand16(6) + rand16(6); |
|
275 |
}, |
|
276 |
isLocalURL : function(url) { |
|
277 |
var matches = url.match(/^(\w+:)\/\/([^/]+)/); |
|
278 |
if (matches) { |
|
279 |
return(matches[1] === document.location.protocol && matches[2] === document.location.host) |
|
| 638 | 280 |
} |
| 719 | 281 |
return true; |
| 598 | 282 |
}, |
| 719 | 283 |
regexpFromTextOrArray : function(_textOrArray, _testOnly, _iexact) { |
284 |
var _testOnly = _testOnly || false, |
|
285 |
_iexact = _iexact || false; |
|
| 598 | 286 |
function escapeText(_text) { |
287 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
288 |
} |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
289 |
var _source = |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
290 |
typeof _textOrArray === "string" |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
291 |
? escapeText(_textOrArray) |
| 719 | 292 |
: ns._(_textOrArray).map(escapeText).join("|"), |
293 |
_flags = 'im'; |
|
294 |
if (!_testOnly) { |
|
295 |
_source = '(' + _source + ')'; |
|
296 |
_flags += 'g'; |
|
297 |
} |
|
298 |
if (_iexact) { |
|
299 |
_source = '^' + _source + '$'; |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
300 |
} |
| 719 | 301 |
return new RegExp( _source, _flags); |
302 |
}, |
|
303 |
fullTextRegexps: function(_text) { |
|
304 |
var remsrc = "[\\" + removeChars.join("\\") + "]", |
|
305 |
remrx = new RegExp(remsrc,"gm"), |
|
306 |
txt = _text.toLowerCase().replace(remrx,"") |
|
307 |
res = [], |
|
308 |
charsrc = ns._(charsub).map(function(c) { |
|
309 |
return "(" + c.join("|") + ")"; |
|
310 |
}), |
|
311 |
charsrx = ns._(charsrc).map(function(c) { |
|
312 |
return new RegExp(c); |
|
313 |
}), |
|
314 |
src = ""; |
|
315 |
for (var j = 0; j < txt.length; j++) { |
|
316 |
if (j) { |
|
317 |
src += remsrc + "*"; |
|
318 |
} |
|
319 |
var l = txt[j]; |
|
320 |
ns._(charsrc).each(function(v, k) { |
|
321 |
l = l.replace(charsrx[k], v); |
|
322 |
}); |
|
323 |
src += l; |
|
324 |
} |
|
325 |
return "(" + src + ")"; |
|
| 598 | 326 |
}, |
327 |
isoToDate : function(_str) { |
|
328 |
// http://delete.me.uk/2005/03/iso8601.html |
|
329 |
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})))?)?)?)?"; |
|
330 |
var d = _str.match(new RegExp(regexp)); |
|
331 |
|
|
332 |
var offset = 0; |
|
333 |
var date = new Date(d[1], 0, 1); |
|
334 |
|
|
335 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
336 |
if (d[5]) { date.setDate(d[5]); } |
|
337 |
if (d[7]) { date.setHours(d[7]); } |
|
338 |
if (d[8]) { date.setMinutes(d[8]); } |
|
339 |
if (d[10]) { date.setSeconds(d[10]); } |
|
340 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
341 |
if (d[14]) { |
|
342 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
343 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
344 |
} |
|
345 |
|
|
346 |
offset -= date.getTimezoneOffset(); |
|
347 |
time = (Number(date) + (offset * 60 * 1000)); |
|
348 |
var _res = new Date(); |
|
349 |
_res.setTime(Number(time)); |
|
350 |
return _res; |
|
351 |
}, |
|
| 719 | 352 |
dateToIso : function(_d) { |
353 |
var d = _d ? new Date(_d) : new Date(); |
|
| 598 | 354 |
return d.getUTCFullYear()+'-' |
| 719 | 355 |
+ pad(2, d.getUTCMonth()+1)+'-' |
356 |
+ pad(2, d.getUTCDate())+'T' |
|
357 |
+ pad(2, d.getUTCHours())+':' |
|
358 |
+ pad(2, d.getUTCMinutes())+':' |
|
359 |
+ pad(2, d.getUTCSeconds())+'Z' |
|
| 598 | 360 |
} |
361 |
} |
|
362 |
||
363 |
/* |
|
| 719 | 364 |
* Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
| 598 | 365 |
*/ |
| 719 | 366 |
Model.List = function(_directory) { |
| 598 | 367 |
Array.call(this); |
368 |
this.directory = _directory; |
|
369 |
this.idIndex = []; |
|
| 694 | 370 |
this.__events = {}; |
| 598 | 371 |
if (typeof _directory == "undefined") { |
| 623 | 372 |
console.trace(); |
| 719 | 373 |
throw "Error : new Model.List(directory): directory is undefined"; |
| 598 | 374 |
} |
| 719 | 375 |
var _this = this; |
376 |
this.on("clear-search", function() { |
|
377 |
_this.searching = false; |
|
378 |
_this.regexp = undefined; |
|
379 |
_this.forEach(function(_element) { |
|
380 |
_element.found = undefined; |
|
381 |
}); |
|
382 |
_this.trigger("search-cleared"); |
|
383 |
}) |
|
| 598 | 384 |
} |
385 |
||
| 719 | 386 |
Model.List.prototype = new Array(); |
| 598 | 387 |
|
| 719 | 388 |
Model.List.prototype.hasId = function(_id) { |
389 |
return ns._(this.idIndex).include(_id); |
|
| 598 | 390 |
} |
391 |
||
392 |
/* On recent browsers, forEach and map are defined and do what we want. |
|
393 |
* Otherwise, we'll use the Underscore.js functions |
|
394 |
*/ |
|
395 |
if (typeof Array.prototype.forEach === "undefined") { |
|
| 719 | 396 |
Model.List.prototype.forEach = function(_callback) { |
| 598 | 397 |
var _this = this; |
| 719 | 398 |
ns._(this).forEach(function(_value, _key) { |
| 598 | 399 |
_callback(_value, _key, _this); |
400 |
}); |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
if (typeof Array.prototype.map === "undefined") { |
|
| 719 | 405 |
Model.List.prototype.map = function(_callback) { |
| 598 | 406 |
var _this = this; |
| 719 | 407 |
return ns._(this).map(function(_value, _key) { |
| 598 | 408 |
return _callback(_value, _key, _this); |
409 |
}); |
|
410 |
} |
|
411 |
} |
|
412 |
||
| 719 | 413 |
Model.List.prototype.pluck = function(_key) { |
| 623 | 414 |
return this.map(function(_value) { |
415 |
return _value[_key]; |
|
416 |
}); |
|
417 |
} |
|
418 |
||
| 719 | 419 |
/* We override Array's filter function because it doesn't return an Model.List |
| 598 | 420 |
*/ |
| 719 | 421 |
Model.List.prototype.filter = function(_callback) { |
| 598 | 422 |
var _this = this, |
| 719 | 423 |
_res = new Model.List(this.directory); |
424 |
_res.addElements(ns._(this).filter(function(_value, _key) { |
|
| 598 | 425 |
return _callback(_value, _key, _this); |
426 |
})); |
|
427 |
return _res; |
|
428 |
} |
|
429 |
||
| 719 | 430 |
Model.List.prototype.slice = function(_start, _end) { |
431 |
var _res = new Model.List(this.directory); |
|
| 598 | 432 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
433 |
return _res; |
|
434 |
} |
|
435 |
||
| 719 | 436 |
Model.List.prototype.splice = function(_start, _end) { |
437 |
var _res = new Model.List(this.directory); |
|
| 598 | 438 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
439 |
this.idIndex.splice(_start, _end); |
|
440 |
return _res; |
|
441 |
} |
|
442 |
||
443 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
|
| 719 | 444 |
* and won't return a new Model.List |
| 598 | 445 |
*/ |
| 719 | 446 |
Model.List.prototype.sortBy = function(_callback) { |
| 598 | 447 |
var _this = this, |
| 719 | 448 |
_res = new Model.List(this.directory); |
449 |
_res.addElements(ns._(this).sortBy(function(_value, _key) { |
|
| 598 | 450 |
return _callback(_value, _key, _this); |
451 |
})); |
|
452 |
return _res; |
|
453 |
} |
|
454 |
||
455 |
/* Title and Description are basic information for (almost) all element types, |
|
456 |
* here we can search by these criteria |
|
457 |
*/ |
|
| 719 | 458 |
Model.List.prototype.searchByTitle = function(_text, _iexact) { |
459 |
var _iexact = _iexact || false, |
|
460 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 598 | 461 |
return this.filter(function(_element) { |
462 |
return _rgxp.test(_element.title); |
|
463 |
}); |
|
464 |
} |
|
465 |
||
| 719 | 466 |
Model.List.prototype.searchByDescription = function(_text, _iexact) { |
467 |
var _iexact = _iexact || false, |
|
468 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 598 | 469 |
return this.filter(function(_element) { |
470 |
return _rgxp.test(_element.description); |
|
471 |
}); |
|
472 |
} |
|
473 |
||
| 719 | 474 |
Model.List.prototype.searchByTextFields = function(_text, _iexact) { |
475 |
var _iexact = _iexact || false, |
|
476 |
_rgxp = Model.regexpFromTextOrArray(_text, true); |
|
| 598 | 477 |
return this.filter(function(_element) { |
478 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
|
479 |
}); |
|
480 |
} |
|
481 |
||
| 719 | 482 |
Model.List.prototype.search = function(_text) { |
483 |
if (!_text) { |
|
484 |
this.trigger("clear-search"); |
|
485 |
return this; |
|
486 |
} |
|
487 |
this.searching = true; |
|
488 |
this.trigger("search", _text); |
|
489 |
var rxsource = Model.fullTextRegexps(_text) |
|
490 |
rgxp = new RegExp(rxsource,"im"), |
|
491 |
this.regexp = new RegExp(rxsource,"gim"); |
|
492 |
var res = this.filter(function(_element, _k) { |
|
493 |
var titlematch = rgxp.test(_element.title), |
|
494 |
descmatch = rgxp.test(_element.description), |
|
495 |
_isfound = !!(titlematch || descmatch); |
|
496 |
_element.found = _isfound; |
|
497 |
_element.trigger(_isfound ? "found" : "not-found"); |
|
498 |
return _isfound; |
|
499 |
}); |
|
500 |
this.trigger(res.length ? "found" : "not-found",res); |
|
501 |
return res; |
|
502 |
} |
|
503 |
||
504 |
Model.List.prototype.getTitles = function() { |
|
| 598 | 505 |
return this.map(function(_el) { |
506 |
return _el.title; |
|
507 |
}); |
|
508 |
} |
|
509 |
||
| 719 | 510 |
Model.List.prototype.addId = function(_id) { |
| 598 | 511 |
var _el = this.directory.getElement(_id) |
512 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
513 |
this.idIndex.push(_id); |
|
514 |
Array.prototype.push.call(this, _el); |
|
515 |
} |
|
516 |
} |
|
517 |
||
| 719 | 518 |
Model.List.prototype.push = function(_el) { |
| 598 | 519 |
if (typeof _el === "undefined") { |
520 |
return; |
|
521 |
} |
|
| 719 | 522 |
var _index = (ns._(this.idIndex).indexOf(_el.id)); |
| 598 | 523 |
if (_index === -1) { |
524 |
this.idIndex.push(_el.id); |
|
525 |
Array.prototype.push.call(this, _el); |
|
526 |
} else { |
|
527 |
this[_index] = _el; |
|
528 |
} |
|
529 |
} |
|
530 |
||
| 719 | 531 |
Model.List.prototype.addIds = function(_array) { |
| 598 | 532 |
var _l = _array.length, |
533 |
_this = this; |
|
| 719 | 534 |
ns._(_array).forEach(function(_id) { |
| 598 | 535 |
_this.addId(_id); |
536 |
}); |
|
537 |
} |
|
538 |
||
| 719 | 539 |
Model.List.prototype.addElements = function(_array) { |
| 598 | 540 |
var _this = this; |
| 719 | 541 |
ns._(_array).forEach(function(_el) { |
| 598 | 542 |
_this.push(_el); |
543 |
}); |
|
544 |
} |
|
545 |
||
| 719 | 546 |
Model.List.prototype.removeId = function(_id, _deleteFromDirectory) { |
| 638 | 547 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
| 719 | 548 |
_index = (ns._(this.idIndex).indexOf(_id)); |
| 598 | 549 |
if (_index !== -1) { |
550 |
this.splice(_index,1); |
|
551 |
} |
|
| 638 | 552 |
if (_deleteFromDirectory) { |
553 |
delete this.directory.elements[_id]; |
|
554 |
} |
|
| 598 | 555 |
} |
556 |
||
| 719 | 557 |
Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) { |
| 638 | 558 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
| 598 | 559 |
this.removeId(_el.id); |
560 |
} |
|
561 |
||
| 719 | 562 |
Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) { |
| 638 | 563 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
564 |
_this = this; |
|
| 719 | 565 |
ns._(_list).forEach(function(_id) { |
| 598 | 566 |
_this.removeId(_id); |
567 |
}); |
|
568 |
} |
|
569 |
||
| 719 | 570 |
Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
| 638 | 571 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
572 |
_this = this; |
|
| 719 | 573 |
ns._(_list).forEach(function(_el) { |
| 598 | 574 |
_this.removeElement(_el); |
575 |
}); |
|
576 |
} |
|
577 |
||
| 719 | 578 |
Model.List.prototype.on = function(_event, _callback) { |
| 694 | 579 |
if (typeof this.__events[_event] === "undefined") { |
580 |
this.__events[_event] = []; |
|
581 |
} |
|
582 |
this.__events[_event].push(_callback); |
|
583 |
} |
|
584 |
||
| 719 | 585 |
Model.List.prototype.off = function(_event, _callback) { |
586 |
if (typeof this.__events[_event] !== "undefined") { |
|
587 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
588 |
return _fn === _callback; |
|
589 |
}); |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
Model.List.prototype.trigger = function(_event, _data) { |
|
| 694 | 594 |
var _list = this; |
| 719 | 595 |
ns._(this.__events[_event]).each(function(_callback) { |
| 694 | 596 |
_callback.call(_list, _data); |
597 |
}); |
|
598 |
} |
|
599 |
||
| 598 | 600 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
601 |
* without the clumsiness of the original Date object. |
|
602 |
*/ |
|
603 |
||
| 719 | 604 |
Model.Time = function(_milliseconds) { |
| 623 | 605 |
this.milliseconds = 0; |
606 |
this.setMilliseconds(_milliseconds); |
|
607 |
} |
|
608 |
||
| 719 | 609 |
Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
610 |
var _ante = this.milliseconds; |
|
| 623 | 611 |
switch(typeof _milliseconds) { |
612 |
case "string": |
|
| 719 | 613 |
this.milliseconds = parseInt(_milliseconds); |
| 623 | 614 |
break; |
615 |
case "number": |
|
| 719 | 616 |
this.milliseconds = Math.floor(_milliseconds); |
| 623 | 617 |
break; |
618 |
case "object": |
|
| 719 | 619 |
this.milliseconds = parseInt(_milliseconds.valueOf()); |
| 623 | 620 |
break; |
621 |
default: |
|
622 |
this.milliseconds = 0; |
|
623 |
} |
|
624 |
if (this.milliseconds === NaN) { |
|
625 |
this.milliseconds = _ante; |
|
626 |
} |
|
| 598 | 627 |
} |
628 |
||
| 719 | 629 |
Model.Time.prototype.setSeconds = function(_seconds) { |
| 598 | 630 |
this.milliseconds = 1000 * _seconds; |
631 |
} |
|
632 |
||
| 719 | 633 |
Model.Time.prototype.getSeconds = function() { |
| 638 | 634 |
return this.milliseconds / 1000; |
| 598 | 635 |
} |
636 |
||
| 719 | 637 |
Model.Time.prototype.getHMS = function() { |
| 638 | 638 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
| 598 | 639 |
return { |
640 |
hours : Math.floor(_totalSeconds / 3600), |
|
641 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
| 719 | 642 |
seconds : _totalSeconds % 60, |
643 |
milliseconds: this.milliseconds % 1000 |
|
| 598 | 644 |
} |
645 |
} |
|
646 |
||
| 719 | 647 |
Model.Time.prototype.add = function(_milliseconds) { |
648 |
this.milliseconds += new Model.Time(_milliseconds).milliseconds; |
|
| 623 | 649 |
} |
650 |
||
| 719 | 651 |
Model.Time.prototype.valueOf = function() { |
| 598 | 652 |
return this.milliseconds; |
653 |
} |
|
654 |
||
| 719 | 655 |
Model.Time.prototype.toString = function(showCs) { |
| 598 | 656 |
var _hms = this.getHMS(), |
657 |
_res = ''; |
|
658 |
if (_hms.hours) { |
|
| 719 | 659 |
_res += _hms.hours + ':' |
| 598 | 660 |
} |
| 719 | 661 |
_res += pad(2, _hms.minutes) + ':' + pad(2, _hms.seconds); |
662 |
if (showCs) { |
|
663 |
_res += "." + Math.round(_hms.milliseconds / 100) |
|
664 |
} |
|
| 598 | 665 |
return _res; |
666 |
} |
|
667 |
||
| 719 | 668 |
/* Model.Reference handles references between elements |
| 598 | 669 |
*/ |
670 |
||
| 719 | 671 |
Model.Reference = function(_source, _idRef) { |
| 598 | 672 |
this.source = _source; |
| 638 | 673 |
this.id = _idRef; |
| 598 | 674 |
if (typeof _idRef === "object") { |
675 |
this.isList = true; |
|
676 |
} else { |
|
677 |
this.isList = false; |
|
678 |
} |
|
679 |
this.refresh(); |
|
680 |
} |
|
681 |
||
| 719 | 682 |
Model.Reference.prototype.refresh = function() { |
| 598 | 683 |
if (this.isList) { |
| 719 | 684 |
this.contents = new Model.List(this.source.directory); |
| 598 | 685 |
this.contents.addIds(this.id); |
686 |
} else { |
|
| 694 | 687 |
this.contents = this.source.getElement(this.id); |
| 598 | 688 |
} |
689 |
|
|
690 |
} |
|
691 |
||
| 719 | 692 |
Model.Reference.prototype.getContents = function() { |
| 598 | 693 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
694 |
this.refresh(); |
|
695 |
} |
|
696 |
return this.contents; |
|
697 |
} |
|
698 |
||
| 719 | 699 |
Model.Reference.prototype.isOrHasId = function(_idRef) { |
| 598 | 700 |
if (this.isList) { |
| 719 | 701 |
return (ns._(this.id).indexOf(_idRef) !== -1) |
| 598 | 702 |
} else { |
703 |
return (this.id == _idRef); |
|
704 |
} |
|
705 |
} |
|
706 |
||
707 |
/* */ |
|
708 |
||
| 719 | 709 |
Model.Element = function(_id, _source) { |
| 598 | 710 |
this.elementType = 'element'; |
| 719 | 711 |
this.title = ""; |
712 |
this.description = ""; |
|
713 |
this.__events = {} |
|
| 598 | 714 |
if (typeof _source === "undefined") { |
715 |
return; |
|
716 |
} |
|
717 |
if (typeof _id === "undefined" || !_id) { |
|
| 719 | 718 |
_id = Model.getUID(); |
| 598 | 719 |
} |
| 638 | 720 |
this.id = _id; |
| 719 | 721 |
this.source = _source; |
722 |
if (_source !== this) { |
|
723 |
this.source.directory.addElement(this); |
|
724 |
} |
|
| 598 | 725 |
} |
726 |
||
| 719 | 727 |
Model.Element.prototype.toString = function() { |
| 598 | 728 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
729 |
} |
|
730 |
||
| 719 | 731 |
Model.Element.prototype.setReference = function(_elementType, _idRef) { |
732 |
this[_elementType] = new Model.Reference(this.source, _idRef); |
|
| 598 | 733 |
} |
734 |
||
| 719 | 735 |
Model.Element.prototype.getReference = function(_elementType) { |
| 598 | 736 |
if (typeof this[_elementType] !== "undefined") { |
737 |
return this[_elementType].getContents(); |
|
738 |
} |
|
739 |
} |
|
740 |
||
| 719 | 741 |
Model.Element.prototype.getRelated = function(_elementType, _global) { |
| 598 | 742 |
_global = (typeof _global !== "undefined" && _global); |
743 |
var _this = this; |
|
744 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
|
745 |
var _ref = _el[_this.elementType]; |
|
| 719 | 746 |
return _ref && _ref.isOrHasId(_this.id); |
| 598 | 747 |
}); |
748 |
} |
|
749 |
||
| 719 | 750 |
Model.Element.prototype.on = function(_event, _callback) { |
| 694 | 751 |
if (typeof this.__events[_event] === "undefined") { |
752 |
this.__events[_event] = []; |
|
753 |
} |
|
754 |
this.__events[_event].push(_callback); |
|
755 |
} |
|
756 |
||
| 719 | 757 |
Model.Element.prototype.off = function(_event, _callback) { |
758 |
if (typeof this.__events[_event] !== "undefined") { |
|
759 |
this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) { |
|
760 |
return _fn === _callback; |
|
761 |
}); |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
Model.Element.prototype.trigger = function(_event, _data) { |
|
| 694 | 766 |
var _element = this; |
| 719 | 767 |
ns._(this.__events[_event]).each(function(_callback) { |
| 694 | 768 |
_callback.call(_element, _data); |
769 |
}); |
|
770 |
} |
|
771 |
||
| 598 | 772 |
/* */ |
773 |
||
| 719 | 774 |
Model.Playable = function(_id, _source) { |
775 |
Model.Element.call(this, _id, _source); |
|
776 |
if (typeof _source === "undefined") { |
|
777 |
return; |
|
778 |
} |
|
779 |
this.elementType = 'playable'; |
|
780 |
this.currentTime = new Model.Time(); |
|
781 |
this.volume = .5; |
|
782 |
this.paused = true; |
|
783 |
this.muted = false; |
|
| 694 | 784 |
var _this = this; |
| 719 | 785 |
this.on("play", function() { |
786 |
_this.paused = false; |
|
787 |
}); |
|
788 |
this.on("pause", function() { |
|
789 |
_this.paused = true; |
|
790 |
}); |
|
| 694 | 791 |
this.on("timeupdate", function(_time) { |
| 719 | 792 |
_this.currentTime = _time; |
| 694 | 793 |
_this.getAnnotations().filter(function(_a) { |
794 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
795 |
}).forEach(function(_a) { |
|
796 |
_a.playing = false; |
|
797 |
_a.trigger("leave"); |
|
| 719 | 798 |
_this.trigger("leave-annotation",_a); |
| 694 | 799 |
}); |
800 |
_this.getAnnotations().filter(function(_a) { |
|
801 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
802 |
}).forEach(function(_a) { |
|
803 |
_a.playing = true; |
|
804 |
_a.trigger("enter"); |
|
| 719 | 805 |
_this.trigger("enter-annotation",_a); |
| 694 | 806 |
}); |
807 |
}); |
|
| 598 | 808 |
} |
809 |
||
| 719 | 810 |
Model.Playable.prototype = new Model.Element(); |
811 |
||
812 |
Model.Playable.prototype.getCurrentTime = function() { |
|
813 |
return this.currentTime; |
|
814 |
} |
|
815 |
||
816 |
Model.Playable.prototype.getVolume = function() { |
|
817 |
return this.volume; |
|
818 |
} |
|
819 |
||
820 |
Model.Playable.prototype.getPaused = function() { |
|
821 |
return this.paused; |
|
822 |
} |
|
823 |
||
824 |
Model.Playable.prototype.getMuted = function() { |
|
825 |
return this.muted; |
|
826 |
} |
|
827 |
||
828 |
Model.Playable.prototype.setCurrentTime = function(_time) { |
|
829 |
this.trigger("setcurrenttime",_time); |
|
830 |
} |
|
831 |
||
832 |
Model.Playable.prototype.setVolume = function(_vol) { |
|
833 |
this.trigger("setvolume",_vol); |
|
834 |
} |
|
835 |
||
836 |
Model.Playable.prototype.setMuted = function(_muted) { |
|
837 |
this.trigger("setmuted",_muted); |
|
838 |
} |
|
839 |
||
840 |
Model.Playable.prototype.play = function() { |
|
841 |
this.trigger("setplay"); |
|
842 |
} |
|
843 |
||
844 |
Model.Playable.prototype.pause = function() { |
|
845 |
this.trigger("setpause"); |
|
846 |
} |
|
847 |
||
848 |
Model.Playable.prototype.show = function() {} |
|
849 |
||
850 |
Model.Playable.prototype.hide = function() {} |
|
851 |
||
852 |
/* */ |
|
853 |
||
854 |
Model.Media = function(_id, _source) { |
|
855 |
Model.Playable.call(this, _id, _source); |
|
856 |
this.elementType = 'media'; |
|
857 |
this.duration = new Model.Time(); |
|
858 |
this.video = ''; |
|
859 |
var _this = this; |
|
860 |
} |
|
861 |
||
862 |
Model.Media.prototype = new Model.Playable(); |
|
| 598 | 863 |
|
| 694 | 864 |
/* Default functions to be overriden by players */ |
865 |
|
|
| 719 | 866 |
Model.Media.prototype.setDuration = function(_durationMs) { |
| 623 | 867 |
this.duration.setMilliseconds(_durationMs); |
| 598 | 868 |
} |
869 |
||
| 719 | 870 |
Model.Media.prototype.getAnnotations = function() { |
| 598 | 871 |
return this.getRelated("annotation"); |
872 |
} |
|
873 |
||
| 719 | 874 |
Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
| 623 | 875 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
876 |
if (_annTypes.length) { |
|
877 |
return this.getAnnotations().filter(function(_annotation) { |
|
| 719 | 878 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
| 623 | 879 |
}); |
880 |
} else { |
|
| 719 | 881 |
return new Model.List(this.source.directory) |
| 623 | 882 |
} |
883 |
} |
|
884 |
||
| 598 | 885 |
/* */ |
886 |
||
| 719 | 887 |
Model.Tag = function(_id, _source) { |
888 |
Model.Element.call(this, _id, _source); |
|
| 598 | 889 |
this.elementType = 'tag'; |
890 |
} |
|
891 |
||
| 719 | 892 |
Model.Tag.prototype = new Model.Element(); |
| 598 | 893 |
|
| 719 | 894 |
Model.Tag.prototype.getAnnotations = function() { |
| 598 | 895 |
return this.getRelated("annotation"); |
896 |
} |
|
897 |
||
898 |
/* */ |
|
| 719 | 899 |
Model.AnnotationType = function(_id, _source) { |
900 |
Model.Element.call(this, _id, _source); |
|
| 598 | 901 |
this.elementType = 'annotationType'; |
902 |
} |
|
903 |
||
| 719 | 904 |
Model.AnnotationType.prototype = new Model.Element(); |
| 598 | 905 |
|
| 719 | 906 |
Model.AnnotationType.prototype.getAnnotations = function() { |
| 598 | 907 |
return this.getRelated("annotation"); |
908 |
} |
|
909 |
||
910 |
/* Annotation |
|
911 |
* */ |
|
912 |
||
| 719 | 913 |
Model.Annotation = function(_id, _source) { |
914 |
Model.Element.call(this, _id, _source); |
|
| 598 | 915 |
this.elementType = 'annotation'; |
| 719 | 916 |
this.begin = new Model.Time(); |
917 |
this.end = new Model.Time(); |
|
918 |
this.tag = new Model.Reference(_source, []); |
|
| 694 | 919 |
this.playing = false; |
920 |
var _this = this; |
|
921 |
this.on("click", function() { |
|
922 |
_this.getMedia().setCurrentTime(_this.begin); |
|
923 |
}); |
|
| 598 | 924 |
} |
925 |
||
| 719 | 926 |
Model.Annotation.prototype = new Model.Element(); |
| 598 | 927 |
|
| 719 | 928 |
Model.Annotation.prototype.setBegin = function(_beginMs) { |
929 |
this.begin.setMilliseconds(Math.max(0,_beginMs)); |
|
930 |
this.trigger("change-begin"); |
|
931 |
if (this.end < this.begin) { |
|
932 |
this.setEnd(this.begin); |
|
933 |
} |
|
| 598 | 934 |
} |
935 |
||
| 719 | 936 |
Model.Annotation.prototype.setEnd = function(_endMs) { |
937 |
this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds)); |
|
938 |
this.trigger("change-end"); |
|
939 |
if (this.end < this.begin) { |
|
940 |
this.setBegin(this.end); |
|
941 |
} |
|
| 598 | 942 |
} |
943 |
||
| 719 | 944 |
Model.Annotation.prototype.setDuration = function(_durMs) { |
945 |
this.setEnd(_durMs + this.begin.milliseconds); |
|
946 |
} |
|
947 |
||
948 |
Model.Annotation.prototype.setMedia = function(_idRef) { |
|
| 598 | 949 |
this.setReference("media", _idRef); |
950 |
} |
|
951 |
||
| 719 | 952 |
Model.Annotation.prototype.getMedia = function() { |
| 598 | 953 |
return this.getReference("media"); |
954 |
} |
|
955 |
||
| 719 | 956 |
Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
| 598 | 957 |
this.setReference("annotationType", _idRef); |
958 |
} |
|
959 |
||
| 719 | 960 |
Model.Annotation.prototype.getAnnotationType = function() { |
| 598 | 961 |
return this.getReference("annotationType"); |
962 |
} |
|
963 |
||
| 719 | 964 |
Model.Annotation.prototype.setTags = function(_idRefs) { |
| 598 | 965 |
this.setReference("tag", _idRefs); |
966 |
} |
|
967 |
||
| 719 | 968 |
Model.Annotation.prototype.getTags = function() { |
| 598 | 969 |
return this.getReference("tag"); |
970 |
} |
|
971 |
||
| 719 | 972 |
Model.Annotation.prototype.getTagTexts = function() { |
| 598 | 973 |
return this.getTags().getTitles(); |
974 |
} |
|
975 |
||
| 719 | 976 |
Model.Annotation.prototype.getDuration = function() { |
977 |
return new Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
| 623 | 978 |
} |
979 |
||
980 |
/* */ |
|
981 |
||
| 719 | 982 |
Model.MashedAnnotation = function(_mashup, _annotation) { |
983 |
Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
|
| 623 | 984 |
this.elementType = 'mashedAnnotation'; |
985 |
this.annotation = _annotation; |
|
| 719 | 986 |
this.begin = new Model.Time(); |
987 |
this.end = new Model.Time(); |
|
988 |
this.duration = new Model.Time(); |
|
| 623 | 989 |
this.title = this.annotation.title; |
990 |
this.description = this.annotation.description; |
|
991 |
this.color = this.annotation.color; |
|
| 694 | 992 |
var _this = this; |
993 |
this.on("click", function() { |
|
994 |
_mashup.setCurrentTime(_this.begin); |
|
995 |
}); |
|
| 719 | 996 |
this.on("enter", function() { |
997 |
_this.annotation.trigger("enter"); |
|
998 |
}); |
|
999 |
this.on("leave", function() { |
|
1000 |
_this.annotation.trigger("leave"); |
|
1001 |
}); |
|
| 623 | 1002 |
} |
1003 |
||
| 719 | 1004 |
Model.MashedAnnotation.prototype = new Model.Element(null); |
| 623 | 1005 |
|
| 719 | 1006 |
Model.MashedAnnotation.prototype.getMedia = function() { |
| 623 | 1007 |
return this.annotation.getReference("media"); |
1008 |
} |
|
1009 |
||
| 719 | 1010 |
Model.MashedAnnotation.prototype.getAnnotationType = function() { |
| 623 | 1011 |
return this.annotation.getReference("annotationType"); |
1012 |
} |
|
1013 |
||
| 719 | 1014 |
Model.MashedAnnotation.prototype.getTags = function() { |
| 623 | 1015 |
return this.annotation.getReference("tag"); |
1016 |
} |
|
1017 |
||
| 719 | 1018 |
Model.MashedAnnotation.prototype.getTagTexts = function() { |
| 623 | 1019 |
return this.annotation.getTags().getTitles(); |
1020 |
} |
|
1021 |
||
| 719 | 1022 |
Model.MashedAnnotation.prototype.getDuration = function() { |
| 694 | 1023 |
return this.annotation.getDuration(); |
1024 |
} |
|
1025 |
||
| 719 | 1026 |
Model.MashedAnnotation.prototype.setBegin = function(_begin) { |
1027 |
this.begin.setMilliseconds(_begin); |
|
1028 |
this.duration.setMilliseconds(this.annotation.getDuration()); |
|
1029 |
this.end.setMilliseconds(_begin + this.duration); |
|
1030 |
} |
|
1031 |
||
| 623 | 1032 |
/* */ |
1033 |
||
| 719 | 1034 |
Model.Mashup = function(_id, _source) { |
1035 |
Model.Playable.call(this, _id, _source); |
|
| 623 | 1036 |
this.elementType = 'mashup'; |
| 719 | 1037 |
this.duration = new Model.Time(); |
1038 |
this.segments = new Model.List(_source.directory); |
|
1039 |
this.loaded = false; |
|
| 694 | 1040 |
var _this = this; |
| 719 | 1041 |
this._updateTimes = function() { |
1042 |
_this.updateTimes(); |
|
1043 |
_this.trigger("change"); |
|
1044 |
} |
|
1045 |
this.on("add", this._updateTimes); |
|
1046 |
this.on("remove", this._updateTimes); |
|
1047 |
} |
|
1048 |
||
1049 |
Model.Mashup.prototype = new Model.Playable(); |
|
1050 |
||
1051 |
Model.Mashup.prototype.checkLoaded = function() { |
|
1052 |
var loaded = !!this.segments.length; |
|
1053 |
this.getMedias().forEach(function(_m) { |
|
1054 |
loaded = loaded && _m.loaded; |
|
1055 |
}); |
|
1056 |
this.loaded = loaded; |
|
1057 |
if (loaded) { |
|
1058 |
this.trigger("loadedmetadata"); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
||
1062 |
Model.Mashup.prototype.updateTimes = function() { |
|
1063 |
var _time = 0; |
|
1064 |
this.segments.forEach(function(_segment) { |
|
1065 |
_segment.setBegin(_time); |
|
1066 |
_time = _segment.end; |
|
1067 |
}); |
|
1068 |
this.duration.setMilliseconds(_time); |
|
1069 |
} |
|
1070 |
||
1071 |
Model.Mashup.prototype.addAnnotation = function(_annotation, _defer) { |
|
1072 |
var _mashedAnnotation = new Model.MashedAnnotation(this, _annotation), |
|
1073 |
_defer = _defer || false; |
|
1074 |
this.segments.push(_mashedAnnotation); |
|
1075 |
_annotation.on("change-begin", this._updateTimes); |
|
1076 |
_annotation.on("change-end", this._updateTimes); |
|
1077 |
if (!_defer) { |
|
1078 |
this.trigger("add"); |
|
1079 |
} |
|
1080 |
} |
|
1081 |
||
1082 |
Model.Mashup.prototype.addAnnotationById = function(_elId, _defer) { |
|
1083 |
var _annotation = this.source.getElement(_elId), |
|
1084 |
_defer = _defer || false; |
|
1085 |
if (typeof _annotation !== "undefined") { |
|
1086 |
this.addAnnotation(_annotation, _defer); |
|
1087 |
} |
|
1088 |
} |
|
1089 |
||
1090 |
Model.Mashup.prototype.addAnnotations = function(_segments) { |
|
1091 |
var _this = this; |
|
1092 |
ns._(_segments).forEach(function(_segment) { |
|
1093 |
_this.addAnnotation(_segment, true); |
|
1094 |
}); |
|
1095 |
this.trigger("add"); |
|
1096 |
} |
|
1097 |
||
1098 |
Model.Mashup.prototype.addAnnotationsById = function(_segments) { |
|
1099 |
var _this = this; |
|
1100 |
ns._(_segments).forEach(function(_segment) { |
|
1101 |
_this.addAnnotationById(_segment, true); |
|
1102 |
}); |
|
1103 |
this.trigger("add"); |
|
1104 |
} |
|
1105 |
||
1106 |
Model.Mashup.prototype.removeAnnotation = function(_annotation, _defer) { |
|
1107 |
var _defer = _defer || false; |
|
1108 |
_annotation.off("change-begin", this._updateTimes); |
|
1109 |
_annotation.off("change-end", this._updateTimes); |
|
1110 |
this.segments.removeId(this.id + "_" + _annotation.id); |
|
1111 |
if (!_defer) { |
|
1112 |
this.trigger("remove"); |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
Model.Mashup.prototype.removeAnnotationById = function(_annId, _defer) { |
|
1117 |
var _defer = _defer || false; |
|
1118 |
var _annotation = this.source.getElement(_annId); |
|
1119 |
||
1120 |
if (_annotation) { |
|
1121 |
this.removeAnnotation(_annotation, _defer); |
|
1122 |
} |
|
1123 |
if (!_defer) { |
|
1124 |
this.trigger("remove"); |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
1128 |
Model.Mashup.prototype.setAnnotations = function(_segments) { |
|
1129 |
while (this.segments.length) { |
|
1130 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
1131 |
} |
|
1132 |
this.addAnnotations(_segments); |
|
1133 |
} |
|
1134 |
||
1135 |
Model.Mashup.prototype.setAnnotationsById = function(_segments) { |
|
1136 |
while (this.segments.length) { |
|
1137 |
this.removeAnnotation(this.segments[0].annotation, true); |
|
1138 |
} |
|
1139 |
this.addAnnotationsById(_segments); |
|
1140 |
} |
|
1141 |
||
1142 |
Model.Mashup.prototype.hasAnnotation = function(_annotation) { |
|
1143 |
return !!ns._(this.segments).find(function(_s) { |
|
1144 |
return _s.annotation === _annotation |
|
| 694 | 1145 |
}); |
| 623 | 1146 |
} |
1147 |
||
| 719 | 1148 |
Model.Mashup.prototype.getAnnotation = function(_annotation) { |
1149 |
return ns._(this.segments).find(function(_s) { |
|
1150 |
return _s.annotation === _annotation |
|
1151 |
}); |
|
1152 |
} |
|
| 623 | 1153 |
|
| 719 | 1154 |
Model.Mashup.prototype.getAnnotationById = function(_id) { |
1155 |
return ns._(this.segments).find(function(_s) { |
|
1156 |
return _s.annotation.id === _id |
|
1157 |
}); |
|
1158 |
} |
|
1159 |
||
1160 |
Model.Mashup.prototype.getAnnotations = function() { |
|
1161 |
return this.segments; |
|
| 623 | 1162 |
} |
1163 |
||
| 719 | 1164 |
Model.Mashup.prototype.getOriginalAnnotations = function() { |
1165 |
var annotations = new Model.List(this.source.directory); |
|
1166 |
this.segments.forEach(function(_s) { |
|
1167 |
annotations.push(_s.annotation); |
|
1168 |
}); |
|
1169 |
return annotations; |
|
1170 |
} |
|
1171 |
||
1172 |
Model.Mashup.prototype.getMedias = function() { |
|
1173 |
var medias = new Model.List(this.source.directory); |
|
1174 |
this.segments.forEach(function(_annotation) { |
|
1175 |
medias.push(_annotation.getMedia()) |
|
1176 |
}) |
|
1177 |
return medias; |
|
1178 |
} |
|
1179 |
||
1180 |
Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
1181 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
1182 |
if (_annTypes.length) { |
|
1183 |
return this.getAnnotations().filter(function(_annotation) { |
|
1184 |
return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
1185 |
}); |
|
1186 |
} else { |
|
1187 |
return new Model.List(this.source.directory) |
|
| 623 | 1188 |
} |
1189 |
} |
|
1190 |
||
| 719 | 1191 |
Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
| 623 | 1192 |
var _list = this.segments.filter(function(_annotation) { |
1193 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
1194 |
}); |
|
1195 |
if (_list.length) { |
|
1196 |
return _list[0]; |
|
1197 |
} else { |
|
1198 |
return undefined; |
|
1199 |
} |
|
1200 |
} |
|
1201 |
||
| 719 | 1202 |
Model.Mashup.prototype.getMediaAtTime = function(_time) { |
| 623 | 1203 |
var _annotation = this.getAnnotationAtTime(_time); |
1204 |
if (typeof _annotation !== "undefined") { |
|
1205 |
return _annotation.getMedia(); |
|
1206 |
} else { |
|
1207 |
return undefined; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
||
| 598 | 1211 |
/* */ |
1212 |
||
| 719 | 1213 |
Model.Source = function(_config) { |
1214 |
Model.Element.call(this, false, this); |
|
1215 |
this.status = Model._SOURCE_STATUS_EMPTY; |
|
1216 |
this.elementType = "source"; |
|
| 598 | 1217 |
if (typeof _config !== "undefined") { |
1218 |
var _this = this; |
|
| 719 | 1219 |
ns._(_config).forEach(function(_v, _k) { |
| 598 | 1220 |
_this[_k] = _v; |
1221 |
}) |
|
1222 |
this.callbackQueue = []; |
|
1223 |
this.contents = {}; |
|
1224 |
this.get(); |
|
1225 |
} |
|
1226 |
} |
|
1227 |
||
| 719 | 1228 |
Model.Source.prototype = new Model.Element(); |
1229 |
||
1230 |
Model.Source.prototype.addList = function(_listId, _contents) { |
|
| 598 | 1231 |
if (typeof this.contents[_listId] === "undefined") { |
| 719 | 1232 |
this.contents[_listId] = new Model.List(this.directory); |
| 598 | 1233 |
} |
1234 |
this.contents[_listId].addElements(_contents); |
|
1235 |
} |
|
1236 |
||
| 719 | 1237 |
Model.Source.prototype.getList = function(_listId, _global) { |
| 598 | 1238 |
_global = (typeof _global !== "undefined" && _global); |
1239 |
if (_global || typeof this.contents[_listId] === "undefined") { |
|
1240 |
return this.directory.getGlobalList().filter(function(_e) { |
|
1241 |
return (_e.elementType === _listId); |
|
1242 |
}); |
|
1243 |
} else { |
|
1244 |
return this.contents[_listId]; |
|
1245 |
} |
|
1246 |
} |
|
1247 |
||
| 719 | 1248 |
Model.Source.prototype.forEach = function(_callback) { |
| 598 | 1249 |
var _this = this; |
| 719 | 1250 |
ns._(this.contents).forEach(function(_value, _key) { |
| 598 | 1251 |
_callback.call(_this, _value, _key); |
1252 |
}) |
|
1253 |
} |
|
1254 |
||
| 719 | 1255 |
Model.Source.prototype.getElement = function(_elId) { |
| 638 | 1256 |
return this.directory.getElement(_elId); |
| 598 | 1257 |
} |
1258 |
||
| 719 | 1259 |
Model.Source.prototype.get = function() { |
1260 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
| 598 | 1261 |
this.handleCallbacks(); |
1262 |
} |
|
1263 |
||
1264 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
| 719 | 1265 |
Model.Source.prototype.deferCallback = function(_callback) { |
| 598 | 1266 |
var _this = this; |
| 719 | 1267 |
ns._.defer(function() { |
| 598 | 1268 |
_callback.call(_this); |
1269 |
}); |
|
1270 |
} |
|
1271 |
||
| 719 | 1272 |
Model.Source.prototype.handleCallbacks = function() { |
1273 |
this.status = Model._SOURCE_STATUS_READY; |
|
| 598 | 1274 |
while (this.callbackQueue.length) { |
1275 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
1276 |
} |
|
1277 |
} |
|
| 719 | 1278 |
Model.Source.prototype.onLoad = function(_callback) { |
1279 |
if (this.status === Model._SOURCE_STATUS_READY) { |
|
| 598 | 1280 |
this.deferCallback(_callback); |
1281 |
} else { |
|
1282 |
this.callbackQueue.push(_callback); |
|
1283 |
} |
|
1284 |
} |
|
1285 |
||
| 719 | 1286 |
Model.Source.prototype.serialize = function() { |
| 598 | 1287 |
return this.serializer.serialize(this); |
1288 |
} |
|
1289 |
||
| 719 | 1290 |
Model.Source.prototype.deSerialize = function(_data) { |
| 598 | 1291 |
this.serializer.deSerialize(_data, this); |
1292 |
} |
|
1293 |
||
| 719 | 1294 |
Model.Source.prototype.getAnnotations = function(_global) { |
| 598 | 1295 |
_global = (typeof _global !== "undefined" && _global); |
1296 |
return this.getList("annotation", _global); |
|
1297 |
} |
|
1298 |
||
| 719 | 1299 |
Model.Source.prototype.getMedias = function(_global) { |
| 598 | 1300 |
_global = (typeof _global !== "undefined" && _global); |
1301 |
return this.getList("media", _global); |
|
1302 |
} |
|
1303 |
||
| 719 | 1304 |
Model.Source.prototype.getTags = function(_global) { |
| 623 | 1305 |
_global = (typeof _global !== "undefined" && _global); |
1306 |
return this.getList("tag", _global); |
|
1307 |
} |
|
1308 |
||
| 719 | 1309 |
Model.Source.prototype.getMashups = function(_global) { |
| 623 | 1310 |
_global = (typeof _global !== "undefined" && _global); |
1311 |
return this.getList("mashup", _global); |
|
1312 |
} |
|
1313 |
||
| 719 | 1314 |
Model.Source.prototype.getAnnotationTypes = function(_global) { |
| 598 | 1315 |
_global = (typeof _global !== "undefined" && _global); |
1316 |
return this.getList("annotationType", _global); |
|
1317 |
} |
|
1318 |
||
| 719 | 1319 |
Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
| 598 | 1320 |
_global = (typeof _global !== "undefined" && _global); |
| 719 | 1321 |
var _res = new Model.List(this.directory), |
| 598 | 1322 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
1323 |
_annTypes.forEach(function(_annType) { |
|
1324 |
_res.addElements(_annType.getAnnotations(_global)); |
|
1325 |
}) |
|
1326 |
return _res; |
|
1327 |
} |
|
1328 |
||
| 719 | 1329 |
Model.Source.prototype.getDuration = function() { |
| 598 | 1330 |
var _m = this.currentMedia; |
1331 |
if (typeof _m !== "undefined") { |
|
1332 |
return this.currentMedia.duration; |
|
1333 |
} |
|
1334 |
} |
|
1335 |
||
| 719 | 1336 |
Model.Source.prototype.getCurrentMedia = function(_opts) { |
| 694 | 1337 |
if (typeof this.currentMedia === "undefined") { |
1338 |
if (_opts.is_mashup) { |
|
1339 |
var _mashups = this.getMashups(); |
|
1340 |
if (_mashups.length) { |
|
1341 |
this.currentMedia = _mashups[0]; |
|
1342 |
} |
|
1343 |
} else { |
|
1344 |
var _medias = this.getMedias(); |
|
1345 |
if (_medias.length) { |
|
| 719 | 1346 |
this.currentMedia = _medias[0]; |
| 694 | 1347 |
} |
1348 |
} |
|
1349 |
} |
|
1350 |
return this.currentMedia; |
|
1351 |
} |
|
1352 |
||
| 719 | 1353 |
Model.Source.prototype.merge = function(_source) { |
| 638 | 1354 |
var _this = this; |
1355 |
_source.forEach(function(_value, _key) { |
|
1356 |
_this.getList(_key).addElements(_value); |
|
1357 |
}); |
|
1358 |
} |
|
1359 |
||
| 598 | 1360 |
/* */ |
1361 |
||
| 719 | 1362 |
Model.RemoteSource = function(_config) { |
1363 |
Model.Source.call(this, _config); |
|
| 598 | 1364 |
} |
1365 |
||
| 719 | 1366 |
Model.RemoteSource.prototype = new Model.Source(); |
| 598 | 1367 |
|
| 719 | 1368 |
Model.RemoteSource.prototype.get = function() { |
1369 |
this.status = Model._SOURCE_STATUS_WAITING; |
|
1370 |
var _this = this, |
|
1371 |
urlparams = this.url_params || {}, |
|
1372 |
dataType = (Model.isLocalURL(this.url) ? "json" : "jsonp"); |
|
1373 |
urlparams.format = dataType; |
|
1374 |
ns.jQuery.ajax({ |
|
1375 |
url: this.url, |
|
1376 |
dataType: dataType, |
|
1377 |
data: urlparams, |
|
1378 |
success: function(_result) { |
|
1379 |
_this.deSerialize(_result); |
|
1380 |
_this.handleCallbacks(); |
|
1381 |
} |
|
| 598 | 1382 |
}); |
1383 |
} |
|
1384 |
||
1385 |
/* */ |
|
1386 |
||
| 719 | 1387 |
Model.Directory = function() { |
| 598 | 1388 |
this.remoteSources = {}; |
1389 |
this.elements = {}; |
|
1390 |
} |
|
1391 |
||
| 719 | 1392 |
Model.Directory.prototype.remoteSource = function(_properties) { |
| 638 | 1393 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
| 719 | 1394 |
throw "Error : Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
| 638 | 1395 |
} |
| 719 | 1396 |
var _config = ns._({ directory: this }).extend(_properties); |
1397 |
_config.url_params = _config.url_params || {}; |
|
1398 |
var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params); |
|
1399 |
if (typeof this.remoteSources[_hash] === "undefined") { |
|
1400 |
this.remoteSources[_hash] = new Model.RemoteSource(_config); |
|
| 598 | 1401 |
} |
| 719 | 1402 |
return this.remoteSources[_hash]; |
| 598 | 1403 |
} |
1404 |
||
| 719 | 1405 |
Model.Directory.prototype.newLocalSource = function(_properties) { |
1406 |
var _config = ns._({ directory: this }).extend(_properties), |
|
1407 |
_res = new Model.Source(_config); |
|
| 598 | 1408 |
return _res; |
1409 |
} |
|
1410 |
||
| 719 | 1411 |
Model.Directory.prototype.getElement = function(_id) { |
| 623 | 1412 |
return this.elements[_id]; |
| 598 | 1413 |
} |
1414 |
||
| 719 | 1415 |
Model.Directory.prototype.addElement = function(_element) { |
| 598 | 1416 |
this.elements[_element.id] = _element; |
1417 |
} |
|
1418 |
||
| 719 | 1419 |
Model.Directory.prototype.getGlobalList = function() { |
1420 |
var _res = new Model.List(this); |
|
1421 |
_res.addIds(ns._(this.elements).keys()); |
|
| 598 | 1422 |
return _res; |
1423 |
} |
|
1424 |
||
| 719 | 1425 |
return Model; |
1426 |
||
1427 |
})(IriSP); |
|
| 598 | 1428 |
IriSP.language = 'en'; |
1429 |
||
1430 |
IriSP.libFiles = { |
|
1431 |
defaultDir : "js/libs/", |
|
1432 |
inDefaultDir : { |
|
1433 |
underscore : "underscore-min.js", |
|
1434 |
Mustache : "mustache.js", |
|
1435 |
jQuery : "jquery.min.js", |
|
1436 |
jQueryUI : "jquery-ui.min.js", |
|
1437 |
swfObject : "swfobject.js", |
|
1438 |
cssjQueryUI : "jquery-ui.css", |
|
| 623 | 1439 |
popcorn : "popcorn-complete.min.js", |
| 598 | 1440 |
jwplayer : "jwplayer.js", |
1441 |
raphael : "raphael-min.js", |
|
| 638 | 1442 |
tracemanager : "tracemanager.js", |
1443 |
jwPlayerSWF : "player.swf", |
|
| 694 | 1444 |
json : "json2.js", |
1445 |
zeroClipboardJs: "ZeroClipboard.js", |
|
1446 |
zeroClipboardSwf: "ZeroClipboard.swf", |
|
1447 |
backbone: "backbone.js", |
|
1448 |
backboneRelational: "backbone-relational.js", |
|
1449 |
paper: "paper.js", |
|
1450 |
jqueryMousewheel: "jquery.mousewheel.min.js", |
|
1451 |
renkanPublish: "renkan-publish.js", |
|
1452 |
processing: "processing-1.3.6.min.js", |
|
1453 |
recordMicSwf: "record_mic.swf" |
|
| 598 | 1454 |
}, |
1455 |
locations : { |
|
| 694 | 1456 |
// use to define locations outside default_dir |
| 598 | 1457 |
}, |
1458 |
cdn : { |
|
| 694 | 1459 |
jQuery : "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", |
1460 |
jQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.min.js", |
|
| 598 | 1461 |
swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", |
| 694 | 1462 |
cssjQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/themes/ui-lightness/jquery-ui.css", |
1463 |
underscore : "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js", |
|
1464 |
Mustache : "http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js", |
|
1465 |
raphael : "http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js", |
|
1466 |
json : "http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js" |
|
| 598 | 1467 |
}, |
1468 |
useCdn : false |
|
1469 |
} |
|
1470 |
||
1471 |
IriSP.widgetsDir = 'widgets'; |
|
1472 |
||
1473 |
IriSP.widgetsRequirements = { |
|
| 694 | 1474 |
PopcornPlayer: { |
1475 |
noCss: true, |
|
1476 |
requires: [ "popcorn" ] |
|
1477 |
}, |
|
1478 |
JwpPlayer: { |
|
1479 |
noCss: true, |
|
1480 |
requires: [ "jwplayer" ] |
|
1481 |
}, |
|
1482 |
DailymotionPlayer: { |
|
1483 |
noCss: true, |
|
1484 |
requires: [ "swfObject" ] |
|
1485 |
}, |
|
| 719 | 1486 |
AdaptivePlayer: { |
| 694 | 1487 |
noCss: true |
1488 |
}, |
|
| 719 | 1489 |
AutoPlayer: { |
| 694 | 1490 |
noCss: true |
1491 |
}, |
|
1492 |
AnnotationsList: { |
|
1493 |
requires: [ "jwplayer" ] |
|
1494 |
}, |
|
| 598 | 1495 |
Sparkline: { |
1496 |
noCss: true, |
|
| 694 | 1497 |
requires: [ "raphael" ] |
| 598 | 1498 |
}, |
1499 |
Arrow: { |
|
1500 |
noCss: true, |
|
| 694 | 1501 |
requires: [ "raphael" ] |
| 598 | 1502 |
}, |
1503 |
Mediafragment: { |
|
1504 |
noCss: true |
|
1505 |
}, |
|
1506 |
Trace : { |
|
1507 |
noCss: true, |
|
| 694 | 1508 |
requires: [ "tracemanager" ] |
1509 |
}, |
|
1510 |
Slideshare: { |
|
1511 |
requires: [ "swfObject" ] |
|
1512 |
}, |
|
1513 |
Social: { |
|
1514 |
requires: [ "zeroClipboardJs" ] |
|
1515 |
}, |
|
1516 |
Renkan: { |
|
1517 |
requires: [ "backbone", "backboneRelational", "paper", "jqueryMousewheel", "renkanPublish" ] |
|
1518 |
}, |
|
1519 |
KnowledgeConcierge: { |
|
1520 |
requires: [ "processing" ] |
|
| 719 | 1521 |
}, |
1522 |
MultiSegments: { |
|
1523 |
noCss: true |
|
| 598 | 1524 |
} |
1525 |
} |
|
1526 |
||
1527 |
IriSP.guiDefaults = { |
|
1528 |
width : 640, |
|
1529 |
container : 'LdtPlayer', |
|
1530 |
spacer_div_height : 0 |
|
1531 |
} |
|
1532 |
/* Definition of an ancestor for the Widget classes */ |
|
1533 |
||
1534 |
if (typeof IriSP.Widgets === "undefined") { |
|
1535 |
IriSP.Widgets = {} |
|
1536 |
} |
|
1537 |
||
1538 |
/** |
|
1539 |
* @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
|
1540 |
* |
|
1541 |
* Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
1542 |
* defined in init.js |
|
1543 |
* |
|
1544 |
* @constructor |
|
1545 |
* @param player - a reference to the player widget |
|
1546 |
* @param config - configuration options for the widget |
|
1547 |
*/ |
|
1548 |
||
1549 |
||
1550 |
IriSP.Widgets.Widget = function(player, config) { |
|
1551 |
||
1552 |
if( typeof player === "undefined") { |
|
1553 |
/* Probably an abstract call of the class when |
|
1554 |
* individual widgets set their prototype */ |
|
1555 |
return; |
|
1556 |
} |
|
1557 |
|
|
1558 |
/* Setting all the configuration options */ |
|
1559 |
var _type = config.type, |
|
| 694 | 1560 |
_config = IriSP._.defaults({}, config, player.config.default_options, this.defaults), |
| 598 | 1561 |
_this = this; |
1562 |
|
|
1563 |
IriSP._(_config).forEach(function(_value, _key) { |
|
1564 |
_this[_key] = _value; |
|
1565 |
}); |
|
1566 |
|
|
1567 |
if (typeof this.width === "undefined") { |
|
| 694 | 1568 |
this.width = player.config.width; |
| 598 | 1569 |
} |
1570 |
|
|
1571 |
/* Setting this.player at the end in case it's been overriden |
|
1572 |
* by a configuration option of the same name :-( |
|
1573 |
*/ |
|
1574 |
this.player = player; |
|
1575 |
|
|
1576 |
/* Getting metadata */ |
|
1577 |
this.source = player.loadMetadata(this.metadata); |
|
1578 |
|
|
1579 |
/* Call draw when loaded */ |
|
1580 |
this.source.onLoad(function() { |
|
| 694 | 1581 |
if (_this.media_id) { |
1582 |
_this.media = this.getElement(_this.media_id); |
|
1583 |
} else { |
|
1584 |
var _mediaopts = { |
|
1585 |
is_mashup: _this.is_mashup || false |
|
1586 |
} |
|
1587 |
_this.media = this.getCurrentMedia(_mediaopts); |
|
1588 |
} |
|
1589 |
|
|
| 598 | 1590 |
_this.draw(); |
1591 |
}); |
|
1592 |
|
|
1593 |
/* Adding classes and html attributes */ |
|
1594 |
this.$ = IriSP.jQuery('#' + this.container); |
|
1595 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
|
1596 |
|
|
| 638 | 1597 |
this.l10n = ( |
1598 |
typeof this.messages[IriSP.language] !== "undefined" |
|
1599 |
? this.messages[IriSP.language] |
|
1600 |
: ( |
|
1601 |
IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined" |
|
1602 |
? this.messages[IriSP.language.substr(0,2)] |
|
1603 |
: this.messages["en"] |
|
1604 |
) |
|
1605 |
); |
|
| 598 | 1606 |
|
1607 |
}; |
|
1608 |
||
1609 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
1610 |
||
1611 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
1612 |
||
1613 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
1614 |
||
1615 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
1616 |
return Mustache.to_html(_template, this); |
|
1617 |
} |
|
1618 |
||
1619 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
1620 |
this.$.append(this.templateToHtml(this.template)); |
|
1621 |
} |
|
1622 |
||
1623 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
1624 |
var _this = this, |
|
1625 |
_function = this[_name]; |
|
1626 |
if (typeof _function !== "undefined") { |
|
1627 |
return function() { |
|
1628 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
1629 |
} |
|
1630 |
} else { |
|
| 694 | 1631 |
console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name) |
1632 |
} |
|
1633 |
} |
|
1634 |
||
1635 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
1636 |
switch (typeof _functionOrName) { |
|
1637 |
case "function": |
|
1638 |
return _functionOrName; |
|
1639 |
case "string": |
|
1640 |
return this.functionWrapper(_functionOrName); |
|
1641 |
default: |
|
1642 |
return undefined; |
|
| 598 | 1643 |
} |
1644 |
} |
|
1645 |
||
| 694 | 1646 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
1647 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
1648 |
} |
|
1649 |
||
1650 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
1651 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 598 | 1652 |
} |
1653 |
||
1654 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
|
| 719 | 1655 |
if (typeof this.annotation_type === "undefined") { |
1656 |
return this.media.getAnnotations(); |
|
1657 |
} |
|
1658 |
if (this.annotation_type.elementType === "annotationType") { |
|
1659 |
return this.annotation_type.getAnnotations(); |
|
1660 |
} |
|
1661 |
return this.media.getAnnotationsByTypeTitle(this.annotation_type); |
|
| 598 | 1662 |
} |
1663 |
||
|
652
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1664 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 694 | 1665 |
var _time = this.media.getCurrentTime(); |
|
652
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1666 |
return this.getWidgetAnnotations().filter(function(_annotation) { |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1667 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1668 |
}); |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1669 |
} |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1670 |
|
| 694 | 1671 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1672 |
var _id = _selector.attr("id"), |
| 694 | 1673 |
_this = this, |
1674 |
_type = _widgetoptions.type, |
|
1675 |
$L = $LAB; |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1676 |
if (typeof _id == "undefined") { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1677 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1678 |
_selector.attr("id", _id); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1679 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1680 |
_widgetoptions.container = _id; |
| 694 | 1681 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
1682 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
1683 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
1684 |
} |
|
1685 |
} |
|
1686 |
$L.wait(function() { |
|
1687 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
1688 |
if (_propname) { |
|
1689 |
_this[_propname] = _widget; |
|
1690 |
} |
|
1691 |
}); |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1692 |
}); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1693 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1694 |
|
| 598 | 1695 |
/** |
1696 |
* This method responsible of drawing a widget on screen. |
|
1697 |
*/ |
|
1698 |
IriSP.Widgets.Widget.prototype.draw = function() { |
|
1699 |
/* implemented by "sub-classes" */ |
|
| 638 | 1700 |
};/* LDT Platform Serializer */ |
| 598 | 1701 |
|
1702 |
if (typeof IriSP.serializers === "undefined") { |
|
1703 |
IriSP.serializers = {} |
|
1704 |
} |
|
1705 |
||
1706 |
IriSP.serializers.ldt = { |
|
1707 |
types : { |
|
1708 |
media : { |
|
1709 |
serialized_name : "medias", |
|
1710 |
deserializer : function(_data, _source) { |
|
1711 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
1712 |
_res.video = ( |
|
1713 |
typeof _data.url !== "undefined" |
|
1714 |
? _data.url |
|
1715 |
: ( |
|
1716 |
typeof _data.href !== "undefined" |
|
1717 |
? _data.href |
|
1718 |
: null |
|
1719 |
) |
|
1720 |
); |
|
1721 |
if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
1722 |
_res.streamer = _data.meta.item.value; |
|
1723 |
} |
|
1724 |
_res.title = _data.meta["dc:title"]; |
|
1725 |
_res.description = _data.meta["dc:description"]; |
|
1726 |
_res.setDuration(_data.meta["dc:duration"]); |
|
| 638 | 1727 |
_res.url = _data.meta.url; |
1728 |
if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") { |
|
1729 |
_res.thumbnail = _data.meta.img.src; |
|
1730 |
} |
|
| 598 | 1731 |
return _res; |
1732 |
}, |
|
| 719 | 1733 |
serializer : function(_data, _source, _dest) { |
1734 |
var _res = { |
|
| 638 | 1735 |
id : _data.id, |
| 598 | 1736 |
url : _data.video, |
1737 |
meta : { |
|
| 719 | 1738 |
"dc:title": _data.title || "", |
1739 |
"dc:description": _data.description || "", |
|
1740 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1741 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1742 |
"dc:creator" : _data.creator || _source.creator, |
|
1743 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 598 | 1744 |
"dc:duration" : _data.duration.milliseconds |
1745 |
} |
|
1746 |
} |
|
| 719 | 1747 |
_dest.medias.push(_res); |
1748 |
var _list = { |
|
1749 |
id: IriSP.Model.getUID(), |
|
1750 |
meta : { |
|
1751 |
"dc:title": _data.title || "", |
|
1752 |
"dc:description": _data.description || "", |
|
1753 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1754 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1755 |
"dc:creator" : _data.creator || _source.creator, |
|
1756 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
1757 |
"id-ref": _data.id |
|
1758 |
}, |
|
1759 |
items: _source.getAnnotationTypes().filter(function(_at) { |
|
1760 |
return _at.media === _data; |
|
1761 |
}).map(function(_at) { |
|
1762 |
return { |
|
1763 |
"id-ref": _at.id |
|
1764 |
} |
|
1765 |
}) |
|
1766 |
} |
|
1767 |
_dest.lists.push(_list); |
|
1768 |
_dest.views[0].contents.push(_data.id); |
|
| 598 | 1769 |
} |
1770 |
}, |
|
1771 |
tag : { |
|
1772 |
serialized_name : "tags", |
|
1773 |
model_name : "tag", |
|
1774 |
deserializer : function(_data, _source) { |
|
1775 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
1776 |
_res.title = _data.meta["dc:title"]; |
|
1777 |
return _res; |
|
1778 |
}, |
|
| 719 | 1779 |
serializer : function(_data, _source, _dest) { |
1780 |
var _res = { |
|
| 638 | 1781 |
id : _data.id, |
| 598 | 1782 |
meta : { |
| 719 | 1783 |
"dc:title": _data.title || "", |
1784 |
"dc:description": _data.description || "", |
|
1785 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1786 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1787 |
"dc:creator" : _data.creator || _source.creator, |
|
1788 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 598 | 1789 |
} |
1790 |
} |
|
| 719 | 1791 |
_dest.tags.push(_res); |
| 598 | 1792 |
} |
1793 |
}, |
|
1794 |
annotationType : { |
|
1795 |
serialized_name : "annotation-types", |
|
1796 |
deserializer : function(_data, _source) { |
|
1797 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
1798 |
_res.title = _data["dc:title"]; |
|
1799 |
_res.description = _data["dc:description"]; |
|
1800 |
return _res; |
|
1801 |
}, |
|
| 719 | 1802 |
serializer : function(_data, _source, _dest) { |
1803 |
var _res = { |
|
| 638 | 1804 |
id : _data.id, |
| 719 | 1805 |
"dc:title": _data.title || "", |
1806 |
"dc:description": _data.description || "", |
|
1807 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1808 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1809 |
"dc:creator" : _data.creator || _source.creator, |
|
1810 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 598 | 1811 |
} |
| 719 | 1812 |
_dest["annotation-types"].push(_res); |
1813 |
_dest.views[0].annotation_types.push(_data.id); |
|
| 598 | 1814 |
} |
1815 |
}, |
|
1816 |
annotation : { |
|
1817 |
serialized_name : "annotations", |
|
1818 |
deserializer : function(_data, _source) { |
|
1819 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
1820 |
_res.title = _data.content.title || ""; |
|
1821 |
_res.description = _data.content.description || ""; |
|
1822 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
|
1823 |
_res.thumbnail = _data.content.img.src; |
|
1824 |
} |
|
1825 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
1826 |
if (typeof _data.color !== "undefined") { |
|
1827 |
var _c = parseInt(_data.color).toString(16); |
|
1828 |
while (_c.length < 6) { |
|
1829 |
_c = '0' + _c; |
|
1830 |
} |
|
1831 |
_res.color = '#' + _c; |
|
1832 |
} |
|
| 638 | 1833 |
_res.setMedia(_data.media); |
| 598 | 1834 |
_res.setAnnotationType(_data.meta["id-ref"]); |
1835 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
| 719 | 1836 |
_res.keywords = _res.getTagTexts(); |
| 598 | 1837 |
_res.setBegin(_data.begin); |
1838 |
_res.setEnd(_data.end); |
|
1839 |
_res.creator = _data.meta["dc:creator"] || ""; |
|
1840 |
_res.project = _data.meta.project || ""; |
|
1841 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
|
1842 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
1843 |
} |
|
| 638 | 1844 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
1845 |
_res.audio = _data.content.audio; |
|
1846 |
} |
|
| 598 | 1847 |
return _res; |
1848 |
}, |
|
| 719 | 1849 |
serializer : function(_data, _source, _dest) { |
1850 |
var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
|
1851 |
var _res = { |
|
| 638 | 1852 |
id : _data.id, |
| 623 | 1853 |
begin : _data.begin.milliseconds, |
1854 |
end : _data.end.milliseconds, |
|
| 598 | 1855 |
content : { |
| 719 | 1856 |
title : _data.title || "", |
1857 |
description : _data.description || "", |
|
1858 |
audio : _data.audio, |
|
1859 |
img: { |
|
1860 |
src: _data.thumbnail |
|
1861 |
} |
|
| 598 | 1862 |
}, |
| 719 | 1863 |
color: _color, |
| 638 | 1864 |
media : _data.media.id, |
| 598 | 1865 |
meta : { |
| 719 | 1866 |
"id-ref" : _data.getAnnotationType().id, |
1867 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1868 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1869 |
"dc:creator" : _data.creator || _source.creator, |
|
1870 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
1871 |
// project : _source.projectId |
|
| 598 | 1872 |
}, |
| 623 | 1873 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
| 598 | 1874 |
return { |
| 638 | 1875 |
"id-ref" : _id |
| 598 | 1876 |
} |
1877 |
}) |
|
1878 |
} |
|
| 719 | 1879 |
_dest.annotations.push(_res); |
| 598 | 1880 |
} |
| 623 | 1881 |
}, |
1882 |
mashup : { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1883 |
serialized_name : "lists", |
| 623 | 1884 |
deserializer : function(_data, _source) { |
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1885 |
if (typeof _data.meta !== "object" || typeof _data.meta.listtype !== "string" || _data.meta.listtype !== "mashup") { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1886 |
return undefined; |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1887 |
} |
| 623 | 1888 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
1889 |
_res.title = _data.meta["dc:title"]; |
|
1890 |
_res.description = _data.meta["dc:description"]; |
|
| 719 | 1891 |
_res.creator = _data.meta["dc:creator"]; |
1892 |
_res.setAnnotationsById(_data.items); |
|
| 623 | 1893 |
return _res; |
1894 |
}, |
|
| 719 | 1895 |
serializer : function(_data, _source, _dest) { |
1896 |
var _res = { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1897 |
meta : { |
| 719 | 1898 |
"dc:title": _data.title || "", |
1899 |
"dc:description": _data.description || "", |
|
1900 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
1901 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
1902 |
"dc:creator" : _data.creator || _source.creator, |
|
1903 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1904 |
listtype: "mashup" |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1905 |
}, |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1906 |
items: _data.segments.map(function(_annotation) { |
| 719 | 1907 |
return _annotation.annotation.id; |
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1908 |
}), |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1909 |
id: _data.id |
| 623 | 1910 |
} |
| 719 | 1911 |
_dest.lists.push(_res); |
| 623 | 1912 |
} |
| 598 | 1913 |
} |
1914 |
}, |
|
1915 |
serialize : function(_source) { |
|
| 719 | 1916 |
var _res = { |
1917 |
meta: { |
|
1918 |
"dc:creator": _source.creator, |
|
1919 |
"dc:contributor" : _source.contributor || _source.creator, |
|
1920 |
"dc:created": IriSP.Model.dateToIso(_source.created), |
|
1921 |
"dc:modified" : IriSP.Model.dateToIso(_source.modified), |
|
1922 |
"dc:title": _source.title || "", |
|
1923 |
"dc:description": _source.description || "", |
|
1924 |
id: _source.projectId || _source.id |
|
1925 |
}, |
|
1926 |
views: [ |
|
1927 |
{ |
|
1928 |
id: IriSP.Model.getUID(), |
|
1929 |
contents: [], |
|
1930 |
annotation_types: [] |
|
1931 |
} |
|
1932 |
], |
|
1933 |
lists: [], |
|
1934 |
"annotation-types": [], |
|
1935 |
medias: [], |
|
1936 |
tags: [], |
|
1937 |
annotations: [] |
|
1938 |
}, |
|
| 598 | 1939 |
_this = this; |
1940 |
_source.forEach(function(_list, _typename) { |
|
1941 |
if (typeof _this.types[_typename] !== "undefined") { |
|
| 719 | 1942 |
_list.forEach(function(_el) { |
1943 |
_this.types[_typename].serializer(_el, _source, _res); |
|
| 598 | 1944 |
}); |
1945 |
} |
|
1946 |
}); |
|
| 623 | 1947 |
return JSON.stringify(_res); |
| 598 | 1948 |
}, |
1949 |
deSerialize : function(_data, _source) { |
|
1950 |
if (typeof _data !== "object" || _data === null) { |
|
1951 |
return; |
|
1952 |
} |
|
1953 |
IriSP._(this.types).forEach(function(_type, _typename) { |
|
| 638 | 1954 |
var _listdata = _data[_type.serialized_name], |
1955 |
_list = new IriSP.Model.List(_source.directory); |
|
| 598 | 1956 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
1957 |
if (_listdata.hasOwnProperty("length")) { |
|
1958 |
var _l = _listdata.length; |
|
1959 |
for (var _i = 0; _i < _l; _i++) { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1960 |
var _element = _type.deserializer(_listdata[_i], _source); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1961 |
if (typeof _element !== "undefined" && _element) { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1962 |
_list.push(_element); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1963 |
} |
| 598 | 1964 |
} |
1965 |
} else { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1966 |
var _element = _type.deserializer(_listdata, _source); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1967 |
if (typeof _element !== "undefined" && _element) { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1968 |
_list.push(_element); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1969 |
} |
| 598 | 1970 |
} |
1971 |
} |
|
| 638 | 1972 |
_source.addList(_typename, _list); |
| 598 | 1973 |
}); |
1974 |
|
|
1975 |
if (typeof _data.meta !== "undefined") { |
|
1976 |
_source.projectId = _data.meta.id; |
|
1977 |
} |
|
1978 |
|
|
1979 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
| 694 | 1980 |
_source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
| 598 | 1981 |
} |
1982 |
} |
|
1983 |
} |
|
1984 |
||
| 638 | 1985 |
/* Used when Putting annotations on the platform */ |
1986 |
||
1987 |
if (typeof IriSP.serializers === "undefined") { |
|
1988 |
IriSP.serializers = {} |
|
1989 |
} |
|
1990 |
||
1991 |
IriSP.serializers.ldt_annotate = { |
|
| 719 | 1992 |
serializeAnnotation : function(_data, _source) { |
1993 |
var _annType = _data.getAnnotationType(); |
|
1994 |
return { |
|
1995 |
begin: _data.begin.milliseconds, |
|
1996 |
end: _data.end.milliseconds, |
|
1997 |
content: { |
|
1998 |
description: _data.description, |
|
1999 |
title: _data.title, |
|
2000 |
audio: _data.audio |
|
2001 |
}, |
|
2002 |
tags: _data.getTagTexts(), |
|
2003 |
media: _data.getMedia().id, |
|
2004 |
type_title: _annType.title, |
|
2005 |
type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
|
2006 |
meta: { |
|
2007 |
created: _data.created, |
|
2008 |
creator: _data.creator |
|
| 638 | 2009 |
} |
2010 |
} |
|
2011 |
}, |
|
| 719 | 2012 |
deserializeAnnotation : function(_anndata, _source) { |
2013 |
var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
2014 |
_ann.description = _anndata.content.description || ""; |
|
2015 |
_ann.title = _anndata.content.title || ""; |
|
2016 |
_ann.creator = _anndata.meta.creator || ""; |
|
2017 |
_ann.created = new Date(_anndata.meta.created); |
|
2018 |
_ann.setMedia(_anndata.media, _source); |
|
2019 |
var _anntype = _source.getElement(_anndata.type); |
|
2020 |
if (!_anntype) { |
|
2021 |
_anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
2022 |
_anntype.title = _anndata.type_title; |
|
2023 |
_source.getAnnotationTypes().push(_anntype); |
|
2024 |
} |
|
2025 |
_ann.setAnnotationType(_anntype.id); |
|
2026 |
var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
2027 |
var _tags = _source.getTags(true).searchByTitle(_title, true); |
|
2028 |
if (_tags.length) { |
|
2029 |
var _tag = _tags[0]; |
|
2030 |
} |
|
2031 |
else { |
|
2032 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
2033 |
_tag.title = _title; |
|
2034 |
_source.getTags().push(_tag); |
|
2035 |
} |
|
2036 |
return _tag.id; |
|
2037 |
}); |
|
2038 |
_ann.setTags(_tagIds); |
|
2039 |
_ann.setBegin(_anndata.begin); |
|
2040 |
_ann.setEnd(_anndata.end); |
|
2041 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
2042 |
_ann.audio = _anndata.content.audio; |
|
2043 |
} |
|
2044 |
_source.getAnnotations().push(_ann); |
|
2045 |
}, |
|
| 638 | 2046 |
serialize : function(_source) { |
| 719 | 2047 |
return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
| 638 | 2048 |
}, |
2049 |
deSerialize : function(_data, _source) { |
|
2050 |
if (typeof _data == "string") { |
|
2051 |
_data = JSON.parse(_data); |
|
2052 |
} |
|
| 719 | 2053 |
|
| 638 | 2054 |
_source.addList('tag', new IriSP.Model.List(_source.directory)); |
2055 |
_source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
|
2056 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
|
| 719 | 2057 |
this.deserializeAnnotation(_data, _source); |
| 638 | 2058 |
} |
2059 |
} |