|
2
|
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 |
*/ |
|
|
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 Popcorn and the widgets |
|
|
24 |
*/ |
|
|
25 |
|
|
|
26 |
if (typeof window.IriSP === "undefined") { |
|
|
27 |
IriSP = {}; |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ |
|
|
31 |
|
|
13
|
32 |
IriSP.Metadataplayer = function(config) { |
|
2
|
33 |
IriSP.log("IriSP.Metadataplayer constructor"); |
|
|
34 |
for (var key in IriSP.guiDefaults) { |
|
|
35 |
if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) { |
|
|
36 |
config.gui[key] = IriSP.guiDefaults[key] |
|
|
37 |
} |
|
|
38 |
} |
|
|
39 |
var _container = document.getElementById(config.gui.container); |
|
|
40 |
_container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>'; |
|
|
41 |
this.sourceManager = new IriSP.Model.Directory(); |
|
|
42 |
this.config = config; |
|
|
43 |
this.callbackQueue = []; |
|
|
44 |
this.isLoaded = false; |
|
|
45 |
this.loadLibs(); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
IriSP.Metadataplayer.prototype.toString = function() { |
|
|
49 |
return 'Metadataplayer in #' + this.config.gui.container; |
|
|
50 |
} |
|
|
51 |
|
|
|
52 |
IriSP.Metadataplayer.prototype.deferCallback = function(_callback) { |
|
|
53 |
var _this = this; |
|
|
54 |
IriSP._.defer(function() { |
|
|
55 |
_callback.call(_this); |
|
|
56 |
}); |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
IriSP.Metadataplayer.prototype.handleCallbacks = function() { |
|
|
60 |
this.isLoaded = true; |
|
|
61 |
while (this.callbackQueue.length) { |
|
|
62 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
|
63 |
} |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
IriSP.Metadataplayer.prototype.onLoad = function(_callback) { |
|
|
67 |
if (this.isLoaded) { |
|
|
68 |
this.deferCallback(_callback); |
|
|
69 |
} else { |
|
|
70 |
this.callbackQueue.push(_callback); |
|
|
71 |
} |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
IriSP.Metadataplayer.prototype.loadLibs = function() { |
|
|
75 |
IriSP.log("IriSP.Metadataplayer.prototype.loadLibs"); |
|
|
76 |
var $L = $LAB |
|
|
77 |
.script(IriSP.getLib("underscore")) |
|
|
78 |
.script(IriSP.getLib("Mustache")) |
|
|
79 |
.script(IriSP.getLib("jQuery")) |
|
|
80 |
.script(IriSP.getLib("swfObject")) |
|
|
81 |
.wait() |
|
|
82 |
.script(IriSP.getLib("jQueryUI")); |
|
|
83 |
|
|
|
84 |
if (this.config.player.type === "jwplayer" || this.config.player.type === "auto") { |
|
|
85 |
$L.script(IriSP.getLib("jwplayer")); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
if (this.config.player.type !== "jwplayer" && this.config.player.type !== "allocine" && this.config.player.type !== "dailymotion") { |
|
|
89 |
$L.script(IriSP.getLib("popcorn")); |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
/* widget specific requirements */ |
|
|
93 |
for(var _i = 0; _i < this.config.gui.widgets.length; _i++) { |
|
|
94 |
var _t = this.config.gui.widgets[_i].type; |
|
|
95 |
if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined") { |
|
|
96 |
$L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires)); |
|
|
97 |
} |
|
|
98 |
} |
|
|
99 |
|
|
|
100 |
var _this = this; |
|
|
101 |
IriSP.log($L); |
|
|
102 |
$L.wait(function() { |
|
|
103 |
_this.onLibsLoaded(); |
|
|
104 |
}); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
IriSP.Metadataplayer.prototype.onLibsLoaded = function() { |
|
|
108 |
IriSP.log("IriSP.Metadataplayer.prototype.onLibsLoaded"); |
|
|
109 |
if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined") { |
|
|
110 |
IriSP.jQuery = window.jQuery.noConflict(); |
|
|
111 |
} |
|
|
112 |
if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined") { |
|
|
113 |
IriSP._ = window._.noConflict(); |
|
|
114 |
} |
|
|
115 |
IriSP.loadCss(IriSP.getLib("cssjQueryUI")); |
|
|
116 |
IriSP.loadCss(this.config.gui.css); |
|
|
117 |
|
|
13
|
118 |
this.videoData = this.loadMetadata(this.config.player.metadata); |
|
2
|
119 |
this.$ = IriSP.jQuery('#' + this.config.gui.container); |
|
|
120 |
this.$.css({ |
|
|
121 |
"width": this.config.gui.width, |
|
|
122 |
"clear": "both" |
|
|
123 |
}); |
|
|
124 |
if (typeof this.config.gui.height !== "undefined") { |
|
|
125 |
this.$.css("height", this.config.gui.height); |
|
|
126 |
} |
|
|
127 |
|
|
|
128 |
var _this = this; |
|
|
129 |
this.videoData.onLoad(function() { |
|
|
130 |
_this.onVideoDataLoaded(); |
|
|
131 |
}); |
|
|
132 |
} |
|
|
133 |
|
|
|
134 |
IriSP.Metadataplayer.prototype.loadMetadata = function(_metadataInfo) { |
|
|
135 |
if (typeof _metadataInfo.serializer === "undefined" && typeof _metadataInfo.format !== "undefined") { |
|
|
136 |
_metadataInfo.serializer = IriSP.serializers[_metadataInfo.format]; |
|
|
137 |
} |
|
|
138 |
if (typeof _metadataInfo.url === "undefined" && typeof _metadataInfo.src !== "undefined") { |
|
|
139 |
_metadataInfo.url = _metadataInfo.src; |
|
|
140 |
} |
|
|
141 |
if (typeof _metadataInfo.url !== "undefined" && typeof _metadataInfo.serializer !== "undefined") { |
|
|
142 |
return this.sourceManager.remoteSource(_metadataInfo); |
|
|
143 |
} else { |
|
|
144 |
return this.sourceManager.newLocalSource(_metadataInfo); |
|
|
145 |
} |
|
|
146 |
} |
|
|
147 |
|
|
|
148 |
IriSP.Metadataplayer.prototype.onVideoDataLoaded = function() { |
|
|
149 |
if (typeof this.videoData !== "undefined" && typeof this.config.player.video === "undefined") { |
|
|
150 |
var _media = this.videoData.currentMedia; |
|
|
151 |
if (typeof _media !== "undefined") { |
|
|
152 |
this.config.player.video = _media.video; |
|
|
153 |
if (typeof _media.streamer !== "undefined") { |
|
|
154 |
this.config.player.streamer = _media.streamer; |
|
|
155 |
this.config.player.video = _media.video.replace(_media.streamer,''); |
|
|
156 |
} |
|
|
157 |
} |
|
|
158 |
|
|
|
159 |
} |
|
|
160 |
this.configurePopcorn(); |
|
|
161 |
this.widgets = []; |
|
|
162 |
var _this = this; |
|
|
163 |
for(var i = 0; i < this.config.gui.widgets.length; i++) { |
|
|
164 |
this.loadWidget(this.config.gui.widgets[i], function(_widget) { |
|
|
165 |
_this.widgets.push(_widget) |
|
|
166 |
}); |
|
|
167 |
}; |
|
|
168 |
this.$.find('.Ldt-Loader').detach(); |
|
|
169 |
this.handleCallbacks(); |
|
|
170 |
} |
|
|
171 |
|
|
|
172 |
IriSP.Metadataplayer.prototype.loadWidget = function(_widgetConfig, _callback) { |
|
|
173 |
/* Creating containers if needed */ |
|
|
174 |
if (typeof _widgetConfig.container === "undefined") { |
|
|
175 |
var _divs = this.layoutDivs(_widgetConfig.type); |
|
|
176 |
_widgetConfig.container = _divs[0]; |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
var _this = this; |
|
|
180 |
|
|
|
181 |
if (typeof IriSP.Widgets[_widgetConfig.type] !== "undefined") { |
|
|
182 |
IriSP._.defer(function() { |
|
|
183 |
_callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
|
184 |
}); |
|
|
185 |
} else { |
|
|
186 |
/* Loading Widget CSS */ |
|
|
187 |
if (typeof IriSP.widgetsRequirements[_widgetConfig.type] === "undefined" || typeof IriSP.widgetsRequirements[_widgetConfig.type].noCss === "undefined" || !IriSP.widgetsRequirements[_widgetConfig.type].noCss) { |
|
|
188 |
IriSP.loadCss(IriSP.widgetsDir + '/' + _widgetConfig.type + '.css'); |
|
|
189 |
} |
|
|
190 |
/* Loading Widget JS */ |
|
|
191 |
$LAB.script(IriSP.widgetsDir + '/' + _widgetConfig.type + '.js').wait(function() { |
|
|
192 |
_callback(new IriSP.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
|
193 |
}); |
|
|
194 |
} |
|
|
195 |
} |
|
|
196 |
|
|
|
197 |
IriSP.Metadataplayer.prototype.configurePopcorn = function() { |
|
|
198 |
IriSP.log("IriSP.Metadataplayer.prototype.configurePopcorn"); |
|
|
199 |
var pop, |
|
|
200 |
ret = this.layoutDivs("video"), |
|
|
201 |
containerDiv = ret[0], |
|
|
202 |
spacerDiv = ret[1], |
|
|
203 |
_this = this, |
|
|
204 |
_types = { |
|
|
205 |
"html5" : /\.(ogg|ogv|webm)$/, |
|
|
206 |
"youtube" : /^(https?:\/\/)?(www\.)?youtube\.com/, |
|
|
207 |
"dailymotion" : /^(https?:\/\/)?(www\.)?dailymotion\.com/ |
|
|
208 |
}; |
|
|
209 |
|
|
|
210 |
if (this.config.player.type === "auto") { |
|
|
211 |
this.config.player.type = "jwplayer"; |
|
|
212 |
IriSP._(_types).each(function(_v, _k) { |
|
|
213 |
if (_v.test(_this.config.player.video)) { |
|
|
214 |
_this.config.player.type = _k |
|
|
215 |
} |
|
|
216 |
}); |
|
|
217 |
} |
|
|
218 |
|
|
|
219 |
switch(this.config.player.type) { |
|
|
220 |
/* |
|
|
221 |
todo : dynamically create the div/video tag which |
|
|
222 |
will contain the video. |
|
|
223 |
*/ |
|
|
224 |
case "html5": |
|
|
225 |
var _tmpId = Popcorn.guid("video"), |
|
|
226 |
_videoEl = IriSP.jQuery('<video>'); |
|
|
227 |
|
|
|
228 |
_videoEl.attr({ |
|
|
229 |
"src" : this.config.player.video, |
|
|
230 |
"id" : _tmpId |
|
|
231 |
}) |
|
|
232 |
|
|
|
233 |
if(this.config.player.hasOwnProperty("width")) { |
|
|
234 |
_videoEl.attr("width", this.config.player.width); |
|
|
235 |
} |
|
|
236 |
if(this.config.player.hasOwnProperty("height")) { |
|
|
237 |
_videoEl.attr("height", this.config.player.height); |
|
|
238 |
} |
|
|
239 |
IriSP.jQuery("#" + containerDiv).append(_videoEl); |
|
|
240 |
pop = Popcorn("#" + _tmpId); |
|
|
241 |
break; |
|
13
|
242 |
|
|
2
|
243 |
case "html5-audio": |
|
|
244 |
var _tmpId = Popcorn.guid("audio"), |
|
|
245 |
_videoEl = IriSP.jQuery('<audio>'); |
|
|
246 |
|
|
|
247 |
_videoEl.attr({ |
|
|
248 |
"src" : this.config.player.video, |
|
|
249 |
"id" : _tmpId |
|
|
250 |
}) |
|
|
251 |
|
|
|
252 |
if(this.config.player.hasOwnProperty("width")) { |
|
|
253 |
_videoEl.attr("width", this.config.player.width); |
|
|
254 |
} |
|
|
255 |
if(this.config.player.hasOwnProperty("height")) { |
|
|
256 |
_videoEl.attr("height", this.config.player.height); |
|
|
257 |
} |
|
|
258 |
IriSP.jQuery("#" + containerDiv).append(_videoEl); |
|
|
259 |
pop = Popcorn("#" + _tmpId); |
|
|
260 |
break; |
|
|
261 |
|
|
|
262 |
case "jwplayer": |
|
|
263 |
var opts = IriSP.jQuery.extend({}, this.config.player); |
|
|
264 |
delete opts.container; |
|
|
265 |
delete opts.type; |
|
|
266 |
opts.file = opts.video; |
|
|
267 |
delete opts.video; |
|
|
268 |
|
|
|
269 |
if(!opts.hasOwnProperty("flashplayer")) { |
|
13
|
270 |
opts.flashplayer = IriSP.getLib("jwPlayerSWF"); |
|
2
|
271 |
} |
|
|
272 |
|
|
|
273 |
if(!opts.hasOwnProperty("controlbar.position")) { |
|
|
274 |
opts["controlbar.position"] = "none"; |
|
|
275 |
} |
|
|
276 |
pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts); |
|
|
277 |
break; |
|
|
278 |
|
|
|
279 |
case "youtube": |
|
|
280 |
// Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div. |
|
|
281 |
IriSP.jQuery("#" + containerDiv).css({ |
|
|
282 |
width : this.config.player.width + "px", |
|
|
283 |
height : this.config.player.height + "px" |
|
|
284 |
}); |
|
|
285 |
var _urlparts = this.config.player.video.split(/[?&]/), |
|
|
286 |
_params = {}; |
|
|
287 |
for (var _j = 1; _j < _urlparts.length; _j++) { |
|
|
288 |
var _ppart = _urlparts[_j].split('='); |
|
|
289 |
_params[_ppart[0]] = decodeURIComponent(_ppart[1]); |
|
|
290 |
} |
|
|
291 |
_params.controls = 0; |
|
|
292 |
_params.modestbranding = 1; |
|
|
293 |
_url = _urlparts[0] + '?' + IriSP.jQuery.param(_params); |
|
|
294 |
pop = Popcorn.youtube("#" + containerDiv, _url); |
|
|
295 |
break; |
|
|
296 |
|
|
|
297 |
case "dailymotion": |
|
|
298 |
pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, this.config.player); |
|
|
299 |
break; |
|
|
300 |
|
|
|
301 |
case "mashup": |
|
|
302 |
pop = new IriSP.PopcornReplacement.mashup("#" + containerDiv, this.config.player); |
|
|
303 |
break; |
|
|
304 |
|
|
|
305 |
case "allocine": |
|
|
306 |
/* pass the options as-is to the allocine player and let it handle everything */ |
|
|
307 |
pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, this.config.player); |
|
|
308 |
break; |
|
|
309 |
|
|
|
310 |
default: |
|
|
311 |
pop = undefined; |
|
|
312 |
}; |
|
|
313 |
|
|
|
314 |
this.popcorn = pop; |
|
|
315 |
} |
|
|
316 |
|
|
|
317 |
/** create a subdiv with an unique id, and a spacer div as well. |
|
|
318 |
@param widgetName the name of the widget. |
|
|
319 |
@return an array of the form [createdivId, spacerdivId]. |
|
|
320 |
*/ |
|
|
321 |
IriSP.Metadataplayer.prototype.layoutDivs = function(_name) { |
|
|
322 |
if (typeof(_name) === "undefined") { |
|
|
323 |
_name = ""; |
|
|
324 |
} |
|
|
325 |
var newDiv = IriSP._.uniqueId(this.config.gui.container + "_widget_" + _name + "_"), |
|
|
326 |
spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"), |
|
|
327 |
divHtml = IriSP.jQuery('<div>') |
|
|
328 |
.attr("id",newDiv) |
|
|
329 |
.css({ |
|
|
330 |
width: this.config.gui.width + "px", |
|
|
331 |
position: "relative", |
|
|
332 |
clear: "both" |
|
|
333 |
}), |
|
|
334 |
spacerHtml = IriSP.jQuery('<div>') |
|
|
335 |
.attr("id",spacerDiv) |
|
|
336 |
.css({ |
|
|
337 |
width: this.config.gui.width + "px", |
|
|
338 |
height: this.config.gui.spacer_div_height + "px", |
|
|
339 |
position: "relative", |
|
|
340 |
clear: "both" |
|
|
341 |
}); |
|
|
342 |
|
|
|
343 |
this.$.append(divHtml); |
|
|
344 |
this.$.append(spacerHtml); |
|
|
345 |
|
|
|
346 |
return [newDiv, spacerDiv]; |
|
|
347 |
}; |
|
|
348 |
/* utils.js - various utils that don't belong anywhere else */ |
|
|
349 |
|
|
|
350 |
IriSP.jqEscape = function(_text) { |
|
|
351 |
return _text.replace(/(:|\.)/g,'\\$1'); |
|
|
352 |
} |
|
|
353 |
|
|
|
354 |
IriSP.getLib = function(lib) { |
|
|
355 |
if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { |
|
|
356 |
return IriSP.libFiles.cdn[lib]; |
|
|
357 |
} |
|
|
358 |
if (typeof IriSP.libFiles.locations[lib] == "string") { |
|
|
359 |
return IriSP.libFiles.locations[lib]; |
|
|
360 |
} |
|
|
361 |
if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { |
|
|
362 |
return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib]; |
|
|
363 |
} |
|
|
364 |
} |
|
|
365 |
|
|
|
366 |
IriSP._cssCache = []; |
|
|
367 |
|
|
|
368 |
IriSP.loadCss = function(_cssFile) { |
|
|
369 |
if (IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) { |
|
|
370 |
IriSP.jQuery("<link>", { |
|
|
371 |
rel : "stylesheet", |
|
|
372 |
type : "text/css", |
|
|
373 |
href : _cssFile |
|
|
374 |
}).appendTo('head'); |
|
|
375 |
IriSP._cssCache.push(_cssFile); |
|
|
376 |
} |
|
|
377 |
} |
|
|
378 |
|
|
|
379 |
IriSP.log = function() { |
|
|
380 |
if (typeof console !== "undefined" && typeof IriSP.logging !== "undefined" && IriSP.logging) { |
|
|
381 |
console.log.apply(console, arguments); |
|
|
382 |
} |
|
|
383 |
} |
|
|
384 |
/* wrapper that simulates popcorn.js because |
|
|
385 |
popcorn is a bit unstable at the time */ |
|
|
386 |
|
|
|
387 |
IriSP.PopcornReplacement = { |
|
|
388 |
}; |
|
|
389 |
|
|
|
390 |
/** base class for our popcorn-compatible players. |
|
|
391 |
*/ |
|
|
392 |
IriSP.PopcornReplacement.player = function(container, options) { |
|
|
393 |
/* the jwplayer calls the callbacks in the global space so we need to |
|
|
394 |
preserve them this way */ |
|
|
395 |
if (typeof IriSP._ === "undefined") { |
|
|
396 |
return; |
|
|
397 |
} |
|
|
398 |
|
|
|
399 |
this.callbacks = { |
|
|
400 |
onReady: IriSP._.bind(this.__initApi, this), |
|
|
401 |
onTime: IriSP._.bind(this.__timeHandler, this), |
|
|
402 |
onPlay: IriSP._.bind(this.__playHandler, this), |
|
|
403 |
onPause: IriSP._.bind(this.__pauseHandler, this), |
|
|
404 |
onSeek: IriSP._.bind(this.__seekHandler, this) |
|
|
405 |
}; |
|
|
406 |
|
|
|
407 |
this.media = { |
|
|
408 |
"paused": true, |
|
|
409 |
"muted": false |
|
|
410 |
}; |
|
|
411 |
|
|
|
412 |
this.container = container.replace(/^#/,''); //eschew the '#' |
|
|
413 |
|
|
|
414 |
this.msgPump = {}; /* dictionnary used to receive and send messages */ |
|
|
415 |
this.__codes = []; /* used to schedule the execution of a piece of code in |
|
|
416 |
a segment (similar to the popcorn.code plugin). */ |
|
|
417 |
|
|
|
418 |
this._options = options; |
|
|
419 |
|
|
|
420 |
}; |
|
|
421 |
|
|
|
422 |
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
|
|
423 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
|
424 |
this.msgPump[msg] = []; |
|
|
425 |
|
|
|
426 |
this.msgPump[msg].push(callback); |
|
|
427 |
}; |
|
|
428 |
|
|
|
429 |
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
|
|
430 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
|
431 |
return; |
|
|
432 |
|
|
|
433 |
var d = this.msgPump[msg]; |
|
|
434 |
|
|
|
435 |
for(var i = 0; i < d.length; i++) { |
|
|
436 |
d[i].call(window, params); |
|
|
437 |
} |
|
|
438 |
|
|
|
439 |
}; |
|
|
440 |
|
|
|
441 |
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
|
|
442 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
|
|
443 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
|
444 |
return v.toString(16); |
|
|
445 |
}); |
|
|
446 |
|
|
|
447 |
return prefix + str; |
|
|
448 |
}; |
|
|
449 |
|
|
|
450 |
/** init the api after that flash player has been setup - called by the callback |
|
|
451 |
defined by the embedded flash player |
|
|
452 |
*/ |
|
|
453 |
IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
|
|
454 |
this.trigger("loadedmetadata"); // we've done more than loading metadata of course, |
|
|
455 |
// but popcorn doesn't need to know more. |
|
|
456 |
this.media.muted = this.playerFns.getMute(); |
|
|
457 |
/* some programmed segments are supposed to be run at the beginning */ |
|
|
458 |
var i = 0; |
|
|
459 |
for(i = 0; i < this.__codes.length; i++) { |
|
|
460 |
var c = this.__codes[i]; |
|
|
461 |
if (0 == c.start) { |
|
|
462 |
c.onStart(); |
|
|
463 |
} |
|
|
464 |
|
|
|
465 |
if (0 == c.end) { |
|
|
466 |
c.onEnd(); |
|
|
467 |
} |
|
|
468 |
} |
|
|
469 |
}; |
|
|
470 |
|
|
|
471 |
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) { |
|
|
472 |
if (typeof(time) === "undefined") { |
|
|
473 |
return this.playerFns.getPosition(); |
|
|
474 |
} else { |
|
|
475 |
var currentTime = +time; |
|
|
476 |
this.playerFns.seek(currentTime); |
|
|
477 |
return currentTime; |
|
|
478 |
} |
|
|
479 |
}; |
|
|
480 |
|
|
|
481 |
IriSP.PopcornReplacement.player.prototype.play = function() { |
|
|
482 |
this.media.paused = false; |
|
|
483 |
this.trigger("play"); |
|
|
484 |
//IriSP.PopcornReplacement.trigger("playing"); |
|
|
485 |
this.playerFns.play(); |
|
|
486 |
}; |
|
|
487 |
|
|
|
488 |
IriSP.PopcornReplacement.player.prototype.pause = function() { |
|
|
489 |
// if ( !this.media.paused ) { |
|
|
490 |
this.media.paused = true; |
|
|
491 |
this.trigger( "pause" ); |
|
|
492 |
this.playerFns.pause(); |
|
|
493 |
// } |
|
|
494 |
}; |
|
|
495 |
|
|
|
496 |
IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
|
|
497 |
if (typeof(val) !== "undefined") { |
|
|
498 |
|
|
|
499 |
if (this.playerFns.getMute() !== val) { |
|
|
500 |
if (val) { |
|
|
501 |
this.playerFns.setMute(true); |
|
|
502 |
this.media.muted = true; |
|
|
503 |
} else { |
|
|
504 |
this.playerFns.setMute(false); |
|
|
505 |
this.media.muted = false; |
|
|
506 |
} |
|
|
507 |
|
|
|
508 |
this.trigger( "volumechange" ); |
|
|
509 |
} |
|
|
510 |
|
|
|
511 |
return this.playerFns.getMute(); |
|
|
512 |
} else { |
|
|
513 |
return this.playerFns.getMute(); |
|
|
514 |
} |
|
|
515 |
}; |
|
|
516 |
|
|
|
517 |
IriSP.PopcornReplacement.player.prototype.volume = function(val) { |
|
|
518 |
if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") { |
|
|
519 |
return false; |
|
|
520 |
} |
|
|
521 |
var _vol = this.playerFns.getVolume(); |
|
|
522 |
if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) { |
|
|
523 |
val = Math.max(0, Math.min(1, val)); |
|
|
524 |
if (parseFloat(val) != parseFloat(_vol)) { |
|
|
525 |
this.playerFns.setVolume(val); |
|
|
526 |
this.trigger("volumechange"); |
|
|
527 |
_vol = this.playerFns.getVolume(); |
|
|
528 |
} |
|
|
529 |
} |
|
|
530 |
return _vol; |
|
|
531 |
}; |
|
|
532 |
|
|
|
533 |
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
|
|
534 |
|
|
|
535 |
IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
|
536 |
this.__codes.push(options); |
|
|
537 |
return this; |
|
|
538 |
}; |
|
|
539 |
|
|
|
540 |
/* called everytime the player updates itself |
|
|
541 |
(onTime event) |
|
|
542 |
*/ |
|
|
543 |
|
|
|
544 |
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
|
545 |
var pos = event.position; |
|
|
546 |
|
|
|
547 |
var i = 0; |
|
|
548 |
for(i = 0; i < this.__codes.length; i++) { |
|
|
549 |
var c = this.__codes[i]; |
|
|
550 |
|
|
|
551 |
if (pos >= c.start && pos < c.end && |
|
|
552 |
pos - 1 <= c.start) { |
|
|
553 |
c.onStart(); |
|
|
554 |
} |
|
|
555 |
|
|
|
556 |
if (pos > c.start && pos > c.end && |
|
|
557 |
pos - 1 <= c.end) { |
|
|
558 |
c.onEnd(); |
|
|
559 |
} |
|
|
560 |
|
|
|
561 |
} |
|
|
562 |
|
|
|
563 |
this.trigger("timeupdate"); |
|
|
564 |
}; |
|
|
565 |
|
|
|
566 |
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
|
567 |
var i = 0; |
|
|
568 |
|
|
|
569 |
for(i = 0; i < this.__codes.length; i++) { |
|
|
570 |
var c = this.__codes[i]; |
|
|
571 |
|
|
|
572 |
if (event.position >= c.start && event.position < c.end) { |
|
|
573 |
c.onEnd(); |
|
|
574 |
} |
|
|
575 |
} |
|
|
576 |
|
|
|
577 |
for(i = 0; i < this.__codes.length; i++) { |
|
|
578 |
var c = this.__codes[i]; |
|
|
579 |
|
|
|
580 |
if (typeof(event.offset) === "undefined") |
|
|
581 |
event.offset = 0; |
|
|
582 |
|
|
|
583 |
if (event.offset >= c.start && event.offset < c.end) { |
|
|
584 |
c.onStart(); |
|
|
585 |
} |
|
|
586 |
|
|
|
587 |
} |
|
|
588 |
|
|
|
589 |
/* this signal sends as an extra argument the position in the video. |
|
|
590 |
As far as I know, this argument is not provided by popcorn */ |
|
|
591 |
this.trigger("seeked", event.offset); |
|
|
592 |
}; |
|
|
593 |
|
|
|
594 |
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
|
595 |
this.media.paused = false; |
|
|
596 |
this.trigger("play"); |
|
|
597 |
}; |
|
|
598 |
|
|
|
599 |
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
|
|
600 |
this.media.paused = true; |
|
|
601 |
this.trigger("pause"); |
|
|
602 |
}; |
|
|
603 |
|
|
|
604 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
|
|
605 |
var currentTime = this.currentTime(); |
|
|
606 |
return Math.round(currentTime); |
|
|
607 |
};/* model.js is where data is stored in a standard form, whatever the serializer */ |
|
|
608 |
|
|
|
609 |
IriSP.Model = { |
|
|
610 |
_SOURCE_STATUS_EMPTY : 0, |
|
|
611 |
_SOURCE_STATUS_WAITING : 1, |
|
|
612 |
_SOURCE_STATUS_READY : 2, |
|
|
613 |
_ID_AUTO_INCREMENT : 0, |
|
|
614 |
getUID : function() { |
|
|
615 |
return "autoid-" + (++this._ID_AUTO_INCREMENT); |
|
|
616 |
}, |
|
|
617 |
regexpFromTextOrArray : function(_textOrArray) { |
|
|
618 |
function escapeText(_text) { |
|
|
619 |
return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
|
620 |
} |
|
|
621 |
return new RegExp( '(' |
|
|
622 |
+ ( |
|
|
623 |
typeof _textOrArray === "string" |
|
|
624 |
? escapeText(_textOrArray) |
|
|
625 |
: IriSP._(_textOrArray).map(escapeText).join("|") |
|
|
626 |
) |
|
|
627 |
+ ')', |
|
|
628 |
'gim' |
|
|
629 |
); |
|
|
630 |
}, |
|
|
631 |
isoToDate : function(_str) { |
|
|
632 |
// http://delete.me.uk/2005/03/iso8601.html |
|
|
633 |
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})))?)?)?)?"; |
|
|
634 |
var d = _str.match(new RegExp(regexp)); |
|
|
635 |
|
|
|
636 |
var offset = 0; |
|
|
637 |
var date = new Date(d[1], 0, 1); |
|
|
638 |
|
|
|
639 |
if (d[3]) { date.setMonth(d[3] - 1); } |
|
|
640 |
if (d[5]) { date.setDate(d[5]); } |
|
|
641 |
if (d[7]) { date.setHours(d[7]); } |
|
|
642 |
if (d[8]) { date.setMinutes(d[8]); } |
|
|
643 |
if (d[10]) { date.setSeconds(d[10]); } |
|
|
644 |
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); } |
|
|
645 |
if (d[14]) { |
|
|
646 |
offset = (Number(d[16]) * 60) + Number(d[17]); |
|
|
647 |
offset *= ((d[15] == '-') ? 1 : -1); |
|
|
648 |
} |
|
|
649 |
|
|
|
650 |
offset -= date.getTimezoneOffset(); |
|
|
651 |
time = (Number(date) + (offset * 60 * 1000)); |
|
|
652 |
var _res = new Date(); |
|
|
653 |
_res.setTime(Number(time)); |
|
|
654 |
return _res; |
|
|
655 |
}, |
|
|
656 |
dateToIso : function(d) { |
|
|
657 |
function pad(n){return n<10 ? '0'+n : n} |
|
|
658 |
return d.getUTCFullYear()+'-' |
|
|
659 |
+ pad(d.getUTCMonth()+1)+'-' |
|
|
660 |
+ pad(d.getUTCDate())+'T' |
|
|
661 |
+ pad(d.getUTCHours())+':' |
|
|
662 |
+ pad(d.getUTCMinutes())+':' |
|
|
663 |
+ pad(d.getUTCSeconds())+'Z' |
|
|
664 |
} |
|
|
665 |
} |
|
|
666 |
|
|
|
667 |
/* |
|
|
668 |
* IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID) |
|
|
669 |
*/ |
|
|
670 |
IriSP.Model.List = function(_directory) { |
|
|
671 |
Array.call(this); |
|
|
672 |
this.directory = _directory; |
|
|
673 |
this.idIndex = []; |
|
|
674 |
if (typeof _directory == "undefined") { |
|
|
675 |
console.trace(); |
|
|
676 |
throw "Error : new IriSP.Model.List(directory): directory is undefined"; |
|
|
677 |
} |
|
|
678 |
} |
|
|
679 |
|
|
|
680 |
IriSP.Model.List.prototype = new Array(); |
|
|
681 |
|
|
|
682 |
IriSP.Model.List.prototype.getElement = function(_id) { |
|
|
683 |
return this[_id]; |
|
|
684 |
} |
|
|
685 |
|
|
|
686 |
IriSP.Model.List.prototype.hasId = function(_id) { |
|
|
687 |
return (IriSP._(this.idIndex).indexOf(_id) !== -1); |
|
|
688 |
} |
|
|
689 |
|
|
|
690 |
/* On recent browsers, forEach and map are defined and do what we want. |
|
|
691 |
* Otherwise, we'll use the Underscore.js functions |
|
|
692 |
*/ |
|
|
693 |
if (typeof Array.prototype.forEach === "undefined") { |
|
|
694 |
IriSP.Model.List.prototype.forEach = function(_callback) { |
|
|
695 |
var _this = this; |
|
|
696 |
IriSP._(this).forEach(function(_value, _key) { |
|
|
697 |
_callback(_value, _key, _this); |
|
|
698 |
}); |
|
|
699 |
} |
|
|
700 |
} |
|
|
701 |
|
|
|
702 |
if (typeof Array.prototype.map === "undefined") { |
|
|
703 |
IriSP.Model.List.prototype.map = function(_callback) { |
|
|
704 |
var _this = this; |
|
|
705 |
return IriSP._(this).map(function(_value, _key) { |
|
|
706 |
return _callback(_value, _key, _this); |
|
|
707 |
}); |
|
|
708 |
} |
|
|
709 |
} |
|
|
710 |
|
|
|
711 |
IriSP.Model.List.prototype.pluck = function(_key) { |
|
|
712 |
return this.map(function(_value) { |
|
|
713 |
return _value[_key]; |
|
|
714 |
}); |
|
|
715 |
} |
|
|
716 |
|
|
|
717 |
/* We override Array's filter function because it doesn't return an IriSP.Model.List |
|
|
718 |
*/ |
|
|
719 |
IriSP.Model.List.prototype.filter = function(_callback) { |
|
|
720 |
var _this = this, |
|
|
721 |
_res = new IriSP.Model.List(this.directory); |
|
|
722 |
_res.addElements(IriSP._(this).filter(function(_value, _key) { |
|
|
723 |
return _callback(_value, _key, _this); |
|
|
724 |
})); |
|
|
725 |
return _res; |
|
|
726 |
} |
|
|
727 |
|
|
|
728 |
IriSP.Model.List.prototype.slice = function(_start, _end) { |
|
|
729 |
var _res = new IriSP.Model.List(this.directory); |
|
|
730 |
_res.addElements(Array.prototype.slice.call(this, _start, _end)); |
|
|
731 |
return _res; |
|
|
732 |
} |
|
|
733 |
|
|
|
734 |
IriSP.Model.List.prototype.splice = function(_start, _end) { |
|
|
735 |
var _res = new IriSP.Model.List(this.directory); |
|
|
736 |
_res.addElements(Array.prototype.splice.call(this, _start, _end)); |
|
|
737 |
this.idIndex.splice(_start, _end); |
|
|
738 |
return _res; |
|
|
739 |
} |
|
|
740 |
|
|
|
741 |
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy |
|
|
742 |
* and won't return a new IriSP.Model.List |
|
|
743 |
*/ |
|
|
744 |
IriSP.Model.List.prototype.sortBy = function(_callback) { |
|
|
745 |
var _this = this, |
|
|
746 |
_res = new IriSP.Model.List(this.directory); |
|
|
747 |
_res.addElements(IriSP._(this).sortBy(function(_value, _key) { |
|
|
748 |
return _callback(_value, _key, _this); |
|
|
749 |
})); |
|
|
750 |
return _res; |
|
|
751 |
} |
|
|
752 |
|
|
|
753 |
/* Title and Description are basic information for (almost) all element types, |
|
|
754 |
* here we can search by these criteria |
|
|
755 |
*/ |
|
|
756 |
IriSP.Model.List.prototype.searchByTitle = function(_text) { |
|
|
757 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
|
758 |
return this.filter(function(_element) { |
|
|
759 |
return _rgxp.test(_element.title); |
|
|
760 |
}); |
|
|
761 |
} |
|
|
762 |
|
|
|
763 |
IriSP.Model.List.prototype.searchByDescription = function(_text) { |
|
|
764 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
|
765 |
return this.filter(function(_element) { |
|
|
766 |
return _rgxp.test(_element.description); |
|
|
767 |
}); |
|
|
768 |
} |
|
|
769 |
|
|
|
770 |
IriSP.Model.List.prototype.searchByTextFields = function(_text) { |
|
|
771 |
var _rgxp = IriSP.Model.regexpFromTextOrArray(_text); |
|
|
772 |
return this.filter(function(_element) { |
|
|
773 |
return _rgxp.test(_element.description) || _rgxp.test(_element.title); |
|
|
774 |
}); |
|
|
775 |
} |
|
|
776 |
|
|
|
777 |
IriSP.Model.List.prototype.getTitles = function() { |
|
|
778 |
return this.map(function(_el) { |
|
|
779 |
return _el.title; |
|
|
780 |
}); |
|
|
781 |
} |
|
|
782 |
|
|
|
783 |
IriSP.Model.List.prototype.addId = function(_id) { |
|
|
784 |
var _el = this.directory.getElement(_id) |
|
|
785 |
if (!this.hasId(_id) && typeof _el !== "undefined") { |
|
|
786 |
this.idIndex.push(_id); |
|
|
787 |
Array.prototype.push.call(this, _el); |
|
|
788 |
} |
|
|
789 |
} |
|
|
790 |
|
|
|
791 |
IriSP.Model.List.prototype.push = function(_el) { |
|
|
792 |
if (typeof _el === "undefined") { |
|
|
793 |
return; |
|
|
794 |
} |
|
|
795 |
var _index = (IriSP._(this.idIndex).indexOf(_el.id)); |
|
|
796 |
if (_index === -1) { |
|
|
797 |
this.idIndex.push(_el.id); |
|
|
798 |
Array.prototype.push.call(this, _el); |
|
|
799 |
} else { |
|
|
800 |
this[_index] = _el; |
|
|
801 |
} |
|
|
802 |
} |
|
|
803 |
|
|
|
804 |
IriSP.Model.List.prototype.addIds = function(_array) { |
|
|
805 |
var _l = _array.length, |
|
|
806 |
_this = this; |
|
|
807 |
IriSP._(_array).forEach(function(_id) { |
|
|
808 |
_this.addId(_id); |
|
|
809 |
}); |
|
|
810 |
} |
|
|
811 |
|
|
|
812 |
IriSP.Model.List.prototype.addElements = function(_array) { |
|
|
813 |
var _this = this; |
|
|
814 |
IriSP._(_array).forEach(function(_el) { |
|
|
815 |
_this.push(_el); |
|
|
816 |
}); |
|
|
817 |
} |
|
|
818 |
|
|
|
819 |
IriSP.Model.List.prototype.removeId = function(_id, _deleteFromDirectory) { |
|
|
820 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
821 |
_index = (IriSP._(this.idIndex).indexOf(_id)); |
|
|
822 |
if (_index !== -1) { |
|
|
823 |
this.splice(_index,1); |
|
|
824 |
} |
|
|
825 |
if (_deleteFromDirectory) { |
|
|
826 |
delete this.directory.elements[_id]; |
|
|
827 |
} |
|
|
828 |
} |
|
|
829 |
|
|
|
830 |
IriSP.Model.List.prototype.removeElement = function(_el, _deleteFromDirectory) { |
|
|
831 |
var _deleteFromDirectory = _deleteFromDirectory || false; |
|
|
832 |
this.removeId(_el.id); |
|
|
833 |
} |
|
|
834 |
|
|
|
835 |
IriSP.Model.List.prototype.removeIds = function(_list, _deleteFromDirectory) { |
|
|
836 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
837 |
_this = this; |
|
|
838 |
IriSP._(_list).forEach(function(_id) { |
|
|
839 |
_this.removeId(_id); |
|
|
840 |
}); |
|
|
841 |
} |
|
|
842 |
|
|
|
843 |
IriSP.Model.List.prototype.removeElements = function(_list, _deleteFromDirectory) { |
|
|
844 |
var _deleteFromDirectory = _deleteFromDirectory || false, |
|
|
845 |
_this = this; |
|
|
846 |
IriSP._(_list).forEach(function(_el) { |
|
|
847 |
_this.removeElement(_el); |
|
|
848 |
}); |
|
|
849 |
} |
|
|
850 |
|
|
|
851 |
/* A simple time management object, that helps converting millisecs to seconds and strings, |
|
|
852 |
* without the clumsiness of the original Date object. |
|
|
853 |
*/ |
|
|
854 |
|
|
|
855 |
IriSP.Model.Time = function(_milliseconds) { |
|
|
856 |
this.milliseconds = 0; |
|
|
857 |
this.setMilliseconds(_milliseconds); |
|
|
858 |
} |
|
|
859 |
|
|
|
860 |
IriSP.Model.Time.prototype.setMilliseconds = function(_milliseconds) { |
|
|
861 |
var _ante = _milliseconds; |
|
|
862 |
switch(typeof _milliseconds) { |
|
|
863 |
case "string": |
|
|
864 |
this.milliseconds = parseFloat(_milliseconds); |
|
|
865 |
break; |
|
|
866 |
case "number": |
|
|
867 |
this.milliseconds = _milliseconds; |
|
|
868 |
break; |
|
|
869 |
case "object": |
|
|
870 |
this.milliseconds = parseFloat(_milliseconds.valueOf()); |
|
|
871 |
break; |
|
|
872 |
default: |
|
|
873 |
this.milliseconds = 0; |
|
|
874 |
} |
|
|
875 |
if (this.milliseconds === NaN) { |
|
|
876 |
this.milliseconds = _ante; |
|
|
877 |
} |
|
|
878 |
} |
|
|
879 |
|
|
|
880 |
IriSP.Model.Time.prototype.setSeconds = function(_seconds) { |
|
|
881 |
this.milliseconds = 1000 * _seconds; |
|
|
882 |
} |
|
|
883 |
|
|
|
884 |
IriSP.Model.Time.prototype.getSeconds = function() { |
|
|
885 |
return Math.floor(this.milliseconds / 1000); |
|
|
886 |
} |
|
|
887 |
|
|
|
888 |
IriSP.Model.Time.prototype.getHMS = function() { |
|
|
889 |
var _totalSeconds = Math.abs(this.getSeconds()); |
|
|
890 |
return { |
|
|
891 |
hours : Math.floor(_totalSeconds / 3600), |
|
|
892 |
minutes : (Math.floor(_totalSeconds / 60) % 60), |
|
|
893 |
seconds : _totalSeconds % 60 |
|
|
894 |
} |
|
|
895 |
} |
|
|
896 |
|
|
|
897 |
IriSP.Model.Time.prototype.add = function(_milliseconds) { |
|
|
898 |
this.milliseconds += new IriSP.Model.Time(_milliseconds).milliseconds; |
|
|
899 |
} |
|
|
900 |
|
|
|
901 |
IriSP.Model.Time.prototype.valueOf = function() { |
|
|
902 |
return this.milliseconds; |
|
|
903 |
} |
|
|
904 |
|
|
|
905 |
IriSP.Model.Time.prototype.toString = function() { |
|
|
906 |
function pad(_n) { |
|
|
907 |
var _res = _n.toString(); |
|
|
908 |
while (_res.length < 2) { |
|
|
909 |
_res = '0' + _res; |
|
|
910 |
} |
|
|
911 |
return _res; |
|
|
912 |
} |
|
|
913 |
var _hms = this.getHMS(), |
|
|
914 |
_res = ''; |
|
|
915 |
if (_hms.hours) { |
|
|
916 |
_res += pad(_hms.hours) + ':' |
|
|
917 |
} |
|
|
918 |
_res += pad(_hms.minutes) + ':' + pad(_hms.seconds); |
|
|
919 |
return _res; |
|
|
920 |
} |
|
|
921 |
|
|
|
922 |
/* IriSP.Model.Reference handles references between elements |
|
|
923 |
*/ |
|
|
924 |
|
|
|
925 |
IriSP.Model.Reference = function(_source, _idRef) { |
|
|
926 |
this.source = _source; |
|
|
927 |
if (typeof _idRef === "object") { |
|
|
928 |
this.isList = true; |
|
|
929 |
this.id = IriSP._(_idRef).map(function(_id) { |
|
|
930 |
return _source.getNamespaced(_id).fullname; |
|
|
931 |
}); |
|
|
932 |
} else { |
|
|
933 |
this.isList = false; |
|
|
934 |
this.id = _source.getNamespaced(_idRef).fullname; |
|
|
935 |
} |
|
|
936 |
this.refresh(); |
|
|
937 |
} |
|
|
938 |
|
|
|
939 |
IriSP.Model.Reference.prototype.refresh = function() { |
|
|
940 |
if (this.isList) { |
|
|
941 |
this.contents = new IriSP.Model.List(this.source.directory); |
|
|
942 |
this.contents.addIds(this.id); |
|
|
943 |
} else { |
|
|
944 |
this.contents = this.source.directory.getElement(this.id); |
|
|
945 |
} |
|
|
946 |
|
|
|
947 |
} |
|
|
948 |
|
|
|
949 |
IriSP.Model.Reference.prototype.getContents = function() { |
|
|
950 |
if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) { |
|
|
951 |
this.refresh(); |
|
|
952 |
} |
|
|
953 |
return this.contents; |
|
|
954 |
} |
|
|
955 |
|
|
|
956 |
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) { |
|
|
957 |
if (this.isList) { |
|
|
958 |
return (IriSP._(this.id).indexOf(_idRef) !== -1) |
|
|
959 |
} else { |
|
|
960 |
return (this.id == _idRef); |
|
|
961 |
} |
|
|
962 |
} |
|
|
963 |
|
|
|
964 |
/* */ |
|
|
965 |
|
|
|
966 |
IriSP.Model.Element = function(_id, _source) { |
|
|
967 |
this.elementType = 'element'; |
|
|
968 |
if (typeof _source === "undefined") { |
|
|
969 |
return; |
|
|
970 |
} |
|
|
971 |
if (typeof _id === "undefined" || !_id) { |
|
|
972 |
_id = IriSP.Model.getUID(); |
|
|
973 |
} |
|
|
974 |
this.source = _source; |
|
|
975 |
this.namespacedId = _source.getNamespaced(_id) |
|
|
976 |
this.id = this.namespacedId.fullname; |
|
|
977 |
this.title = ""; |
|
|
978 |
this.description = ""; |
|
|
979 |
this.source.directory.addElement(this); |
|
|
980 |
} |
|
|
981 |
|
|
|
982 |
IriSP.Model.Element.prototype.toString = function() { |
|
|
983 |
return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : ''); |
|
|
984 |
} |
|
|
985 |
|
|
|
986 |
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) { |
|
|
987 |
this[_elementType] = new IriSP.Model.Reference(this.source, _idRef); |
|
|
988 |
} |
|
|
989 |
|
|
|
990 |
IriSP.Model.Element.prototype.getReference = function(_elementType) { |
|
|
991 |
if (typeof this[_elementType] !== "undefined") { |
|
|
992 |
return this[_elementType].getContents(); |
|
|
993 |
} |
|
|
994 |
} |
|
|
995 |
|
|
|
996 |
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) { |
|
|
997 |
_global = (typeof _global !== "undefined" && _global); |
|
|
998 |
var _this = this; |
|
|
999 |
return this.source.getList(_elementType, _global).filter(function(_el) { |
|
|
1000 |
var _ref = _el[_this.elementType]; |
|
|
1001 |
return _ref.isOrHasId(_this.id); |
|
|
1002 |
}); |
|
|
1003 |
} |
|
|
1004 |
|
|
|
1005 |
/* */ |
|
|
1006 |
|
|
|
1007 |
IriSP.Model.Media = function(_id, _source) { |
|
|
1008 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
1009 |
this.elementType = 'media'; |
|
|
1010 |
this.duration = new IriSP.Model.Time(); |
|
|
1011 |
this.video = ''; |
|
|
1012 |
} |
|
|
1013 |
|
|
|
1014 |
IriSP.Model.Media.prototype = new IriSP.Model.Element(); |
|
|
1015 |
|
|
|
1016 |
IriSP.Model.Media.prototype.setDuration = function(_durationMs) { |
|
|
1017 |
this.duration.setMilliseconds(_durationMs); |
|
|
1018 |
} |
|
|
1019 |
|
|
|
1020 |
IriSP.Model.Media.prototype.getAnnotations = function() { |
|
|
1021 |
return this.getRelated("annotation"); |
|
|
1022 |
} |
|
|
1023 |
|
|
|
1024 |
IriSP.Model.Media.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
|
1025 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
|
1026 |
if (_annTypes.length) { |
|
|
1027 |
return this.getAnnotations().filter(function(_annotation) { |
|
|
1028 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
|
1029 |
}); |
|
|
1030 |
} else { |
|
|
1031 |
return new IriSP.Model.List(this.source.directory) |
|
|
1032 |
} |
|
|
1033 |
} |
|
|
1034 |
|
|
|
1035 |
/* */ |
|
|
1036 |
|
|
|
1037 |
IriSP.Model.Tag = function(_id, _source) { |
|
|
1038 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
1039 |
this.elementType = 'tag'; |
|
|
1040 |
} |
|
|
1041 |
|
|
|
1042 |
IriSP.Model.Tag.prototype = new IriSP.Model.Element(); |
|
|
1043 |
|
|
|
1044 |
IriSP.Model.Tag.prototype.getAnnotations = function() { |
|
|
1045 |
return this.getRelated("annotation"); |
|
|
1046 |
} |
|
|
1047 |
|
|
|
1048 |
/* */ |
|
|
1049 |
|
|
|
1050 |
IriSP.Model.AnnotationType = function(_id, _source) { |
|
|
1051 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
1052 |
this.elementType = 'annotationType'; |
|
|
1053 |
} |
|
|
1054 |
|
|
|
1055 |
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(); |
|
|
1056 |
|
|
|
1057 |
IriSP.Model.AnnotationType.prototype.getAnnotations = function() { |
|
|
1058 |
return this.getRelated("annotation"); |
|
|
1059 |
} |
|
|
1060 |
|
|
|
1061 |
/* Annotation |
|
|
1062 |
* */ |
|
|
1063 |
|
|
|
1064 |
IriSP.Model.Annotation = function(_id, _source) { |
|
|
1065 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
1066 |
this.elementType = 'annotation'; |
|
|
1067 |
this.begin = new IriSP.Model.Time(); |
|
|
1068 |
this.end = new IriSP.Model.Time(); |
|
|
1069 |
} |
|
|
1070 |
|
|
|
1071 |
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null); |
|
|
1072 |
|
|
|
1073 |
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) { |
|
|
1074 |
this.begin.setMilliseconds(_beginMs); |
|
|
1075 |
} |
|
|
1076 |
|
|
|
1077 |
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) { |
|
|
1078 |
this.end.setMilliseconds(_beginMs); |
|
|
1079 |
} |
|
|
1080 |
|
|
|
1081 |
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) { |
|
|
1082 |
this.setReference("media", _idRef); |
|
|
1083 |
} |
|
|
1084 |
|
|
|
1085 |
IriSP.Model.Annotation.prototype.getMedia = function() { |
|
|
1086 |
return this.getReference("media"); |
|
|
1087 |
} |
|
|
1088 |
|
|
|
1089 |
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) { |
|
|
1090 |
this.setReference("annotationType", _idRef); |
|
|
1091 |
} |
|
|
1092 |
|
|
|
1093 |
IriSP.Model.Annotation.prototype.getAnnotationType = function() { |
|
|
1094 |
return this.getReference("annotationType"); |
|
|
1095 |
} |
|
|
1096 |
|
|
|
1097 |
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) { |
|
|
1098 |
this.setReference("tag", _idRefs); |
|
|
1099 |
} |
|
|
1100 |
|
|
|
1101 |
IriSP.Model.Annotation.prototype.getTags = function() { |
|
|
1102 |
return this.getReference("tag"); |
|
|
1103 |
} |
|
|
1104 |
|
|
|
1105 |
IriSP.Model.Annotation.prototype.getTagTexts = function() { |
|
|
1106 |
return this.getTags().getTitles(); |
|
|
1107 |
} |
|
|
1108 |
|
|
|
1109 |
IriSP.Model.Annotation.prototype.getDuration = function() { |
|
|
1110 |
return new IriSP.Model.Time(this.end.milliseconds - this.begin.milliseconds) |
|
|
1111 |
} |
|
|
1112 |
|
|
|
1113 |
/* */ |
|
|
1114 |
|
|
|
1115 |
IriSP.Model.MashedAnnotation = function(_mashup, _annotation) { |
|
|
1116 |
IriSP.Model.Element.call(this, _mashup.namespacedId.name + "_" + _annotation.namespacedId.name, _annotation.source); |
|
|
1117 |
this.elementType = 'mashedAnnotation'; |
|
|
1118 |
this.annotation = _annotation; |
|
|
1119 |
this.begin = new IriSP.Model.Time(_mashup.duration); |
|
|
1120 |
this.end = new IriSP.Model.Time(_mashup.duration + _annotation.getDuration()); |
|
|
1121 |
this.title = this.annotation.title; |
|
|
1122 |
this.description = this.annotation.description; |
|
|
1123 |
this.color = this.annotation.color; |
|
|
1124 |
} |
|
|
1125 |
|
|
|
1126 |
IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null); |
|
|
1127 |
|
|
|
1128 |
IriSP.Model.MashedAnnotation.prototype.getMedia = function() { |
|
|
1129 |
return this.annotation.getReference("media"); |
|
|
1130 |
} |
|
|
1131 |
|
|
|
1132 |
IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() { |
|
|
1133 |
return this.annotation.getReference("annotationType"); |
|
|
1134 |
} |
|
|
1135 |
|
|
|
1136 |
IriSP.Model.MashedAnnotation.prototype.getTags = function() { |
|
|
1137 |
return this.annotation.getReference("tag"); |
|
|
1138 |
} |
|
|
1139 |
|
|
|
1140 |
IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() { |
|
|
1141 |
return this.annotation.getTags().getTitles(); |
|
|
1142 |
} |
|
|
1143 |
|
|
|
1144 |
/* */ |
|
|
1145 |
|
|
|
1146 |
IriSP.Model.Mashup = function(_id, _source) { |
|
|
1147 |
IriSP.Model.Element.call(this, _id, _source); |
|
|
1148 |
this.elementType = 'mashup'; |
|
|
1149 |
this.duration = new IriSP.Model.Time(); |
|
|
1150 |
this.segments = new IriSP.Model.List(_source.directory); |
|
|
1151 |
this.medias = new IriSP.Model.List(_source.directory); |
|
|
1152 |
} |
|
|
1153 |
|
|
|
1154 |
IriSP.Model.Mashup.prototype = new IriSP.Model.Element(); |
|
|
1155 |
|
|
|
1156 |
IriSP.Model.Mashup.prototype.addSegment = function(_annotation) { |
|
|
1157 |
var _mashedAnnotation = new IriSP.Model.MashedAnnotation(this, _annotation); |
|
|
1158 |
this.duration.setMilliseconds(_mashedAnnotation.end); |
|
|
1159 |
this.segments.push(_mashedAnnotation); |
|
|
1160 |
this.medias.push(_annotation.getMedia()); |
|
|
1161 |
} |
|
|
1162 |
|
|
|
1163 |
IriSP.Model.Mashup.prototype.addSegmentById = function(_elId) { |
|
|
1164 |
var _annotation = this.source.getElement(_elId); |
|
|
1165 |
if (typeof _annotation !== "undefined") { |
|
|
1166 |
this.addSegment(_annotation); |
|
|
1167 |
} |
|
|
1168 |
} |
|
|
1169 |
|
|
|
1170 |
IriSP.Model.Mashup.prototype.getAnnotations = function() { |
|
|
1171 |
return this.segments; |
|
|
1172 |
} |
|
|
1173 |
|
|
|
1174 |
IriSP.Model.Mashup.prototype.getMedias = function() { |
|
|
1175 |
return this.medias; |
|
|
1176 |
} |
|
|
1177 |
|
|
|
1178 |
IriSP.Model.Mashup.prototype.getAnnotationsByTypeTitle = function(_title) { |
|
|
1179 |
var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id"); |
|
|
1180 |
if (_annTypes.length) { |
|
|
1181 |
return this.getAnnotations().filter(function(_annotation) { |
|
|
1182 |
return IriSP._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1; |
|
|
1183 |
}); |
|
|
1184 |
} else { |
|
|
1185 |
return new IriSP.Model.List(this.source.directory) |
|
|
1186 |
} |
|
|
1187 |
} |
|
|
1188 |
|
|
|
1189 |
IriSP.Model.Mashup.prototype.getAnnotationAtTime = function(_time) { |
|
|
1190 |
var _list = this.segments.filter(function(_annotation) { |
|
|
1191 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
|
1192 |
}); |
|
|
1193 |
if (_list.length) { |
|
|
1194 |
return _list[0]; |
|
|
1195 |
} else { |
|
|
1196 |
return undefined; |
|
|
1197 |
} |
|
|
1198 |
} |
|
|
1199 |
|
|
|
1200 |
IriSP.Model.Mashup.prototype.getMediaAtTime = function(_time) { |
|
|
1201 |
var _annotation = this.getAnnotationAtTime(_time); |
|
|
1202 |
if (typeof _annotation !== "undefined") { |
|
|
1203 |
return _annotation.getMedia(); |
|
|
1204 |
} else { |
|
|
1205 |
return undefined; |
|
|
1206 |
} |
|
|
1207 |
} |
|
|
1208 |
|
|
|
1209 |
/* */ |
|
|
1210 |
|
|
|
1211 |
IriSP.Model.Source = function(_config) { |
|
|
1212 |
this.status = IriSP.Model._SOURCE_STATUS_EMPTY; |
|
|
1213 |
if (typeof _config !== "undefined") { |
|
|
1214 |
var _this = this; |
|
|
1215 |
IriSP._(_config).forEach(function(_v, _k) { |
|
|
1216 |
_this[_k] = _v; |
|
|
1217 |
}) |
|
|
1218 |
this.callbackQueue = []; |
|
|
1219 |
this.contents = {}; |
|
|
1220 |
if (typeof this.namespace === "undefined") { |
|
|
1221 |
this.namespace = "metadataplayer"; |
|
|
1222 |
} else { |
|
|
1223 |
if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") { |
|
|
1224 |
var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g), |
|
|
1225 |
_url = _matches[0]; |
|
|
1226 |
if (_matches.length > 1) { |
|
|
1227 |
_matches = IriSP._(_matches.slice(1)).reject(function(_txt) { |
|
|
1228 |
return /\?$/.test(_txt); |
|
|
1229 |
}); |
|
|
1230 |
} |
|
|
1231 |
if (_matches.length > 0) { |
|
|
1232 |
_url += '?' + _matches.join('&'); |
|
|
1233 |
} |
|
|
1234 |
this.namespaceUrl = _url; |
|
|
1235 |
} |
|
|
1236 |
} |
|
|
1237 |
if (typeof this.namespaceUrl === "undefined") { |
|
|
1238 |
this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/"; |
|
|
1239 |
} |
|
|
1240 |
this.directory.addNamespace(this.namespace, this.namespaceUrl); |
|
|
1241 |
this.get(); |
|
|
1242 |
} |
|
|
1243 |
} |
|
|
1244 |
|
|
|
1245 |
IriSP.Model.Source.prototype.getNamespaced = function(_id) { |
|
|
1246 |
var _tab = _id.split(':'); |
|
|
1247 |
if (_tab.length > 1) { |
|
|
1248 |
return { |
|
|
1249 |
namespace : _tab[0], |
|
|
1250 |
name : _tab[1], |
|
|
1251 |
fullname : _id |
|
|
1252 |
} |
|
|
1253 |
} else { |
|
|
1254 |
return { |
|
|
1255 |
namespace : this.namespace, |
|
|
1256 |
name : _id, |
|
|
1257 |
fullname : this.namespace + ':' + _id |
|
|
1258 |
} |
|
|
1259 |
} |
|
|
1260 |
} |
|
|
1261 |
|
|
|
1262 |
IriSP.Model.Source.prototype.unNamespace = function(_id) { |
|
|
1263 |
if (typeof _id !== "undefined") { |
|
|
1264 |
return _id.replace(this.namespace + ':', ''); |
|
|
1265 |
} |
|
|
1266 |
} |
|
|
1267 |
|
|
|
1268 |
IriSP.Model.Source.prototype.addList = function(_listId, _contents) { |
|
|
1269 |
if (typeof this.contents[_listId] === "undefined") { |
|
|
1270 |
this.contents[_listId] = new IriSP.Model.List(this.directory); |
|
|
1271 |
} |
|
|
1272 |
this.contents[_listId].addElements(_contents); |
|
|
1273 |
} |
|
|
1274 |
|
|
|
1275 |
IriSP.Model.Source.prototype.getList = function(_listId, _global) { |
|
|
1276 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1277 |
if (_global || typeof this.contents[_listId] === "undefined") { |
|
|
1278 |
return this.directory.getGlobalList().filter(function(_e) { |
|
|
1279 |
return (_e.elementType === _listId); |
|
|
1280 |
}); |
|
|
1281 |
} else { |
|
|
1282 |
return this.contents[_listId]; |
|
|
1283 |
} |
|
|
1284 |
} |
|
|
1285 |
|
|
|
1286 |
IriSP.Model.Source.prototype.forEach = function(_callback) { |
|
|
1287 |
var _this = this; |
|
|
1288 |
IriSP._(this.contents).forEach(function(_value, _key) { |
|
|
1289 |
_callback.call(_this, _value, _key); |
|
|
1290 |
}) |
|
|
1291 |
} |
|
|
1292 |
|
|
|
1293 |
IriSP.Model.Source.prototype.getElement = function(_elId) { |
|
|
1294 |
return this.directory.getElement(this.getNamespaced(_elId).fullname); |
|
|
1295 |
} |
|
|
1296 |
|
|
|
1297 |
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) { |
|
|
1298 |
if (typeof _idRef !== "undefined") { |
|
|
1299 |
this.currentMedia = this.getElement(_idRef); |
|
|
1300 |
} |
|
|
1301 |
} |
|
|
1302 |
|
|
|
1303 |
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() { |
|
|
1304 |
if (typeof this.currentMedia === "undefined" && this.getMedias().length) { |
|
|
1305 |
this.currentMedia = this.getMedias()[0]; |
|
|
1306 |
} |
|
|
1307 |
} |
|
|
1308 |
|
|
|
1309 |
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) { |
|
|
1310 |
var _this = this, |
|
|
1311 |
_nsls = [], |
|
|
1312 |
_excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf); |
|
|
1313 |
this.forEach(function(_list) { |
|
|
1314 |
IriSP._(_list).forEach(function(_el) { |
|
|
1315 |
var _ns = _el.id.replace(/:.*$/,''); |
|
|
1316 |
if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) { |
|
|
1317 |
_nsls.push(_ns); |
|
|
1318 |
} |
|
|
1319 |
}) |
|
|
1320 |
}); |
|
|
1321 |
return _nsls; |
|
|
1322 |
} |
|
|
1323 |
|
|
|
1324 |
IriSP.Model.Source.prototype.get = function() { |
|
|
1325 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
|
1326 |
this.handleCallbacks(); |
|
|
1327 |
} |
|
|
1328 |
|
|
|
1329 |
/* We defer the callbacks calls so they execute after the queue is cleared */ |
|
|
1330 |
IriSP.Model.Source.prototype.deferCallback = function(_callback) { |
|
|
1331 |
var _this = this; |
|
|
1332 |
IriSP._.defer(function() { |
|
|
1333 |
_callback.call(_this); |
|
|
1334 |
}); |
|
|
1335 |
} |
|
|
1336 |
|
|
|
1337 |
IriSP.Model.Source.prototype.handleCallbacks = function() { |
|
|
1338 |
this.status = IriSP.Model._SOURCE_STATUS_READY; |
|
|
1339 |
while (this.callbackQueue.length) { |
|
|
1340 |
this.deferCallback(this.callbackQueue.splice(0,1)[0]); |
|
|
1341 |
} |
|
|
1342 |
} |
|
|
1343 |
IriSP.Model.Source.prototype.onLoad = function(_callback) { |
|
|
1344 |
if (this.status === IriSP.Model._SOURCE_STATUS_READY) { |
|
|
1345 |
this.deferCallback(_callback); |
|
|
1346 |
} else { |
|
|
1347 |
this.callbackQueue.push(_callback); |
|
|
1348 |
} |
|
|
1349 |
} |
|
|
1350 |
|
|
|
1351 |
IriSP.Model.Source.prototype.serialize = function() { |
|
|
1352 |
return this.serializer.serialize(this); |
|
|
1353 |
} |
|
|
1354 |
|
|
|
1355 |
IriSP.Model.Source.prototype.deSerialize = function(_data) { |
|
|
1356 |
this.serializer.deSerialize(_data, this); |
|
|
1357 |
} |
|
|
1358 |
|
|
|
1359 |
IriSP.Model.Source.prototype.getAnnotations = function(_global) { |
|
|
1360 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1361 |
return this.getList("annotation", _global); |
|
|
1362 |
} |
|
|
1363 |
|
|
|
1364 |
IriSP.Model.Source.prototype.getMedias = function(_global) { |
|
|
1365 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1366 |
return this.getList("media", _global); |
|
|
1367 |
} |
|
|
1368 |
|
|
|
1369 |
IriSP.Model.Source.prototype.getTags = function(_global) { |
|
|
1370 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1371 |
return this.getList("tag", _global); |
|
|
1372 |
} |
|
|
1373 |
|
|
|
1374 |
IriSP.Model.Source.prototype.getMashups = function(_global) { |
|
|
1375 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1376 |
return this.getList("mashup", _global); |
|
|
1377 |
} |
|
|
1378 |
|
|
|
1379 |
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) { |
|
|
1380 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1381 |
return this.getList("annotationType", _global); |
|
|
1382 |
} |
|
|
1383 |
|
|
|
1384 |
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) { |
|
|
1385 |
_global = (typeof _global !== "undefined" && _global); |
|
|
1386 |
var _res = new IriSP.Model.List(this.directory), |
|
|
1387 |
_annTypes = this.getAnnotationTypes(_global).searchByTitle(_title); |
|
|
1388 |
_annTypes.forEach(function(_annType) { |
|
|
1389 |
_res.addElements(_annType.getAnnotations(_global)); |
|
|
1390 |
}) |
|
|
1391 |
return _res; |
|
|
1392 |
} |
|
|
1393 |
|
|
|
1394 |
IriSP.Model.Source.prototype.getDuration = function() { |
|
|
1395 |
var _m = this.currentMedia; |
|
|
1396 |
if (typeof _m !== "undefined") { |
|
|
1397 |
return this.currentMedia.duration; |
|
|
1398 |
} |
|
|
1399 |
} |
|
|
1400 |
|
|
|
1401 |
IriSP.Model.Source.prototype.merge = function(_source) { |
|
|
1402 |
var _this = this; |
|
|
1403 |
_source.forEach(function(_value, _key) { |
|
|
1404 |
_this.getList(_key).addElements(_value); |
|
|
1405 |
}); |
|
|
1406 |
} |
|
|
1407 |
|
|
|
1408 |
/* */ |
|
|
1409 |
|
|
|
1410 |
IriSP.Model.RemoteSource = function(_config) { |
|
|
1411 |
IriSP.Model.Source.call(this, _config); |
|
|
1412 |
} |
|
|
1413 |
|
|
|
1414 |
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source(); |
|
|
1415 |
|
|
|
1416 |
IriSP.Model.RemoteSource.prototype.get = function() { |
|
|
1417 |
this.status = IriSP.Model._SOURCE_STATUS_WAITING; |
|
|
1418 |
var _this = this; |
|
|
1419 |
this.serializer.loadData(this.url, function(_result) { |
|
|
1420 |
_this.deSerialize(_result); |
|
|
1421 |
_this.handleCallbacks(); |
|
|
1422 |
}); |
|
|
1423 |
} |
|
|
1424 |
|
|
|
1425 |
/* */ |
|
|
1426 |
|
|
|
1427 |
IriSP.Model.Directory = function() { |
|
|
1428 |
this.remoteSources = {}; |
|
|
1429 |
this.elements = {}; |
|
|
1430 |
this.namespaces = {}; |
|
|
1431 |
} |
|
|
1432 |
|
|
|
1433 |
IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) { |
|
|
1434 |
this.namespaces[_namespace] = _url; |
|
|
1435 |
} |
|
|
1436 |
|
|
|
1437 |
IriSP.Model.Directory.prototype.remoteSource = function(_properties) { |
|
|
1438 |
var _config = IriSP._({ directory: this }).extend(_properties); |
|
|
1439 |
if (typeof this.remoteSources[_properties.url] === "undefined") { |
|
|
1440 |
this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config); |
|
|
1441 |
} |
|
|
1442 |
return this.remoteSources[_properties.url]; |
|
|
1443 |
} |
|
|
1444 |
|
|
|
1445 |
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) { |
|
|
1446 |
var _config = IriSP._({ directory: this }).extend(_properties), |
|
|
1447 |
_res = new IriSP.Model.Source(_config); |
|
|
1448 |
return _res; |
|
|
1449 |
} |
|
|
1450 |
|
|
|
1451 |
IriSP.Model.Directory.prototype.getElement = function(_id) { |
|
|
1452 |
return this.elements[_id]; |
|
|
1453 |
} |
|
|
1454 |
|
|
|
1455 |
IriSP.Model.Directory.prototype.addElement = function(_element) { |
|
|
1456 |
this.elements[_element.id] = _element; |
|
|
1457 |
} |
|
|
1458 |
|
|
|
1459 |
IriSP.Model.Directory.prototype.getGlobalList = function() { |
|
|
1460 |
var _res = new IriSP.Model.List(this); |
|
|
1461 |
_res.addIds(IriSP._(this.elements).keys()); |
|
|
1462 |
return _res; |
|
|
1463 |
} |
|
|
1464 |
|
|
|
1465 |
/* */ |
|
|
1466 |
IriSP.language = 'en'; |
|
|
1467 |
|
|
|
1468 |
IriSP.libFiles = { |
|
|
1469 |
defaultDir : "js/libs/", |
|
|
1470 |
inDefaultDir : { |
|
|
1471 |
underscore : "underscore-min.js", |
|
|
1472 |
Mustache : "mustache.js", |
|
|
1473 |
jQuery : "jquery.min.js", |
|
|
1474 |
jQueryUI : "jquery-ui.min.js", |
|
|
1475 |
swfObject : "swfobject.js", |
|
|
1476 |
cssjQueryUI : "jquery-ui.css", |
|
|
1477 |
popcorn : "popcorn-complete.min.js", |
|
|
1478 |
jwplayer : "jwplayer.js", |
|
|
1479 |
raphael : "raphael-min.js", |
|
13
|
1480 |
tracemanager : "tracemanager.js", |
|
|
1481 |
jwPlayerSWF : "player.swf" |
|
2
|
1482 |
}, |
|
|
1483 |
locations : { |
|
|
1484 |
// use to define locations outside defautl_dir |
|
|
1485 |
}, |
|
|
1486 |
cdn : { |
|
|
1487 |
jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js", |
|
|
1488 |
swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js", |
|
|
1489 |
cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" |
|
|
1490 |
}, |
|
|
1491 |
useCdn : false |
|
|
1492 |
} |
|
|
1493 |
|
|
|
1494 |
IriSP.widgetsDir = 'widgets'; |
|
|
1495 |
|
|
|
1496 |
IriSP.widgetsRequirements = { |
|
|
1497 |
Sparkline: { |
|
|
1498 |
noCss: true, |
|
|
1499 |
requires: "raphael" |
|
|
1500 |
}, |
|
|
1501 |
Arrow: { |
|
|
1502 |
noCss: true, |
|
|
1503 |
requires: "raphael" |
|
|
1504 |
}, |
|
|
1505 |
Mediafragment: { |
|
|
1506 |
noCss: true |
|
|
1507 |
}, |
|
|
1508 |
Trace : { |
|
|
1509 |
noCss: true, |
|
|
1510 |
requires: "tracemanager" |
|
|
1511 |
} |
|
|
1512 |
} |
|
|
1513 |
|
|
|
1514 |
IriSP.guiDefaults = { |
|
|
1515 |
width : 640, |
|
|
1516 |
container : 'LdtPlayer', |
|
|
1517 |
spacer_div_height : 0 |
|
|
1518 |
} |
|
|
1519 |
/* Definition of an ancestor for the Widget classes */ |
|
|
1520 |
|
|
|
1521 |
if (typeof IriSP.Widgets === "undefined") { |
|
|
1522 |
IriSP.Widgets = {} |
|
|
1523 |
} |
|
|
1524 |
|
|
|
1525 |
/** |
|
|
1526 |
* @class IriSP.Widget is an "abstract" class. It's mostly used to define some properties common to every widget. |
|
|
1527 |
* |
|
|
1528 |
* Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions |
|
|
1529 |
* defined in init.js |
|
|
1530 |
* |
|
|
1531 |
* @constructor |
|
|
1532 |
* @param player - a reference to the player widget |
|
|
1533 |
* @param config - configuration options for the widget |
|
|
1534 |
*/ |
|
|
1535 |
|
|
|
1536 |
|
|
|
1537 |
IriSP.Widgets.Widget = function(player, config) { |
|
|
1538 |
|
|
|
1539 |
if( typeof player === "undefined") { |
|
|
1540 |
/* Probably an abstract call of the class when |
|
|
1541 |
* individual widgets set their prototype */ |
|
|
1542 |
return; |
|
|
1543 |
} |
|
|
1544 |
|
|
|
1545 |
/* Setting all the configuration options */ |
|
|
1546 |
var _type = config.type, |
|
|
1547 |
_config = IriSP._.defaults({}, config, player.config.gui.default_options, this.defaults), |
|
|
1548 |
_this = this; |
|
|
1549 |
|
|
|
1550 |
IriSP._(_config).forEach(function(_value, _key) { |
|
|
1551 |
_this[_key] = _value; |
|
|
1552 |
}); |
|
|
1553 |
|
|
|
1554 |
if (typeof this.width === "undefined") { |
|
|
1555 |
this.width = player.config.gui.width; |
|
|
1556 |
} |
|
|
1557 |
|
|
|
1558 |
/* Setting this.player at the end in case it's been overriden |
|
|
1559 |
* by a configuration option of the same name :-( |
|
|
1560 |
*/ |
|
|
1561 |
this.player = player; |
|
|
1562 |
|
|
|
1563 |
/* Getting metadata */ |
|
|
1564 |
this.source = player.loadMetadata(this.metadata); |
|
|
1565 |
|
|
|
1566 |
/* Call draw when loaded */ |
|
|
1567 |
this.source.onLoad(function() { |
|
|
1568 |
_this.draw(); |
|
|
1569 |
}); |
|
|
1570 |
|
|
|
1571 |
/* Adding classes and html attributes */ |
|
|
1572 |
this.$ = IriSP.jQuery('#' + this.container); |
|
|
1573 |
this.$.addClass("Ldt-TraceMe Ldt-Widget").attr("widget-type", _type); |
|
|
1574 |
|
|
|
1575 |
/* Does the widget require other widgets ? */ |
|
|
1576 |
if (typeof this.requires !== "undefined") { |
|
|
1577 |
for (var _i = 0; _i < this.requires.length; _i++) { |
|
|
1578 |
var _subconfig = this.requires[_i]; |
|
|
1579 |
_subconfig.container = IriSP._.uniqueId(this.container + '_' + _subconfig.type + '_'); |
|
|
1580 |
this.$.append(IriSP.jQuery('<div>').attr("id",_subconfig.container)); |
|
|
1581 |
this.player.loadWidget(_subconfig, function(_widget) { |
|
|
1582 |
_this[_subconfig.type.replace(/^./,function(_s){return _s.toLowerCase();})] = _widget |
|
|
1583 |
}); |
|
|
1584 |
} |
|
|
1585 |
} |
|
|
1586 |
|
|
|
1587 |
this.l10n = (typeof this.messages[IriSP.language] !== "undefined" ? this.messages[IriSP.language] : this.messages["en"]); |
|
|
1588 |
|
|
|
1589 |
}; |
|
|
1590 |
|
|
|
1591 |
IriSP.Widgets.Widget.prototype.defaults = {} |
|
|
1592 |
|
|
|
1593 |
IriSP.Widgets.Widget.prototype.template = ''; |
|
|
1594 |
|
|
|
1595 |
IriSP.Widgets.Widget.prototype.messages = {"en":{}}; |
|
|
1596 |
|
|
|
1597 |
IriSP.Widgets.Widget.prototype.templateToHtml = function(_template) { |
|
|
1598 |
return Mustache.to_html(_template, this); |
|
|
1599 |
} |
|
|
1600 |
|
|
|
1601 |
IriSP.Widgets.Widget.prototype.renderTemplate = function() { |
|
|
1602 |
this.$.append(this.templateToHtml(this.template)); |
|
|
1603 |
} |
|
|
1604 |
|
|
|
1605 |
IriSP.Widgets.Widget.prototype.functionWrapper = function(_name) { |
|
|
1606 |
var _this = this, |
|
|
1607 |
_function = this[_name]; |
|
|
1608 |
if (typeof _function !== "undefined") { |
|
|
1609 |
return function() { |
|
|
1610 |
return _function.apply(_this, Array.prototype.slice.call(arguments, 0)); |
|
|
1611 |
} |
|
|
1612 |
} else { |
|
|
1613 |
console.log("Error, Unknown function IriSP." + this.type + "." + _name) |
|
|
1614 |
} |
|
|
1615 |
} |
|
|
1616 |
|
|
|
1617 |
IriSP.Widgets.Widget.prototype.bindPopcorn = function(_popcornEvent, _functionName) { |
|
|
1618 |
this.player.popcorn.listen(_popcornEvent, this.functionWrapper(_functionName)) |
|
|
1619 |
} |
|
|
1620 |
|
|
|
1621 |
IriSP.Widgets.Widget.prototype.getWidgetAnnotations = function() { |
|
|
1622 |
var _curmedia = this.source.currentMedia; |
|
|
1623 |
return typeof this.annotation_type !== "undefined" && this.annotation_type ? _curmedia.getAnnotationsByTypeTitle(this.annotation_type) : _curmedia.getAnnotations(); |
|
|
1624 |
} |
|
|
1625 |
|
|
|
1626 |
/** |
|
|
1627 |
* This method responsible of drawing a widget on screen. |
|
|
1628 |
*/ |
|
|
1629 |
IriSP.Widgets.Widget.prototype.draw = function() { |
|
|
1630 |
/* implemented by "sub-classes" */ |
|
|
1631 |
};/* To wrap a player the develop should create a new class derived from |
|
|
1632 |
the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
|
1633 |
|
|
|
1634 |
/** allocine player wrapper */ |
|
|
1635 |
IriSP.PopcornReplacement.allocine = function(container, options) { |
|
|
1636 |
// console.log("Calling allocine player"); |
|
|
1637 |
/* appel du parent pour initialiser les structures communes à tous les players */ |
|
|
1638 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
1639 |
|
|
|
1640 |
var _this = this; |
|
|
1641 |
|
|
|
1642 |
/* Définition des fonctions de l'API - */ |
|
|
1643 |
|
|
|
1644 |
this.playerFns = { |
|
|
1645 |
play : function() { |
|
|
1646 |
return _this.apiCall("play"); |
|
|
1647 |
}, |
|
|
1648 |
pause : function() { |
|
|
1649 |
return _this.apiCall("pause"); |
|
|
1650 |
}, |
|
|
1651 |
getPosition : function() { |
|
|
1652 |
return _this.apiCall("getSeek","return") || 0; |
|
|
1653 |
}, |
|
|
1654 |
seek : function(pos) { |
|
|
1655 |
return _this.apiCall("seek",pos); |
|
|
1656 |
}, |
|
|
1657 |
getMute : function() { |
|
|
1658 |
return _this.apiCall("getMute","return"); |
|
|
1659 |
}, |
|
|
1660 |
setMute : function(p) { |
|
|
1661 |
return _this.apiCall("setMute", p); |
|
|
1662 |
} |
|
|
1663 |
} |
|
|
1664 |
|
|
|
1665 |
window.onReady = function() { |
|
|
1666 |
_this.ready(); |
|
|
1667 |
}; |
|
|
1668 |
window.onAllocineStateChange = function(_state) { |
|
|
1669 |
_this.stateHandler(_state) |
|
|
1670 |
} |
|
|
1671 |
window.onTime = function(_progress) { |
|
|
1672 |
_this.progressHandler(_progress) |
|
|
1673 |
}; |
|
|
1674 |
|
|
|
1675 |
var _flashVars = { |
|
|
1676 |
"streamFMS" : true, |
|
|
1677 |
"adVast" : false, |
|
|
1678 |
"lg" : "fr_cinecast", |
|
|
1679 |
"autoPlay" : options.autoPlay, |
|
|
1680 |
"directVideoTitle" : "", |
|
|
1681 |
"urlAcData" : options.urlAcData, |
|
|
1682 |
"directVideoPath" : options.video, |
|
|
1683 |
"host" : "http://allocine.fr" |
|
|
1684 |
} |
|
|
1685 |
|
|
|
1686 |
if (typeof IriSP.__jsonMetadata["medias"][0].meta == "object" && typeof IriSP.__jsonMetadata["medias"][0].meta.subtitles == "string") { |
|
|
1687 |
_flashVars.subTitlePath = IriSP.__jsonMetadata["medias"][0].meta.subtitles; |
|
|
1688 |
} |
|
|
1689 |
|
|
|
1690 |
|
|
|
1691 |
var params = { |
|
|
1692 |
"allowScriptAccess" : "always", |
|
|
1693 |
"wmode": "opaque", |
|
|
1694 |
"flashvars" : IriSP.jQuery.param(_flashVars), |
|
|
1695 |
"allowfullscreen" : true |
|
|
1696 |
}; |
|
|
1697 |
var atts = { |
|
|
1698 |
id : this.container |
|
|
1699 |
}; |
|
|
1700 |
swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "10", null, null, params, atts); |
|
|
1701 |
|
|
|
1702 |
}; |
|
|
1703 |
|
|
|
1704 |
IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
1705 |
|
|
|
1706 |
IriSP.PopcornReplacement.allocine.prototype.ready = function() { |
|
|
1707 |
this.player = document.getElementById(this.container); |
|
|
1708 |
this.player.addEventListener("onStateChange", "onAllocineStateChange"); |
|
|
1709 |
this.player.cueVideoByUrl(this._options.video); |
|
|
1710 |
this.callbacks.onReady(); |
|
|
1711 |
}; |
|
|
1712 |
|
|
|
1713 |
IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) { |
|
|
1714 |
this.callbacks.onTime({ |
|
|
1715 |
position: progressInfo.mediaTime |
|
|
1716 |
}); |
|
|
1717 |
} |
|
|
1718 |
|
|
|
1719 |
|
|
|
1720 |
IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) { |
|
|
1721 |
if (this.player) { |
|
|
1722 |
try { |
|
|
1723 |
if (typeof _arg == "undefined") { |
|
|
1724 |
return this.player.sendToActionScript(_method); |
|
|
1725 |
} else { |
|
|
1726 |
return this.player.sendToActionScript(_method, _arg); |
|
|
1727 |
} |
|
|
1728 |
} catch(e) { |
|
|
1729 |
console.error('Exception while requesting AcPlayer for "' + _method + (typeof _arg == "undefined" ? '' : '" with argument "' + _arg ) + '"\n', e); |
|
|
1730 |
return false; |
|
|
1731 |
} |
|
|
1732 |
} else { |
|
|
1733 |
return false; |
|
|
1734 |
} |
|
|
1735 |
} |
|
|
1736 |
|
|
|
1737 |
IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) { |
|
|
1738 |
console.log("stateHandler"); |
|
|
1739 |
switch(state) { |
|
|
1740 |
case 1: |
|
|
1741 |
this.callbacks.onPlay(); |
|
|
1742 |
break; |
|
|
1743 |
|
|
|
1744 |
case 2: |
|
|
1745 |
this.callbacks.onPause(); |
|
|
1746 |
break; |
|
|
1747 |
|
|
|
1748 |
case 3: |
|
|
1749 |
this.callbacks.onSeek({ |
|
|
1750 |
position: this.player.getCurrentTime() |
|
|
1751 |
}); |
|
|
1752 |
break; |
|
|
1753 |
|
|
|
1754 |
/* |
|
|
1755 |
case 5: |
|
|
1756 |
this.callbacks.onReady(); |
|
|
1757 |
break; |
|
|
1758 |
*/ |
|
|
1759 |
} |
|
|
1760 |
|
|
|
1761 |
};/* To wrap a player the develop should create a new class derived from |
|
|
1762 |
the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
|
1763 |
|
|
|
1764 |
/** jwplayer player wrapper */ |
|
|
1765 |
IriSP.PopcornReplacement.dailymotion = function(container, options) { |
|
|
1766 |
/* Appel du constructeur de la classe parente */ |
|
|
1767 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
1768 |
|
|
|
1769 |
var _this = this; |
|
|
1770 |
|
|
|
1771 |
/* Définition des fonctions de commande : |
|
|
1772 |
this.playerFns.play, .pause, .getPosition, .seek, |
|
|
1773 |
.getMute, .setMute, .getVolume, .setVolume |
|
|
1774 |
doivent être rattachés aux fonctions du player |
|
|
1775 |
* */ |
|
|
1776 |
|
|
|
1777 |
this.playerFns = { |
|
|
1778 |
play : function() { |
|
|
1779 |
if (_this.player) { |
|
|
1780 |
return _this.player.playVideo(); |
|
|
1781 |
} else { |
|
|
1782 |
return false; |
|
|
1783 |
} |
|
|
1784 |
}, |
|
|
1785 |
pause : function() { |
|
|
1786 |
if (_this.player) { |
|
|
1787 |
return _this.player.pauseVideo(); |
|
|
1788 |
} else { |
|
|
1789 |
return false; |
|
|
1790 |
} |
|
|
1791 |
}, |
|
|
1792 |
getPosition : function() { |
|
|
1793 |
if (_this.player) { |
|
|
1794 |
return _this.player.getCurrentTime(); |
|
|
1795 |
} else { |
|
|
1796 |
return 0; |
|
|
1797 |
} |
|
|
1798 |
}, |
|
|
1799 |
seek : function(pos) { |
|
|
1800 |
if (_this.player) { |
|
|
1801 |
return _this.player.seekTo(pos); |
|
|
1802 |
} else { |
|
|
1803 |
return false; |
|
|
1804 |
} |
|
|
1805 |
}, |
|
|
1806 |
getMute : function() { |
|
|
1807 |
if (_this.player) { |
|
|
1808 |
return _this.player.isMuted(); |
|
|
1809 |
} else { |
|
|
1810 |
return false; |
|
|
1811 |
} |
|
|
1812 |
}, |
|
|
1813 |
setMute : function(p) { |
|
|
1814 |
if (_this.player) { |
|
|
1815 |
if (p) { |
|
|
1816 |
_this.player.mute(); |
|
|
1817 |
} |
|
|
1818 |
else { |
|
|
1819 |
_this.player.unMute(); |
|
|
1820 |
} |
|
|
1821 |
} |
|
|
1822 |
}, |
|
|
1823 |
getVolume : function() { |
|
|
1824 |
if (_this.player) { |
|
|
1825 |
return _this.player.getVolume() / 100; |
|
|
1826 |
} else { |
|
|
1827 |
return false; |
|
|
1828 |
} |
|
|
1829 |
}, |
|
|
1830 |
setVolume : function(p) { |
|
|
1831 |
if (_this.player) { |
|
|
1832 |
_this.player.setVolume(Math.floor(100 * p)); |
|
|
1833 |
} |
|
|
1834 |
}, |
|
|
1835 |
} |
|
|
1836 |
|
|
|
1837 |
/* Dailymotion utilise un système de fonctions référencées dans |
|
|
1838 |
* des variables globales pour la gestion des événements. |
|
|
1839 |
*/ |
|
|
1840 |
|
|
|
1841 |
window.onDailymotionPlayerReady = function() { |
|
|
1842 |
_this.onReady(); |
|
|
1843 |
}; |
|
|
1844 |
window.onDailymotionStateChange = function(_state) { |
|
|
1845 |
_this.onStateChange(_state); |
|
|
1846 |
} |
|
|
1847 |
window.onDailymotionVideoProgress = function(_progress) { |
|
|
1848 |
_this.onProgress(_progress); |
|
|
1849 |
} |
|
|
1850 |
|
|
|
1851 |
var params = { |
|
|
1852 |
"allowScriptAccess" : "always", |
|
|
1853 |
"wmode": "opaque" |
|
|
1854 |
}; |
|
|
1855 |
var atts = { |
|
|
1856 |
id : this.container |
|
|
1857 |
}; |
|
|
1858 |
swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts); |
|
|
1859 |
|
|
|
1860 |
}; |
|
|
1861 |
|
|
|
1862 |
IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
1863 |
|
|
|
1864 |
IriSP.PopcornReplacement.dailymotion.prototype.onReady = function() { |
|
|
1865 |
|
|
|
1866 |
this.player = document.getElementById(this.container); |
|
|
1867 |
|
|
|
1868 |
this.player.addEventListener("onStateChange", "onDailymotionStateChange"); |
|
|
1869 |
this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress"); |
|
|
1870 |
this.player.cueVideoByUrl(this._options.video); |
|
|
1871 |
|
|
|
1872 |
this.callbacks.onReady(); |
|
|
1873 |
}; |
|
|
1874 |
|
|
|
1875 |
IriSP.PopcornReplacement.dailymotion.prototype.onProgress = function(progressInfo) { |
|
|
1876 |
|
|
|
1877 |
this.callbacks.onTime({ |
|
|
1878 |
position: progressInfo.mediaTime |
|
|
1879 |
}); |
|
|
1880 |
} |
|
|
1881 |
|
|
|
1882 |
IriSP.PopcornReplacement.dailymotion.prototype.onStateChange = function(state) { |
|
|
1883 |
|
|
|
1884 |
switch(state) { |
|
|
1885 |
case 1: |
|
|
1886 |
this.callbacks.onPlay(); |
|
|
1887 |
break; |
|
|
1888 |
|
|
|
1889 |
case 2: |
|
|
1890 |
this.callbacks.onPause(); |
|
|
1891 |
break; |
|
|
1892 |
|
|
|
1893 |
case 3: |
|
|
1894 |
this.callbacks.onSeek({ |
|
|
1895 |
position: this.player.getCurrentTime() |
|
|
1896 |
}); |
|
|
1897 |
break; |
|
|
1898 |
} |
|
|
1899 |
|
|
|
1900 |
};/* To wrap a player the develop should create a new class derived from |
|
|
1901 |
the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
|
1902 |
|
|
|
1903 |
/** jwplayer player wrapper */ |
|
|
1904 |
IriSP.PopcornReplacement.jwplayer = function(container, options) { |
|
30
|
1905 |
/* appel du parent pour initialiser les structures communes à tous les players */ |
|
|
1906 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
2
|
1907 |
|
|
30
|
1908 |
this.media.duration = options.duration; /* optional */ |
|
|
1909 |
|
|
|
1910 |
var _player = jwplayer(this.container); |
|
2
|
1911 |
|
|
|
1912 |
/* Définition des fonctions de l'API - */ |
|
30
|
1913 |
this.playerFns = { |
|
|
1914 |
play: function() { return _player.play(); }, |
|
|
1915 |
pause: function() { return _player.pause(); }, |
|
|
1916 |
getPosition: function() { return _player.getPosition(); }, |
|
|
1917 |
seek: function(pos) { return _player.seek(pos); }, |
|
|
1918 |
getMute: function() { return _player.getMute() }, |
|
|
1919 |
setMute: function(p) { return _player.setMute(p); }, |
|
|
1920 |
getVolume: function() { return _player.getVolume() / 100; }, |
|
|
1921 |
setVolume: function(p) { return _player.setVolume(Math.floor(100*p)); } |
|
|
1922 |
} |
|
2
|
1923 |
|
|
30
|
1924 |
options.events = this.callbacks; |
|
2
|
1925 |
|
|
30
|
1926 |
_player.setup(options); |
|
2
|
1927 |
}; |
|
|
1928 |
|
|
|
1929 |
IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
1930 |
/* To wrap a player the develop should create a new class derived from |
|
|
1931 |
the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
|
1932 |
|
|
|
1933 |
/** jwplayer player wrapper */ |
|
|
1934 |
IriSP.PopcornReplacement.mashup = function(container, options) { |
|
|
1935 |
/* Appel du constructeur de la classe parente */ |
|
|
1936 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
1937 |
|
|
|
1938 |
var _this = this; |
|
|
1939 |
|
|
|
1940 |
/* Définition des fonctions de commande : |
|
|
1941 |
this.playerFns.play, .pause, .getPosition, .seek, |
|
|
1942 |
.getMute, .setMute, .getVolume, .setVolume |
|
|
1943 |
doivent être rattachés aux fonctions du player |
|
|
1944 |
* */ |
|
|
1945 |
|
|
|
1946 |
this.playerFns = { |
|
|
1947 |
play : function() { |
|
|
1948 |
if (_this.player) { |
|
|
1949 |
return _this.player.playVideo(); |
|
|
1950 |
} else { |
|
|
1951 |
return false; |
|
|
1952 |
} |
|
|
1953 |
}, |
|
|
1954 |
pause : function() { |
|
|
1955 |
if (_this.player) { |
|
|
1956 |
return _this.player.pauseVideo(); |
|
|
1957 |
} else { |
|
|
1958 |
return false; |
|
|
1959 |
} |
|
|
1960 |
}, |
|
|
1961 |
getPosition : function() { |
|
|
1962 |
if (_this.player) { |
|
|
1963 |
return _this.player.getCurrentTime(); |
|
|
1964 |
} else { |
|
|
1965 |
return 0; |
|
|
1966 |
} |
|
|
1967 |
}, |
|
|
1968 |
seek : function(pos) { |
|
|
1969 |
if (_this.player) { |
|
|
1970 |
return _this.player.seekTo(pos); |
|
|
1971 |
} else { |
|
|
1972 |
return false; |
|
|
1973 |
} |
|
|
1974 |
}, |
|
|
1975 |
getMute : function() { |
|
|
1976 |
if (_this.player) { |
|
|
1977 |
return _this.player.isMuted(); |
|
|
1978 |
} else { |
|
|
1979 |
return false; |
|
|
1980 |
} |
|
|
1981 |
}, |
|
|
1982 |
setMute : function(p) { |
|
|
1983 |
if (_this.player) { |
|
|
1984 |
if (p) { |
|
|
1985 |
_this.player.mute(); |
|
|
1986 |
} |
|
|
1987 |
else { |
|
|
1988 |
_this.player.unMute(); |
|
|
1989 |
} |
|
|
1990 |
} |
|
|
1991 |
}, |
|
|
1992 |
getVolume : function() { |
|
|
1993 |
if (_this.player) { |
|
|
1994 |
return _this.player.getVolume() / 2; |
|
|
1995 |
} else { |
|
|
1996 |
return false; |
|
|
1997 |
} |
|
|
1998 |
}, |
|
|
1999 |
setVolume : function(p) { |
|
|
2000 |
if (_this.player) { |
|
|
2001 |
_this.player.setVolume(Math.floor(2 * p)); |
|
|
2002 |
} |
|
|
2003 |
}, |
|
|
2004 |
} |
|
|
2005 |
|
|
|
2006 |
/* Dailymotion utilise un système de fonctions référencées dans |
|
|
2007 |
* des variables globales pour la gestion des événements. |
|
|
2008 |
*/ |
|
|
2009 |
|
|
|
2010 |
window.onBabPlayerReady = function() { |
|
|
2011 |
_this.onReady(); |
|
|
2012 |
}; |
|
|
2013 |
window.onBabStateChange = function(_state) { |
|
|
2014 |
_this.onStateChange(_state); |
|
|
2015 |
} |
|
|
2016 |
window.onBabVideoProgress = function(_progress) { |
|
|
2017 |
_this.onProgress(_progress); |
|
|
2018 |
} |
|
|
2019 |
|
|
|
2020 |
var params = { |
|
|
2021 |
allowScriptAccess : "always", |
|
|
2022 |
wmode: "transparent", |
|
|
2023 |
quality: "high", |
|
|
2024 |
menu: true, |
|
|
2025 |
bgcolor: "#869ca7" |
|
|
2026 |
}; |
|
|
2027 |
var atts = { |
|
|
2028 |
id : this.container |
|
|
2029 |
}; |
|
|
2030 |
var flashvars = { |
|
|
2031 |
urlData: options.mashup_xml |
|
|
2032 |
}; |
|
|
2033 |
swfobject.embedSWF(options.mashup_swf, this.container, options.width, options.height, "8", null, flashvars, params, atts); |
|
|
2034 |
|
|
|
2035 |
}; |
|
|
2036 |
|
|
|
2037 |
IriSP.PopcornReplacement.mashup.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
2038 |
|
|
|
2039 |
IriSP.PopcornReplacement.mashup.prototype.onReady = function() { |
|
|
2040 |
|
|
|
2041 |
this.player = document.getElementById(this.container); |
|
|
2042 |
|
|
|
2043 |
this.callbacks.onReady(); |
|
|
2044 |
}; |
|
|
2045 |
|
|
|
2046 |
IriSP.PopcornReplacement.mashup.prototype.onProgress = function(progressInfo) { |
|
|
2047 |
|
|
|
2048 |
this.callbacks.onTime({ |
|
|
2049 |
position: progressInfo.mediaTime |
|
|
2050 |
}); |
|
|
2051 |
} |
|
|
2052 |
|
|
|
2053 |
IriSP.PopcornReplacement.mashup.prototype.onStateChange = function(state) { |
|
|
2054 |
|
|
|
2055 |
switch(state) { |
|
|
2056 |
case 1: |
|
|
2057 |
this.callbacks.onPlay(); |
|
|
2058 |
break; |
|
|
2059 |
|
|
|
2060 |
case 2: |
|
|
2061 |
this.callbacks.onPause(); |
|
|
2062 |
break; |
|
|
2063 |
|
|
|
2064 |
case 3: |
|
|
2065 |
this.callbacks.onSeek({ |
|
|
2066 |
position: this.player.getCurrentTime() |
|
|
2067 |
}); |
|
|
2068 |
break; |
|
|
2069 |
} |
|
|
2070 |
|
|
15
|
2071 |
};/* LDT Platform Serializer */ |
|
2
|
2072 |
|
|
|
2073 |
if (typeof IriSP.serializers === "undefined") { |
|
|
2074 |
IriSP.serializers = {} |
|
|
2075 |
} |
|
|
2076 |
|
|
|
2077 |
IriSP.serializers.ldt = { |
|
|
2078 |
types : { |
|
|
2079 |
media : { |
|
|
2080 |
serialized_name : "medias", |
|
|
2081 |
deserializer : function(_data, _source) { |
|
|
2082 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
|
2083 |
_res.video = ( |
|
|
2084 |
typeof _data.url !== "undefined" |
|
|
2085 |
? _data.url |
|
|
2086 |
: ( |
|
|
2087 |
typeof _data.href !== "undefined" |
|
|
2088 |
? _data.href |
|
|
2089 |
: null |
|
|
2090 |
) |
|
|
2091 |
); |
|
|
2092 |
if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
|
2093 |
_res.streamer = _data.meta.item.value; |
|
|
2094 |
} |
|
|
2095 |
_res.title = _data.meta["dc:title"]; |
|
|
2096 |
_res.description = _data.meta["dc:description"]; |
|
|
2097 |
_res.setDuration(_data.meta["dc:duration"]); |
|
|
2098 |
return _res; |
|
|
2099 |
}, |
|
|
2100 |
serializer : function(_data, _source) { |
|
|
2101 |
return { |
|
|
2102 |
id : _source.unNamespace(_data.id), |
|
|
2103 |
url : _data.video, |
|
|
2104 |
meta : { |
|
|
2105 |
"dc:title" : _data.title, |
|
|
2106 |
"dc:description" : _data.description, |
|
|
2107 |
"dc:duration" : _data.duration.milliseconds |
|
|
2108 |
} |
|
|
2109 |
} |
|
|
2110 |
} |
|
|
2111 |
}, |
|
|
2112 |
tag : { |
|
|
2113 |
serialized_name : "tags", |
|
|
2114 |
model_name : "tag", |
|
|
2115 |
deserializer : function(_data, _source) { |
|
|
2116 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
|
2117 |
_res.title = _data.meta["dc:title"]; |
|
|
2118 |
return _res; |
|
|
2119 |
}, |
|
|
2120 |
serializer : function(_data, _source) { |
|
|
2121 |
return { |
|
|
2122 |
id : _source.unNamespace(_data.id), |
|
|
2123 |
meta : { |
|
|
2124 |
"dc:title" : _data.title |
|
|
2125 |
} |
|
|
2126 |
} |
|
|
2127 |
} |
|
|
2128 |
}, |
|
|
2129 |
annotationType : { |
|
|
2130 |
serialized_name : "annotation-types", |
|
|
2131 |
deserializer : function(_data, _source) { |
|
|
2132 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
|
2133 |
_res.title = _data["dc:title"]; |
|
|
2134 |
_res.description = _data["dc:description"]; |
|
|
2135 |
return _res; |
|
|
2136 |
}, |
|
|
2137 |
serializer : function(_data, _source) { |
|
|
2138 |
return { |
|
|
2139 |
id : _source.unNamespace(_data.id), |
|
|
2140 |
"dc:title" : _data.title, |
|
|
2141 |
"dc:description" : _data.description |
|
|
2142 |
} |
|
|
2143 |
} |
|
|
2144 |
}, |
|
|
2145 |
annotation : { |
|
|
2146 |
serialized_name : "annotations", |
|
|
2147 |
deserializer : function(_data, _source) { |
|
|
2148 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
2149 |
_res.title = _data.content.title || ""; |
|
|
2150 |
_res.description = _data.content.description || ""; |
|
|
2151 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
|
|
2152 |
_res.thumbnail = _data.content.img.src; |
|
|
2153 |
} |
|
|
2154 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
|
2155 |
if (typeof _data.color !== "undefined") { |
|
|
2156 |
var _c = parseInt(_data.color).toString(16); |
|
|
2157 |
while (_c.length < 6) { |
|
|
2158 |
_c = '0' + _c; |
|
|
2159 |
} |
|
|
2160 |
_res.color = '#' + _c; |
|
|
2161 |
} |
|
|
2162 |
_res.setMedia(_data.media); |
|
|
2163 |
_res.setAnnotationType(_data.meta["id-ref"]); |
|
|
2164 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
|
2165 |
_res.setBegin(_data.begin); |
|
|
2166 |
_res.setEnd(_data.end); |
|
|
2167 |
_res.creator = _data.meta["dc:creator"] || ""; |
|
|
2168 |
_res.project = _data.meta.project || ""; |
|
|
2169 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
|
|
2170 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
|
2171 |
} |
|
30
|
2172 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
|
|
2173 |
_res.audio = _data.content.audio; |
|
15
|
2174 |
} |
|
2
|
2175 |
return _res; |
|
|
2176 |
}, |
|
|
2177 |
serializer : function(_data, _source) { |
|
|
2178 |
return { |
|
|
2179 |
id : _source.unNamespace(_data.id), |
|
|
2180 |
begin : _data.begin.milliseconds, |
|
|
2181 |
end : _data.end.milliseconds, |
|
|
2182 |
content : { |
|
|
2183 |
title : _data.title, |
|
30
|
2184 |
description : _data.description, |
|
|
2185 |
audio : _data.audio |
|
2
|
2186 |
}, |
|
|
2187 |
media : _source.unNamespace(_data.media.id), |
|
|
2188 |
meta : { |
|
|
2189 |
"id-ref" : _source.unNamespace(_data.annotationType.id), |
|
|
2190 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
|
2191 |
"dc:creator" : _data.creator, |
|
|
2192 |
project : _source.projectId |
|
|
2193 |
}, |
|
|
2194 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
|
|
2195 |
return { |
|
|
2196 |
"id-ref" : _source.unNamespace(_id) |
|
|
2197 |
} |
|
30
|
2198 |
}) |
|
2
|
2199 |
} |
|
|
2200 |
} |
|
|
2201 |
}, |
|
|
2202 |
mashup : { |
|
|
2203 |
serialized_name : "mashups", |
|
|
2204 |
deserializer : function(_data, _source) { |
|
|
2205 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
|
|
2206 |
_res.title = _data.meta["dc:title"]; |
|
|
2207 |
_res.description = _data.meta["dc:description"]; |
|
|
2208 |
for (var _i = 0; _i < _data.segments.length; _i++) { |
|
|
2209 |
_res.addSegmentById(_data.segments[_i]); |
|
|
2210 |
} |
|
|
2211 |
return _res; |
|
|
2212 |
}, |
|
|
2213 |
serializer : function(_data, _source) { |
|
|
2214 |
return { |
|
|
2215 |
"dc:title": _data.title, |
|
|
2216 |
"dc:description": _data.description, |
|
|
2217 |
segments: _data.segments.map(function(_annotation) { |
|
|
2218 |
return _source.unNamespace(_id); |
|
|
2219 |
}) |
|
|
2220 |
} |
|
|
2221 |
} |
|
|
2222 |
} |
|
|
2223 |
}, |
|
|
2224 |
serialize : function(_source) { |
|
|
2225 |
var _res = {}, |
|
|
2226 |
_this = this; |
|
|
2227 |
_source.forEach(function(_list, _typename) { |
|
|
2228 |
if (typeof _this.types[_typename] !== "undefined") { |
|
|
2229 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
|
2230 |
return _this.types[_typename].serializer(_el, _source); |
|
|
2231 |
}); |
|
|
2232 |
} |
|
|
2233 |
}); |
|
|
2234 |
return JSON.stringify(_res); |
|
|
2235 |
}, |
|
|
2236 |
loadData : function(_url, _callback) { |
|
|
2237 |
IriSP.jQuery.getJSON(_url, _callback) |
|
|
2238 |
}, |
|
|
2239 |
deSerialize : function(_data, _source) { |
|
|
2240 |
if (typeof _data !== "object" || _data === null) { |
|
|
2241 |
return; |
|
|
2242 |
} |
|
|
2243 |
IriSP._(this.types).forEach(function(_type, _typename) { |
|
|
2244 |
var _listdata = _data[_type.serialized_name]; |
|
|
2245 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
|
|
2246 |
var _list = new IriSP.Model.List(_source.directory); |
|
|
2247 |
if (_listdata.hasOwnProperty("length")) { |
|
|
2248 |
var _l = _listdata.length; |
|
|
2249 |
for (var _i = 0; _i < _l; _i++) { |
|
|
2250 |
_list.push(_type.deserializer(_listdata[_i], _source)); |
|
|
2251 |
} |
|
|
2252 |
} else { |
|
|
2253 |
_list.push(_type.deserializer(_listdata, _source)); |
|
|
2254 |
} |
|
|
2255 |
_source.addList(_typename, _list); |
|
|
2256 |
} |
|
|
2257 |
}); |
|
|
2258 |
|
|
|
2259 |
if (typeof _data.meta !== "undefined") { |
|
|
2260 |
_source.projectId = _data.meta.id; |
|
|
2261 |
} |
|
|
2262 |
|
|
|
2263 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
|
2264 |
_source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
|
2265 |
} |
|
|
2266 |
_source.setDefaultCurrentMedia(); |
|
|
2267 |
} |
|
|
2268 |
} |
|
|
2269 |
|
|
15
|
2270 |
/* Used when Putting annotations on the platform */ |
|
|
2271 |
|
|
|
2272 |
if (typeof IriSP.serializers === "undefined") { |
|
|
2273 |
IriSP.serializers = {} |
|
|
2274 |
} |
|
|
2275 |
|
|
|
2276 |
IriSP.serializers.ldt_annotate = { |
|
|
2277 |
types : { |
|
|
2278 |
annotation : { |
|
|
2279 |
serialized_name : "annotations", |
|
|
2280 |
serializer : function(_data, _source) { |
|
|
2281 |
return { |
|
|
2282 |
begin: _data.begin.milliseconds, |
|
|
2283 |
end: _data.end.milliseconds, |
|
|
2284 |
content: { |
|
38
|
2285 |
data: _data.description, |
|
|
2286 |
audio: _data.audio |
|
15
|
2287 |
}, |
|
|
2288 |
tags: _data.getTagTexts(), |
|
|
2289 |
media: _source.unNamespace(_data.getMedia().id), |
|
|
2290 |
title: _data.title, |
|
|
2291 |
type_title: _data.getAnnotationType().title, |
|
40
|
2292 |
type: ( typeof _data.getAnnotationType().dont_send_id !== "undefined" && _data.getAnnotationType().dont_send_id ? "" : _source.unNamespace(_data.getAnnotationType().id) ) |
|
15
|
2293 |
} |
|
|
2294 |
} |
|
|
2295 |
} |
|
|
2296 |
}, |
|
|
2297 |
serialize : function(_source) { |
|
|
2298 |
var _res = {}, |
|
|
2299 |
_this = this; |
|
|
2300 |
_source.forEach(function(_list, _typename) { |
|
|
2301 |
if (typeof _this.types[_typename] !== "undefined") { |
|
|
2302 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
|
2303 |
return _this.types[_typename].serializer(_el, _source); |
|
|
2304 |
}); |
|
|
2305 |
} |
|
|
2306 |
}); |
|
|
2307 |
_res.meta = { |
|
|
2308 |
creator: _source.creator, |
|
|
2309 |
created: _source.created |
|
|
2310 |
} |
|
|
2311 |
return JSON.stringify(_res); |
|
|
2312 |
}, |
|
|
2313 |
deSerialize : function(_data, _source) { |
|
|
2314 |
if (typeof _data == "string") { |
|
|
2315 |
_data = JSON.parse(_data); |
|
|
2316 |
} |
|
|
2317 |
_source.addList('tag', new IriSP.Model.List(_source.directory)); |
|
|
2318 |
_source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
|
|
2319 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
|
|
2320 |
if (typeof _data.annotations == "object" && _data.annotations && _data.annotations.length) { |
|
|
2321 |
var _anndata = _data.annotations[0], |
|
|
2322 |
_ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
|
2323 |
_ann.title = _anndata.content.title || ""; |
|
|
2324 |
_ann.description = _anndata.content.data || ""; |
|
|
2325 |
_ann.created = new Date(_data.meta.created); |
|
|
2326 |
_ann.setMedia(_anndata.media, _source); |
|
|
2327 |
var _anntypes = _source.getAnnotationTypes(true).searchByTitle(_anndata.type_title); |
|
|
2328 |
if (_anntypes.length) { |
|
|
2329 |
var _anntype = _anntypes[0]; |
|
|
2330 |
} else { |
|
|
2331 |
var _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
|
2332 |
_anntype.title = _anndata.type_title; |
|
|
2333 |
_source.getAnnotationTypes().push(_anntype); |
|
|
2334 |
} |
|
|
2335 |
_ann.setAnnotationType(_anntype.id); |
|
|
2336 |
var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
|
2337 |
var _tags = _source.getTags(true).searchByTitle(_title); |
|
|
2338 |
if (_tags.length) { |
|
|
2339 |
var _tag = _tags[0]; |
|
|
2340 |
} |
|
|
2341 |
else { |
|
|
2342 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
|
2343 |
_tag.title = _title; |
|
|
2344 |
_source.getTags().push(_tag); |
|
|
2345 |
} |
|
|
2346 |
return _tag.id; |
|
|
2347 |
}); |
|
|
2348 |
_ann.setTags(_tagIds); |
|
|
2349 |
_ann.setBegin(_anndata.begin); |
|
|
2350 |
_ann.setEnd(_anndata.end); |
|
|
2351 |
_ann.creator = _data.meta.creator; |
|
38
|
2352 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
|
2353 |
_ann.audio = _anndata.content.audio; |
|
|
2354 |
} |
|
15
|
2355 |
_source.getAnnotations().push(_ann); |
|
|
2356 |
} |
|
|
2357 |
} |
|
|
2358 |
} |