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