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