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