| author | Raphael Velt <raph.velt@gmail.com> |
| Tue, 02 Oct 2012 14:40:14 +0200 | |
| changeset 694 | e9400c80e1e4 |
| parent 654 | a5977736d2b0 |
| child 719 | d0d3a9369f84 |
| 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) { |
|
127 |
if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { |
|
128 |
_metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; |
|
129 |
} |
|
130 |
if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { |
|
131 |
_metadataInfo.url = _metadataInfo.src; |
|
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 */ |
|
| 598 | 238 |
|
239 |
IriSP.Model = { |
|
240 |
_SOURCE_STATUS_EMPTY : 0, |
|
241 |
_SOURCE_STATUS_WAITING : 1, |
|
242 |
_SOURCE_STATUS_READY : 2, |
|
243 |
_ID_AUTO_INCREMENT : 0, |
|
| 638 | 244 |
_ID_BASE : (function(_d) { |
245 |
function pad(n){return n<10 ? '0'+n : n} |
|
246 |
function fillrand(n) { |
|
247 |
var _res = '' |
|
248 |
for (var i=0; i<n; i++) { |
|
249 |
_res += Math.floor(16*Math.random()).toString(16); |
|
250 |
} |
|
251 |
return _res; |
|
252 |
} |
|
253 |
return _d.getUTCFullYear() + '-' |
|
254 |
+ pad(_d.getUTCMonth()+1) + '-' |
|
255 |
+ pad(_d.getUTCDate()) + '-' |
|
256 |
+ fillrand(16); |
|
257 |
})(new Date()), |
|
| 598 | 258 |
getUID : function() { |
| 638 | 259 |
var _n = (++this._ID_AUTO_INCREMENT).toString(); |
260 |
while (_n.length < 4) { |
|
261 |
_n = '0' + _n |
|
262 |
} |
|
263 |
return "autoid-" + this._ID_BASE + '-' + _n; |
|
| 598 | 264 |
}, |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
265 |
regexpFromTextOrArray : function(_textOrArray, _testOnly) { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
266 |
var _testOnly = _testOnly || false; |
| 598 | 267 |
function escapeText(_text) { |
268 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
269 |
} |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
270 |
var _source = |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
271 |
typeof _textOrArray === "string" |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
272 |
? escapeText(_textOrArray) |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
273 |
: IriSP._(_textOrArray).map(escapeText).join("|"); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
274 |
if (_testOnly) { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
275 |
return new RegExp( _source, 'im'); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
276 |
} else { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
277 |
return new RegExp( '(' + _source + ')', 'gim'); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
278 |
} |
| 598 | 279 |
}, |
280 |
isoToDate : function(_str) { |
|
281 |
// http://delete.me.uk/2005/03/iso8601.html |
|
282 |
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})))?)?)?)?"; |
|
283 |
var d = _str.match(new RegExp(regexp)); |
|
284 |
|
|
285 |
var offset = 0; |
|
286 |
var date = new Date(d[1], 0, 1); |
|
287 |
|
|
288 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
289 |
if (d[5]) { date.setDate(d[5]); } |
|
290 |
if (d[7]) { date.setHours(d[7]); } |
|
291 |
if (d[8]) { date.setMinutes(d[8]); } |
|
292 |
if (d[10]) { date.setSeconds(d[10]); } |
|
293 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
294 |
if (d[14]) { |
|
295 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
296 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
297 |
} |
|
298 |
|
|
299 |
offset -= date.getTimezoneOffset(); |
|
300 |
time = (Number(date) + (offset * 60 * 1000)); |
|
301 |
var _res = new Date(); |
|
302 |
_res.setTime(Number(time)); |
|
303 |
return _res; |
|
304 |
}, |
|
| 638 | 305 |
dateToIso : function(d) { |
| 598 | 306 |
function pad(n){return n<10 ? '0'+n : n} |
307 |
return d.getUTCFullYear()+'-' |
|
308 |
+ pad(d.getUTCMonth()+1)+'-' |
|
309 |
+ pad(d.getUTCDate())+'T' |
|
310 |
+ pad(d.getUTCHours())+':' |
|
311 |
+ pad(d.getUTCMinutes())+':' |
|
312 |
+ pad(d.getUTCSeconds())+'Z' |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
/* |
|
317 |
* IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
318 |
*/ |
|
319 |
IriSP.Model.List = function(_directory) { |
|
320 |
Array.call(this); |
|
321 |
this.directory = _directory; |
|
322 |
this.idIndex = []; |
|
| 694 | 323 |
this.__events = {}; |
| 598 | 324 |
if (typeof _directory == "undefined") { |
| 623 | 325 |
console.trace(); |
| 598 | 326 |
throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
327 |
} |
|
328 |
} |
|
329 |
||
330 |
IriSP.Model.List.prototype = new Array(); |
|
331 |
||
332 |
IriSP.Model.List.prototype.hasId = function(_id) { |
|
| 694 | 333 |
return IriSP._(this.idIndex).include(_id); |
| 598 | 334 |
} |
335 |
||
336 |
/* On recent browsers, forEach and map are defined and do what we want. |
|
337 |
* Otherwise, we'll use the Underscore.js functions |
|
338 |
*/ |
|
339 |
if (typeof Array.prototype.forEach === "undefined") { |
|
340 |
IriSP.Model.List.prototype.forEach = function(_callback) { |
|
341 |
var _this = this; |
|
342 |
IriSP._(this).forEach(function(_value, _key) { |
|
343 |
_callback(_value, _key, _this); |
|
344 |
}); |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
if (typeof Array.prototype.map === "undefined") { |
|
349 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
350 |
var _this = this; |
|
351 |
return IriSP._(this).map(function(_value, _key) { |
|
352 |
return _callback(_value, _key, _this); |
|
353 |
}); |
|
354 |
} |
|
355 |
} |
|
356 |
||
| 623 | 357 |
IriSP.Model.List.prototype.pluck = function(_key) { |
358 |
return this.map(function(_value) { |
|
359 |
return _value[_key]; |
|
360 |
}); |
|
361 |
} |
|
362 |
||
| 598 | 363 |
/* We override Array's filter function because it doesn't return an IriSP.Model.List |
364 |
*/ |
|
365 |
IriSP.Model.List.prototype.filter = function(_callback) { |
|
366 |
var _this = this, |
|
367 |
_res = new IriSP.Model.List(this.directory); |
|
368 |
_res.addElements(IriSP._(this).filter(function(_value, _key) { |
|
369 |
return _callback(_value, _key, _this); |
|
370 |
})); |
|
371 |
return _res; |
|
372 |
} |
|
373 |
||
374 |
IriSP.Model.List.prototype.slice = function(_start, _end) { |
|
375 |
var _res = new IriSP.Model.List(this.directory); |
|
376 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
377 |
return _res; |
|
378 |
} |
|
379 |
||
380 |
IriSP.Model.List.prototype.splice = function(_start, _end) { |
|
381 |
var _res = new IriSP.Model.List(this.directory); |
|
382 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
383 |
this.idIndex.splice(_start, _end); |
|
384 |
return _res; |
|
385 |
} |
|
386 |
||
387 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
|
388 |
* and won't return a new IriSP.Model.List |
|
389 |
*/ |
|
390 |
IriSP.Model.List.prototype.sortBy = function(_callback) { |
|
391 |
var _this = this, |
|
392 |
_res = new IriSP.Model.List(this.directory); |
|
393 |
_res.addElements(IriSP._(this).sortBy(function(_value, _key) { |
|
394 |
return _callback(_value, _key, _this); |
|
395 |
})); |
|
396 |
return _res; |
|
397 |
} |
|
398 |
||
399 |
/* Title and Description are basic information for (almost) all element types, |
|
400 |
* here we can search by these criteria |
|
401 |
*/ |
|
402 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
403 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text, true); |
| 598 | 404 |
return this.filter(function(_element) { |
405 |
return _rgxp.test(_element.title); |
|
406 |
}); |
|
407 |
} |
|
408 |
||
409 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
410 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text, true); |
| 598 | 411 |
return this.filter(function(_element) { |
412 |
return _rgxp.test(_element.description); |
|
413 |
}); |
|
414 |
} |
|
415 |
||
416 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
417 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text, true); |
| 598 | 418 |
return this.filter(function(_element) { |
419 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
|
420 |
}); |
|
421 |
} |
|
422 |
||
423 |
IriSP.Model.List.prototype.getTitles = function() { |
|
424 |
return this.map(function(_el) { |
|
425 |
return _el.title; |
|
426 |
}); |
|
427 |
} |
|
428 |
||
429 |
IriSP.Model.List.prototype.addId = function(_id) { |
|
430 |
var _el = this.directory.getElement(_id) |
|
431 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
432 |
this.idIndex.push(_id); |
|
433 |
Array.prototype.push.call(this, _el); |
|
434 |
} |
|
435 |
} |
|
436 |
||
437 |
IriSP.Model.List.prototype.push = function(_el) { |
|
438 |
if (typeof _el === "undefined") { |
|
439 |
return; |
|
440 |
} |
|
441 |
var _index = (IriSP._(this.idIndex).indexOf(_el.id)); |
|
442 |
if (_index === -1) { |
|
443 |
this.idIndex.push(_el.id); |
|
444 |
Array.prototype.push.call(this, _el); |
|
445 |
} else { |
|
446 |
this[_index] = _el; |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
IriSP.Model.List.prototype.addIds = function(_array) { |
|
451 |
var _l = _array.length, |
|
452 |
_this = this; |
|
453 |
IriSP._(_array).forEach(function(_id) { |
|
454 |
_this.addId(_id); |
|
455 |
}); |
|
456 |
} |
|
457 |
||
458 |
IriSP.Model.List.prototype.addElements = function(_array) { |
|
459 |
var _this = this; |
|
460 |
IriSP._(_array).forEach(function(_el) { |
|
461 |
_this.push(_el); |
|
462 |
}); |
|
463 |
} |
|
464 |
||
| 638 | 465 |
IriSP.Model.List.prototype.removeId = function(_id, _deleteFromDirectory) { |
466 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
467 |
_index = (IriSP._(this.idIndex).indexOf(_id)); |
|
| 598 | 468 |
if (_index !== -1) { |
469 |
this.splice(_index,1); |
|
470 |
} |
|
| 638 | 471 |
if (_deleteFromDirectory) { |
472 |
delete this.directory.elements[_id]; |
|
473 |
} |
|
| 598 | 474 |
} |
475 |
||
| 638 | 476 |
IriSP.Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) { |
477 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
| 598 | 478 |
this.removeId(_el.id); |
479 |
} |
|
480 |
||
| 638 | 481 |
IriSP.Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) { |
482 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
483 |
_this = this; |
|
| 598 | 484 |
IriSP._(_list).forEach(function(_id) { |
485 |
_this.removeId(_id); |
|
486 |
}); |
|
487 |
} |
|
488 |
||
| 638 | 489 |
IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
490 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
491 |
_this = this; |
|
| 598 | 492 |
IriSP._(_list).forEach(function(_el) { |
493 |
_this.removeElement(_el); |
|
494 |
}); |
|
495 |
} |
|
496 |
||
| 694 | 497 |
IriSP.Model.List.prototype.on = function(_event, _callback) { |
498 |
if (typeof this.__events[_event] === "undefined") { |
|
499 |
this.__events[_event] = []; |
|
500 |
} |
|
501 |
this.__events[_event].push(_callback); |
|
502 |
} |
|
503 |
||
504 |
IriSP.Model.List.prototype.trigger = function(_event, _data) { |
|
505 |
var _list = this; |
|
506 |
IriSP._(this.__events[_event]).each(function(_callback) { |
|
507 |
_callback.call(_list, _data); |
|
508 |
}); |
|
509 |
} |
|
510 |
||
| 598 | 511 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
512 |
* without the clumsiness of the original Date object. |
|
513 |
*/ |
|
514 |
||
515 |
IriSP.Model.Time = function(_milliseconds) { |
|
| 623 | 516 |
this.milliseconds = 0; |
517 |
this.setMilliseconds(_milliseconds); |
|
518 |
} |
|
519 |
||
520 |
IriSP.Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
|
521 |
var _ante = _milliseconds; |
|
522 |
switch(typeof _milliseconds) { |
|
523 |
case "string": |
|
524 |
this.milliseconds = parseFloat(_milliseconds); |
|
525 |
break; |
|
526 |
case "number": |
|
527 |
this.milliseconds = _milliseconds; |
|
528 |
break; |
|
529 |
case "object": |
|
530 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
531 |
break; |
|
532 |
default: |
|
533 |
this.milliseconds = 0; |
|
534 |
} |
|
535 |
if (this.milliseconds === NaN) { |
|
536 |
this.milliseconds = _ante; |
|
537 |
} |
|
| 598 | 538 |
} |
539 |
||
540 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
541 |
this.milliseconds = 1000 * _seconds; |
|
542 |
} |
|
543 |
||
544 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
| 638 | 545 |
return this.milliseconds / 1000; |
| 598 | 546 |
} |
547 |
||
548 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
| 638 | 549 |
var _totalSeconds = Math.abs(Math.floor(this.getSeconds())); |
| 598 | 550 |
return { |
551 |
hours : Math.floor(_totalSeconds / 3600), |
|
552 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
553 |
seconds : _totalSeconds % 60 |
|
554 |
} |
|
555 |
} |
|
556 |
||
| 623 | 557 |
IriSP.Model.Time.prototype.add = function(_milliseconds) { |
558 |
this.milliseconds += new IriSP.Model.Time(_milliseconds).milliseconds; |
|
559 |
} |
|
560 |
||
| 598 | 561 |
IriSP.Model.Time.prototype.valueOf = function() { |
562 |
return this.milliseconds; |
|
563 |
} |
|
564 |
||
565 |
IriSP.Model.Time.prototype.toString = function() { |
|
566 |
function pad(_n) { |
|
567 |
var _res = _n.toString(); |
|
568 |
while (_res.length < 2) { |
|
569 |
_res = '0' + _res; |
|
570 |
} |
|
571 |
return _res; |
|
572 |
} |
|
573 |
var _hms = this.getHMS(), |
|
574 |
_res = ''; |
|
575 |
if (_hms.hours) { |
|
576 |
_res += pad(_hms.hours) + ':' |
|
577 |
} |
|
578 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
579 |
return _res; |
|
580 |
} |
|
581 |
||
582 |
/* IriSP.Model.Reference handles references between elements |
|
583 |
*/ |
|
584 |
||
585 |
IriSP.Model.Reference = function(_source, _idRef) { |
|
586 |
this.source = _source; |
|
| 638 | 587 |
this.id = _idRef; |
| 598 | 588 |
if (typeof _idRef === "object") { |
589 |
this.isList = true; |
|
590 |
} else { |
|
591 |
this.isList = false; |
|
592 |
} |
|
593 |
this.refresh(); |
|
594 |
} |
|
595 |
||
596 |
IriSP.Model.Reference.prototype.refresh = function() { |
|
597 |
if (this.isList) { |
|
598 |
this.contents = new IriSP.Model.List(this.source.directory); |
|
599 |
this.contents.addIds(this.id); |
|
600 |
} else { |
|
| 694 | 601 |
this.contents = this.source.getElement(this.id); |
| 598 | 602 |
} |
603 |
|
|
604 |
} |
|
605 |
||
606 |
IriSP.Model.Reference.prototype.getContents = function() { |
|
607 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
608 |
this.refresh(); |
|
609 |
} |
|
610 |
return this.contents; |
|
611 |
} |
|
612 |
||
613 |
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
614 |
if (this.isList) { |
|
615 |
return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
616 |
} else { |
|
617 |
return (this.id == _idRef); |
|
618 |
} |
|
619 |
} |
|
620 |
||
621 |
/* */ |
|
622 |
||
623 |
IriSP.Model.Element = function(_id, _source) { |
|
624 |
this.elementType = 'element'; |
|
625 |
if (typeof _source === "undefined") { |
|
626 |
return; |
|
627 |
} |
|
628 |
if (typeof _id === "undefined" || !_id) { |
|
629 |
_id = IriSP.Model.getUID(); |
|
630 |
} |
|
631 |
this.source = _source; |
|
| 638 | 632 |
this.id = _id; |
| 598 | 633 |
this.title = ""; |
634 |
this.description = ""; |
|
| 694 | 635 |
this.__events = {} |
| 598 | 636 |
this.source.directory.addElement(this); |
637 |
} |
|
638 |
||
639 |
IriSP.Model.Element.prototype.toString = function() { |
|
640 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
641 |
} |
|
642 |
||
643 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
|
644 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
|
645 |
} |
|
646 |
||
647 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
|
648 |
if (typeof this[_elementType] !== "undefined") { |
|
649 |
return this[_elementType].getContents(); |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
654 |
_global = (typeof _global !== "undefined" && _global); |
|
655 |
var _this = this; |
|
656 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
|
657 |
var _ref = _el[_this.elementType]; |
|
658 |
return _ref.isOrHasId(_this.id); |
|
659 |
}); |
|
660 |
} |
|
661 |
||
| 694 | 662 |
IriSP.Model.Element.prototype.on = function(_event, _callback) { |
663 |
if (typeof this.__events[_event] === "undefined") { |
|
664 |
this.__events[_event] = []; |
|
665 |
} |
|
666 |
this.__events[_event].push(_callback); |
|
667 |
} |
|
668 |
||
669 |
IriSP.Model.Element.prototype.trigger = function(_event, _data) { |
|
670 |
var _element = this; |
|
671 |
IriSP._(this.__events[_event]).each(function(_callback) { |
|
672 |
_callback.call(_element, _data); |
|
673 |
}); |
|
674 |
} |
|
675 |
||
| 598 | 676 |
/* */ |
677 |
||
678 |
IriSP.Model.Media = function(_id, _source) { |
|
679 |
IriSP.Model.Element.call(this, _id, _source); |
|
680 |
this.elementType = 'media'; |
|
681 |
this.duration = new IriSP.Model.Time(); |
|
682 |
this.video = ''; |
|
| 694 | 683 |
var _this = this; |
684 |
this.on("timeupdate", function(_time) { |
|
685 |
_this.getAnnotations().filter(function(_a) { |
|
686 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
687 |
}).forEach(function(_a) { |
|
688 |
_a.playing = false; |
|
689 |
_a.trigger("leave"); |
|
690 |
}); |
|
691 |
_this.getAnnotations().filter(function(_a) { |
|
692 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
693 |
}).forEach(function(_a) { |
|
694 |
_a.playing = true; |
|
695 |
_a.trigger("enter"); |
|
696 |
}); |
|
697 |
}); |
|
| 598 | 698 |
} |
699 |
||
700 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
701 |
||
| 694 | 702 |
/* Default functions to be overriden by players */ |
703 |
||
704 |
IriSP.Model.Media.prototype.getCurrentTime = function() { return new IriSP.Model.Time(0); } |
|
705 |
||
706 |
IriSP.Model.Media.prototype.getVolume = function() { return .5; } |
|
707 |
||
708 |
IriSP.Model.Media.prototype.getPaused = function() { return true; } |
|
709 |
||
710 |
IriSP.Model.Media.prototype.getMuted = function() { return false; } |
|
711 |
||
712 |
IriSP.Model.Media.prototype.setCurrentTime |
|
713 |
= IriSP.Model.Media.prototype.setVolume |
|
714 |
= IriSP.Model.Media.prototype.setMuted |
|
715 |
= IriSP.Model.Media.prototype.play |
|
716 |
= IriSP.Model.Media.prototype.pause |
|
717 |
= function() {} |
|
718 |
|
|
| 598 | 719 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
| 623 | 720 |
this.duration.setMilliseconds(_durationMs); |
| 598 | 721 |
} |
722 |
||
723 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
|
724 |
return this.getRelated("annotation"); |
|
725 |
} |
|
726 |
||
| 623 | 727 |
IriSP.Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
728 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
729 |
if (_annTypes.length) { |
|
730 |
return this.getAnnotations().filter(function(_annotation) { |
|
731 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
732 |
}); |
|
733 |
} else { |
|
734 |
return new IriSP.Model.List(this.source.directory) |
|
735 |
} |
|
736 |
} |
|
737 |
||
| 598 | 738 |
/* */ |
739 |
||
740 |
IriSP.Model.Tag = function(_id, _source) { |
|
741 |
IriSP.Model.Element.call(this, _id, _source); |
|
742 |
this.elementType = 'tag'; |
|
743 |
} |
|
744 |
||
745 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
746 |
||
747 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
|
748 |
return this.getRelated("annotation"); |
|
749 |
} |
|
750 |
||
751 |
/* */ |
|
752 |
||
753 |
IriSP.Model.AnnotationType = function(_id, _source) { |
|
754 |
IriSP.Model.Element.call(this, _id, _source); |
|
755 |
this.elementType = 'annotationType'; |
|
756 |
} |
|
757 |
||
758 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
759 |
||
760 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
|
761 |
return this.getRelated("annotation"); |
|
762 |
} |
|
763 |
||
764 |
/* Annotation |
|
765 |
* */ |
|
766 |
||
767 |
IriSP.Model.Annotation = function(_id, _source) { |
|
768 |
IriSP.Model.Element.call(this, _id, _source); |
|
769 |
this.elementType = 'annotation'; |
|
770 |
this.begin = new IriSP.Model.Time(); |
|
771 |
this.end = new IriSP.Model.Time(); |
|
| 694 | 772 |
this.playing = false; |
773 |
var _this = this; |
|
774 |
this.on("click", function() { |
|
775 |
_this.getMedia().setCurrentTime(_this.begin); |
|
776 |
}); |
|
| 598 | 777 |
} |
778 |
||
779 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
780 |
||
781 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
| 623 | 782 |
this.begin.setMilliseconds(_beginMs); |
| 598 | 783 |
} |
784 |
||
785 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
| 623 | 786 |
this.end.setMilliseconds(_beginMs); |
| 598 | 787 |
} |
788 |
||
789 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
|
790 |
this.setReference("media", _idRef); |
|
791 |
} |
|
792 |
||
793 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
|
794 |
return this.getReference("media"); |
|
795 |
} |
|
796 |
||
797 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
|
798 |
this.setReference("annotationType", _idRef); |
|
799 |
} |
|
800 |
||
801 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
|
802 |
return this.getReference("annotationType"); |
|
803 |
} |
|
804 |
||
805 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
|
806 |
this.setReference("tag", _idRefs); |
|
807 |
} |
|
808 |
||
809 |
IriSP.Model.Annotation.prototype.getTags = function() { |
|
810 |
return this.getReference("tag"); |
|
811 |
} |
|
812 |
||
813 |
IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
814 |
return this.getTags().getTitles(); |
|
815 |
} |
|
816 |
||
| 623 | 817 |
IriSP.Model.Annotation.prototype.getDuration = function() { |
818 |
return new IriSP.Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
819 |
} |
|
820 |
||
821 |
/* */ |
|
822 |
||
823 |
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { |
|
| 638 | 824 |
IriSP.Model.Element.call(this, _mashup.id + "_" + _annotation.id, _annotation.source); |
| 623 | 825 |
this.elementType = 'mashedAnnotation'; |
826 |
this.annotation = _annotation; |
|
827 |
this.begin = new IriSP.Model.Time(_mashup.duration); |
|
828 |
this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration()); |
|
829 |
this.title = this.annotation.title; |
|
830 |
this.description = this.annotation.description; |
|
831 |
this.color = this.annotation.color; |
|
| 694 | 832 |
var _this = this; |
833 |
this.on("click", function() { |
|
834 |
_mashup.setCurrentTime(_this.begin); |
|
835 |
}); |
|
| 623 | 836 |
} |
837 |
||
838 |
IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null); |
|
839 |
||
840 |
IriSP.Model.MashedAnnotation.prototype.getMedia = function() { |
|
841 |
return this.annotation.getReference("media"); |
|
842 |
} |
|
843 |
||
844 |
IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() { |
|
845 |
return this.annotation.getReference("annotationType"); |
|
846 |
} |
|
847 |
||
848 |
IriSP.Model.MashedAnnotation.prototype.getTags = function() { |
|
849 |
return this.annotation.getReference("tag"); |
|
850 |
} |
|
851 |
||
852 |
IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() { |
|
853 |
return this.annotation.getTags().getTitles(); |
|
854 |
} |
|
855 |
||
| 694 | 856 |
IriSP.Model.MashedAnnotation.prototype.getDuration = function() { |
857 |
return this.annotation.getDuration(); |
|
858 |
} |
|
859 |
||
| 623 | 860 |
/* */ |
861 |
||
862 |
IriSP.Model.Mashup = function(_id, _source) { |
|
863 |
IriSP.Model.Element.call(this, _id, _source); |
|
864 |
this.elementType = 'mashup'; |
|
865 |
this.duration = new IriSP.Model.Time(); |
|
866 |
this.segments = new IriSP.Model.List(_source.directory); |
|
867 |
this.medias = new IriSP.Model.List(_source.directory); |
|
| 694 | 868 |
var _currentMedia = null; |
869 |
var _this = this; |
|
870 |
this.on("timeupdate", function(_time) { |
|
871 |
_this.getAnnotations().filter(function(_a) { |
|
872 |
return (_a.end <= _time || _a.begin > _time) && _a.playing |
|
873 |
}).forEach(function(_a) { |
|
874 |
_a.playing = false; |
|
875 |
_a.trigger("leave"); |
|
876 |
}); |
|
877 |
_this.getAnnotations().filter(function(_a) { |
|
878 |
return _a.begin <= _time && _a.end > _time && !_a.playing |
|
879 |
}).forEach(function(_a) { |
|
880 |
_a.playing = true; |
|
881 |
_a.trigger("enter"); |
|
882 |
var _m = _a.getMedia(); |
|
883 |
if (_m !== _currentMedia) { |
|
884 |
if (_currentMedia) { |
|
885 |
_currentMedia.trigger("leave"); |
|
886 |
} |
|
887 |
_m.trigger("enter"); |
|
888 |
_currentMedia = _m; |
|
889 |
} |
|
890 |
}); |
|
891 |
}); |
|
| 623 | 892 |
} |
893 |
||
894 |
IriSP.Model.Mashup.prototype = new IriSP.Model.Element(); |
|
895 |
||
896 |
IriSP.Model.Mashup.prototype.addSegment = function(_annotation) { |
|
897 |
var _mashedAnnotation = new IriSP.Model.MashedAnnotation(this, _annotation); |
|
898 |
this.duration.setMilliseconds(_mashedAnnotation.end); |
|
899 |
this.segments.push(_mashedAnnotation); |
|
900 |
this.medias.push(_annotation.getMedia()); |
|
901 |
} |
|
902 |
||
903 |
IriSP.Model.Mashup.prototype.addSegmentById = function(_elId) { |
|
904 |
var _annotation = this.source.getElement(_elId); |
|
905 |
if (typeof _annotation !== "undefined") { |
|
906 |
this.addSegment(_annotation); |
|
907 |
} |
|
908 |
} |
|
909 |
||
910 |
IriSP.Model.Mashup.prototype.getAnnotations = function() { |
|
911 |
return this.segments; |
|
912 |
} |
|
913 |
||
914 |
IriSP.Model.Mashup.prototype.getMedias = function() { |
|
915 |
return this.medias; |
|
916 |
} |
|
917 |
||
918 |
IriSP.Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
919 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
920 |
if (_annTypes.length) { |
|
921 |
return this.getAnnotations().filter(function(_annotation) { |
|
922 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
923 |
}); |
|
924 |
} else { |
|
925 |
return new IriSP.Model.List(this.source.directory) |
|
926 |
} |
|
927 |
} |
|
928 |
||
929 |
IriSP.Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
|
930 |
var _list = this.segments.filter(function(_annotation) { |
|
931 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
932 |
}); |
|
933 |
if (_list.length) { |
|
934 |
return _list[0]; |
|
935 |
} else { |
|
936 |
return undefined; |
|
937 |
} |
|
938 |
} |
|
939 |
||
940 |
IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) { |
|
941 |
var _annotation = this.getAnnotationAtTime(_time); |
|
942 |
if (typeof _annotation !== "undefined") { |
|
943 |
return _annotation.getMedia(); |
|
944 |
} else { |
|
945 |
return undefined; |
|
946 |
} |
|
947 |
} |
|
948 |
||
| 694 | 949 |
/* Default functions to be overriden by players */ |
950 |
||
951 |
IriSP.Model.Mashup.prototype.getCurrentTime = function() { return new IriSP.Model.Time(0); } |
|
952 |
||
953 |
IriSP.Model.Mashup.prototype.getVolume = function() { return .5; } |
|
954 |
||
955 |
IriSP.Model.Mashup.prototype.getPaused = function() { return true; } |
|
956 |
||
957 |
IriSP.Model.Mashup.prototype.getMuted = function() { return false; } |
|
958 |
||
959 |
IriSP.Model.Mashup.prototype.setCurrentTime |
|
960 |
= IriSP.Model.Mashup.prototype.setVolume |
|
961 |
= IriSP.Model.Mashup.prototype.setMuted |
|
962 |
= IriSP.Model.Mashup.prototype.play |
|
963 |
= IriSP.Model.Mashup.prototype.pause |
|
964 |
= function() {} |
|
965 |
||
| 598 | 966 |
/* */ |
967 |
||
968 |
IriSP.Model.Source = function(_config) { |
|
969 |
this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
|
970 |
if (typeof _config !== "undefined") { |
|
971 |
var _this = this; |
|
972 |
IriSP._(_config).forEach(function(_v, _k) { |
|
973 |
_this[_k] = _v; |
|
974 |
}) |
|
975 |
this.callbackQueue = []; |
|
976 |
this.contents = {}; |
|
977 |
this.get(); |
|
978 |
} |
|
979 |
} |
|
980 |
||
981 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
982 |
if (typeof this.contents[_listId] === "undefined") { |
|
983 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
984 |
} |
|
985 |
this.contents[_listId].addElements(_contents); |
|
986 |
} |
|
987 |
||
988 |
IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
989 |
_global = (typeof _global !== "undefined" && _global); |
|
990 |
if (_global || typeof this.contents[_listId] === "undefined") { |
|
991 |
return this.directory.getGlobalList().filter(function(_e) { |
|
992 |
return (_e.elementType === _listId); |
|
993 |
}); |
|
994 |
} else { |
|
995 |
return this.contents[_listId]; |
|
996 |
} |
|
997 |
} |
|
998 |
||
999 |
IriSP.Model.Source.prototype.forEach = function(_callback) { |
|
1000 |
var _this = this; |
|
1001 |
IriSP._(this.contents).forEach(function(_value, _key) { |
|
1002 |
_callback.call(_this, _value, _key); |
|
1003 |
}) |
|
1004 |
} |
|
1005 |
||
1006 |
IriSP.Model.Source.prototype.getElement = function(_elId) { |
|
| 638 | 1007 |
return this.directory.getElement(_elId); |
| 598 | 1008 |
} |
1009 |
||
1010 |
IriSP.Model.Source.prototype.get = function() { |
|
1011 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
1012 |
this.handleCallbacks(); |
|
1013 |
} |
|
1014 |
||
1015 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
1016 |
IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
1017 |
var _this = this; |
|
1018 |
IriSP._.defer(function() { |
|
1019 |
_callback.call(_this); |
|
1020 |
}); |
|
1021 |
} |
|
1022 |
||
1023 |
IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
1024 |
this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
1025 |
while (this.callbackQueue.length) { |
|
1026 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
1027 |
} |
|
1028 |
} |
|
1029 |
IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
1030 |
if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
1031 |
this.deferCallback(_callback); |
|
1032 |
} else { |
|
1033 |
this.callbackQueue.push(_callback); |
|
1034 |
} |
|
1035 |
} |
|
1036 |
||
1037 |
IriSP.Model.Source.prototype.serialize = function() { |
|
1038 |
return this.serializer.serialize(this); |
|
1039 |
} |
|
1040 |
||
1041 |
IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
1042 |
this.serializer.deSerialize(_data, this); |
|
1043 |
} |
|
1044 |
||
1045 |
IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
1046 |
_global = (typeof _global !== "undefined" && _global); |
|
1047 |
return this.getList("annotation", _global); |
|
1048 |
} |
|
1049 |
||
1050 |
IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
1051 |
_global = (typeof _global !== "undefined" && _global); |
|
1052 |
return this.getList("media", _global); |
|
1053 |
} |
|
1054 |
||
| 623 | 1055 |
IriSP.Model.Source.prototype.getTags = function(_global) { |
1056 |
_global = (typeof _global !== "undefined" && _global); |
|
1057 |
return this.getList("tag", _global); |
|
1058 |
} |
|
1059 |
||
1060 |
IriSP.Model.Source.prototype.getMashups = function(_global) { |
|
1061 |
_global = (typeof _global !== "undefined" && _global); |
|
1062 |
return this.getList("mashup", _global); |
|
1063 |
} |
|
1064 |
||
| 598 | 1065 |
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
1066 |
_global = (typeof _global !== "undefined" && _global); |
|
1067 |
return this.getList("annotationType", _global); |
|
1068 |
} |
|
1069 |
||
1070 |
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
1071 |
_global = (typeof _global !== "undefined" && _global); |
|
1072 |
var _res = new IriSP.Model.List(this.directory), |
|
1073 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
1074 |
_annTypes.forEach(function(_annType) { |
|
1075 |
_res.addElements(_annType.getAnnotations(_global)); |
|
1076 |
}) |
|
1077 |
return _res; |
|
1078 |
} |
|
1079 |
||
1080 |
IriSP.Model.Source.prototype.getDuration = function() { |
|
1081 |
var _m = this.currentMedia; |
|
1082 |
if (typeof _m !== "undefined") { |
|
1083 |
return this.currentMedia.duration; |
|
1084 |
} |
|
1085 |
} |
|
1086 |
||
| 694 | 1087 |
IriSP.Model.Source.prototype.getCurrentMedia = function(_opts) { |
1088 |
if (typeof this.currentMedia === "undefined") { |
|
1089 |
if (_opts.is_mashup) { |
|
1090 |
var _mashups = this.getMashups(); |
|
1091 |
if (_mashups.length) { |
|
1092 |
this.currentMedia = _mashups[0]; |
|
1093 |
} |
|
1094 |
} else { |
|
1095 |
var _medias = this.getMedias(); |
|
1096 |
if (_medias.length) { |
|
1097 |
_media = _medias[0]; |
|
1098 |
} |
|
1099 |
} |
|
1100 |
} |
|
1101 |
return this.currentMedia; |
|
1102 |
} |
|
1103 |
||
| 638 | 1104 |
IriSP.Model.Source.prototype.merge = function(_source) { |
1105 |
var _this = this; |
|
1106 |
_source.forEach(function(_value, _key) { |
|
1107 |
_this.getList(_key).addElements(_value); |
|
1108 |
}); |
|
1109 |
} |
|
1110 |
||
| 598 | 1111 |
/* */ |
1112 |
||
1113 |
IriSP.Model.RemoteSource = function(_config) { |
|
1114 |
IriSP.Model.Source.call(this, _config); |
|
1115 |
} |
|
1116 |
||
1117 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
1118 |
||
1119 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
1120 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
1121 |
var _this = this; |
|
1122 |
this.serializer.loadData(this.url, function(_result) { |
|
1123 |
_this.deSerialize(_result); |
|
1124 |
_this.handleCallbacks(); |
|
1125 |
}); |
|
1126 |
} |
|
1127 |
||
1128 |
/* */ |
|
1129 |
||
1130 |
IriSP.Model.Directory = function() { |
|
1131 |
this.remoteSources = {}; |
|
1132 |
this.elements = {}; |
|
1133 |
} |
|
1134 |
||
1135 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
| 638 | 1136 |
if (typeof _properties !== "object" || typeof _properties.url === "undefined") { |
1137 |
throw "Error : IriSP.Model.Directory.remoteSource(configuration): configuration.url is undefined"; |
|
1138 |
} |
|
| 598 | 1139 |
var _config = IriSP._({ directory: this }).extend(_properties); |
1140 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
|
1141 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
|
1142 |
} |
|
1143 |
return this.remoteSources[_properties.url]; |
|
1144 |
} |
|
1145 |
||
1146 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
|
1147 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
1148 |
_res = new IriSP.Model.Source(_config); |
|
1149 |
return _res; |
|
1150 |
} |
|
1151 |
||
1152 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
|
| 623 | 1153 |
return this.elements[_id]; |
| 598 | 1154 |
} |
1155 |
||
1156 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
|
1157 |
this.elements[_element.id] = _element; |
|
1158 |
} |
|
1159 |
||
1160 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
1161 |
var _res = new IriSP.Model.List(this); |
|
1162 |
_res.addIds(IriSP._(this.elements).keys()); |
|
1163 |
return _res; |
|
1164 |
} |
|
1165 |
||
1166 |
/* */ |
|
1167 |
IriSP.language = 'en'; |
|
1168 |
||
1169 |
IriSP.libFiles = { |
|
1170 |
defaultDir : "js/libs/", |
|
1171 |
inDefaultDir : { |
|
1172 |
underscore : "underscore-min.js", |
|
1173 |
Mustache : "mustache.js", |
|
1174 |
jQuery : "jquery.min.js", |
|
1175 |
jQueryUI : "jquery-ui.min.js", |
|
1176 |
swfObject : "swfobject.js", |
|
1177 |
cssjQueryUI : "jquery-ui.css", |
|
| 623 | 1178 |
popcorn : "popcorn-complete.min.js", |
| 598 | 1179 |
jwplayer : "jwplayer.js", |
1180 |
raphael : "raphael-min.js", |
|
| 638 | 1181 |
tracemanager : "tracemanager.js", |
1182 |
jwPlayerSWF : "player.swf", |
|
| 694 | 1183 |
json : "json2.js", |
1184 |
zeroClipboardJs: "ZeroClipboard.js", |
|
1185 |
zeroClipboardSwf: "ZeroClipboard.swf", |
|
1186 |
backbone: "backbone.js", |
|
1187 |
backboneRelational: "backbone-relational.js", |
|
1188 |
paper: "paper.js", |
|
1189 |
jqueryMousewheel: "jquery.mousewheel.min.js", |
|
1190 |
renkanPublish: "renkan-publish.js", |
|
1191 |
processing: "processing-1.3.6.min.js", |
|
1192 |
recordMicSwf: "record_mic.swf" |
|
| 598 | 1193 |
}, |
1194 |
locations : { |
|
| 694 | 1195 |
// use to define locations outside default_dir |
| 598 | 1196 |
}, |
1197 |
cdn : { |
|
| 694 | 1198 |
jQuery : "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js", |
1199 |
jQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.min.js", |
|
| 598 | 1200 |
swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", |
| 694 | 1201 |
cssjQueryUI : "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/themes/ui-lightness/jquery-ui.css", |
1202 |
underscore : "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js", |
|
1203 |
Mustache : "http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.5.0-dev/mustache.min.js", |
|
1204 |
raphael : "http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js", |
|
1205 |
json : "http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js" |
|
| 598 | 1206 |
}, |
1207 |
useCdn : false |
|
1208 |
} |
|
1209 |
||
1210 |
IriSP.widgetsDir = 'widgets'; |
|
1211 |
||
1212 |
IriSP.widgetsRequirements = { |
|
| 694 | 1213 |
PopcornPlayer: { |
1214 |
noCss: true, |
|
1215 |
requires: [ "popcorn" ] |
|
1216 |
}, |
|
1217 |
JwpPlayer: { |
|
1218 |
noCss: true, |
|
1219 |
requires: [ "jwplayer" ] |
|
1220 |
}, |
|
1221 |
DailymotionPlayer: { |
|
1222 |
noCss: true, |
|
1223 |
requires: [ "swfObject" ] |
|
1224 |
}, |
|
1225 |
AutoPlayer: { |
|
1226 |
noCss: true |
|
1227 |
}, |
|
1228 |
MashupPlayer: { |
|
1229 |
noCss: true |
|
1230 |
}, |
|
1231 |
AnnotationsList: { |
|
1232 |
requires: [ "jwplayer" ] |
|
1233 |
}, |
|
| 598 | 1234 |
Sparkline: { |
1235 |
noCss: true, |
|
| 694 | 1236 |
requires: [ "raphael" ] |
| 598 | 1237 |
}, |
1238 |
Arrow: { |
|
1239 |
noCss: true, |
|
| 694 | 1240 |
requires: [ "raphael" ] |
| 598 | 1241 |
}, |
1242 |
Mediafragment: { |
|
1243 |
noCss: true |
|
1244 |
}, |
|
1245 |
Trace : { |
|
1246 |
noCss: true, |
|
| 694 | 1247 |
requires: [ "tracemanager" ] |
1248 |
}, |
|
1249 |
Slideshare: { |
|
1250 |
requires: [ "swfObject" ] |
|
1251 |
}, |
|
1252 |
Social: { |
|
1253 |
requires: [ "zeroClipboardJs" ] |
|
1254 |
}, |
|
1255 |
Renkan: { |
|
1256 |
requires: [ "backbone", "backboneRelational", "paper", "jqueryMousewheel", "renkanPublish" ] |
|
1257 |
}, |
|
1258 |
KnowledgeConcierge: { |
|
1259 |
requires: [ "processing" ] |
|
| 598 | 1260 |
} |
1261 |
} |
|
1262 |
||
1263 |
IriSP.guiDefaults = { |
|
1264 |
width : 640, |
|
1265 |
container : 'LdtPlayer', |
|
1266 |
spacer_div_height : 0 |
|
1267 |
} |
|
1268 |
/* Definition of an ancestor for the Widget classes */ |
|
1269 |
||
1270 |
if (typeof IriSP.Widgets === "undefined") { |
|
1271 |
IriSP.Widgets = {} |
|
1272 |
} |
|
1273 |
||
1274 |
/** |
|
1275 |
* @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
|
1276 |
* |
|
1277 |
* Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
1278 |
* defined in init.js |
|
1279 |
* |
|
1280 |
* @constructor |
|
1281 |
* @param player - a reference to the player widget |
|
1282 |
* @param config - configuration options for the widget |
|
1283 |
*/ |
|
1284 |
||
1285 |
||
1286 |
IriSP.Widgets.Widget = function(player, config) { |
|
1287 |
||
1288 |
if( typeof player === "undefined") { |
|
1289 |
/* Probably an abstract call of the class when |
|
1290 |
* individual widgets set their prototype */ |
|
1291 |
return; |
|
1292 |
} |
|
1293 |
|
|
1294 |
/* Setting all the configuration options */ |
|
1295 |
var _type = config.type, |
|
| 694 | 1296 |
_config = IriSP._.defaults({}, config, player.config.default_options, this.defaults), |
| 598 | 1297 |
_this = this; |
1298 |
|
|
1299 |
IriSP._(_config).forEach(function(_value, _key) { |
|
1300 |
_this[_key] = _value; |
|
1301 |
}); |
|
1302 |
|
|
1303 |
if (typeof this.width === "undefined") { |
|
| 694 | 1304 |
this.width = player.config.width; |
| 598 | 1305 |
} |
1306 |
|
|
1307 |
/* Setting this.player at the end in case it's been overriden |
|
1308 |
* by a configuration option of the same name :-( |
|
1309 |
*/ |
|
1310 |
this.player = player; |
|
1311 |
|
|
1312 |
/* Getting metadata */ |
|
1313 |
this.source = player.loadMetadata(this.metadata); |
|
1314 |
|
|
1315 |
/* Call draw when loaded */ |
|
1316 |
this.source.onLoad(function() { |
|
| 694 | 1317 |
if (_this.media_id) { |
1318 |
_this.media = this.getElement(_this.media_id); |
|
1319 |
} else { |
|
1320 |
var _mediaopts = { |
|
1321 |
is_mashup: _this.is_mashup || false |
|
1322 |
} |
|
1323 |
_this.media = this.getCurrentMedia(_mediaopts); |
|
1324 |
} |
|
1325 |
|
|
| 598 | 1326 |
_this.draw(); |
1327 |
}); |
|
1328 |
|
|
1329 |
/* Adding classes and html attributes */ |
|
1330 |
this.$ = IriSP.jQuery('#' + this.container); |
|
1331 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
|
1332 |
|
|
| 638 | 1333 |
this.l10n = ( |
1334 |
typeof this.messages[IriSP.language] !== "undefined" |
|
1335 |
? this.messages[IriSP.language] |
|
1336 |
: ( |
|
1337 |
IriSP.language.length > 2 && typeof this.messages[IriSP.language.substr(0,2)] !== "undefined" |
|
1338 |
? this.messages[IriSP.language.substr(0,2)] |
|
1339 |
: this.messages["en"] |
|
1340 |
) |
|
1341 |
); |
|
| 598 | 1342 |
|
1343 |
}; |
|
1344 |
||
1345 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
1346 |
||
1347 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
1348 |
||
1349 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
1350 |
||
1351 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
1352 |
return Mustache.to_html(_template, this); |
|
1353 |
} |
|
1354 |
||
1355 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
1356 |
this.$.append(this.templateToHtml(this.template)); |
|
1357 |
} |
|
1358 |
||
1359 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
1360 |
var _this = this, |
|
1361 |
_function = this[_name]; |
|
1362 |
if (typeof _function !== "undefined") { |
|
1363 |
return function() { |
|
1364 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
1365 |
} |
|
1366 |
} else { |
|
| 694 | 1367 |
console.log("Error, Unknown function IriSP.Widgets." + this.type + "." + _name) |
1368 |
} |
|
1369 |
} |
|
1370 |
||
1371 |
IriSP.Widgets.Widget.prototype.getFunctionOrName = function(_functionOrName) { |
|
1372 |
switch (typeof _functionOrName) { |
|
1373 |
case "function": |
|
1374 |
return _functionOrName; |
|
1375 |
case "string": |
|
1376 |
return this.functionWrapper(_functionOrName); |
|
1377 |
default: |
|
1378 |
return undefined; |
|
| 598 | 1379 |
} |
1380 |
} |
|
1381 |
||
| 694 | 1382 |
IriSP.Widgets.Widget.prototype.onMdpEvent = function(_eventName, _functionOrName) { |
1383 |
this.player.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
1384 |
} |
|
1385 |
||
1386 |
IriSP.Widgets.Widget.prototype.onMediaEvent = function(_eventName, _functionOrName) { |
|
1387 |
this.media.on(_eventName, this.getFunctionOrName(_functionOrName)); |
|
| 598 | 1388 |
} |
1389 |
||
1390 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
|
| 694 | 1391 |
return typeof this.annotation_type !== "undefined" && this.annotation_type ? this.media.getAnnotationsByTypeTitle(this.annotation_type) : this.media.getAnnotations(); |
| 598 | 1392 |
} |
1393 |
||
|
652
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1394 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotationsAtTime = function() { |
| 694 | 1395 |
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
|
1396 |
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
|
1397 |
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
|
1398 |
}); |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1399 |
} |
|
b3ccfdbd581b
Added a default subject in the Trace Widget
Raphael Velt <raph.velt@gmail.com>
parents:
648
diff
changeset
|
1400 |
|
| 694 | 1401 |
IriSP.Widgets.Widget.prototype.insertSubwidget = function(_selector, _widgetoptions, _propname) { |
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1402 |
var _id = _selector.attr("id"), |
| 694 | 1403 |
_this = this, |
1404 |
_type = _widgetoptions.type, |
|
1405 |
$L = $LAB; |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1406 |
if (typeof _id == "undefined") { |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1407 |
_id = IriSP._.uniqueId(this.container + '_sub_widget_' + _widgetoptions.type); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1408 |
_selector.attr("id", _id); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1409 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1410 |
_widgetoptions.container = _id; |
| 694 | 1411 |
if (typeof IriSP.widgetsRequirements[_type] !== "undefined" && typeof IriSP.widgetsRequirements[_type].requires !== "undefined" ) { |
1412 |
for (var _j = 0; _j < IriSP.widgetsRequirements[_type].requires.length; _j++) { |
|
1413 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_type].requires[_j])); |
|
1414 |
} |
|
1415 |
} |
|
1416 |
$L.wait(function() { |
|
1417 |
_this.player.loadWidget(_widgetoptions, function(_widget) { |
|
1418 |
if (_propname) { |
|
1419 |
_this[_propname] = _widget; |
|
1420 |
} |
|
1421 |
}); |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1422 |
}); |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1423 |
} |
|
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1424 |
|
| 598 | 1425 |
/** |
1426 |
* This method responsible of drawing a widget on screen. |
|
1427 |
*/ |
|
1428 |
IriSP.Widgets.Widget.prototype.draw = function() { |
|
1429 |
/* implemented by "sub-classes" */ |
|
| 638 | 1430 |
};/* LDT Platform Serializer */ |
| 598 | 1431 |
|
1432 |
if (typeof IriSP.serializers === "undefined") { |
|
1433 |
IriSP.serializers = {} |
|
1434 |
} |
|
1435 |
||
1436 |
IriSP.serializers.ldt = { |
|
1437 |
types : { |
|
1438 |
media : { |
|
1439 |
serialized_name : "medias", |
|
1440 |
deserializer : function(_data, _source) { |
|
1441 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
1442 |
_res.video = ( |
|
1443 |
typeof _data.url !== "undefined" |
|
1444 |
? _data.url |
|
1445 |
: ( |
|
1446 |
typeof _data.href !== "undefined" |
|
1447 |
? _data.href |
|
1448 |
: null |
|
1449 |
) |
|
1450 |
); |
|
1451 |
if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
1452 |
_res.streamer = _data.meta.item.value; |
|
1453 |
} |
|
1454 |
_res.title = _data.meta["dc:title"]; |
|
1455 |
_res.description = _data.meta["dc:description"]; |
|
1456 |
_res.setDuration(_data.meta["dc:duration"]); |
|
| 638 | 1457 |
_res.url = _data.meta.url; |
1458 |
if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") { |
|
1459 |
_res.thumbnail = _data.meta.img.src; |
|
1460 |
} |
|
| 598 | 1461 |
return _res; |
1462 |
}, |
|
1463 |
serializer : function(_data, _source) { |
|
1464 |
return { |
|
| 638 | 1465 |
id : _data.id, |
| 598 | 1466 |
url : _data.video, |
1467 |
meta : { |
|
1468 |
"dc:title" : _data.title, |
|
1469 |
"dc:description" : _data.description, |
|
1470 |
"dc:duration" : _data.duration.milliseconds |
|
1471 |
} |
|
1472 |
} |
|
1473 |
} |
|
1474 |
}, |
|
1475 |
tag : { |
|
1476 |
serialized_name : "tags", |
|
1477 |
model_name : "tag", |
|
1478 |
deserializer : function(_data, _source) { |
|
1479 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
1480 |
_res.title = _data.meta["dc:title"]; |
|
1481 |
return _res; |
|
1482 |
}, |
|
1483 |
serializer : function(_data, _source) { |
|
1484 |
return { |
|
| 638 | 1485 |
id : _data.id, |
| 598 | 1486 |
meta : { |
1487 |
"dc:title" : _data.title |
|
1488 |
} |
|
1489 |
} |
|
1490 |
} |
|
1491 |
}, |
|
1492 |
annotationType : { |
|
1493 |
serialized_name : "annotation-types", |
|
1494 |
deserializer : function(_data, _source) { |
|
1495 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
1496 |
_res.title = _data["dc:title"]; |
|
1497 |
_res.description = _data["dc:description"]; |
|
1498 |
return _res; |
|
1499 |
}, |
|
1500 |
serializer : function(_data, _source) { |
|
1501 |
return { |
|
| 638 | 1502 |
id : _data.id, |
| 598 | 1503 |
"dc:title" : _data.title, |
1504 |
"dc:description" : _data.description |
|
1505 |
} |
|
1506 |
} |
|
1507 |
}, |
|
1508 |
annotation : { |
|
1509 |
serialized_name : "annotations", |
|
1510 |
deserializer : function(_data, _source) { |
|
1511 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
1512 |
_res.title = _data.content.title || ""; |
|
1513 |
_res.description = _data.content.description || ""; |
|
1514 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
|
1515 |
_res.thumbnail = _data.content.img.src; |
|
1516 |
} |
|
1517 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
1518 |
if (typeof _data.color !== "undefined") { |
|
1519 |
var _c = parseInt(_data.color).toString(16); |
|
1520 |
while (_c.length < 6) { |
|
1521 |
_c = '0' + _c; |
|
1522 |
} |
|
1523 |
_res.color = '#' + _c; |
|
1524 |
} |
|
| 638 | 1525 |
_res.setMedia(_data.media); |
| 598 | 1526 |
_res.setAnnotationType(_data.meta["id-ref"]); |
1527 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
1528 |
_res.setBegin(_data.begin); |
|
1529 |
_res.setEnd(_data.end); |
|
1530 |
_res.creator = _data.meta["dc:creator"] || ""; |
|
1531 |
_res.project = _data.meta.project || ""; |
|
1532 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
|
1533 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
1534 |
} |
|
| 638 | 1535 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
1536 |
_res.audio = _data.content.audio; |
|
1537 |
} |
|
| 598 | 1538 |
return _res; |
1539 |
}, |
|
1540 |
serializer : function(_data, _source) { |
|
1541 |
return { |
|
| 638 | 1542 |
id : _data.id, |
| 623 | 1543 |
begin : _data.begin.milliseconds, |
1544 |
end : _data.end.milliseconds, |
|
| 598 | 1545 |
content : { |
1546 |
title : _data.title, |
|
| 638 | 1547 |
description : _data.description, |
1548 |
audio : _data.audio |
|
| 598 | 1549 |
}, |
| 638 | 1550 |
media : _data.media.id, |
| 598 | 1551 |
meta : { |
| 638 | 1552 |
"id-ref" : _data.annotationType.id, |
| 598 | 1553 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
1554 |
"dc:creator" : _data.creator, |
|
1555 |
project : _source.projectId |
|
1556 |
}, |
|
| 623 | 1557 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
| 598 | 1558 |
return { |
| 638 | 1559 |
"id-ref" : _id |
| 598 | 1560 |
} |
1561 |
}) |
|
1562 |
} |
|
1563 |
} |
|
| 623 | 1564 |
}, |
1565 |
mashup : { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1566 |
serialized_name : "lists", |
| 623 | 1567 |
deserializer : function(_data, _source) { |
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1568 |
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
|
1569 |
return undefined; |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1570 |
} |
| 623 | 1571 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
1572 |
_res.title = _data.meta["dc:title"]; |
|
1573 |
_res.description = _data.meta["dc:description"]; |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1574 |
for (var _i = 0; _i < _data.items.length; _i++) { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1575 |
_res.addSegmentById(_data.items[_i]); |
| 623 | 1576 |
} |
1577 |
return _res; |
|
1578 |
}, |
|
1579 |
serializer : function(_data, _source) { |
|
1580 |
return { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1581 |
meta : { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1582 |
"dc:title": _data.title, |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1583 |
"dc:description": _data.description, |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1584 |
listtype: "mashup" |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1585 |
}, |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1586 |
items: _data.segments.map(function(_annotation) { |
| 638 | 1587 |
return _id; |
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1588 |
}), |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1589 |
id: _data.id |
| 623 | 1590 |
} |
1591 |
} |
|
| 598 | 1592 |
} |
1593 |
}, |
|
1594 |
serialize : function(_source) { |
|
1595 |
var _res = {}, |
|
1596 |
_this = this; |
|
1597 |
_source.forEach(function(_list, _typename) { |
|
1598 |
if (typeof _this.types[_typename] !== "undefined") { |
|
1599 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
1600 |
return _this.types[_typename].serializer(_el, _source); |
|
1601 |
}); |
|
1602 |
} |
|
1603 |
}); |
|
| 623 | 1604 |
return JSON.stringify(_res); |
| 598 | 1605 |
}, |
1606 |
loadData : function(_url, _callback) { |
|
1607 |
IriSP.jQuery.getJSON(_url, _callback) |
|
1608 |
}, |
|
1609 |
deSerialize : function(_data, _source) { |
|
1610 |
if (typeof _data !== "object" || _data === null) { |
|
1611 |
return; |
|
1612 |
} |
|
1613 |
IriSP._(this.types).forEach(function(_type, _typename) { |
|
| 638 | 1614 |
var _listdata = _data[_type.serialized_name], |
1615 |
_list = new IriSP.Model.List(_source.directory); |
|
| 598 | 1616 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
1617 |
if (_listdata.hasOwnProperty("length")) { |
|
1618 |
var _l = _listdata.length; |
|
1619 |
for (var _i = 0; _i < _l; _i++) { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1620 |
var _element = _type.deserializer(_listdata[_i], _source); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1621 |
if (typeof _element !== "undefined" && _element) { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1622 |
_list.push(_element); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1623 |
} |
| 598 | 1624 |
} |
1625 |
} else { |
|
|
648
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1626 |
var _element = _type.deserializer(_listdata, _source); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1627 |
if (typeof _element !== "undefined" && _element) { |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1628 |
_list.push(_element); |
|
b28afee5470b
Changed Segment widget parameters
Raphael Velt <raph.velt@gmail.com>
parents:
638
diff
changeset
|
1629 |
} |
| 598 | 1630 |
} |
1631 |
} |
|
| 638 | 1632 |
_source.addList(_typename, _list); |
| 598 | 1633 |
}); |
1634 |
|
|
1635 |
if (typeof _data.meta !== "undefined") { |
|
1636 |
_source.projectId = _data.meta.id; |
|
1637 |
} |
|
1638 |
|
|
1639 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
| 694 | 1640 |
_source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
| 598 | 1641 |
} |
1642 |
} |
|
1643 |
} |
|
1644 |
||
| 638 | 1645 |
/* Used when Putting annotations on the platform */ |
1646 |
||
1647 |
if (typeof IriSP.serializers === "undefined") { |
|
1648 |
IriSP.serializers = {} |
|
1649 |
} |
|
1650 |
||
1651 |
IriSP.serializers.ldt_annotate = { |
|
1652 |
types : { |
|
1653 |
annotation : { |
|
1654 |
serialized_name : "annotations", |
|
1655 |
serializer : function(_data, _source) { |
|
1656 |
var _annType = _data.getAnnotationType(); |
|
1657 |
return { |
|
1658 |
begin: _data.begin.milliseconds, |
|
1659 |
end: _data.end.milliseconds, |
|
1660 |
content: { |
|
1661 |
data: _data.description, |
|
1662 |
audio: _data.audio |
|
1663 |
}, |
|
1664 |
tags: _data.getTagTexts(), |
|
1665 |
media: _data.getMedia().id, |
|
1666 |
type_title: _annType.title, |
|
1667 |
type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ) |
|
1668 |
} |
|
1669 |
} |
|
1670 |
} |
|
1671 |
}, |
|
1672 |
serialize : function(_source) { |
|
1673 |
var _res = {}, |
|
1674 |
_this = this; |
|
1675 |
_source.forEach(function(_list, _typename) { |
|
1676 |
if (typeof _this.types[_typename] !== "undefined") { |
|
1677 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
1678 |
return _this.types[_typename].serializer(_el, _source); |
|
1679 |
}); |
|
1680 |
} |
|
1681 |
}); |
|
1682 |
_res.meta = { |
|
1683 |
creator: _source.creator, |
|
1684 |
created: _source.created |
|
1685 |
} |
|
1686 |
return JSON.stringify(_res); |
|
1687 |
}, |
|
1688 |
deSerialize : function(_data, _source) { |
|
1689 |
if (typeof _data == "string") { |
|
1690 |
_data = JSON.parse(_data); |
|
1691 |
} |
|
1692 |
_source.addList('tag', new IriSP.Model.List(_source.directory)); |
|
1693 |
_source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
|
1694 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
|
1695 |
if (typeof _data.annotations == "object" && _data.annotations && _data.annotations.length) { |
|
1696 |
var _anndata = _data.annotations[0], |
|
1697 |
_ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
1698 |
_ann.description = _anndata.content.data || ""; |
|
|
654
a5977736d2b0
Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
652
diff
changeset
|
1699 |
_ann.title = _data.creator || ""; |
| 638 | 1700 |
_ann.created = new Date(_data.meta.created); |
1701 |
_ann.setMedia(_anndata.media, _source); |
|
1702 |
var _anntypes = _source.getAnnotationTypes(true).searchByTitle(_anndata.type_title); |
|
1703 |
if (_anntypes.length) { |
|
1704 |
var _anntype = _anntypes[0]; |
|
1705 |
} else { |
|
1706 |
var _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
1707 |
_anntype.title = _anndata.type_title; |
|
1708 |
_source.getAnnotationTypes().push(_anntype); |
|
1709 |
} |
|
1710 |
_ann.setAnnotationType(_anntype.id); |
|
1711 |
var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
1712 |
var _tags = _source.getTags(true).searchByTitle(_title); |
|
1713 |
if (_tags.length) { |
|
1714 |
var _tag = _tags[0]; |
|
1715 |
} |
|
1716 |
else { |
|
1717 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
1718 |
_tag.title = _title; |
|
1719 |
_source.getTags().push(_tag); |
|
1720 |
} |
|
1721 |
return _tag.id; |
|
1722 |
}); |
|
1723 |
_ann.setTags(_tagIds); |
|
1724 |
_ann.setBegin(_anndata.begin); |
|
1725 |
_ann.setEnd(_anndata.end); |
|
1726 |
_ann.creator = _data.meta.creator; |
|
1727 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
1728 |
_ann.audio = _anndata.content.audio; |
|
1729 |
} |
|
1730 |
_source.getAnnotations().push(_ann); |
|
1731 |
} |
|
1732 |
} |
|
1733 |
} |