player/js/metadataplayer-core.js
author cavaliet
Wed, 10 Jul 2013 11:14:06 +0200
changeset 86 88017f00714b
parent 32 06d7faebcb8d
child 87 017f45c5209f
permissions -rwxr-xr-x
Added tag V00.01.18 for changeset bd1c13cad4f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     1
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     2
/* 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     3
 *
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     4
  __  __      _            _       _              _                       
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     5
 |  \/  | ___| |_ __ _  __| | __ _| |_ __ _ _ __ | | __ _ _   _  ___ _ __ 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     6
 | |\/| |/ _ \ __/ _` |/ _` |/ _` | __/ _` | '_ \| |/ _` | | | |/ _ \ '__|
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     7
 | |  | |  __/ || (_| | (_| | (_| | || (_| | |_) | | (_| | |_| |  __/ |   
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     8
 |_|  |_|\___|\__\__,_|\__,_|\__,_|\__\__,_| .__/|_|\__,_|\__, |\___|_|   
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
     9
                                           |_|            |___/         
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    10
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    11
 *  Copyright 2010-2012 Institut de recherche et d'innovation 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    12
 *	contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    13
 *	 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    14
 *	contact@iri.centrepompidou.fr
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    15
 *	http://www.iri.centrepompidou.fr 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    16
 *	 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    17
 *	This software is a computer program whose purpose is to show and add annotations on a video .
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    18
 *	This software is governed by the CeCILL-C license under French law and
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    19
 *	abiding by the rules of distribution of free software. You can  use, 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    20
 *	modify and/ or redistribute the software under the terms of the CeCILL-C
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    21
 *	license as circulated by CEA, CNRS and INRIA at the following URL
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    22
 *	"http://www.cecill.info". 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    23
 *	
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    24
 *	The fact that you are presently reading this means that you have had
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    25
 *	knowledge of the CeCILL-C license and that you accept its terms.
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    26
*/
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    27
/* Initialization of the namespace */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    28
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    29
if (typeof window.IriSP === "undefined") {
32
06d7faebcb8d Some tweaks
veltr
parents: 18
diff changeset
    30
    window.IriSP = {
06d7faebcb8d Some tweaks
veltr
parents: 18
diff changeset
    31
        VERSION: "0.3.1"
06d7faebcb8d Some tweaks
veltr
parents: 18
diff changeset
    32
    };
3
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    33
}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    34
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    35
if (typeof IriSP.jQuery === "undefined" && typeof window.jQuery !== "undefined" && parseFloat(window.jQuery().jquery) >= 1.7) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    36
    IriSP.jQuery = window.jQuery;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    37
}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    38
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    39
if (typeof IriSP._ === "undefined" && typeof window._ !== "undefined" && parseFloat(window._.VERSION) >= 1.4) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    40
    IriSP._ = window._;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    41
}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    42
/* utils.js - various utils that don't belong anywhere else */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    43
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    44
IriSP.jqEscape = function(_text) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    45
    return _text.replace(/(:|\.)/g,'\\$1');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    46
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    47
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    48
IriSP.getLib = function(lib) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    49
    if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    50
        return IriSP.libFiles.cdn[lib];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    51
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    52
    if (typeof IriSP.libFiles.locations[lib] == "string") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    53
        return IriSP.libFiles.locations[lib];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    54
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    55
    if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    56
        return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    57
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    58
}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    59
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    60
IriSP._cssCache = [];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    61
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    62
IriSP.loadCss = function(_cssFile) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    63
    if (IriSP._(IriSP._cssCache).indexOf(_cssFile) === -1) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    64
        IriSP.jQuery("<link>", {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    65
            rel : "stylesheet",
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    66
            type : "text/css",
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    67
            href : _cssFile
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    68
        }).appendTo('head');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    69
        IriSP._cssCache.push(_cssFile);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    70
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    71
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    72
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    73
IriSP.textFieldHtml = function(_text, _regexp, _extend) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    74
    var list = [],
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    75
        positions = [],
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    76
        text = _text.replace(/(^\s+|\s+$)/g,'');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    77
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    78
    function addToList(_rx, _startHtml, _endHtml) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    79
        while(true) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    80
            var result = _rx.exec(text);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    81
            if (!result) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    82
                break;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    83
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    84
            var end = _rx.lastIndex,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    85
                start = result.index;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    86
            list.push({
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    87
                start: start,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    88
                end: end,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    89
                startHtml: (typeof _startHtml === "function" ? _startHtml(result) : _startHtml),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    90
                endHtml: (typeof _endHtml === "function" ? _endHtml(result) : _endHtml)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    91
            });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    92
            positions.push(start);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    93
            positions.push(end);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    94
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    95
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    96
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    97
    if (_regexp) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    98
        addToList(_regexp, '<span class="Ldt-Highlight">', '</span>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
    99
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   100
    
32
06d7faebcb8d Some tweaks
veltr
parents: 18
diff changeset
   101
    addToList(/(https?:\/\/)?[\w\d\-]+\.[\w\d\-]+\S+/gm, function(matches) {
3
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   102
        return '<a href="' + (matches[1] ? '' : 'http://') + matches[0] + '" target="_blank">'
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   103
    }, '</a>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   104
    addToList(/@([\d\w]{1,15})/gm, function(matches) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   105
        return '<a href="http://twitter.com/' + matches[1] + '" target="_blank">'
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   106
    }, '</a>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   107
    addToList(/\*[^*]+\*/gm, '<b>', '</b>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   108
    addToList(/[\n\r]+/gm, '', '<br />');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   109
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   110
    IriSP._(_extend).each(function(x) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   111
        addToList.apply(null, x);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   112
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   113
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   114
    positions = IriSP._(positions)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   115
        .chain()
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   116
        .uniq()
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   117
        .sortBy(function(p) { return parseInt(p) })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   118
        .value();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   119
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   120
    var res = "", lastIndex = 0;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   121
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   122
    for (var i = 0; i < positions.length; i++) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   123
        var pos = positions[i];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   124
        res += text.substring(lastIndex, pos);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   125
        for (var j = list.length - 1; j >= 0; j--) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   126
            var item = list[j];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   127
            if (item.start < pos && item.end >= pos) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   128
                res += item.endHtml;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   129
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   130
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   131
        for (var j = 0; j < list.length; j++) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   132
            var item = list[j];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   133
            if (item.start <= pos && item.end > pos) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   134
                res += item.startHtml;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   135
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   136
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   137
        lastIndex = pos;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   138
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   139
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   140
    res += text.substring(lastIndex);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   141
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   142
    return res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   143
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   144
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   145
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   146
IriSP.log = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   147
    if (typeof console !== "undefined" && typeof IriSP.logging !== "undefined" && IriSP.logging) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   148
        console.log.apply(console, arguments);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   149
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   150
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   151
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   152
IriSP.attachDndData = function(jqSel, data) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   153
	jqSel.attr("draggable", "true").on("dragstart", function(_event) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   154
		var d = (typeof data === "function" ? data.call(this) : data);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   155
		try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   156
			IriSP._(d).each(function(v, k) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   157
				if (v) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   158
					_event.originalEvent.dataTransfer.setData("text/x-iri-" + k, v);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   159
				}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   160
			});
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   161
		} catch(err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   162
			_event.originalEvent.dataTransfer.setData("Text", JSON.stringify(d));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   163
		}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   164
	});
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   165
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   166
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   167
IriSP.FakeClass = function(properties) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   168
    var _this = this,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   169
        noop = (function() {});
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   170
    IriSP._(properties).each(function(p) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   171
        _this[p] = noop
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   172
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   173
}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   174
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   175
/* js is where data is stored in a standard form, whatever the serializer */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   176
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   177
//TODO: Separate Project-specific data from Source
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   178
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   179
IriSP.Model = (function (ns) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   180
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   181
    function pad(n, x, b) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   182
        b = b || 10;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   183
        var s = (x).toString(b);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   184
        while (s.length < n) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   185
            s = "0" + s;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   186
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   187
        return s;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   188
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   189
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   190
    function rand16(n) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   191
        return pad(n, Math.floor(Math.random()*Math.pow(16,n)), 16);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   192
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   193
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   194
    var uidbase = rand16(8) + "-" + rand16(4) + "-", uidincrement = Math.floor(Math.random()*0x10000);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   195
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   196
    var charsub = [
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   197
        '[aáàâä]',
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   198
        '[cç]',
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   199
        '[eéèêë]',
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   200
        '[iíìîï]',
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   201
        '[oóòôö]',
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   202
        '[uùûü]'
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   203
    ];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   204
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   205
    var removeChars = [
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   206
        String.fromCharCode(768), String.fromCharCode(769), String.fromCharCode(770), String.fromCharCode(771), String.fromCharCode(807),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   207
        "{", "}", "(", ")", "[", "]", "【", "】", "、", "・", "‥", "。", "「", "」", "『", "』", "〜", ":", "!", "?", " ",
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   208
        ",", " ", ";", "(", ")", ".", "*", "+", "\\", "?", "|", "{", "}", "[", "]", "^", "#", "/"
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   209
    ];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   210
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   211
var Model = {},
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   212
    _SOURCE_STATUS_EMPTY = Model._SOURCE_STATUS_EMPTY = 0,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   213
    _SOURCE_STATUS_WAITING = Model._SOURCE_STATUS_WAITING = 1,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   214
    _SOURCE_STATUS_READY = Model._SOURCE_STATUS_READY = 2,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   215
    extendPrototype = Model.extendPrototype = function(toClass, fromClass) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   216
        var fromP = fromClass.prototype,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   217
            toP = toClass.prototype;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   218
        for (var k in fromP) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   219
            if (fromP.hasOwnProperty(k)) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   220
                toP[k] = fromP[k];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   221
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   222
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   223
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   224
    getUID = Model.getUID = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   225
        return uidbase + pad(4, (++uidincrement % 0x10000), 16) + "-" + rand16(4) + "-" + rand16(6) + rand16(6);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   226
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   227
    isLocalURL = Model.isLocalURL = function(url) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   228
        var matches = url.match(/^(\w+:)\/\/([^/]+)/);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   229
        if (matches) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   230
            return(matches[1] === document.location.protocol && matches[2] === document.location.host)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   231
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   232
        return true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   233
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   234
    regexpFromTextOrArray = Model.regexpFromTextOrArray = function(_textOrArray, _testOnly, _iexact) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   235
        var _testOnly = _testOnly || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   236
            _iexact = _iexact || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   237
        function escapeText(_text) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   238
            return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   239
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   240
        var _source = 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   241
            typeof _textOrArray === "string"
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   242
            ? escapeText(_textOrArray)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   243
            : ns._(_textOrArray).map(escapeText).join("|"),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   244
            _flags = 'im';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   245
        if (!_testOnly) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   246
            _source = '(' + _source + ')';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   247
            _flags += 'g';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   248
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   249
        if (_iexact) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   250
            _source = '^' + _source + '$';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   251
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   252
        return new RegExp( _source, _flags);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   253
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   254
    fullTextRegexps = Model.fullTextRegexps = function(_text) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   255
        var remsrc = "[\\" + removeChars.join("\\") + "]",
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   256
            remrx = new RegExp(remsrc,"gm"),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   257
            txt = _text.toLowerCase().replace(remrx,"")
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   258
            res = [],
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   259
            charsrx = ns._(charsub).map(function(c) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   260
                return new RegExp(c);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   261
            }),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   262
            src = "";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   263
        for (var j = 0; j < txt.length; j++) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   264
            if (j) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   265
                src += remsrc + "*";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   266
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   267
            var l = txt[j];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   268
            ns._(charsub).each(function(v, k) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   269
                l = l.replace(charsrx[k], v);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   270
            });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   271
            src += l;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   272
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   273
        return "(" + src + ")";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   274
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   275
    isoToDate = Model.isoToDate = function(_str) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   276
        // http://delete.me.uk/2005/03/iso8601.html
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   277
        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})))?)?)?)?";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   278
        var d = _str.match(new RegExp(regexp));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   279
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   280
        var offset = 0;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   281
        var date = new Date(d[1], 0, 1);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   282
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   283
        if (d[3]) { date.setMonth(d[3] - 1); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   284
        if (d[5]) { date.setDate(d[5]); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   285
        if (d[7]) { date.setHours(d[7]); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   286
        if (d[8]) { date.setMinutes(d[8]); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   287
        if (d[10]) { date.setSeconds(d[10]); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   288
        if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   289
        if (d[14]) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   290
            offset = (Number(d[16]) * 60) + Number(d[17]);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   291
            offset *= ((d[15] == '-') ? 1 : -1);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   292
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   293
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   294
        offset -= date.getTimezoneOffset();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   295
        time = (Number(date) + (offset * 60 * 1000));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   296
        var _res = new Date();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   297
        _res.setTime(Number(time));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   298
        return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   299
    },
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   300
    dateToIso = Model.dateToIso = function(_d) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   301
        var d = _d ? new Date(_d) : new Date();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   302
        return d.getUTCFullYear()+'-'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   303
            + pad(2, d.getUTCMonth()+1)+'-'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   304
            + pad(2, d.getUTCDate())+'T'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   305
            + pad(2, d.getUTCHours())+':'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   306
            + pad(2, d.getUTCMinutes())+':'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   307
            + pad(2, d.getUTCSeconds())+'Z'  
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   308
    };
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   309
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   310
/*
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   311
 * List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   312
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   313
var List = Model.List = function(_directory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   314
    Array.call(this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   315
    this.directory = _directory;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   316
    this.idIndex = [];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   317
    this.__events = {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   318
    if (typeof _directory == "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   319
        console.trace();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   320
        throw "Error : new List(directory): directory is undefined";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   321
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   322
    var _this =  this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   323
    this.on("clear-search", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   324
        _this.searching = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   325
        _this.regexp = undefined;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   326
        _this.forEach(function(_element) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   327
            _element.found = undefined;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   328
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   329
        _this.trigger("search-cleared");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   330
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   331
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   332
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   333
List.prototype = new Array();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   334
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   335
List.prototype.hasId = function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   336
    return ns._(this.idIndex).include(_id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   337
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   338
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   339
/* On recent browsers, forEach and map are defined and do what we want.
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   340
 * Otherwise, we'll use the Underscore.js functions
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   341
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   342
if (typeof Array.prototype.forEach === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   343
    List.prototype.forEach = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   344
        var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   345
        ns._(this).forEach(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   346
            _callback(_value, _key, _this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   347
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   348
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   349
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   350
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   351
if (typeof Array.prototype.map === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   352
    List.prototype.map = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   353
        var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   354
        return ns._(this).map(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   355
            return _callback(_value, _key, _this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   356
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   357
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   358
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   359
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   360
List.prototype.pluck = function(_key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   361
    return this.map(function(_value) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   362
        return _value[_key];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   363
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   364
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   365
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   366
/* We override Array's filter function because it doesn't return an List
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   367
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   368
List.prototype.filter = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   369
    var _this = this,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   370
        _res = new List(this.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   371
    _res.addElements(ns._(this).filter(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   372
        return _callback(_value, _key, _this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   373
    }));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   374
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   375
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   376
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   377
List.prototype.slice = function(_start, _end) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   378
    var _res = new List(this.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   379
    _res.addElements(Array.prototype.slice.call(this, _start, _end));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   380
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   381
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   382
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   383
List.prototype.splice = function(_start, _end) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   384
    var _res = new List(this.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   385
    _res.addElements(Array.prototype.splice.call(this, _start, _end));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   386
    this.idIndex.splice(_start, _end);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   387
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   388
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   389
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   390
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   391
 * and won't return a new List
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   392
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   393
List.prototype.sortBy = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   394
    var _this = this,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   395
        _res = new List(this.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   396
    _res.addElements(ns._(this).sortBy(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   397
        return _callback(_value, _key, _this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   398
    }));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   399
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   400
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   401
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   402
/* Title and Description are basic information for (almost) all element types,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   403
 * here we can search by these criteria
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   404
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   405
List.prototype.searchByTitle = function(_text, _iexact) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   406
    var _iexact = _iexact || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   407
        _rgxp = regexpFromTextOrArray(_text, true, _iexact);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   408
    return this.filter(function(_element) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   409
        return _rgxp.test(_element.title);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   410
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   411
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   412
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   413
List.prototype.searchByDescription = function(_text, _iexact) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   414
    var _iexact = _iexact || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   415
        _rgxp = regexpFromTextOrArray(_text, true, _iexact);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   416
    return this.filter(function(_element) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   417
        return _rgxp.test(_element.description);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   418
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   419
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   420
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   421
List.prototype.searchByTextFields = function(_text, _iexact) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   422
    var _iexact = _iexact || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   423
        _rgxp =  regexpFromTextOrArray(_text, true, _iexact);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   424
    return this.filter(function(_element) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   425
        var keywords = (_element.keywords || _element.getTagTexts() || []).join(", ");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   426
        return _rgxp.test(_element.description) || _rgxp.test(_element.title) || _rgxp.test(keywords);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   427
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   428
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   429
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   430
List.prototype.search = function(_text) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   431
    if (!_text) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   432
        this.trigger("clear-search");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   433
        return this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   434
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   435
    this.searching = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   436
    this.trigger("search", _text);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   437
    var rxsource = fullTextRegexps(_text)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   438
        rgxp = new RegExp(rxsource,"im"),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   439
        this.regexp = new RegExp(rxsource,"gim");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   440
    var res = this.filter(function(_element, _k) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   441
        var titlematch = rgxp.test(_element.title),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   442
            descmatch = rgxp.test(_element.description),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   443
            _isfound = !!(titlematch || descmatch);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   444
        _element.found = _isfound;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   445
        _element.trigger(_isfound ? "found" : "not-found");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   446
        return _isfound;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   447
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   448
    this.trigger(res.length ? "found" : "not-found",res);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   449
    return res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   450
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   451
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   452
List.prototype.getTitles = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   453
    return this.map(function(_el) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   454
        return _el.title;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   455
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   456
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   457
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   458
List.prototype.addId = function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   459
    var _el = this.directory.getElement(_id)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   460
    if (!this.hasId(_id) && typeof _el !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   461
        this.idIndex.push(_id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   462
        Array.prototype.push.call(this, _el);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   463
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   464
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   465
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   466
List.prototype.push = function(_el) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   467
    if (typeof _el === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   468
        return;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   469
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   470
    var _index = (ns._(this.idIndex).indexOf(_el.id));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   471
    if (_index === -1) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   472
        this.idIndex.push(_el.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   473
        Array.prototype.push.call(this, _el);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   474
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   475
        this[_index] = _el;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   476
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   477
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   478
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   479
List.prototype.addIds = function(_array) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   480
    var _l = _array.length,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   481
        _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   482
    ns._(_array).forEach(function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   483
        _this.addId(_id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   484
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   485
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   486
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   487
List.prototype.addElements = function(_array) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   488
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   489
    ns._(_array).forEach(function(_el) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   490
        _this.push(_el);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   491
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   492
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   493
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   494
List.prototype.removeId = function(_id, _deleteFromDirectory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   495
    var _deleteFromDirectory = _deleteFromDirectory || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   496
        _index = (ns._(this.idIndex).indexOf(_id));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   497
    if (_index !== -1) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   498
        this.splice(_index,1);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   499
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   500
    if (_deleteFromDirectory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   501
        delete this.directory.elements[_id];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   502
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   503
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   504
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   505
List.prototype.removeElement = function(_el, _deleteFromDirectory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   506
    var _deleteFromDirectory = _deleteFromDirectory || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   507
    this.removeId(_el.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   508
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   509
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   510
List.prototype.removeIds = function(_list, _deleteFromDirectory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   511
    var _deleteFromDirectory = _deleteFromDirectory || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   512
        _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   513
    ns._(_list).forEach(function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   514
        _this.removeId(_id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   515
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   516
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   517
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   518
List.prototype.removeElements = function(_list, _deleteFromDirectory) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   519
    var _deleteFromDirectory = _deleteFromDirectory || false,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   520
        _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   521
    ns._(_list).forEach(function(_el) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   522
        _this.removeElement(_el);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   523
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   524
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   525
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   526
List.prototype.on = function(_event, _callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   527
    if (typeof this.__events[_event] === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   528
        this.__events[_event] = [];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   529
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   530
    this.__events[_event].push(_callback);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   531
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   532
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   533
List.prototype.off = function(_event, _callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   534
    if (typeof this.__events[_event] !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   535
        this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   536
            return _fn === _callback;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   537
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   538
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   539
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   540
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   541
List.prototype.trigger = function(_event, _data) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   542
    var _list = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   543
    ns._(this.__events[_event]).each(function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   544
        _callback.call(_list, _data);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   545
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   546
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   547
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   548
/* A simple time management object, that helps converting millisecs to seconds and strings,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   549
 * without the clumsiness of the original Date object.
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   550
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   551
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   552
var Time = Model.Time = function(_milliseconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   553
    this.milliseconds = 0;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   554
    this.setMilliseconds(_milliseconds);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   555
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   556
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   557
Time.prototype.setMilliseconds = function(_milliseconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   558
    var _ante = this.milliseconds;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   559
    switch(typeof _milliseconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   560
        case "string":
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   561
            this.milliseconds = parseInt(_milliseconds);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   562
            break;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   563
        case "number":
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   564
            this.milliseconds = Math.floor(_milliseconds);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   565
            break;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   566
        case "object":
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   567
            this.milliseconds = parseInt(_milliseconds.valueOf());
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   568
            break;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   569
        default:
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   570
            this.milliseconds = 0;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   571
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   572
    if (this.milliseconds === NaN) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   573
        this.milliseconds = _ante;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   574
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   575
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   576
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   577
Time.prototype.setSeconds = function(_seconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   578
    this.milliseconds = 1000 * _seconds;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   579
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   580
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   581
Time.prototype.getSeconds = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   582
    return this.milliseconds / 1000;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   583
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   584
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   585
Time.prototype.getHMS = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   586
    var _totalSeconds = Math.abs(Math.floor(this.getSeconds()));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   587
    return {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   588
        hours : Math.floor(_totalSeconds / 3600),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   589
        minutes : (Math.floor(_totalSeconds / 60) % 60),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   590
        seconds : _totalSeconds % 60,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   591
        milliseconds: this.milliseconds % 1000
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   592
    } 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   593
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   594
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   595
Time.prototype.add = function(_milliseconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   596
    this.milliseconds += new Time(_milliseconds).milliseconds;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   597
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   598
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   599
Time.prototype.valueOf = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   600
    return this.milliseconds;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   601
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   602
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   603
Time.prototype.toString = function(showCs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   604
    var _hms = this.getHMS(),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   605
        _res = '';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   606
    if (_hms.hours) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   607
        _res += _hms.hours + ':'
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   608
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   609
    _res += pad(2, _hms.minutes) + ':' + pad(2, _hms.seconds);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   610
    if (showCs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   611
        _res += "." + Math.floor(_hms.milliseconds / 100)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   612
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   613
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   614
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   615
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   616
/* Reference handles references between elements
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   617
 */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   618
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   619
var Reference = Model.Reference = function(_source, _idRef) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   620
    this.source = _source;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   621
    this.id = _idRef;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   622
    if (typeof _idRef === "object") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   623
        this.isList = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   624
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   625
        this.isList = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   626
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   627
    this.refresh();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   628
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   629
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   630
Reference.prototype.refresh = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   631
    if (this.isList) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   632
        this.contents = new List(this.source.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   633
        this.contents.addIds(this.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   634
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   635
        this.contents = this.source.getElement(this.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   636
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   637
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   638
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   639
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   640
Reference.prototype.getContents = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   641
    if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   642
        this.refresh();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   643
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   644
    return this.contents;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   645
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   646
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   647
Reference.prototype.isOrHasId = function(_idRef) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   648
    if (this.isList) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   649
        return (ns._(this.id).indexOf(_idRef) !== -1)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   650
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   651
        return (this.id == _idRef);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   652
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   653
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   654
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   655
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   656
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   657
var BaseElement = Model.Element = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   658
    this.elementType = 'element';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   659
    this.title = "";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   660
    this.description = "";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   661
    this.__events = {}
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   662
    if (typeof _source === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   663
        return;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   664
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   665
    if (typeof _id === "undefined" || !_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   666
        _id = getUID();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   667
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   668
    this.id = _id;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   669
    this.source = _source;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   670
    if (_source !== this) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   671
        this.source.directory.addElement(this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   672
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   673
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   674
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   675
BaseElement.prototype.toString = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   676
    return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : '');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   677
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   678
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   679
BaseElement.prototype.setReference = function(_elementType, _idRef) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   680
    this[_elementType] = new Reference(this.source, _idRef);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   681
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   682
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   683
BaseElement.prototype.getReference = function(_elementType) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   684
    if (typeof this[_elementType] !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   685
        return this[_elementType].getContents();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   686
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   687
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   688
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   689
BaseElement.prototype.getRelated = function(_elementType, _global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   690
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   691
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   692
    return this.source.getList(_elementType, _global).filter(function(_el) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   693
        var _ref = _el[_this.elementType];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   694
        return _ref && _ref.isOrHasId(_this.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   695
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   696
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   697
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   698
BaseElement.prototype.on = function(_event, _callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   699
    if (typeof this.__events[_event] === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   700
        this.__events[_event] = [];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   701
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   702
    this.__events[_event].push(_callback);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   703
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   704
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   705
BaseElement.prototype.off = function(_event, _callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   706
    if (typeof this.__events[_event] !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   707
        this.__events[_event] = ns._(this.__events[_event]).reject(function(_fn) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   708
            return _fn === _callback;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   709
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   710
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   711
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   712
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   713
BaseElement.prototype.trigger = function(_event, _data) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   714
    var _element = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   715
    ns._(this.__events[_event]).each(function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   716
        _callback.call(_element, _data);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   717
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   718
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   719
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   720
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   721
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   722
var Playable = Model.Playable = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   723
    BaseElement.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   724
    if (typeof _source === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   725
        return;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   726
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   727
    this.elementType = 'playable';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   728
    this.currentTime = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   729
    this.volume = .5;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   730
    this.paused = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   731
    this.muted = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   732
    this.loadedMetadata = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   733
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   734
    this.on("play", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   735
        _this.paused = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   736
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   737
    this.on("pause", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   738
        _this.paused = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   739
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   740
    this.on("timeupdate", function(_time) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   741
        _this.currentTime = _time;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   742
        _this.getAnnotations().filter(function(_a) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   743
            return (_a.end <= _time || _a.begin > _time) && _a.playing
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   744
        }).forEach(function(_a) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   745
            _a.playing = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   746
            _a.trigger("leave");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   747
            _this.trigger("leave-annotation",_a);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   748
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   749
        _this.getAnnotations().filter(function(_a) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   750
            return _a.begin <= _time && _a.end > _time && !_a.playing
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   751
        }).forEach(function(_a) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   752
            _a.playing = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   753
            _a.trigger("enter");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   754
            _this.trigger("enter-annotation",_a);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   755
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   756
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   757
    this.on("loadedmetadata", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   758
        _this.loadedMetadata = true;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   759
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   760
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   761
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   762
extendPrototype(Playable, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   763
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   764
Playable.prototype.getCurrentTime = function() { 
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   765
    return this.currentTime;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   766
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   767
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   768
Playable.prototype.getVolume = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   769
    return this.volume;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   770
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   771
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   772
Playable.prototype.getPaused = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   773
    return this.paused;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   774
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   775
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   776
Playable.prototype.getMuted = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   777
    return this.muted;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   778
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   779
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   780
Playable.prototype.setCurrentTime = function(_time) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   781
    this.trigger("setcurrenttime",_time);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   782
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   783
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   784
Playable.prototype.setVolume = function(_vol) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   785
    this.trigger("setvolume",_vol);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   786
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   787
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   788
Playable.prototype.setMuted = function(_muted) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   789
    this.trigger("setmuted",_muted);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   790
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   791
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   792
Playable.prototype.play = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   793
    this.trigger("setplay");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   794
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   795
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   796
Playable.prototype.pause = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   797
    this.trigger("setpause");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   798
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   799
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   800
Playable.prototype.show = function() {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   801
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   802
Playable.prototype.hide = function() {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   803
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   804
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   805
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   806
var Media = Model.Media = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   807
    Playable.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   808
    this.elementType = 'media';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   809
    this.duration = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   810
    this.video = '';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   811
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   812
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   813
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   814
extendPrototype(Media, Playable);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   815
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   816
/* Default functions to be overriden by players */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   817
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   818
Media.prototype.setDuration = function(_durationMs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   819
    this.duration.setMilliseconds(_durationMs);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   820
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   821
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   822
Media.prototype.getAnnotations = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   823
    return this.getRelated("annotation");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   824
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   825
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   826
Media.prototype.getAnnotationsByTypeTitle = function(_title) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   827
    var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   828
    if (_annTypes.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   829
        return this.getAnnotations().filter(function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   830
            return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   831
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   832
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   833
        return new List(this.source.directory)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   834
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   835
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   836
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   837
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   838
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   839
var Tag = Model.Tag = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   840
    BaseElement.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   841
    this.elementType = 'tag';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   842
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   843
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   844
extendPrototype(Tag, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   845
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   846
Tag.prototype.getAnnotations = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   847
    return this.getRelated("annotation");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   848
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   849
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   850
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   851
var AnnotationType = Model.AnnotationType = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   852
    BaseElement.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   853
    this.elementType = 'annotationType';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   854
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   855
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   856
extendPrototype(AnnotationType, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   857
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   858
AnnotationType.prototype.getAnnotations = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   859
    return this.getRelated("annotation");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   860
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   861
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   862
/* Annotation
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   863
 * */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   864
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   865
var Annotation = Model.Annotation = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   866
    BaseElement.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   867
    this.elementType = 'annotation';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   868
    this.begin = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   869
    this.end = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   870
    this.tag = new Reference(_source, []);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   871
    this.playing = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   872
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   873
    this.on("click", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   874
        _this.getMedia().setCurrentTime(_this.begin);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   875
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   876
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   877
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   878
extendPrototype(Annotation, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   879
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   880
Annotation.prototype.setBegin = function(_beginMs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   881
    this.begin.setMilliseconds(Math.max(0,_beginMs));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   882
    this.trigger("change-begin");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   883
    if (this.end < this.begin) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   884
        this.setEnd(this.begin);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   885
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   886
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   887
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   888
Annotation.prototype.setEnd = function(_endMs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   889
    this.end.setMilliseconds(Math.min(_endMs, this.getMedia().duration.milliseconds));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   890
    this.trigger("change-end");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   891
    if (this.end < this.begin) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   892
        this.setBegin(this.end);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   893
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   894
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   895
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   896
Annotation.prototype.setDuration = function(_durMs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   897
    this.setEnd(_durMs + this.begin.milliseconds);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   898
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   899
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   900
Annotation.prototype.setMedia = function(_idRef) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   901
    this.setReference("media", _idRef);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   902
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   903
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   904
Annotation.prototype.getMedia = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   905
    return this.getReference("media");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   906
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   907
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   908
Annotation.prototype.setAnnotationType = function(_idRef) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   909
    this.setReference("annotationType", _idRef);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   910
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   911
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   912
Annotation.prototype.getAnnotationType = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   913
    return this.getReference("annotationType");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   914
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   915
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   916
Annotation.prototype.setTags = function(_idRefs) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   917
    this.setReference("tag", _idRefs);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   918
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   919
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   920
Annotation.prototype.getTags = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   921
    return this.getReference("tag");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   922
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   923
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   924
Annotation.prototype.getTagTexts = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   925
    return this.getTags().getTitles();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   926
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   927
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   928
Annotation.prototype.getDuration = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   929
    return new Time(this.end.milliseconds - this.begin.milliseconds)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   930
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   931
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   932
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   933
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   934
var MashedAnnotation = Model.MashedAnnotation = function(_mashup, _annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   935
    BaseElement.call(this, _mashup.id + "_" + _annotation.id, _annotation.source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   936
    this.elementType = 'mashedAnnotation';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   937
    this.annotation = _annotation;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   938
    this.begin = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   939
    this.end = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   940
    this.duration = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   941
    this.title = this.annotation.title;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   942
    this.description = this.annotation.description;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   943
    this.color = this.annotation.color;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   944
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   945
    this.on("click", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   946
        _mashup.setCurrentTime(_this.begin);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   947
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   948
    this.on("enter", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   949
        _this.annotation.trigger("enter");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   950
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   951
    this.on("leave", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   952
        _this.annotation.trigger("leave");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   953
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   954
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   955
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   956
extendPrototype(MashedAnnotation, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   957
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   958
MashedAnnotation.prototype.getMedia = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   959
    return this.annotation.getReference("media");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   960
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   961
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   962
MashedAnnotation.prototype.getAnnotationType = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   963
    return this.annotation.getReference("annotationType");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   964
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   965
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   966
MashedAnnotation.prototype.getTags = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   967
    return this.annotation.getReference("tag");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   968
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   969
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   970
MashedAnnotation.prototype.getTagTexts = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   971
    return this.annotation.getTags().getTitles();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   972
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   973
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   974
MashedAnnotation.prototype.getDuration = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   975
    return this.annotation.getDuration();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   976
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   977
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   978
MashedAnnotation.prototype.setBegin = function(_begin) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   979
    this.begin.setMilliseconds(_begin);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   980
    this.duration.setMilliseconds(this.annotation.getDuration());
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   981
    this.end.setMilliseconds(_begin + this.duration);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   982
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   983
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   984
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   985
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   986
var Mashup = Model.Mashup = function(_id, _source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   987
    Playable.call(this, _id, _source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   988
    this.elementType = 'mashup';
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   989
    this.duration = new Time();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   990
    this.segments = new List(_source.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   991
    this.loaded = false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   992
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   993
    this._updateTimes = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   994
        _this.updateTimes();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   995
        _this.trigger("change");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   996
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   997
    this.on("add", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   998
    this.on("remove", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
   999
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1000
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1001
extendPrototype(Mashup, Playable);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1002
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1003
Mashup.prototype.updateTimes = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1004
    var _time = 0;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1005
    this.segments.forEach(function(_segment) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1006
        _segment.setBegin(_time);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1007
        _time = _segment.end;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1008
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1009
    this.duration.setMilliseconds(_time);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1010
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1011
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1012
Mashup.prototype.addAnnotation = function(_annotation, _defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1013
    var _mashedAnnotation = new MashedAnnotation(this, _annotation),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1014
        _defer = _defer || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1015
    this.segments.push(_mashedAnnotation);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1016
    _annotation.on("change-begin", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1017
    _annotation.on("change-end", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1018
    if (!_defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1019
        this.trigger("add");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1020
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1021
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1022
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1023
Mashup.prototype.addAnnotationById = function(_elId, _defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1024
    var _annotation = this.source.getElement(_elId),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1025
        _defer = _defer || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1026
    if (typeof _annotation !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1027
        this.addAnnotation(_annotation, _defer);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1028
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1029
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1030
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1031
Mashup.prototype.addAnnotations = function(_segments) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1032
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1033
    ns._(_segments).forEach(function(_segment) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1034
        _this.addAnnotation(_segment, true);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1035
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1036
    this.trigger("add");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1037
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1038
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1039
Mashup.prototype.addAnnotationsById = function(_segments) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1040
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1041
    ns._(_segments).forEach(function(_segment) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1042
        _this.addAnnotationById(_segment, true);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1043
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1044
    this.trigger("add");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1045
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1046
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1047
Mashup.prototype.removeAnnotation = function(_annotation, _defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1048
    var _defer = _defer || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1049
    _annotation.off("change-begin", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1050
    _annotation.off("change-end", this._updateTimes);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1051
    this.segments.removeId(this.id + "_" + _annotation.id);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1052
    if (!_defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1053
        this.trigger("remove");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1054
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1055
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1056
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1057
Mashup.prototype.removeAnnotationById = function(_annId, _defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1058
    var _defer = _defer || false;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1059
    var _annotation = this.source.getElement(_annId);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1060
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1061
    if (_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1062
        this.removeAnnotation(_annotation, _defer);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1063
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1064
    if (!_defer) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1065
        this.trigger("remove");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1066
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1067
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1068
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1069
Mashup.prototype.setAnnotations = function(_segments) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1070
    while (this.segments.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1071
        this.removeAnnotation(this.segments[0].annotation, true);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1072
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1073
    this.addAnnotations(_segments);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1074
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1075
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1076
Mashup.prototype.setAnnotationsById = function(_segments) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1077
    while (this.segments.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1078
        this.removeAnnotation(this.segments[0].annotation, true);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1079
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1080
    this.addAnnotationsById(_segments);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1081
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1082
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1083
Mashup.prototype.hasAnnotation = function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1084
    return !!ns._(this.segments).find(function(_s) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1085
        return _s.annotation === _annotation
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1086
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1087
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1088
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1089
Mashup.prototype.getAnnotation = function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1090
    return ns._(this.segments).find(function(_s) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1091
        return _s.annotation === _annotation
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1092
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1093
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1094
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1095
Mashup.prototype.getAnnotationById = function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1096
    return ns._(this.segments).find(function(_s) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1097
        return _s.annotation.id === _id
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1098
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1099
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1100
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1101
Mashup.prototype.getAnnotations = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1102
    return this.segments;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1103
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1104
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1105
Mashup.prototype.getOriginalAnnotations = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1106
    var annotations = new List(this.source.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1107
    this.segments.forEach(function(_s) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1108
        annotations.push(_s.annotation);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1109
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1110
    return annotations;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1111
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1112
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1113
Mashup.prototype.getMedias = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1114
    var medias = new List(this.source.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1115
    this.segments.forEach(function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1116
        medias.push(_annotation.getMedia())
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1117
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1118
    return medias;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1119
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1120
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1121
Mashup.prototype.getAnnotationsByTypeTitle = function(_title) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1122
    var _annTypes = this.source.getAnnotationTypes().searchByTitle(_title).pluck("id");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1123
    if (_annTypes.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1124
        return this.getAnnotations().filter(function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1125
            return ns._(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1126
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1127
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1128
        return new List(this.source.directory)
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1129
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1130
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1131
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1132
Mashup.prototype.getAnnotationAtTime = function(_time) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1133
    var _list = this.segments.filter(function(_annotation) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1134
        return _annotation.begin <= _time && _annotation.end > _time;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1135
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1136
    if (_list.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1137
        return _list[0];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1138
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1139
        return undefined;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1140
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1141
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1142
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1143
Mashup.prototype.getMediaAtTime = function(_time) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1144
    var _annotation = this.getAnnotationAtTime(_time);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1145
    if (typeof _annotation !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1146
        return _annotation.getMedia();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1147
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1148
        return undefined;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1149
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1150
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1151
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1152
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1153
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1154
var Source = Model.Source = function(_config) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1155
    BaseElement.call(this, false, this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1156
    this.status = _SOURCE_STATUS_EMPTY;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1157
    this.elementType = "source";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1158
    if (typeof _config !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1159
        var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1160
        ns._(_config).forEach(function(_v, _k) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1161
            _this[_k] = _v;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1162
        })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1163
        this.callbackQueue = [];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1164
        this.contents = {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1165
        this.get();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1166
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1167
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1168
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1169
extendPrototype(Source, BaseElement);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1170
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1171
Source.prototype.addList = function(_listId, _contents) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1172
    if (typeof this.contents[_listId] === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1173
        this.contents[_listId] = new List(this.directory);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1174
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1175
    this.contents[_listId].addElements(_contents);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1176
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1177
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1178
Source.prototype.getList = function(_listId, _global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1179
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1180
    if (_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1181
        return this.directory.getGlobalList().filter(function(_e) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1182
            return (_e.elementType === _listId);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1183
        });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1184
    } else {
18
b8a45e2fd6fd Updated player styles, full screen, new fonts
veltr
parents: 3
diff changeset
  1185
        if (typeof this.contents[_listId] === "undefined") {
b8a45e2fd6fd Updated player styles, full screen, new fonts
veltr
parents: 3
diff changeset
  1186
            this.contents[_listId] = new IriSP.List(this.directory);
b8a45e2fd6fd Updated player styles, full screen, new fonts
veltr
parents: 3
diff changeset
  1187
        }
b8a45e2fd6fd Updated player styles, full screen, new fonts
veltr
parents: 3
diff changeset
  1188
        return this.contents[_listId];
3
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1189
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1190
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1191
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1192
Source.prototype.forEach = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1193
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1194
    ns._(this.contents).forEach(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1195
        _callback.call(_this, _value, _key);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1196
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1197
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1198
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1199
Source.prototype.getElement = function(_elId) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1200
    return this.directory.getElement(_elId);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1201
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1202
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1203
Source.prototype.get = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1204
    this.status = _SOURCE_STATUS_WAITING;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1205
    this.handleCallbacks();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1206
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1207
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1208
/* We defer the callbacks calls so they execute after the queue is cleared */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1209
Source.prototype.deferCallback = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1210
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1211
    ns._.defer(function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1212
        _callback.call(_this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1213
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1214
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1215
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1216
Source.prototype.handleCallbacks = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1217
    this.status = _SOURCE_STATUS_READY;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1218
    while (this.callbackQueue.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1219
        this.deferCallback(this.callbackQueue.splice(0,1)[0]);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1220
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1221
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1222
Source.prototype.onLoad = function(_callback) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1223
    if (this.status === _SOURCE_STATUS_READY) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1224
        this.deferCallback(_callback);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1225
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1226
        this.callbackQueue.push(_callback);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1227
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1228
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1229
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1230
Source.prototype.serialize = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1231
    return this.serializer.serialize(this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1232
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1233
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1234
Source.prototype.deSerialize = function(_data) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1235
    this.serializer.deSerialize(_data, this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1236
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1237
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1238
Source.prototype.getAnnotations = function(_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1239
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1240
    return this.getList("annotation", _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1241
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1242
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1243
Source.prototype.getMedias = function(_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1244
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1245
    return this.getList("media", _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1246
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1247
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1248
Source.prototype.getTags = function(_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1249
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1250
    return this.getList("tag", _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1251
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1252
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1253
Source.prototype.getMashups = function(_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1254
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1255
    return this.getList("mashup", _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1256
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1257
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1258
Source.prototype.getAnnotationTypes = function(_global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1259
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1260
    return this.getList("annotationType", _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1261
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1262
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1263
Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1264
    _global = (typeof _global !== "undefined" && _global);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1265
    var _res = new List(this.directory),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1266
        _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1267
    _annTypes.forEach(function(_annType) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1268
        _res.addElements(_annType.getAnnotations(_global));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1269
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1270
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1271
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1272
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1273
Source.prototype.getDuration = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1274
    var _m = this.currentMedia;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1275
    if (typeof _m !== "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1276
        return this.currentMedia.duration;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1277
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1278
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1279
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1280
Source.prototype.getCurrentMedia = function(_opts) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1281
    if (typeof this.currentMedia === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1282
        if (_opts.is_mashup) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1283
            var _mashups = this.getMashups();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1284
            if (_mashups.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1285
                this.currentMedia = _mashups[0];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1286
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1287
        } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1288
            var _medias = this.getMedias();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1289
            if (_medias.length) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1290
                this.currentMedia = _medias[0];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1291
            }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1292
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1293
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1294
    return this.currentMedia;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1295
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1296
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1297
Source.prototype.merge = function(_source) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1298
    var _this = this;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1299
    _source.forEach(function(_value, _key) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1300
        _this.getList(_key).addElements(_value);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1301
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1302
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1303
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1304
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1305
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1306
var RemoteSource = Model.RemoteSource = function(_config) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1307
    Source.call(this, _config);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1308
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1309
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1310
extendPrototype(RemoteSource, Source);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1311
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1312
RemoteSource.prototype.get = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1313
    this.status = _SOURCE_STATUS_WAITING;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1314
    var _this = this,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1315
        urlparams = this.url_params || {},
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1316
        dataType = (isLocalURL(this.url) ? "json" : "jsonp");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1317
    urlparams.format = dataType;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1318
    ns.jQuery.ajax({
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1319
        url: this.url,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1320
        dataType: dataType,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1321
        data: urlparams,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1322
        traditional: true,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1323
        success: function(_result) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1324
            _this.deSerialize(_result);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1325
            _this.handleCallbacks();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1326
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1327
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1328
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1329
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1330
/* */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1331
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1332
var Directory = Model.Directory = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1333
    this.remoteSources = {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1334
    this.elements = {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1335
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1336
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1337
Directory.prototype.remoteSource = function(_properties) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1338
    if (typeof _properties !== "object" || typeof _properties.url === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1339
        throw "Error : Directory.remoteSource(configuration): configuration.url is undefined";
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1340
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1341
    var _config = ns._({ directory: this }).extend(_properties);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1342
    _config.url_params = _config.url_params || {};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1343
    var _hash = _config.url + "?" + ns.jQuery.param(_config.url_params);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1344
    if (typeof this.remoteSources[_hash] === "undefined") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1345
        this.remoteSources[_hash] = new RemoteSource(_config);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1346
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1347
    return this.remoteSources[_hash];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1348
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1349
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1350
Directory.prototype.newLocalSource = function(_properties) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1351
    var _config = ns._({ directory: this }).extend(_properties),
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1352
        _res = new Source(_config);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1353
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1354
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1355
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1356
Directory.prototype.getElement = function(_id) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1357
    return this.elements[_id];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1358
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1359
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1360
Directory.prototype.addElement = function(_element) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1361
    this.elements[_element.id] = _element;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1362
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1363
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1364
Directory.prototype.getGlobalList = function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1365
    var _res = new List(this);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1366
    _res.addIds(ns._(this.elements).keys());
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1367
    return _res;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1368
};
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1369
return Model;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1370
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1371
})(IriSP);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1372
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1373
/* END js */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1374
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1375
/* HTML player, to be reused in a widget, or elsewhere */
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1376
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1377
IriSP.htmlPlayer = function(media, jqselector, options) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1378
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1379
    var opts = options || {},
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1380
        videoURL = opts.video || media.video;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1381
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1382
    if (typeof opts.url_transform === "function") {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1383
        videoURL = opts.url_transform(videoURL);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1384
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1385
        
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1386
    var videoEl = IriSP.jQuery('<video>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1387
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1388
    videoEl.attr({
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1389
        width : opts.width || undefined,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1390
        height : opts.height || undefined,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1391
        controls : opts.controls || undefined,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1392
        autoplay : opts.autostart || opts.autoplay || undefined
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1393
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1394
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1395
    if(typeof videoURL === "string"){
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1396
        videoEl.attr("src",videoURL);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1397
    } else {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1398
        for (var i = 0; i < videoURL.length; i++) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1399
            var _srcNode = IriSP.jQuery('<source>');
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1400
            _srcNode.attr({
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1401
                src: videoURL[i].src,
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1402
                type: videoURL[i].type
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1403
            });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1404
            videoEl.append(_srcNode);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1405
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1406
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1407
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1408
    jqselector.html(videoEl);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1409
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1410
    var mediaEl = videoEl[0];
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1411
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1412
    // Binding HTML video functions to media events
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1413
    media.on("setcurrenttime", function(_milliseconds) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1414
        try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1415
            mediaEl.currentTime = (_milliseconds / 1000);
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1416
        } catch (err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1417
            
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1418
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1419
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1420
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1421
    media.on("setvolume", function(_vol) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1422
        media.volume = _vol;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1423
        try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1424
            mediaEl.volume = _vol;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1425
        } catch (err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1426
            
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1427
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1428
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1429
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1430
    media.on("setmuted", function(_muted) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1431
        media.muted = _muted;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1432
        try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1433
            mediaEl.muted = _muted;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1434
        } catch (err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1435
            
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1436
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1437
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1438
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1439
    media.on("setplay", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1440
        try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1441
            mediaEl.play();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1442
        } catch (err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1443
            
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1444
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1445
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1446
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1447
    media.on("setpause", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1448
        try {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1449
            mediaEl.pause();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1450
        } catch (err) {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1451
            
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1452
        }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1453
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1454
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1455
    // Binding DOM events to media
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1456
    function getVolume() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1457
        media.muted = mediaEl.muted;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1458
        media.volume = mediaEl.volume;
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1459
    }
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1460
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1461
    videoEl.on("loadedmetadata", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1462
        getVolume();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1463
        media.trigger("loadedmetadata");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1464
        media.trigger("volumechange");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1465
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1466
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1467
    videoEl.on("timeupdate", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1468
        media.trigger("timeupdate", new IriSP.Model.Time(1000*mediaEl.currentTime));
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1469
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1470
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1471
    videoEl.on("volumechange", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1472
        getVolume();
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1473
        media.trigger("volumechange");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1474
    })
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1475
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1476
    videoEl.on("play", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1477
        media.trigger("play");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1478
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1479
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1480
    videoEl.on("pause", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1481
        media.trigger("pause");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1482
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1483
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1484
    videoEl.on("seeking", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1485
        media.trigger("seeking");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1486
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1487
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1488
    videoEl.on("seeked", function() {
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1489
        media.trigger("seeked");
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1490
    });
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1491
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1492
    
5a4dd4e6bbe7 Video and soundcloud player
veltr
parents:
diff changeset
  1493
};