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