web/res/js/LdtPlayer-release.js
author Raphael Velt <raph.velt@gmail.com>
Thu, 29 Mar 2012 16:21:06 +0200
changeset 573 6ec62b3610c8
parent 535 8276f3ff7a3f
child 581 7607516bd9f1
permissions -rw-r--r--
Update metadataplayer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     1
/* 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     2
 * 	
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     3
 *	Copyright 2010-2012 Institut de recherche et d'innovation 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
     4
 *	contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     5
 *	 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     6
 *	contact@iri.centrepompidou.fr
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     7
 *	http://www.iri.centrepompidou.fr 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     8
 *	 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     9
 *	This software is a computer program whose purpose is to show and add annotations on a video .
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    10
 *	This software is governed by the CeCILL-C license under French law and
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    11
 *	abiding by the rules of distribution of free software. You can  use, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    12
 *	modify and/ or redistribute the software under the terms of the CeCILL-C
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    13
 *	license as circulated by CEA, CNRS and INRIA at the following URL
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    14
 *	"http://www.cecill.info". 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    15
 *	
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    16
 *	The fact that you are presently reading this means that you have had
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    17
 *	knowledge of the CeCILL-C license and that you accept its terms.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    18
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    19
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    20
    v2.0.3 (c) Kyle Simpson
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    21
    MIT License
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    22
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    23
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    24
(function(global){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    25
	var _$LAB = global.$LAB,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    26
	
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    27
		// constants for the valid keys of the options object
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    28
		_UseLocalXHR = "UseLocalXHR",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    29
		_AlwaysPreserveOrder = "AlwaysPreserveOrder",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    30
		_AllowDuplicates = "AllowDuplicates",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    31
		_CacheBust = "CacheBust",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    32
		/*!START_DEBUG*/_Debug = "Debug",/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    33
		_BasePath = "BasePath",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    34
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    35
		// stateless variables used across all $LAB instances
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    36
		root_page = /^[^?#]*\//.exec(location.href)[0],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    37
		root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    38
		append_to = document.head || document.getElementsByTagName("head"),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    39
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    40
		// inferences... ick, but still necessary
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    41
		opera_or_gecko = (global.opera && Object.prototype.toString.call(global.opera) == "[object Opera]") || ("MozAppearance" in document.documentElement.style),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    42
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    43
/*!START_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    44
		// console.log() and console.error() wrappers
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    45
		log_msg = function(){}, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    46
		log_error = log_msg,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    47
/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    48
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    49
		// feature sniffs (yay!)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    50
		test_script_elem = document.createElement("script"),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    51
		explicit_preloading = typeof test_script_elem.preload == "boolean", // http://wiki.whatwg.org/wiki/Script_Execution_Control#Proposal_1_.28Nicholas_Zakas.29
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    52
		real_preloading = explicit_preloading || (test_script_elem.readyState && test_script_elem.readyState == "uninitialized"), // will a script preload with `src` set before DOM append?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    53
		script_ordered_async = !real_preloading && test_script_elem.async === true, // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    54
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    55
		// XHR preloading (same-domain) and cache-preloading (remote-domain) are the fallbacks (for some browsers)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    56
		xhr_or_cache_preloading = !real_preloading && !script_ordered_async && !opera_or_gecko
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    57
	;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    58
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    59
/*!START_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    60
	// define console wrapper functions if applicable
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    61
	if (global.console && global.console.log) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    62
		if (!global.console.error) global.console.error = global.console.log;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    63
		log_msg = function(msg) { global.console.log(msg); };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    64
		log_error = function(msg,err) { global.console.error(msg,err); };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    65
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    66
/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    67
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    68
	// test for function
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    69
	function is_func(func) { return Object.prototype.toString.call(func) == "[object Function]"; }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    70
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    71
	// test for array
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    72
	function is_array(arr) { return Object.prototype.toString.call(arr) == "[object Array]"; }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    73
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    74
	// make script URL absolute/canonical
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    75
	function canonical_uri(src,base_path) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    76
		var absolute_regex = /^\w+\:\/\//;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    77
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    78
		// is `src` is protocol-relative (begins with // or ///), prepend protocol
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    79
		if (/^\/\/\/?/.test(src)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    80
			src = location.protocol + src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    81
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    82
		// is `src` page-relative? (not an absolute URL, and not a domain-relative path, beginning with /)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    83
		else if (!absolute_regex.test(src) && src.charAt(0) != "/") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    84
			// prepend `base_path`, if any
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    85
			src = (base_path || "") + src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    86
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    87
		// make sure to return `src` as absolute
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    88
		return absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    89
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    90
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    91
	// merge `source` into `target`
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    92
	function merge_objs(source,target) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    93
		for (var k in source) { if (source.hasOwnProperty(k)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    94
			target[k] = source[k]; // TODO: does this need to be recursive for our purposes?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    95
		}}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    96
		return target;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    97
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    98
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    99
	// does the chain group have any ready-to-execute scripts?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   100
	function check_chain_group_scripts_ready(chain_group) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   101
		var any_scripts_ready = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   102
		for (var i=0; i<chain_group.scripts.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   103
			if (chain_group.scripts[i].ready && chain_group.scripts[i].exec_trigger) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   104
				any_scripts_ready = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   105
				chain_group.scripts[i].exec_trigger();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   106
				chain_group.scripts[i].exec_trigger = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   107
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   108
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   109
		return any_scripts_ready;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   110
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   111
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   112
	// creates a script load listener
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   113
	function create_script_load_listener(elem,registry_item,flag,onload) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   114
		elem.onload = elem.onreadystatechange = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   115
			if ((elem.readyState && elem.readyState != "complete" && elem.readyState != "loaded") || registry_item[flag]) return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   116
			elem.onload = elem.onreadystatechange = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   117
			onload();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   118
		};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   119
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   120
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   121
	// script executed handler
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   122
	function script_executed(registry_item) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   123
		registry_item.ready = registry_item.finished = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   124
		for (var i=0; i<registry_item.finished_listeners.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   125
			registry_item.finished_listeners[i]();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   126
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   127
		registry_item.ready_listeners = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   128
		registry_item.finished_listeners = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   129
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   130
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   131
	// make the request for a scriptha
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   132
	function request_script(chain_opts,script_obj,registry_item,onload,preload_this_script) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   133
		// setTimeout() "yielding" prevents some weird race/crash conditions in older browsers
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   134
		setTimeout(function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   135
			var script, src = script_obj.real_src, xhr;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   136
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   137
			// don't proceed until `append_to` is ready to append to
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   138
			if ("item" in append_to) { // check if `append_to` ref is still a live node list
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   139
				if (!append_to[0]) { // `append_to` node not yet ready
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   140
					// try again in a little bit -- note: will re-call the anonymous function in the outer setTimeout, not the parent `request_script()`
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   141
					setTimeout(arguments.callee,25);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   142
					return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   143
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   144
				// reassign from live node list ref to pure node ref -- avoids nasty IE bug where changes to DOM invalidate live node lists
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   145
				append_to = append_to[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   146
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   147
			script = document.createElement("script");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   148
			if (script_obj.type) script.type = script_obj.type;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   149
			if (script_obj.charset) script.charset = script_obj.charset;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   150
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   151
			// should preloading be used for this script?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   152
			if (preload_this_script) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   153
				// real script preloading?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   154
				if (real_preloading) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   155
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload: "+src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   156
					registry_item.elem = script;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   157
					if (explicit_preloading) { // explicit preloading (aka, Zakas' proposal)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   158
						script.preload = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   159
						script.onpreload = onload;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   160
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   161
					else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   162
						script.onreadystatechange = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   163
							if (script.readyState == "loaded") onload();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   164
						};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   165
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   166
					script.src = src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   167
					// NOTE: no append to DOM yet, appending will happen when ready to execute
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   168
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   169
				// same-domain and XHR allowed? use XHR preloading
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   170
				else if (preload_this_script && src.indexOf(root_domain) == 0 && chain_opts[_UseLocalXHR]) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   171
					xhr = new XMLHttpRequest(); // note: IE never uses XHR (it supports true preloading), so no more need for ActiveXObject fallback for IE <= 7
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   172
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload (xhr): "+src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   173
					xhr.onreadystatechange = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   174
						if (xhr.readyState == 4) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   175
							xhr.onreadystatechange = function(){}; // fix a memory leak in IE
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   176
							registry_item.text = xhr.responseText + "\n//@ sourceURL=" + src; // http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   177
							onload();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   178
						}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   179
					};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   180
					xhr.open("GET",src);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   181
					xhr.send();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   182
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   183
				// as a last resort, use cache-preloading
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   184
				else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   185
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload (cache): "+src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   186
					script.type = "text/cache-script";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   187
					create_script_load_listener(script,registry_item,"ready",function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   188
						append_to.removeChild(script);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   189
						onload();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   190
					});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   191
					script.src = src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   192
					append_to.insertBefore(script,append_to.firstChild);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   193
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   194
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   195
			// use async=false for ordered async? parallel-load-serial-execute http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   196
			else if (script_ordered_async) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   197
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script load (ordered async): "+src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   198
				script.async = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   199
				create_script_load_listener(script,registry_item,"finished",onload);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   200
				script.src = src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   201
				append_to.insertBefore(script,append_to.firstChild);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   202
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   203
			// otherwise, just a normal script element
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   204
			else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   205
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script load: "+src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   206
				create_script_load_listener(script,registry_item,"finished",onload);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   207
				script.src = src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   208
				append_to.insertBefore(script,append_to.firstChild);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   209
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   210
		},0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   211
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   212
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   213
	// create a clean instance of $LAB
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   214
	function create_sandbox() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   215
		var global_defaults = {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   216
			can_use_preloading = real_preloading || xhr_or_cache_preloading,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   217
			queue = [],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   218
			registry = {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   219
			instanceAPI
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   220
		;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   221
		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   222
		// global defaults
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   223
		global_defaults[_UseLocalXHR] = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   224
		global_defaults[_AlwaysPreserveOrder] = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   225
		global_defaults[_AllowDuplicates] = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   226
		global_defaults[_CacheBust] = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   227
		/*!START_DEBUG*/global_defaults[_Debug] = false;/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   228
		global_defaults[_BasePath] = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   229
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   230
		// execute a script that has been preloaded already
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   231
		function execute_preloaded_script(chain_opts,script_obj,registry_item) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   232
			var script;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   233
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   234
			function preload_execute_finished() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   235
				if (script != null) { // make sure this only ever fires once
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   236
					script = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   237
					script_executed(registry_item);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   238
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   239
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   240
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   241
			if (registry[script_obj.src].finished) return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   242
			if (!chain_opts[_AllowDuplicates]) registry[script_obj.src].finished = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   243
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   244
			script = registry_item.elem || document.createElement("script");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   245
			if (script_obj.type) script.type = script_obj.type;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   246
			if (script_obj.charset) script.charset = script_obj.charset;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   247
			create_script_load_listener(script,registry_item,"finished",preload_execute_finished);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   248
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   249
			// script elem was real-preloaded
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   250
			if (registry_item.elem) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   251
				registry_item.elem = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   252
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   253
			// script was XHR preloaded
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   254
			else if (registry_item.text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   255
				script.onload = script.onreadystatechange = null;	// script injection doesn't fire these events
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   256
				script.text = registry_item.text;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   257
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   258
			// script was cache-preloaded
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   259
			else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   260
				script.src = script_obj.real_src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   261
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   262
			append_to.insertBefore(script,append_to.firstChild);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   263
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   264
			// manually fire execution callback for injected scripts, since events don't fire
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   265
			if (registry_item.text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   266
				preload_execute_finished();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   267
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   268
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   269
	
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   270
		// process the script request setup
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   271
		function do_script(chain_opts,script_obj,chain_group,preload_this_script) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   272
			var registry_item,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   273
				registry_items,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   274
				ready_cb = function(){ script_obj.ready_cb(script_obj,function(){ execute_preloaded_script(chain_opts,script_obj,registry_item); }); },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   275
				finished_cb = function(){ script_obj.finished_cb(script_obj,chain_group); }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   276
			;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   277
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   278
			script_obj.src = canonical_uri(script_obj.src,chain_opts[_BasePath]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   279
			script_obj.real_src = script_obj.src + 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   280
				// append cache-bust param to URL?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   281
				(chain_opts[_CacheBust] ? ((/\?.*$/.test(script_obj.src) ? "&_" : "?_") + ~~(Math.random()*1E9) + "=") : "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   282
			;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   283
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   284
			if (!registry[script_obj.src]) registry[script_obj.src] = {items:[],finished:false};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   285
			registry_items = registry[script_obj.src].items;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   286
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   287
			// allowing duplicates, or is this the first recorded load of this script?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   288
			if (chain_opts[_AllowDuplicates] || registry_items.length == 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   289
				registry_item = registry_items[registry_items.length] = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   290
					ready:false,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   291
					finished:false,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   292
					ready_listeners:[ready_cb],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   293
					finished_listeners:[finished_cb]
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   294
				};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   295
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   296
				request_script(chain_opts,script_obj,registry_item,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   297
					// which callback type to pass?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   298
					(
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   299
					 	(preload_this_script) ? // depends on script-preloading
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   300
						function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   301
							registry_item.ready = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   302
							for (var i=0; i<registry_item.ready_listeners.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   303
								registry_item.ready_listeners[i]();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   304
							}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   305
							registry_item.ready_listeners = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   306
						} :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   307
						function(){ script_executed(registry_item); }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   308
					),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   309
					// signal if script-preloading should be used or not
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   310
					preload_this_script
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   311
				);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   312
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   313
			else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   314
				registry_item = registry_items[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   315
				if (registry_item.finished) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   316
					finished_cb();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   317
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   318
				else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   319
					registry_item.finished_listeners.push(finished_cb);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   320
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   321
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   322
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   323
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   324
		// creates a closure for each separate chain spawned from this $LAB instance, to keep state cleanly separated between chains
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   325
		function create_chain() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   326
			var chainedAPI,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   327
				chain_opts = merge_objs(global_defaults,{}),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   328
				chain = [],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   329
				exec_cursor = 0,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   330
				scripts_currently_loading = false,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   331
				group
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   332
			;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   333
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   334
			// called when a script has finished preloading
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   335
			function chain_script_ready(script_obj,exec_trigger) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   336
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("script preload finished: "+script_obj.real_src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   337
				script_obj.ready = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   338
				script_obj.exec_trigger = exec_trigger;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   339
				advance_exec_cursor(); // will only check for 'ready' scripts to be executed
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   340
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   341
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   342
			// called when a script has finished executing
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   343
			function chain_script_executed(script_obj,chain_group) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   344
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("script execution finished: "+script_obj.real_src);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   345
				script_obj.ready = script_obj.finished = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   346
				script_obj.exec_trigger = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   347
				// check if chain group is all finished
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   348
				for (var i=0; i<chain_group.scripts.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   349
					if (!chain_group.scripts[i].finished) return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   350
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   351
				// chain_group is all finished if we get this far
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   352
				chain_group.finished = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   353
				advance_exec_cursor();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   354
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   355
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   356
			// main driver for executing each part of the chain
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   357
			function advance_exec_cursor() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   358
				while (exec_cursor < chain.length) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   359
					if (is_func(chain[exec_cursor])) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   360
						/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("$LAB.wait() executing: "+chain[exec_cursor]);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   361
						try { chain[exec_cursor++](); } catch (err) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   362
							/*!START_DEBUG*/if (chain_opts[_Debug]) log_error("$LAB.wait() error caught: ",err);/*!END_DEBUG*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   363
						}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   364
						continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   365
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   366
					else if (!chain[exec_cursor].finished) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   367
						if (check_chain_group_scripts_ready(chain[exec_cursor])) continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   368
						break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   369
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   370
					exec_cursor++;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   371
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   372
				// we've reached the end of the chain (so far)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   373
				if (exec_cursor == chain.length) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   374
					scripts_currently_loading = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   375
					group = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   376
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   377
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   378
			
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   379
			// setup next chain script group
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   380
			function init_script_chain_group() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   381
				if (!group || !group.scripts) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   382
					chain.push(group = {scripts:[],finished:true});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   383
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   384
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   385
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   386
			// API for $LAB chains
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   387
			chainedAPI = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   388
				// start loading one or more scripts
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   389
				script:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   390
					for (var i=0; i<arguments.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   391
						(function(script_obj,script_list){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   392
							var splice_args;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   393
							
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   394
							if (!is_array(script_obj)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   395
								script_list = [script_obj];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   396
							}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   397
							for (var j=0; j<script_list.length; j++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   398
								init_script_chain_group();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   399
								script_obj = script_list[j];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   400
								
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   401
								if (is_func(script_obj)) script_obj = script_obj();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   402
								if (!script_obj) continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   403
								if (is_array(script_obj)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   404
									// set up an array of arguments to pass to splice()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   405
									splice_args = [].slice.call(script_obj); // first include the actual array elements we want to splice in
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   406
									splice_args.unshift(j,1); // next, put the `index` and `howMany` parameters onto the beginning of the splice-arguments array
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   407
									[].splice.apply(script_list,splice_args); // use the splice-arguments array as arguments for splice()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   408
									j--; // adjust `j` to account for the loop's subsequent `j++`, so that the next loop iteration uses the same `j` index value
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   409
									continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   410
								}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   411
								if (typeof script_obj == "string") script_obj = {src:script_obj};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   412
								script_obj = merge_objs(script_obj,{
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   413
									ready:false,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   414
									ready_cb:chain_script_ready,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   415
									finished:false,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   416
									finished_cb:chain_script_executed
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   417
								});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   418
								group.finished = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   419
								group.scripts.push(script_obj);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   420
								
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   421
								do_script(chain_opts,script_obj,group,(can_use_preloading && scripts_currently_loading));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   422
								scripts_currently_loading = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   423
								
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   424
								if (chain_opts[_AlwaysPreserveOrder]) chainedAPI.wait();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   425
							}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   426
						})(arguments[i],arguments[i]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   427
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   428
					return chainedAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   429
				},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   430
				// force LABjs to pause in execution at this point in the chain, until the execution thus far finishes, before proceeding
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   431
				wait:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   432
					if (arguments.length > 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   433
						for (var i=0; i<arguments.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   434
							chain.push(arguments[i]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   435
						}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   436
						group = chain[chain.length-1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   437
					}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   438
					else group = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   439
					
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   440
					advance_exec_cursor();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   441
					
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   442
					return chainedAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   443
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   444
			};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   445
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   446
			// the first chain link API (includes `setOptions` only this first time)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   447
			return {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   448
				script:chainedAPI.script, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   449
				wait:chainedAPI.wait, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   450
				setOptions:function(opts){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   451
					merge_objs(opts,chain_opts);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   452
					return chainedAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   453
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   454
			};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   455
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   456
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   457
		// API for each initial $LAB instance (before chaining starts)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   458
		instanceAPI = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   459
			// main API functions
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   460
			setGlobalDefaults:function(opts){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   461
				merge_objs(opts,global_defaults);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   462
				return instanceAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   463
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   464
			setOptions:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   465
				return create_chain().setOptions.apply(null,arguments);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   466
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   467
			script:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   468
				return create_chain().script.apply(null,arguments);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   469
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   470
			wait:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   471
				return create_chain().wait.apply(null,arguments);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   472
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   473
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   474
			// built-in queuing for $LAB `script()` and `wait()` calls
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   475
			// useful for building up a chain programmatically across various script locations, and simulating
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   476
			// execution of the chain
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   477
			queueScript:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   478
				queue[queue.length] = {type:"script", args:[].slice.call(arguments)};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   479
				return instanceAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   480
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   481
			queueWait:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   482
				queue[queue.length] = {type:"wait", args:[].slice.call(arguments)};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   483
				return instanceAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   484
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   485
			runQueue:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   486
				var $L = instanceAPI, len=queue.length, i=len, val;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   487
				for (;--i>=0;) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   488
					val = queue.shift();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   489
					$L = $L[val.type].apply(null,val.args);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   490
				}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   491
				return $L;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   492
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   493
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   494
			// rollback `[global].$LAB` to what it was before this file was loaded, the return this current instance of $LAB
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   495
			noConflict:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   496
				global.$LAB = _$LAB;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   497
				return instanceAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   498
			},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   499
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   500
			// create another clean instance of $LAB
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   501
			sandbox:function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   502
				return create_sandbox();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   503
			}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   504
		};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   505
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   506
		return instanceAPI;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   507
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   508
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   509
	// create the main instance of $LAB
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   510
	global.$LAB = create_sandbox();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   511
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   512
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   513
	/* The following "hack" was suggested by Andrea Giammarchi and adapted from: http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   514
	   NOTE: this hack only operates in FF and then only in versions where document.readyState is not present (FF < 3.6?).
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   515
	   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   516
	   The hack essentially "patches" the **page** that LABjs is loaded onto so that it has a proper conforming document.readyState, so that if a script which does 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   517
	   proper and safe dom-ready detection is loaded onto a page, after dom-ready has passed, it will still be able to detect this state, by inspecting the now hacked 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   518
	   document.readyState property. The loaded script in question can then immediately trigger any queued code executions that were waiting for the DOM to be ready. 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   519
	   For instance, jQuery 1.4+ has been patched to take advantage of document.readyState, which is enabled by this hack. But 1.3.2 and before are **not** safe or 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   520
	   fixed by this hack, and should therefore **not** be lazy-loaded by script loader tools such as LABjs.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   521
	*/ 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   522
	(function(addEvent,domLoaded,handler){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   523
		if (document.readyState == null && document[addEvent]){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   524
			document.readyState = "loading";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   525
			document[addEvent](domLoaded,handler = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   526
				document.removeEventListener(domLoaded,handler,false);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   527
				document.readyState = "complete";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   528
			},false);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   529
		}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   530
	})("addEventListener","DOMContentLoaded");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   531
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   532
})(this);/*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   533
  mustache.js — Logic-less templates in JavaScript
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   535
  See http://mustache.github.com/ for more info.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   536
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   537
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   538
var Mustache = function () {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   539
  var _toString = Object.prototype.toString;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   540
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   541
  Array.isArray = Array.isArray || function (obj) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   542
    return _toString.call(obj) == "[object Array]";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   543
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   544
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   545
  var _trim = String.prototype.trim, trim;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   546
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   547
  if (_trim) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   548
    trim = function (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   549
      return text == null ? "" : _trim.call(text);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   550
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   551
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   552
    var trimLeft, trimRight;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   553
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   554
    // IE doesn't match non-breaking spaces with \s.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   555
    if ((/\S/).test("\xA0")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   556
      trimLeft = /^[\s\xA0]+/;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   557
      trimRight = /[\s\xA0]+$/;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   558
    } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   559
      trimLeft = /^\s+/;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   560
      trimRight = /\s+$/;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   561
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   562
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   563
    trim = function (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   564
      return text == null ? "" :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   565
        text.toString().replace(trimLeft, "").replace(trimRight, "");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   566
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   567
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   568
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   569
  var escapeMap = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   570
    "&": "&amp;",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   571
    "<": "&lt;",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   572
    ">": "&gt;",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   573
    '"': '&quot;',
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   574
    "'": '&#39;'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   575
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   576
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   577
  function escapeHTML(string) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   578
    return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   579
      return escapeMap[s] || s;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   580
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   581
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   582
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   583
  var regexCache = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   584
  var Renderer = function () {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   585
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   586
  Renderer.prototype = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   587
    otag: "{{",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   588
    ctag: "}}",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   589
    pragmas: {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   590
    buffer: [],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   591
    pragmas_implemented: {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   592
      "IMPLICIT-ITERATOR": true
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   593
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   594
    context: {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   595
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   596
    render: function (template, context, partials, in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   597
      // reset buffer & set context
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   598
      if (!in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   599
        this.context = context;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   600
        this.buffer = []; // TODO: make this non-lazy
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   601
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   602
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   603
      // fail fast
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   604
      if (!this.includes("", template)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   605
        if (in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   606
          return template;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   607
        } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   608
          this.send(template);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   609
          return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   610
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   611
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   612
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   613
      // get the pragmas together
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   614
      template = this.render_pragmas(template);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   615
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   616
      // render the template
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   617
      var html = this.render_section(template, context, partials);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   618
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   619
      // render_section did not find any sections, we still need to render the tags
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   620
      if (html === false) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   621
        html = this.render_tags(template, context, partials, in_recursion);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   622
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   623
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   624
      if (in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   625
        return html;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   626
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   627
        this.sendLines(html);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   628
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   629
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   630
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   631
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   632
      Sends parsed lines
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   633
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   634
    send: function (line) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   635
      if (line !== "") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   636
        this.buffer.push(line);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   637
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   638
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   639
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   640
    sendLines: function (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   641
      if (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   642
        var lines = text.split("\n");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   643
        for (var i = 0; i < lines.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   644
          this.send(lines[i]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   645
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   646
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   647
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   648
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   649
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   650
      Looks for %PRAGMAS
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   651
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   652
    render_pragmas: function (template) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   653
      // no pragmas
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   654
      if (!this.includes("%", template)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   655
        return template;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   656
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   657
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   658
      var that = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   659
      var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   660
        return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   661
      });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   662
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   663
      return template.replace(regex, function (match, pragma, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   664
        if (!that.pragmas_implemented[pragma]) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   665
          throw({message:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   666
            "This implementation of mustache doesn't understand the '" +
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   667
            pragma + "' pragma"});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   668
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   669
        that.pragmas[pragma] = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   670
        if (options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   671
          var opts = options.split("=");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   672
          that.pragmas[pragma][opts[0]] = opts[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   673
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   674
        return "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   675
        // ignore unknown pragmas silently
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   676
      });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   677
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   678
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   679
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   680
      Tries to find a partial in the curent scope and render it
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   681
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   682
    render_partial: function (name, context, partials) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   683
      name = trim(name);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   684
      if (!partials || partials[name] === undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   685
        throw({message: "unknown_partial '" + name + "'"});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   686
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   687
      if (!context || typeof context[name] != "object") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   688
        return this.render(partials[name], context, partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   689
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   690
      return this.render(partials[name], context[name], partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   691
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   692
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   693
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   694
      Renders inverted (^) and normal (#) sections
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   695
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   696
    render_section: function (template, context, partials) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   697
      if (!this.includes("#", template) && !this.includes("^", template)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   698
        // did not render anything, there were no sections
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   699
        return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   700
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   701
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   702
      var that = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   703
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   704
      var regex = this.getCachedRegex("render_section", function (otag, ctag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   705
        // This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   706
        return new RegExp(
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   707
          "^([\\s\\S]*?)" +         // all the crap at the beginning that is not {{*}} ($1)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   708
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   709
          otag +                    // {{
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   710
          "(\\^|\\#)\\s*(.+)\\s*" + //  #foo (# == $2, foo == $3)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   711
          ctag +                    // }}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   712
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   713
          "\n*([\\s\\S]*?)" +       // between the tag ($2). leading newlines are dropped
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   714
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   715
          otag +                    // {{
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   716
          "\\/\\s*\\3\\s*" +        //  /foo (backreference to the opening tag).
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   717
          ctag +                    // }}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   718
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   719
          "\\s*([\\s\\S]*)$",       // everything else in the string ($4). leading whitespace is dropped.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   720
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   721
        "g");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   722
      });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   723
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   724
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   725
      // for each {{#foo}}{{/foo}} section do...
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   726
      return template.replace(regex, function (match, before, type, name, content, after) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   727
        // before contains only tags, no sections
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   728
        var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   729
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   730
        // after may contain both sections and tags, so use full rendering function
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   731
            renderedAfter = after ? that.render(after, context, partials, true) : "",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   732
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   733
        // will be computed below
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   734
            renderedContent,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   735
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   736
            value = that.find(name, context);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   737
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   738
        if (type === "^") { // inverted section
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   739
          if (!value || Array.isArray(value) && value.length === 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   740
            // false or empty list, render it
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   741
            renderedContent = that.render(content, context, partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   742
          } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   743
            renderedContent = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   744
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   745
        } else if (type === "#") { // normal section
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   746
          if (Array.isArray(value)) { // Enumerable, Let's loop!
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   747
            renderedContent = that.map(value, function (row) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   748
              return that.render(content, that.create_context(row), partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   749
            }).join("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   750
          } else if (that.is_object(value)) { // Object, Use it as subcontext!
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   751
            renderedContent = that.render(content, that.create_context(value),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   752
              partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   753
          } else if (typeof value == "function") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   754
            // higher order section
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   755
            renderedContent = value.call(context, content, function (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   756
              return that.render(text, context, partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   757
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   758
          } else if (value) { // boolean section
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   759
            renderedContent = that.render(content, context, partials, true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   760
          } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   761
            renderedContent = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   762
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   763
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   764
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   765
        return renderedBefore + renderedContent + renderedAfter;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   766
      });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   767
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   768
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   769
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   770
      Replace {{foo}} and friends with values from our view
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   771
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   772
    render_tags: function (template, context, partials, in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   773
      // tit for tat
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   774
      var that = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   775
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   776
      var new_regex = function () {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   777
        return that.getCachedRegex("render_tags", function (otag, ctag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   778
          return new RegExp(otag + "(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   779
        });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   780
      };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   781
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   782
      var regex = new_regex();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   783
      var tag_replace_callback = function (match, operator, name) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   784
        switch(operator) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   785
        case "!": // ignore comments
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   786
          return "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   787
        case "=": // set new delimiters, rebuild the replace regexp
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   788
          that.set_delimiters(name);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   789
          regex = new_regex();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   790
          return "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   791
        case ">": // render partial
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   792
          return that.render_partial(name, context, partials);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   793
        case "{": // the triple mustache is unescaped
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   794
        case "&": // & operator is an alternative unescape method
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   795
          return that.find(name, context);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   796
        default: // escape the value
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   797
          return escapeHTML(that.find(name, context));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   798
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   799
      };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   800
      var lines = template.split("\n");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   801
      for(var i = 0; i < lines.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   802
        lines[i] = lines[i].replace(regex, tag_replace_callback, this);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   803
        if (!in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   804
          this.send(lines[i]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   805
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   806
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   807
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   808
      if (in_recursion) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   809
        return lines.join("\n");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   810
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   811
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   812
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   813
    set_delimiters: function (delimiters) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   814
      var dels = delimiters.split(" ");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   815
      this.otag = this.escape_regex(dels[0]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   816
      this.ctag = this.escape_regex(dels[1]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   817
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   818
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   819
    escape_regex: function (text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   820
      // thank you Simon Willison
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   821
      if (!arguments.callee.sRE) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   822
        var specials = [
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   823
          '/', '.', '*', '+', '?', '|',
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   824
          '(', ')', '[', ']', '{', '}', '\\'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   825
        ];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   826
        arguments.callee.sRE = new RegExp(
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   827
          '(\\' + specials.join('|\\') + ')', 'g'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   828
        );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   829
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   830
      return text.replace(arguments.callee.sRE, '\\$1');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   831
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   832
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   833
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   834
      find `name` in current `context`. That is find me a value
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   835
      from the view object
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   836
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   837
    find: function (name, context) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   838
      name = trim(name);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   839
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   840
      // Checks whether a value is thruthy or false or 0
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   841
      function is_kinda_truthy(bool) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   842
        return bool === false || bool === 0 || bool;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   843
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   844
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   845
      var value;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   846
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   847
      // check for dot notation eg. foo.bar
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   848
      if (name.match(/([a-z_]+)\./ig)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   849
        var childValue = this.walk_context(name, context);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   850
        if (is_kinda_truthy(childValue)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   851
          value = childValue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   852
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   853
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   854
        if (is_kinda_truthy(context[name])) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   855
          value = context[name];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   856
        } else if (is_kinda_truthy(this.context[name])) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   857
          value = this.context[name];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   858
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   859
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   860
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   861
      if (typeof value == "function") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   862
        return value.apply(context);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   863
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   864
      if (value !== undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   865
        return value;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   866
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   867
      // silently ignore unkown variables
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   868
      return "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   869
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   870
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   871
    walk_context: function (name, context) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   872
      var path = name.split('.');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   873
      // if the var doesn't exist in current context, check the top level context
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   874
      var value_context = (context[path[0]] != undefined) ? context : this.context;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   875
      var value = value_context[path.shift()];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   876
      while (value != undefined && path.length > 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   877
        value_context = value;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   878
        value = value[path.shift()];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   879
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   880
      // if the value is a function, call it, binding the correct context
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   881
      if (typeof value == "function") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   882
        return value.apply(value_context);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   883
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   884
      return value;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   885
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   886
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   887
    // Utility methods
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   888
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   889
    /* includes tag */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   890
    includes: function (needle, haystack) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   891
      return haystack.indexOf(this.otag + needle) != -1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   892
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   893
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   894
    // by @langalex, support for arrays of strings
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   895
    create_context: function (_context) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   896
      if (this.is_object(_context)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   897
        return _context;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   898
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   899
        var iterator = ".";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   900
        if (this.pragmas["IMPLICIT-ITERATOR"]) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   901
          iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   902
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   903
        var ctx = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   904
        ctx[iterator] = _context;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   905
        return ctx;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   906
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   907
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   908
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   909
    is_object: function (a) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   910
      return a && typeof a == "object";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   911
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   912
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   913
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   914
      Why, why, why? Because IE. Cry, cry cry.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   915
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   916
    map: function (array, fn) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   917
      if (typeof array.map == "function") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   918
        return array.map(fn);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   919
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   920
        var r = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   921
        var l = array.length;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   922
        for(var i = 0; i < l; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   923
          r.push(fn(array[i]));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   924
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   925
        return r;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   926
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   927
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   928
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   929
    getCachedRegex: function (name, generator) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   930
      var byOtag = regexCache[this.otag];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   931
      if (!byOtag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   932
        byOtag = regexCache[this.otag] = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   933
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   934
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   935
      var byCtag = byOtag[this.ctag];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   936
      if (!byCtag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   937
        byCtag = byOtag[this.ctag] = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   938
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   939
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   940
      var regex = byCtag[name];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   941
      if (!regex) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   942
        regex = byCtag[name] = generator(this.otag, this.ctag);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   943
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   944
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   945
      return regex;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   946
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   947
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   948
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   949
  return({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   950
    name: "mustache.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   951
    version: "0.5.0-dev",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   952
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   953
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   954
      Turns a template and view into HTML
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   955
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   956
    to_html: function (template, view, partials, send_fun) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   957
      var renderer = new Renderer();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   958
      if (send_fun) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   959
        renderer.send = send_fun;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   960
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   961
      renderer.render(template, view || {}, partials);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   962
      if (!send_fun) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   963
        return renderer.buffer.join("\n");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   964
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   965
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   966
  });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   967
}();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   968
// Underscore.js 1.2.3
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   969
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   970
// Underscore is freely distributable under the MIT license.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   971
// Portions of Underscore are inspired or borrowed from Prototype,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   972
// Oliver Steele's Functional, and John Resig's Micro-Templating.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   973
// For all details and documentation:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   974
// http://documentcloud.github.com/underscore
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   975
(function(){function r(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   976
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&r(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(m.call(a,h)&&(f++,!(g=m.call(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(m.call(c,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   977
h)&&!f--)break;g=!f}}d.pop();return g}var s=this,F=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,G=k.concat,H=k.unshift,l=p.toString,m=p.hasOwnProperty,v=k.forEach,w=k.map,x=k.reduce,y=k.reduceRight,z=k.filter,A=k.every,B=k.some,q=k.indexOf,C=k.lastIndexOf,p=Array.isArray,I=Object.keys,t=Function.prototype.bind,b=function(a){return new n(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else typeof define==="function"&&
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   978
define.amd?define("underscore",function(){return b}):s._=b;b.VERSION="1.2.3";var j=b.each=b.forEach=function(a,c,b){if(a!=null)if(v&&a.forEach===v)a.forEach(c,b);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(b,a[e],e,a)===o)break}else for(e in a)if(m.call(a,e)&&c.call(b,a[e],e,a)===o)break};b.map=function(a,c,b){var e=[];if(a==null)return e;if(w&&a.map===w)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});return e};b.reduce=b.foldl=b.inject=function(a,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   979
c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(x&&a.reduce===x)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(y&&a.reduceRight===y)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   980
c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,c,b){var e;D(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(z&&a.filter===z)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(A&&a.every===A)return a.every(c,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   981
b);j(a,function(a,g,h){if(!(e=e&&c.call(b,a,g,h)))return o});return e};var D=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(B&&a.some===B)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return q&&a.indexOf===q?a.indexOf(c)!=-1:b=D(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(c.call?c||a:a[c]).apply(a,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   982
d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   983
computed:b})});return e.value};b.shuffle=function(a){var c=[],b;j(a,function(a,f){f==0?c[0]=a:(b=Math.floor(Math.random()*(f+1)),c[f]=c[b],c[b]=a)});return c};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,c){var b=a.criteria,d=c.criteria;return b<d?-1:b>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   984
function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   985
1]};b.rest=b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   986
[]);return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   987
c,d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(q&&a.indexOf===q)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(C&&a.lastIndexOf===C)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   988
var E=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));E.prototype=a.prototype;var b=new E,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   989
c){var d={};c||(c=b.identity);return function(){var b=c.apply(this,arguments);return m.call(d,b)?d[b]:d[b]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   990
a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=G.apply([a],arguments);return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   991
function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=I||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   992
1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   993
Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)==
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   994
"[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=F;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")};b.mixin=function(a){j(b.functions(a),function(c){J(c,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   995
b[c]=a[c])})};var K=0;b.uniqueId=function(a){var b=K++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   996
"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},J=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);H.call(a,this._wrapped);return u(c.apply(b,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   997
a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped,arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   998
/* main file */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   999
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1000
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1001
if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1002
  /**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1003
    @class
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1004
    the object under which everything goes.        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1005
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1006
	IriSP = {}; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1007
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1008
  /** Alias to IriSP for backward compatibility */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1009
	__IriSP = IriSP;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1010
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1011
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1012
/* underscore comes bundled with the player and we need 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1013
   it ASAP, so load it that way
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1014
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1015
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1016
IriSP._ = window._.noConflict();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1017
IriSP.underscore = IriSP._;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1018
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1019
IriSP.loadLibs = function( libs, config, metadata_url, callback ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1020
    // Localize jQuery variable
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1021
		IriSP.jQuery = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1022
    var $L = $LAB.script(libs.jQuery).script(libs.swfObject).wait()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1023
                .script(libs.jQueryUI);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1024
                                   
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1025
    if (config.player.type === "jwplayer" || config.player.type === "allocine") {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1026
      // load our popcorn.js lookalike
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1027
      $L.script(libs.jwplayer);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1028
    } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1029
      // load the real popcorn
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1030
      $L.script(libs.popcorn).script(libs["popcorn.code"]);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1031
      if (config.player.type === "youtube") {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1032
        $L.script(libs["popcorn.youtube"]);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1033
      } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1034
      if (config.player.type === "vimeo")
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1035
        $L.script(libs["popcorn.vimeo"]);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1036
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1037
      /* do nothing for html5 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1038
    }       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1039
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1040
    /* widget specific requirements */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1041
    for (var idx in config.gui.widgets) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1042
      if (config.gui.widgets[idx].type === "PolemicWidget" ||
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1043
          config.gui.widgets[idx].type === "StackGraphWidget" ||
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1044
          config.gui.widgets[idx].type === "SparklineWidget") {        
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1045
        $L.script(libs.raphael);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1046
      }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1047
      if (config.gui.widgets[idx].type === "TraceWidget") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1048
          $L.script(libs.tracemanager)
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1049
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1050
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1051
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1052
    // same for modules
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1053
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1054
    for (var idx in config.modules) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1055
      if (config.modules[idx].type === "PolemicWidget")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1056
        $L.script(libs.raphaelJs);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1057
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1058
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1059
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1060
    $L.wait(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1061
      IriSP.jQuery = window.jQuery.noConflict( true );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1062
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1063
      var css_link_jquery = IriSP.jQuery( "<link>", { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1064
        rel: "stylesheet", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1065
        type: "text/css", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1066
        href: libs.cssjQueryUI,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1067
        'class': "dynamic_css"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1068
      } );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1069
      var css_link_custom = IriSP.jQuery( "<link>", { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1070
        rel: "stylesheet", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1071
        type: "text/css", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1072
        href: config.gui.css,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1073
        'class': "dynamic_css"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1074
      } );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1075
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1076
      css_link_jquery.appendTo('head');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1077
      css_link_custom.appendTo('head');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1078
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1079
      IriSP.setupDataLoader();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1080
      IriSP.__dataloader.get(metadata_url, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1081
          function(data) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1082
            /* save the data so that we could re-use it to
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1083
               configure the video
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1084
            */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1085
            IriSP.__jsonMetadata = data;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1086
            callback.call(window) });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1087
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1088
};
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1089
IriSP.annotation_template = "{{! template for an annotation displayed in a segmentWidget }}<div title='{{divTitle}}' id='{{id}}'	class='Ldt-iri-chapter Ldt-TraceMe' 	style='left: {{startPixel}}px;          width: {{pxWidth}}px;          background-color:{{hexa_color}};'    data-seek='{{seekPlace}}'    thumbnail-url='{{thumbnailUrl}}'	></div>";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1090
IriSP.annotationWidget_template = "{{! template for the annotation widget }}<div class='Ldt-AnnotationsWidget'>  <!-- ugly div because we want to have a double border -->  <div class='Ldt-Annotation-DoubleBorder'>      <div class='Ldt-AnnotationContent'>          <div class='Ldt-AnnotationShareIcons'>         <a target='_blank' class='Ldt-fbShare Ldt-TraceMe' title='{{i10n.share_on}} Facebook'></a>         <a target='_blank' class='Ldt-TwShare Ldt-TraceMe' title='{{i10n.share_on}} Twitter'></a>         <a target='_blank'  class='Ldt-GplusShare Ldt-TraceMe' title='{{i10n.share_on}} Google+'></a>        </div>        <div class='Ldt-SaTitle'></div>        <div class='Ldt-SaDescription'></div>        <div class='Ldt-SaKeywords'></div>    </div>  </div></div>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1091
IriSP.annotation_loading_template = "{{! template shown while the annotation widget is loading }}<div id='Ldt-load-container'><div id='Ldt-loader'>&nbsp;</div> Chargement... </div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1092
IriSP.annotationsListWidget_template = "{{! template for the annotation list widget }}<div class='Ldt-AnnotationsListWidget'>    <ul class='Ldt-AnnotationsList-ul'>        {{#annotations}}        <li id='Ldt-Annotation-li-{{id}}' class='Ldt-AnnotationsList-li Ldt-TraceMe'>            <img class='Ldt-AnnotationsList-Thumbnail' src='{{thumbnail}}' />            <div class='Ldt-AnnotationsList-Duration'>                <span class='Ldt-AnnotationsList-Begin'>{{begin}}</span>                <span class='Ldt-AnnotationsList-TcSeparator'>-</span>                <span class='Ldt-AnnotationsList-End'>{{end}}</span>            </div>            <div class='Ldt-AnnotationsList-Title'>            {{! if the url is not present, it means that the annotation exists            in the current project }}            {{^url}} <a href='#id={{id}}'> {{/url}}            {{! otherwise link to url }}            {{#url}} <a href='{{url}}'> {{/url}}                {{title}}            </a>            </div>            <div class='Ldt-AnnotationsList-Description'>                {{desc}}            </div>            {{#tags.length}}            <ul class='Ldt-AnnotationsList-Tags'>                {{#tags}}                <li class='Ldt-AnnotationsList-Tag-Li'>                    <div class='Ldt-AnnotationsList-Tag-Div'>{{.}}</div>                </li>                {{/tags}}            </ul>            {{/tags.length}}        </li>        {{/annotations}}    </ul></div>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1093
IriSP.arrowWidget_template = "<div class='Ldt-arrowWidget Ldt-arrowLeftEdge'></div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1094
IriSP.createAnnotationWidget_template = "{{! template for the annotation creation widget }}<div class='Ldt-createAnnotationWidget'>    <!-- ugly div because we want to have a double border -->    <div class='Ldt-createAnnotation-DoubleBorder'>        <div class='Ldt-createAnnotation-screen Ldt-createAnnotation-startScreen'>            <div style='margin-bottom: 7px; overflow: auto;'>                <div class='Ldt-createAnnotation-Title'></div>                <div class='Ldt-createAnnotation-TimeFrame'></div>                {{^cinecast_version}} <div class='Ldt-createAnnotation-Minimize Ldt-TraceMe' title='Cancel'></div>                {{/cinecast_version}}            </div>            <div class='Ldt-createAnnotation-Container'>                {{#show_from_field}}                <label>{{l10n.your_name}}&nbsp;: </label><input class='Ldt-createAnnotation-userName Ldt-TraceMe' value='{{user_name}}' />                {{/show_from_field}}                <textarea class='Ldt-createAnnotation-Description Ldt-TraceMe'></textarea>                <div class='Ldt-createAnnotation-userAvatar Ldt-TraceMe'>                    {{^user_avatar}} <img src='https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png'></img>                    {{/user_avatar}}                    {{#user_avatar}} <img src='{{ user_avatar }}'></img>                    {{/user_avatar}}                </div>                <div class='Ldt-createAnnotation-profileArrow'></div>            </div>            <button class='Ldt-createAnnotation-submitButton Ldt-TraceMe'>{{l10n.submit}}</button>            {{#keywords.length}}            <div class='Ldt-createAnnotation-btnblock Ldt-createAnnotation-keywords'>                <label>{{l10n.add_keywords}} :</label>                <ul class='Ldt-floatList'>                {{#keywords}}                    <li><button class='Ldt-createAnnotation-keyword-button Ldt-TraceMe'>{{.}}</button></li>                {{/keywords}}                </ul>            </div>            {{/keywords.length}}            {{#polemic_mode}}            {{#polemics.length}}            <div class='Ldt-createAnnotation-btnblock Ldt-createAnnotation-polemics'>                <label>{{l10n.add_polemic_keywords}} :</label>                <ul class='Ldt-floatList'>                {{#polemics}}                    <li><button class='Ldt-createAnnotation-polemic-{{className}} Ldt-createAnnotation-polemic-button Ldt-TraceMe'>{{keyword}}</button></li>                {{/polemics}}                </ul>            </div>            {{/polemics.length}}            {{/polemic_mode}}        </div>        <div class='Ldt-createAnnotation-screen Ldt-createAnnotation-waitScreen' style='display: none; text-align: center'>            <div class='Ldt-createAnnotation-spinner'></div>            {{l10n.wait_while_processed}}        </div>        <div class='Ldt-createAnnotation-screen Ldt-createAnnotation-errorScreen' style='display: none; text-align: center'>            <div class='Ldt-createAnnotation-Minimize' title='Hide'></div>            {{l10n.error_while_contacting}}        </div>        <div class='Ldt-createAnnotation-screen Ldt-createAnnotation-endScreen' style='display: none'>            <div class='Ldt-createAnnotation-Minimize' title='Hide'></div>            {{l10n.annotation_saved}}            <br>            {{l10n.share_annotation}}            <div style='margin-top: 12px; text-align: center;'>                <a target='_blank' class='Ldt-createAnnotation-endScreen-TweetLink Ldt-TraceMe'></a>                <a target='_blank' class='Ldt-createAnnotation-endScreen-FbLink Ldt-TraceMe'></a>                <a target='_blank' class='Ldt-createAnnotation-endScreen-GplusLink Ldt-TraceMe'></a>            </div>        </div>        <div class='Ldt-floatClear'></div>    </div></div>";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1095
IriSP.createAnnotation_errorMessage_template = "<p class='Ldt-createAnnotation-errorMessage'>  {{l10n.empty_annotation}}</p>";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1096
IriSP.loading_template = "<div id='Ldt-loader' style='width: {{width}}px; height: {{height}}px;'>{{l10n.loading_wait}}</div>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1097
IriSP.overlay_marker_template = "{{! the template for the small bars which is z-indexed over our segment widget }}<div class='Ldt-SegmentPositionMarker' style='background-color: #F7268E;'></div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1098
IriSP.player_template = "{{! template for the radio player }}<div class='Ldt-controler'>	<div class='Ldt-LeftPlayerControls'>        <div class='Ldt-Ctrl-button Ldt-CtrlPlay Ldt-CtrlPlay-PlayState Ldt-TraceMe' title='{{l10n.play_pause}}'></div>        <div class='Ldt-Ctrl-spacer'></div>        {{^disable_annotate_btn}}    	<div class='Ldt-Ctrl-button Ldt-CtrlAnnotate Ldt-TraceMe' title='{{l10n.annotate}}'></div>        <div class='Ldt-Ctrl-spacer'></div>        {{/disable_annotate_btn}}        {{^disable_search_btn}}        <div class='Ldt-Ctrl-button Ldt-CtrlSearch Ldt-TraceMe' title='{{l10n.search}}'></div>        <div class='Ldt-Ctrl-spacer'></div>        {{/disable_search_btn}}        <div class='LdtSearch'>          <input class='LdtSearchInput Ldt-TraceMe'></input>        </div>	</div>	<div class='Ldt-RightPlayerControls'>        <div class='Ldt-Ctrl-spacer'></div>        <div class='Ldt-Time'>          <div class='Ldt-ElapsedTime' title='{{l10n.elapsed_time}}'>00:00</div>          <div class='Ldt-TimeSeparator'>/</div>          <div class='Ldt-TotalTime' title='{{l10n.total_time}}'>00:00</div>        </div>        <div class='Ldt-Ctrl-spacer'></div>		<div class='Ldt-Ctrl-button Ldt-CtrlSound Ldt-CtrlSound-Full Ldt-TraceMe' title='{{l10n.mute_unmute}}'></div>	</div>	<div class='Ldt-Ctrl-Volume-Control' title='{{l10n.volume_control}}'>	    <div class='Ldt-Ctrl-Volume-Bar'></div>	    <div class='Ldt-Ctrl-Volume-Cursor'></div>	</div></div>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1099
IriSP.search_template = "{{! template for the search container }}<div class='LdtSearchContainer'	style='margin-left: {{margin_left}}; position: absolute; margin-top: -60px;'>	<div class='LdtSearch'		style='display: none; background-color: #EEE; width: 165px; border-color: #CFCFCF; position: absolute; text-align: center;'>		<input class='LdtSearchInput'			style='margin-top: 1px; margin-bottom: 2px;' />	</div></div><div class='cleaner'></div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1100
IriSP.share_template = "{{! social network sharing template }}<a onclick='__IriSP.MyApiPlayer.share(\'delicious\');' title='{{l10n.share_on}} delicious'><span class='share shareDelicious'>&nbsp;</span></a>		<a onclick='__IriSP.MyApiPlayer.share(\'facebook\');' title='{{l10n.share_on}} facebook'> <span class='share shareFacebook'>&nbsp;</span></a><a onclick='__IriSP.MyApiPlayer.share(\'twitter\');' title='{{l10n.share_on}} twitter'>  <span class='share shareTwitter'>&nbsp;</span></a><a onclick='__IriSP.MyApiPlayer.share(\'myspace\');' title='{{l10n.share_on}} Myspace'>  <span class='share shareMySpace'>&nbsp;</span></a>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1101
IriSP.sliceWidget_template = "{{! template for the slice widget }}<div class='Ldt-sliceWidget'>  {{! the whole bar }}  <div class='Ldt-sliceBackground'></div>    <div class='Ldt-sliceLeftHandle'></div>  {{! the zone which represents our slice }}  <div class='Ldt-sliceZone'></div>     <div class='Ldt-sliceRightHandle'></div></div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1102
IriSP.sliderWidget_template = "{{! template for the slider widget - it's composed of two divs we one overlayed on top    of the other }}<div class='Ldt-sliderBackground'></div><div class='Ldt-sliderForeground'></div><div class='Ldt-sliderPositionMarker Ldt-TraceMe'></div>";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1103
IriSP.tooltip_template = "{{! template used by the jquery ui tooltip }}<div class='Ldt-tooltip'>  <div class='title'>{{title}}</div>  <div class='time'>{{begin}} : {{end}} </div>  <div class='description'>{{description}}</div></div>";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1104
IriSP.tooltipWidget_template = "{{! template for the tooltip widget }}<div class='tip'>	<div class='tipcolor' style='height:10px;width:10px'></div>	<div class='tiptext'></div>";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1105
IriSP.tweetWidget_template = "{{! template for the tweet widget }}<div class='Ldt-tweetWidget'>  <div class='Ldt-tweet-DoubleBorder'>      <div class='Ldt-tweetWidgetKeepOpen Ldt-TraceMe' title='dont minimize automatically'></div>      <div class='Ldt-tweetWidgetMinimize Ldt-TraceMe' title='minimize window'></div>      <div class='Ldt-tweetAvatar'></div>      <div class='Ldt-tweetAvatar-profileArrow'></div>      <div class='Ldt-tweetContents'></div>      <a href='' target='_blank' class='Ldt-Retweet Ldt-TraceMe'><div class='Ldt-RetweetIcon'></div> - Retweet </a>      <a href='' target='_blank' class='Ldt-TweetReply Ldt-TraceMe'><div class='Ldt-TweetReplyIcon'></div> - Reply</a>  </div></div>";/* utils.js - various utils that don't belong anywhere else */
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1106
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1107
/* trace function, for debugging */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1108
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1109
IriSP.traceNum = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1110
IriSP.trace = function( msg, value ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1111
/*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1112
	if( IriSP.config.gui.debug === true ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1113
		IriSP.traceNum += 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1114
		IriSP.jQuery( "<div>"+IriSP.traceNum+" - "+msg+" : "+value+"</div>" ).appendTo( "#Ldt-output" );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1115
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1116
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1117
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1118
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1119
/* used in callbacks - because in callbacks we lose "this",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1120
   we need to have a special function which wraps "this" in 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1121
   a closure. This way, the 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1122
*/   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1123
IriSP.wrap = function (obj, fn) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1124
  return function() {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1125
    var args = Array.prototype.slice.call(arguments, 0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1126
    return fn.apply(obj, args);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1127
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1128
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1129
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1130
/* convert a time to a percentage in the media */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1131
IriSP.timeToPourcent = function(time, timetotal){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1132
	var time = Math.abs(time);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1133
  var timetotal = Math.abs(timetotal);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1134
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1135
	return Math.floor((time/timetotal) * 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1136
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1137
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1138
IriSP.padWithZeros = function(num) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1139
  if (Math.abs(num) < 10) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1140
    return "0" + num.toString();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1141
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1142
    return num.toString();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1143
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1144
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1145
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1146
/* convert a number of milliseconds to a tuple of the form 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1147
   [hours, minutes, seconds]
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1148
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1149
IriSP.msToTime = function(ms) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1150
  return IriSP.secondsToTime(ms / 1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1151
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1152
/* convert a number of seconds to a tuple of the form 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1153
   [hours, minutes, seconds]
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1154
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1155
IriSP.secondsToTime = function(secs) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1156
  var hours = Math.abs(parseInt( secs / 3600 ) % 24);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1157
  var minutes = Math.abs(parseInt( secs / 60 ) % 60);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1158
  var seconds = parseFloat(Math.abs(secs % 60).toFixed(0));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1159
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1160
  var toString_fn = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1161
    var ret = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1162
    if (hours > 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1163
       ret = IriSP.padWithZeros(this.hours) + ":";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1164
    ret += IriSP.padWithZeros(this.minutes) + ":" + IriSP.padWithZeros(this.seconds);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1165
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1166
    return ret;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1167
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1168
  return {"hours" : hours, "minutes" : minutes, "seconds" : seconds, toString: toString_fn};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1169
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1170
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1171
/* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1172
IriSP.formatTweet = function(tweet) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1173
  /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1174
    an array of arrays which hold a regexp and its replacement.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1175
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1176
  var regExps = [
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1177
    /* copied from http://codegolf.stackexchange.com/questions/464/shortest-url-regex-match-in-javascript/480#480 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1178
    [/((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi, "<a href='$1'>$1</a>"],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1179
    [/@(\w+)/gi, "<a href='http://twitter.com/$1'>@$1</a>"], // matches a @handle
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1180
    [/#(\w+)/gi, "<a href='http://twitter.com/search?q=%23$1'>#$1</a>"],// matches a hashtag
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1181
    [/(\+\+)/gi, "<span class='Ldt-PolemicPlusPlus'>$1</span>"],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1182
    [/(--)/gi, "<span class='Ldt-PolemicMinusMinus'>$1</span>"],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1183
    [/(==)/gi, "<span class='Ldt-PolemicEqualEqual'>$1</span>"],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1184
    [/(\?\?)/gi, "<span class='Ldt-PolemicQuestion'>$1</span>"]
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1185
  ]; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1186
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1187
  var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1188
  for(i = 0; i < regExps.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1189
     tweet = tweet.replace(regExps[i][0], regExps[i][1]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1190
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1191
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1192
  return tweet;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1193
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1194
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1195
IriSP.countProperties = function(obj) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1196
    var count = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1197
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1198
    for(var prop in obj) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1199
        if(obj.hasOwnProperty(prop))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1200
                ++count;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1201
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1202
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1203
    return count;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1204
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1205
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1206
// conversion de couleur Decimal vers HexaDecimal || 000 si fff
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1207
IriSP.DEC_HEXA_COLOR = function (dec) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1208
  var val = +dec;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1209
  var str = val.toString(16);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1210
  var zeroes = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1211
  if (str.length < 6) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1212
    for (var i = 0; i < 6 - str.length; i++)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1213
      zeroes += "0";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1214
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1215
  return zeroes + str;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1216
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1217
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1218
/* shortcut to have global variables in templates */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1219
IriSP.templToHTML = function(template, values) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1220
  var params = IriSP.underscore.extend(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1221
      { "defaults" : IriSP.default_templates_vars,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1222
        "l10n" : IriSP.i18n.getMessages()
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1223
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1224
      values);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1225
  return Mustache.to_html(template, params);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1226
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1227
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1228
/* we need to be stricter than encodeURIComponent,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1229
   because of twitter
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1230
*/  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1231
IriSP.encodeURI = function(str) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1232
  return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1233
                                 replace(/\)/g, '%29').replace(/\*/g, '%2A');  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1234
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1235
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1236
IriSP.jqEscape = function(text) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1237
   return text.replace(/(:|\.)/g,'\\$1')
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1238
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1239
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1240
IriSP.jqId = function (text) { 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1241
   return IriSP.jQuery('#' + IriSP.jqEscape(text));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1242
 }  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1243
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1244
IriSP.__guidCounter = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1245
IriSP.guid = function(prefix) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1246
  IriSP.__guidCounter += 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1247
  return prefix + IriSP.__guidCounter;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1248
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1249
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1250
/** returns an url to share on facebook */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1251
IriSP.mkFbUrl = function(url, text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1252
  if (typeof(text) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1253
    text = "I'm watching ";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1254
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1255
  return "http://www.facebook.com/share.php?u=" + IriSP.encodeURI(text) + IriSP.shorten_url(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1256
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1257
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1258
/** returns an url to share on twitter */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1259
IriSP.mkTweetUrl = function(url, text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1260
  if (typeof(text) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1261
    text = "I'm watching ";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1262
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1263
  return "http://twitter.com/home?status=" + IriSP.encodeURI(text) + IriSP.shorten_url(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1264
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1265
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1266
/** returns an url to share on google + */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1267
IriSP.mkGplusUrl = function(url, text) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1268
  return "https://plusone.google.com/_/+1/confirm?hl=en&url=" + IriSP.shorten_url(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1269
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1270
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1271
/** test if a value is null or undefined */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1272
IriSP.null_or_undefined = function(val) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1273
  return (typeof(val) === "undefined" || val === null);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1274
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1275
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1276
/** get a property that can have multiple names **/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1277
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1278
IriSP.get_aliased = function(_obj, _aliases) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1279
    for (var _i = 0; _i < _aliases.length; _i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1280
        if (typeof _obj[_aliases[_i]] !== "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1281
            return _obj[_aliases[_i]];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1282
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1283
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1284
    return null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1285
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1286
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1287
/** issue a call to an url shortener and return the shortened url */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1288
IriSP.shorten_url = function(url) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1289
  if (IriSP.config.shortener.hasOwnProperty("shortening_function"))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1290
    return IriSP.config.shortener.shortening_function(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1291
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1292
  return url;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1293
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1294
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1295
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1296
/* for ie compatibility
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1297
if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1298
   Object.defineProperty=function(obj,prop,desc) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1299
      if ("get" in desc) obj.__defineGetter__(prop,desc.get);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1300
      if ("set" in desc) obj.__defineSetter__(prop,desc.set);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1301
   }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1302
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1303
*/
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1304
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1305
/* Creates regexps from text */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1306
IriSP.regexpFromText = function(_text) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1307
    return new RegExp('(' + _text.replace(/(\W)/gim,'\\$1') + ')','gim');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1308
}
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1309
/* wrapper that simulates popcorn.js because
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1310
   popcorn is a bit unstable at the time */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1311
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1312
IriSP.PopcornReplacement = {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1313
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1314
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1315
/** base class for our popcorn-compatible players.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1316
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1317
IriSP.PopcornReplacement.player = function(container, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1318
  /* the jwplayer calls the callbacks in the global space so we need to 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1319
     preserve them using IriSP.wrap */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1320
  this.callbacks = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1321
      onReady:  IriSP.wrap(this, this.__initApi),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1322
      onTime:   IriSP.wrap(this, this.__timeHandler),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1323
      onPlay:   IriSP.wrap(this, this.__playHandler),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1324
      onPause:  IriSP.wrap(this, this.__pauseHandler),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1325
      onSeek:   IriSP.wrap(this, this.__seekHandler) 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1326
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1327
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1328
  this.media = { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1329
    "paused": true,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1330
    "muted": false
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1331
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1332
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1333
  this.container = container.slice(1); //eschew the '#'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1334
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1335
  this.msgPump = {}; /* dictionnary used to receive and send messages */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1336
  this.__codes = []; /* used to schedule the execution of a piece of code in 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1337
                        a segment (similar to the popcorn.code plugin). */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1338
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1339
  this._options = options;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1340
                          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1341
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1342
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1343
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1344
  if (!this.msgPump.hasOwnProperty(msg))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1345
    this.msgPump[msg] = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1346
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1347
  this.msgPump[msg].push(callback);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1348
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1349
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1350
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1351
  if (!this.msgPump.hasOwnProperty(msg))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1352
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1353
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1354
  var d = this.msgPump[msg];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1355
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1356
  for(var i = 0; i < d.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1357
    d[i].call(window, params);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1358
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1359
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1360
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1361
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1362
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1363
  var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1364
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1365
      return v.toString(16);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1366
   });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1367
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1368
  return prefix + str;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1369
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1370
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1371
/** init the api after that flash player has been setup - called by the callback
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1372
    defined by the embedded flash player 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1373
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1374
IriSP.PopcornReplacement.player.prototype.__initApi = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1375
  this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1376
                                                      // but popcorn doesn't need to know more.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1377
  this.media.muted = this.playerFns.getMute();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1378
  /* some programmed segments are supposed to be run at the beginning */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1379
  var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1380
  for(i = 0; i < this.__codes.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1381
    var c = this.__codes[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1382
    if (0 == c.start) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1383
      c.onStart();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1384
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1385
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1386
    if (0 == c.end) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1387
      c.onEnd();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1388
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1389
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1390
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1391
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1392
/*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1393
IriSP.PopcornReplacement.jwplayer = function(container, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1394
  IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1395
  options.events = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1396
      onReady: IriSP.PopcornReplacement.__initApi,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1397
      onTime: IriSP.PopcornReplacement.__timeHandler,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1398
      onPlay: IriSP.PopcornReplacement.__playHandler,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1399
      onPause: IriSP.PopcornReplacement.__pauseHandler,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1400
      onSeek: IriSP.PopcornReplacement.__seekHandler 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1401
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1402
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1403
  jwplayer(IriSP.PopcornReplacement._container).setup(options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1404
  IriSP.PopcornReplacement.media.duration = options.duration;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1405
  return IriSP.PopcornReplacement;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1406
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1407
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1408
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1409
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1410
  if (typeof(time) === "undefined") {        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1411
      return this.playerFns.getPosition();            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1412
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1413
     var currentTime = +time;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1414
     this.playerFns.seek(currentTime);              
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1415
     return currentTime;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1416
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1417
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1418
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1419
IriSP.PopcornReplacement.player.prototype.play = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1420
  this.media.paused = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1421
  this.trigger("play");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1422
  //IriSP.PopcornReplacement.trigger("playing");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1423
  this.playerFns.play();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1424
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1425
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1426
IriSP.PopcornReplacement.player.prototype.pause = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1427
  if ( !this.media.paused ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1428
    this.media.paused = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1429
    this.trigger( "pause" );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1430
    this.playerFns.pause();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1431
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1432
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1433
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1434
IriSP.PopcornReplacement.player.prototype.muted = function(val) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1435
  if (typeof(val) !== "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1436
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1437
    if (this.playerFns.getMute() !== val) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1438
      if (val) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1439
        this.playerFns.setMute(true);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1440
        this.media.muted = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1441
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1442
        this.playerFns.setMute(false);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1443
        this.media.muted = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1444
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1445
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1446
      this.trigger( "volumechange" );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1447
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1448
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1449
    return this.playerFns.getMute();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1450
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1451
    return this.playerFns.getMute();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1452
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1453
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1454
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1455
IriSP.PopcornReplacement.player.prototype.volume = function(val) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1456
    if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1457
        return false;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1458
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1459
    var _vol = this.playerFns.getVolume();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1460
    if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1461
        val = Math.max(0, Math.min(1, val));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1462
        if (parseFloat(val) != parseFloat(_vol)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1463
            this.playerFns.setVolume(val);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1464
            this.trigger("volumechange");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1465
            _vol = this.playerFns.getVolume();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1466
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1467
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1468
    return _vol;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1469
};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1470
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1471
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1472
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1473
IriSP.PopcornReplacement.player.prototype.code = function(options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1474
  this.__codes.push(options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1475
  return this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1476
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1477
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1478
/* called everytime the player updates itself 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1479
   (onTime event)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1480
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1481
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1482
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1483
  var pos = event.position;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1484
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1485
  var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1486
  for(i = 0; i < this.__codes.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1487
     var c = this.__codes[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1488
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1489
     if (pos >= c.start && pos < c.end && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1490
         pos - 1 <= c.start) {       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1491
        c.onStart();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1492
     }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1493
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1494
     if (pos > c.start && pos > c.end && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1495
         pos - 1 <= c.end) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1496
         c.onEnd();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1497
     }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1498
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1499
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1500
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1501
  this.trigger("timeupdate");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1502
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1503
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1504
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1505
  var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1506
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1507
  for(i = 0; i < this.__codes.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1508
     var c = this.__codes[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1509
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1510
     if (event.position >= c.start && event.position < c.end) {        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1511
        c.onEnd();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1512
     }         
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1513
   }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1514
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1515
   for(i = 0; i < this.__codes.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1516
     var c = this.__codes[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1517
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1518
     if (typeof(event.offset) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1519
       event.offset = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1520
           
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1521
     if (event.offset >= c.start && event.offset < c.end) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1522
       c.onStart();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1523
     }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1524
     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1525
   }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1526
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1527
  /* this signal sends as an extra argument the position in the video.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1528
     As far as I know, this argument is not provided by popcorn */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1529
  this.trigger("seeked", event.offset);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1530
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1531
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1532
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1533
  this.media.paused = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1534
  this.trigger("play");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1535
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1536
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1537
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1538
  this.media.paused = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1539
  this.trigger("pause");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1540
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1541
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1542
IriSP.PopcornReplacement.player.prototype.roundTime = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1543
  var currentTime = this.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1544
  return Math.round(currentTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1545
};/* data.js - this file deals with how the players gets and sends data */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1546
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1547
IriSP.DataLoader = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1548
  this._cache = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1549
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1550
  /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1551
    A structure to hold callbacks for specific urls. We need it because
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1552
    ajax calls are asynchronous, so it means that sometimes we ask
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1553
    multiple times for a ressource because the first call hasn't been
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1554
    received yet.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1555
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1556
  this._callbacks = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1557
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1558
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1559
IriSP.DataLoader.prototype.get = function(url, callback) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1560
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1561
  var base_url = url.split("&")[0]
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1562
  if (this._cache.hasOwnProperty(base_url)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1563
    callback(this._cache[base_url]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1564
  } else {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1565
    if (!this._callbacks.hasOwnProperty(base_url)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1566
      this._callbacks[base_url] = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1567
      this._callbacks[base_url].push(callback);   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1568
      /* we need a closure because this gets lost when it's called back */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1569
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1570
      // uncomment you don't want to use caching.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1571
      // IriSP.jQuery.get(url, callback);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1572
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1573
      var func = function(data) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1574
                  this._cache[base_url] = data;                                
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1575
                  var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1576
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1577
                  for (i = 0; i < this._callbacks[base_url].length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1578
                    this._callbacks[base_url][i](this._cache[base_url]);                                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1579
                  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1580
      };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1581
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1582
      /* automagically choose between json and jsonp */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1583
      if (url.indexOf(document.location.hostname) === -1 &&
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1584
          url.indexOf("http://") !== -1 /* not a relative url */ ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1585
        // we contacting a foreign domain, use JSONP
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1586
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1587
        IriSP.jQuery.get(url, {}, IriSP.wrap(this, func), "jsonp");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1588
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1589
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1590
        // otherwise, hey, whatever rows your boat
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1591
        IriSP.jQuery.get(url, IriSP.wrap(this, func));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1592
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1593
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1594
    } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1595
      /* simply push the callback - it'll get called when the ressource
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1596
         has been received */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1597
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1598
      this._callbacks[base_url].push(callback);   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1599
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1600
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1601
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1602
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1603
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1604
/* the base abstract "class" */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1605
IriSP.Serializer = function(DataLoader, url) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1606
  this._DataLoader = DataLoader;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1607
  this._url = url;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1608
  this._data = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1609
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1610
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1611
IriSP.Serializer.prototype.serialize = function(data) { };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1612
IriSP.Serializer.prototype.deserialize = function(data) {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1613
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1614
IriSP.Serializer.prototype.currentMedia = function() {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1615
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1616
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1617
IriSP.Serializer.prototype.sync = function(callback) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1618
  callback.call(this, this._data);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1619
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1620
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1621
IriSP.SerializerFactory = function(DataLoader) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1622
  this._dataloader = DataLoader;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1623
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1624
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1625
IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1626
  /* This function returns serializer set-up with the correct
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1627
     configuration - takes a metadata struct describing the metadata source
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1628
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1629
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1630
  if (metadataOptions === undefined)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1631
    /* return an empty serializer */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1632
    return IriSP.Serializer("", "");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1633
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1634
  switch(metadataOptions.type) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1635
    case "json":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1636
      return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1637
      break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1638
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1639
    case "dummy": /* only used for unit testing - not defined in production */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1640
      return new IriSP.MockSerializer(this._dataloader, metadataOptions.src);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1641
      break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1642
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1643
    case "empty":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1644
      return new IriSP.Serializer("", "empty");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1645
      break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1646
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1647
    default:      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1648
      return undefined;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1649
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1650
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1651
/* site.js - all our site-dependent config : player chrome, cdn locations, etc...*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1652
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1653
IriSP.defaults = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1654
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1655
/* these objects are filled by configureDefaults. The function doesn't overwrite 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1656
   defaults that were originally defined by the user.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1657
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1658
IriSP.lib = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1659
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1660
/* We need to define those so that the individual settings can be overwritten */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1661
IriSP.widgetsDefaults = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1662
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1663
IriSP.paths = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1664
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1665
IriSP.libdir = "/metadataplayer/src/js/libs/";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1666
IriSP.jwplayer_swf_path = "../test/libs/player.swf";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1667
IriSP.platform_url = "http://192.168.56.101/pf";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1668
IriSP.default_templates_vars = { };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1669
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1670
IriSP.language = 'fr';
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1671
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1672
/** ugly ugly ugly ugly - returns an object defining 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1673
    the paths to the libs
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1674
    We need it that way cause it's called at runtime by
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1675
    IriSP.configureDefaults.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1676
*/   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1677
IriSP.defaults.lib = function(libdir) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1678
  if (IriSP.null_or_undefined(libdir))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1679
    libdir = IriSP.libdir;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1680
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1681
  return { 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1682
//      jQuery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1683
    jQuery : libdir + "jquery.min.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1684
//      jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1685
    jQueryUI : libdir + "jquery-ui.min.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1686
//      jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1687
    jQueryToolTip : libdir + "jquery.tools.min.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1688
//      swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1689
    swfObject : libdir + "swfobject.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1690
//      cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1691
    cssjQueryUI : libdir + "jquery-ui.css",
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1692
      popcorn : libdir + "popcorn.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1693
      jwplayer : libdir + "jwplayer.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1694
      popcornReplacement: libdir + "pop.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1695
      raphael: libdir + "raphael.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1696
      jquery_sparkline: libdir + "jquery.sparkline.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1697
      "popcorn.mediafragment" : libdir + "popcorn.mediafragment.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1698
      "popcorn.code" : libdir + "popcorn.code.js",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1699
      "popcorn.jwplayer": libdir + "popcorn.jwplayer.js",
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1700
      "popcorn.youtube": libdir + "popcorn.youtube.js",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1701
      "tracemanager": libdir + "tracemanager.js"
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1702
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1703
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1704
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1705
//Configuration for the player and utility functions.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1706
// No need to have them configured at runtime
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1707
IriSP.config = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1708
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1709
IriSP.config.shortener = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1710
  // function to call to shorten an url.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1711
  //shortening_function : IriSP.platform_shorten_url
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1712
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1713
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1714
IriSP.defaults.widgetsDefaults = function(platform_url) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1715
  if (IriSP.null_or_undefined(platform_url))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1716
    platform_url = IriSP.platform_url;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1717
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1718
  return {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1719
    "LayoutManager" : {spacer_div_height : "0px" },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1720
    "PlayerWidget" : {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1721
    "AnnotationsWidget": {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1722
      "share_text" : "I'm watching ",     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1723
      "fb_link" : "http://www.facebook.com/share.php?u=",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1724
      "tw_link" : "http://twitter.com/home?status=",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1725
      "gplus_link" : ""
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1726
      },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1727
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1728
    "TweetsWidget" : {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1729
        default_profile_picture : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1730
        tweet_display_period: 10000 // how long do we show a tweet ?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1731
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1732
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1733
    "SliderWidget" : {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1734
        minimize_period: 850 // how long does the slider stays maximized after the user leaves the zone ?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1735
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1736
    "createAnnotationWidget" : {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1737
        keywords: ["#amateur", "#digital-studies"],
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1738
        polemic_mode: true, /* enable polemics ? */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1739
        /* polemics - the corresponding class names defined in the css should be for instance :
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1740
           Ldt-createAnnotation-polemic-positive for positive
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1741
           Ldt-createAnnotation-polemic-equalequal for equalequal, etc.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1742
        */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1743
        polemics: [ { "className" : "positive", "keyword" : "++" }, { "className" : "negative", "keyword" : "--" }, { "className" : "reference", "keyword" : "==" }, { "className" : "question", "keyword" : "??" } ], 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1744
        cinecast_version: false, /* put to false to enable the platform version, true for the festival cinecast one. */
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1745
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1746
        /* where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media ans is filled
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1747
           by the widget. 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1748
        */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1749
        api_endpoint_template: platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1750
        api_method: "PUT"
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1751
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1752
    "SparklineWidget" : {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1753
        column_width: 10 // the width of a column in pixels.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1754
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1755
    "Main" : {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1756
        autoplay: true
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1757
    },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1758
    "AnnotationsListWidget" : {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1759
        ajax_mode: true, /* use ajax to get information about the annotations.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1760
                           if set to false, only search in the annotations for the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1761
                           current project. */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1762
        /* the platform generates some funky urls. We replace them afterwards to point to the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1763
           correct place - this setting will probably be overwritten by the platform 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1764
           implementers.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1765
           Note that the player has to replace the variables between {{ and }} by its own values.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1766
        */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1767
        ajax_url: platform_url + "/ldtplatform/api/ldt/segments/{media}/{begin}/{end}", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1768
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1769
        ajax_granularity: 10000, /* how much ms should we look before and after the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1770
                                   current timecode */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1771
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1772
        default_thumbnail: "/metadataplayer/src/css/imgs/video_sequence.png",
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1773
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1774
        project_url: platform_url + "/ldtplatform/ldt/front/player/" /* the beginning 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1775
                                                                        of a link to the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1776
                                                                        new front */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1777
    } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1778
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1779
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1780
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1781
/*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1782
Override this if you want to change the info the player receives about the user.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1783
It's typically overrided in server-side templates with user-specific data.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1784
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1785
IriSP.defaults.user = function() { return {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1786
      "name" : "Anonymous user",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1787
      "avatar" : IriSP.paths.imgs + "/user_default_icon.png"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1788
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1789
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1790
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1791
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1792
IriSP.defaults.paths = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1793
//  "imgs": "/tweetlive/res/metadataplayer/src/css/imgs"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1794
  "imgs": "/metadataplayer/src/css/imgs"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1795
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1796
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1797
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1798
IriSP.defaults.default_templates_vars = function() { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1799
  return {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1800
  "img_dir" : IriSP.paths.imgs 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1801
  };
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1802
}/* the widget classes and definitions */
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1803
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1804
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1805
  * @class Widget is an "abstract" class. It's mostly used to define some properties common to every widget.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1806
  *
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1807
  *  Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1808
  *  defined in init.js
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1809
  *  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1810
  * @constructor
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1811
  * @param Popcorn a reference to the popcorn Object
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1812
  * @param config configuration options for the widget
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1813
  * @param Serializer a serializer instance from which the widget reads data fromCharCode  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1814
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1815
IriSP.Widget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1816
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1817
  if (config === undefined || config === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1818
    config = {}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1819
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1820
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1821
  this._Popcorn = Popcorn;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1822
  this._config = config;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1823
  this._serializer = Serializer;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1824
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1825
  if (config.hasOwnProperty("container")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1826
     this._id = config.container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1827
     this.selector = IriSP.jQuery("#" + this._id);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1828
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1829
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1830
  if (config.hasOwnProperty("spacer")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1831
     this._spacerId = config.spacer;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1832
     this.spacer = IriSP.jQuery("#" + this._spacerId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1833
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1834
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1835
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1836
  if (config.hasOwnProperty("width")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1837
     // this.width and not this._width because we consider it public.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1838
     this.width = config.width;     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1839
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1840
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1841
  if (config.hasOwnProperty("height")) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1842
     this.height = config.height;     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1843
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1844
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1845
  if (config.hasOwnProperty("heightmax")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1846
     this.heightmax = config.heightmax;     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1847
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1848
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1849
  if (config.hasOwnProperty("widthmax")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1850
     this.widthmax = config.widthmax;     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1851
  } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1852
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1853
  if (config.hasOwnProperty("layoutManager")) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1854
     this.layoutManager = config.layoutManager;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1855
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1856
  if (typeof this.selector != "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1857
      this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1858
      this.selector.attr("widget-type", this._config.type);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1859
  }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1860
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1861
};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1862
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1863
// This functions checks for configuration options
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1864
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1865
IriSP.Widget.prototype.checkOption = function(_name, _default) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1866
    this[_name] = (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1867
        typeof this._config[_name] != "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1868
        ? this._config[_name]
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1869
        : (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1870
            (typeof IriSP.widgetsDefaults[this._config.type] != "undefined" && IriSP.widgetsDefaults[this._config.type][_name] != "undefined")
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1871
            ? IriSP.widgetsDefaults[this._config.type][_name]
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1872
            : (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1873
                typeof _default != "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1874
                ? _default
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1875
                : null
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1876
            )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1877
        )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1878
    )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  1879
}
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1880
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1881
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1882
  * This method responsible of drawing a widget on screen.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1883
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1884
IriSP.Widget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1885
  /* implemented by "sub-classes" */  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1886
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1887
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1888
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1889
  * Optional method if you want your widget to support redraws.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1890
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1891
IriSP.Widget.prototype.redraw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1892
  /* implemented by "sub-classes" */  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1893
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1894
/* modules are non-graphical entities, similar to widgets */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1895
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1896
IriSP.Module = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1897
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1898
  if (config === undefined || config === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1899
    config = {}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1900
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1901
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1902
  this._Popcorn = Popcorn;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1903
  this._config = config;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1904
  this._serializer = Serializer;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1905
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1906
/* layout.js - very basic layout management */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1907
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1908
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1909
  @class a layout manager manages a div and the layout of objects
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1910
  inside it.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1911
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1912
IriSP.LayoutManager = function(options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1913
    this._Popcorn = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1914
    this._widgets = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1915
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1916
    this._div = "LdtPlayer";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1917
    this._width = 640;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1918
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1919
    if (options === undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1920
      options = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1921
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1922
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1923
    if (options.hasOwnProperty('container')) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1924
      this._div = options.container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1925
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1926
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1927
    if (options.hasOwnProperty('width')) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1928
      this._width = options.width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1929
    }    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1930
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1931
    if (options.hasOwnProperty('height')) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1932
      this._height = options.height;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1933
    } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1934
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1935
    /* this is a shortcut */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1936
    this.selector = IriSP.jQuery("#" + this._div);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1937
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1938
    this.selector.css("width", this._width);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1939
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1940
    if (this._height !== undefined)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1941
      this.selector.css("height", this._height);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1942
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1943
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1944
/** 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1945
   Set the popcorn instance used by the manager.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1946
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1947
   we need this special setter because of a chicken and egg problem :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1948
   we want the manager to use popcorn but the popcorn div will be managed
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1949
   by the manager. So we need a way to set the instance the manager uses
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1950
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1951
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1952
IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1953
    this._Popcorn = popcorn;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1954
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1955
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1956
/** create a subdiv with an unique id, and a spacer div as well.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1957
    @param widgetName the name of the widget.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1958
    @return an array of the form [createdivId, spacerdivId].
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1959
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1960
IriSP.LayoutManager.prototype.createDiv = function(widgetName) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1961
    if (typeof(widgetName) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1962
       widgetName = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1963
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1964
    var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1965
    var spacerDiv = IriSP.guid("LdtPlayer_spacer_");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1966
    this._widgets.push([widgetName, newDiv]);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1967
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1968
    var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative;'></div";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1969
    var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1970
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1971
    var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1972
    var spacerCode = Mustache.to_html(spacerTempl, {spacer_id: spacerDiv, width: this._width,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1973
                                                    spacer_div_height: IriSP.widgetsDefaults.LayoutManager.spacer_div_height });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1974
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1975
    this.selector.append(divCode);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1976
    this.selector.append(spacerCode);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1977
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1978
    return [newDiv, spacerDiv];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1979
};/* init.js - initialization and configuration of Popcorn and the widgets
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1980
exemple json configuration:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1981
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1982
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1983
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1984
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1985
    set up the IriSP.__dataloader instance - 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1986
    we need it because we have to get the metadata
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1987
    about the video before that the widget have even
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1988
    loaded.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1989
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1990
IriSP.setupDataLoader = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1991
  /* we set it up separately because we need to
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1992
     get data at the very beginning, for instance when
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1993
     setting up the video */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1994
  IriSP.__dataloader = new IriSP.DataLoader();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1995
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1996
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1997
/** do some magic to configure popcorn according to the options object passed.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1998
    Works for html5, jwplayer and youtube videos 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  1999
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2000
IriSP.configurePopcorn = function (layoutManager, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2001
    var pop;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2002
    var ret = layoutManager.createDiv(); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2003
    var containerDiv = ret[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2004
    var spacerDiv = ret[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2005
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2006
    /* insert one pixel of margin between the video and the first widget, using the 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2007
       spacer.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2008
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2009
    IriSP.jQuery("#" + spacerDiv).css("height", "1px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2010
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2011
    switch(options.type) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2012
      /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2013
        todo : dynamically create the div/video tag which
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2014
        will contain the video.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2015
      */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2016
      case "html5":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2017
           var tmpId = Popcorn.guid("video"); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2018
           IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2019
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2020
           if (options.hasOwnProperty("width"))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2021
             IriSP.jQuery("#" + containerDiv).css("width", options.width);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2022
           
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2023
           if (options.hasOwnProperty("height"))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2024
             IriSP.jQuery("#" + containerDiv).css("height", options.height);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2025
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2026
           pop = Popcorn("#" + tmpId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2027
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2028
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2029
      case "jwplayer":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2030
          var opts = IriSP.jQuery.extend({}, options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2031
          delete opts.container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2032
          delete opts.type;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2033
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2034
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2035
          /* Try to guess options.file and options.streamer only if file and streamer
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2036
             are not already defined in the configuration */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2037
          if (options.provider === "rtmp" && !opts.hasOwnProperty("file") && !opts.hasOwnProperty("streamer")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2038
            /* exit if we can't access the metadata */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2039
            if (typeof(IriSP.__jsonMetadata) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2040
                break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2041
            };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2042
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2043
            // the json format is totally illogical
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2044
            //opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2045
            //var source = IriSP.__jsonMetadata["medias"][0]["href"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2046
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2047
            // the source if a full url but jwplayer wants an url relative to the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2048
            // streamer url, so we've got to remove the common part.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2049
            //opts.file = source.slice(opts.streamer.length);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2050
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2051
            /* sometimes we get served a file with a wrong path and streamer.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2052
               as a streamer is of the form rtmp://domain/path/ and the media is
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2053
               the rest, we uglily do this :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2054
            */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2055
            opts.file = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2056
            opts.streamer = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2057
            var fullPath = IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2058
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2059
            if (fullPath === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2060
              console.log("no url or href field defined in the metadata.");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2061
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2062
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2063
            var pathSplit = fullPath.split('/');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2064
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2065
            for (var i = 0; i < pathSplit.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2066
              if (i < 4) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2067
                 opts.streamer += pathSplit[i] + "/";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2068
              } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2069
                 opts.file += pathSplit[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2070
                 /* omit the last slash if we're on the last element */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2071
                 if (i < pathSplit.length - 1)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2072
                  opts.file += "/";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2073
              }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2074
            }            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2075
          } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2076
            /* other providers type, video for instance -
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2077
               pass everything as is */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2078
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2079
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2080
          if (!options.hasOwnProperty("flashplayer")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2081
            opts.flashplayer = IriSP.jwplayer_swf_path;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2082
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2083
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2084
          if (!options.hasOwnProperty("controlbar.position")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2085
            opts["controlbar.position"] = "none";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2086
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2087
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2088
          pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2089
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2090
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2091
      case "youtube":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2092
          var opts = IriSP.jQuery.extend({}, options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2093
          delete opts.container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2094
          opts.controls = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2095
          opts.autostart = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2096
          templ = "width: {{width}}px; height: {{height}}px;";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2097
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2098
          // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2099
          IriSP.jQuery("#" + containerDiv).attr("style", str);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2100
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2101
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2102
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2103
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2104
    case "dailymotion":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2105
        pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2106
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2107
             
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2108
      case "allocine":
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2109
          /* pass the options as-is to the allocine player and let it handle everything */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2110
          pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2111
          break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2112
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2113
      default:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2114
        pop = undefined;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2115
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2116
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2117
    return pop;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2118
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2119
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2120
/** Configure the gui and instantiate the widgets passed as parameters
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2121
    @param guiOptions the gui object as seen in the examples.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2122
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2123
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2124
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2125
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2126
  var params = {width: guiOptions.width, height: guiOptions.height};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2127
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2128
  var default_options = guiOptions.default_options;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2129
  if (IriSP.null_or_undefined(default_options))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2130
    default_options = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2131
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2132
  var ret_widgets = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2133
  var index;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2134
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2135
  for (index = 0; index < guiOptions.widgets.length; index++) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2136
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, guiOptions.widgets[index], default_options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2137
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2138
    ret_widgets.push(widget);   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2139
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2140
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2141
  return ret_widgets;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2142
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2143
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2144
/** configure modules. @see configureWidgets */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2145
IriSP.configureModules = function (popcornInstance, modulesList) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2146
  if (IriSP.null_or_undefined(modulesList))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2147
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2148
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2149
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2150
  var ret_modules = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2151
  var index;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2152
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2153
  for (index = 0; index < modulesList.length; index++) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2154
    var moduleConfig = modulesList[index];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2155
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2156
    var serializer = serialFactory.getSerializer(moduleConfig.metadata);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2157
    var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2158
    ret_modules.push(module);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2159
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2160
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2161
  return ret_modules;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2162
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2163
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2164
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2165
    dependencies.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2166
    @param popcornInstance popcorn instance the widget will user
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2167
    @param serialFactory serializer factory to instantiate the widget with
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2168
    @param layoutManager layout manager
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2169
    @param widgetConfig configuration options for the widget
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2170
    @param defaultOptions a dictionnary with some options defined for every widget.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2171
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2172
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig, defaultOptions) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2173
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2174
    if (IriSP.null_or_undefined(defaultOptions))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2175
      defaultOptions = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2176
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2177
    widgetConfig = IriSP.underscore.defaults(widgetConfig, defaultOptions);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2178
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2179
    var arr = IriSP.jQuery.extend({}, widgetConfig);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2180
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2181
    /* create a div for those widgets who didn't already specify a container; */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2182
    if (!arr.hasOwnProperty("container")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2183
      /* create div returns us a container for the widget and a spacer */    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2184
      var ret = layoutManager.createDiv(widgetConfig.type);        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2185
      var container = ret[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2186
      var spacer = ret[1];           
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2187
      arr.container = container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2188
      arr.spacer = spacer;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2189
      arr.layoutManager = layoutManager;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2190
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2191
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2192
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2193
    if (typeof serializer == "undefined")   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2194
      debugger;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2195
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2196
    // instantiate the object passed as a string
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2197
    var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2198
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2199
    if (widgetConfig.hasOwnProperty("requires")) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2200
      // also create the widgets this one depends on.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2201
      // the dependency widget is available in the parent widget context as
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2202
      // this.WidgetName (for instance, this.TipWidget);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2203
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2204
      var i = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2205
      for(i = 0; i < widgetConfig.requires.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2206
        var widgetName = widgetConfig.requires[i]["type"],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2207
            _configobj = IriSP.jQuery.extend({}, widgetConfig.requires[i]),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2208
            _div = document.createElement('div'),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2209
            _container = IriSP.guid(arr.container + '_' + widgetName + '_');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2210
        _configobj.container = _container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2211
        _div.id = _container;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2212
        widget.selector.append(_div);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2213
        widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, _configobj, defaultOptions);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2214
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2215
    }       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2216
     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2217
    serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2218
    return widget;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2219
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2220
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2221
/** Go through the defaults to set a reasonable value */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2222
IriSP.configureDefaults = function(libdir, platform_url) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2223
  /* the defaults configuration is messy and complicated. There are two things to know :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2224
     - we want to allow overwriting of defaults - that's why we have IriSP.widgetDefaults
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2225
       and IriSP.defaults.widgetDefaults. The first is filled by the embedder and then fleshed out
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2226
       with the contents of the first. We use underscore.defaults for that, but there's one problem with
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2227
       this function : it doesn't work recursively.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2228
     - we need to compute some values at runtime instead of at compile time
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2229
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2230
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2231
  IriSP.lib = IriSP.underscore.defaults(IriSP.lib, IriSP.defaults.lib(libdir));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2232
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2233
  /* get the factory defaults for the widgets and merge them with the default the user
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2234
     may have defined 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2235
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2236
  var factory_defaults = IriSP.defaults.widgetsDefaults(platform_url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2237
  for(var widget in factory_defaults) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2238
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2239
      /* create the object if it doesn't exists */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2240
      if (IriSP.null_or_undefined(IriSP.widgetsDefaults[widget]))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2241
        IriSP.widgetsDefaults[widget] = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2242
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2243
      IriSP.widgetsDefaults[widget] = IriSP.underscore.defaults(IriSP.widgetsDefaults[widget], factory_defaults[widget]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2244
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2245
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2246
  IriSP.paths = IriSP.underscore.defaults(IriSP.paths, IriSP.defaults.paths);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2247
  IriSP.default_templates_vars = IriSP.underscore.defaults(IriSP.default_templates_vars, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2248
                                       IriSP.defaults.default_templates_vars());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2249
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2250
  if (IriSP.null_or_undefined(IriSP.user))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2251
    IriSP.user = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2252
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2253
  IriSP.user = IriSP.underscore.defaults(IriSP.user, IriSP.defaults.user());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2254
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2255
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2256
/** single point of entry for the metadataplayer */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2257
IriSP.initPlayer = function(config, metadata_url, libdir, platform_url) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2258
    document.getElementById(config.gui.container).innerHTML = IriSP.templToHTML(IriSP.loading_template, config.gui);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2259
    IriSP.configureDefaults(libdir, platform_url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2260
    IriSP.loadLibs(IriSP.lib, config, metadata_url,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2261
      function() {   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2262
              
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2263
              var layoutManager = new IriSP.LayoutManager(config.gui);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2264
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2265
              var pop = IriSP.configurePopcorn(layoutManager, config.player);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2266
              
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2267
              var widgets = IriSP.configureWidgets(pop, layoutManager, config.gui); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2268
              var modules = IriSP.configureModules(pop, config.modules); 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2269
              IriSP.jQuery('#Ldt-loader').detach();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2270
      });
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2271
};IriSP.I18n = function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2272
    this.messages = {};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2273
    this.base_lang = 'en';
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2274
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2275
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2276
IriSP.I18n.prototype.getLanguage = function(lang) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2277
    var _lang = (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2278
        typeof lang != "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2279
        ? lang
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2280
        : (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2281
            typeof IriSP.language != "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2282
            ? IriSP.language
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2283
            : this.base_lang
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2284
        )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2285
    );
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2286
    return (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2287
        typeof this.messages[_lang] == "object"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2288
        ? _lang
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2289
        : (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2290
            typeof this.messages[this.base_lang] == "object"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2291
            ? this.base_lang
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2292
            : null
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2293
        )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2294
    )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2295
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2296
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2297
IriSP.I18n.prototype.getMessages = function(lang) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2298
    var _lang = this.getLanguage(lang);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2299
    return (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2300
        _lang != null
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2301
        ? this.messages[_lang]
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2302
        : {}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2303
    );
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2304
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2305
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2306
IriSP.I18n.prototype.getMessage = function(message, lang) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2307
    var _msgs = this.getMessages(lang);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2308
    return (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2309
        typeof _msgs[message] != "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2310
        ? _msgs[message]
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2311
        : message
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2312
    )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2313
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2314
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2315
IriSP.I18n.prototype.addMessage = function(lang, messagekey, messagevalue) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2316
    if (typeof this.messages[lang] == "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2317
        this.messages[lang] = {};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2318
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2319
    this.messages[lang][messagekey] = messagevalue;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2320
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2321
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2322
IriSP.I18n.prototype.addMessages = function(messagesObj) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2323
    var _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2324
    IriSP.underscore(messagesObj).each(function(_messages, _lang) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2325
        IriSP.underscore(_messages).each(function(_value, _key) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2326
            _this.addMessage(_lang, _key, _value);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2327
        })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2328
    });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2329
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2330
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2331
IriSP.i18n = new IriSP.I18n();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2332
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2333
IriSP.i18n.addMessages({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2334
    "fr": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2335
        "loading_wait": "Chargement en cours, veuillez patienter&hellip;"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2336
    },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2337
    "en": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2338
        "loading_wait": "Loading, please wait&hellip;"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2339
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2340
})
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2341
/* To wrap a player the develop should create a new class derived from
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2342
the IriSP.PopcornReplacement.player and defining the correct functions */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2343
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2344
/** allocine player wrapper */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2345
IriSP.PopcornReplacement.allocine = function(container, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2346
//    console.log("Calling allocine player");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2347
    /* appel du parent pour initialiser les structures communes à tous les players */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2348
    IriSP.PopcornReplacement.player.call(this, container, options);   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2349
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2350
    var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2351
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2352
    /* Définition des fonctions de l'API -  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2353
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2354
    this.playerFns = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2355
        play : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2356
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2357
            //    console.log("ask play _this.player = " + _this.player);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2358
                return _this.player.sendToActionScript("play");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2359
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2360
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2361
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2362
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2363
        pause : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2364
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2365
            //    console.log("ask pause _this.player = " + _this.player);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2366
                return _this.player.sendToActionScript("pause");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2367
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2368
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2369
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2370
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2371
        getPosition : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2372
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2373
                return _this.player.sendToActionScript("getSeek","return");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2374
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2375
                return 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2376
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2377
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2378
        seek : function(pos) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2379
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2380
                return _this.player.sendToActionScript("seek",pos);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2381
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2382
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2383
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2384
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2385
        getMute : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2386
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2387
                return _this.player.sendToActionScript("getMute","return");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2388
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2389
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2390
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2391
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2392
        setMute : function(p) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2393
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2394
                //return p ? _this.player.sendToActionScript("setMute") : _this.player.sendToActionScript("setMute");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2395
            	_this.player.sendToActionScript("setMute");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2396
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2397
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2398
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2399
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2400
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2401
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2402
    window.onReady = IriSP.wrap(this, this.ready);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2403
    window.onAllocineStateChange = IriSP.wrap(this, this.stateHandler);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2404
    window.onTime = IriSP.wrap(this, this.progressHandler);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2405
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2406
    var _videoUrl = (
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2407
        typeof options.directVideoPath == "string"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2408
        ? options.directVideoPath
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2409
        : IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"])
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2410
    );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2411
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2412
    var fv = "streamFMS=true&adVast=false&lg=fr_cinecast&autoPlay=" + options.autoPlay + "&directVideoTitle=&urlAcData=" + options.urlAcData + "&directVideoPath=" + _videoUrl + "&host=http://allocine.fr";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2413
//    console.log("fv = " + fv);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2414
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2415
    var params = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2416
        "allowScriptAccess" : "always",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2417
        "wmode": "opaque",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2418
        "flashvars" : fv
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2419
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2420
    var atts = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2421
        id : this.container
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2422
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2423
    swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "8", null, null, params, atts);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2424
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2425
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2426
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2427
IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2428
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2429
IriSP.PopcornReplacement.allocine.prototype.ready = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2430
    this.player = document.getElementById(this.container);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2431
    this.player.addEventListener("onStateChange", "onAllocineStateChange");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2432
    this.player.addEventListener("onVideoProgress", "onAllocineVideoProgress");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2433
    this.player.cueVideoByUrl(this._options.video);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2434
    this.callbacks.onReady();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2435
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2436
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2437
IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2438
    this.callbacks.onTime({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2439
        position: progressInfo.mediaTime
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2440
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2441
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2442
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2443
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2444
IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2445
    console.log("stateHandler");
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2446
    switch(state) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2447
        case 1:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2448
            this.callbacks.onPlay();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2449
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2450
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2451
        case 2:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2452
            this.callbacks.onPause();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2453
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2454
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2455
        case 3:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2456
            this.callbacks.onSeek({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2457
                position: this.player.getCurrentTime()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2458
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2459
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2460
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2461
        /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2462
        case 5:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2463
            this.callbacks.onReady();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2464
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2465
        */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2466
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2467
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2468
};/* To wrap a player the develop should create a new class derived from
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2469
the IriSP.PopcornReplacement.player and defining the correct functions */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2470
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2471
/** jwplayer player wrapper */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2472
IriSP.PopcornReplacement.dailymotion = function(container, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2473
    console.log("Calling");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2474
    /* appel du parent pour initialiser les structures communes à tous les players */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2475
    IriSP.PopcornReplacement.player.call(this, container, options);   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2476
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2477
    var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2478
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2479
    /* Définition des fonctions de l'API -  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2480
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2481
    this.playerFns = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2482
        play : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2483
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2484
                return _this.player.playVideo();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2485
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2486
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2487
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2488
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2489
        pause : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2490
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2491
                return _this.player.pauseVideo();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2492
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2493
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2494
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2495
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2496
        getPosition : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2497
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2498
                return _this.player.getCurrentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2499
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2500
                return 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2501
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2502
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2503
        seek : function(pos) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2504
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2505
                return _this.player.seekTo(pos);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2506
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2507
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2508
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2509
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2510
        getMute : function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2511
            if (_this.player) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2512
                return _this.player.isMuted();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2513
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2514
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2515
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2516
        },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2517
        setMute : function(p) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2518
            if (_this.player) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2519
                if (p) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2520
                    _this.player.mute();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2521
                }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2522
                else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2523
                    _this.player.unMute();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2524
                }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2525
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2526
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2527
        getVolume : function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2528
            if (_this.player) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2529
                return _this.player.getVolume() / 100;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2530
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2531
                return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2532
            }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2533
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2534
        setVolume : function(p) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2535
            if (_this.player) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2536
                _this.player.setVolume(Math.floor(100 * p));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2537
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2538
        },
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2539
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2540
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2541
    window.onDailymotionPlayerReady = IriSP.wrap(this, this.ready);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2542
    window.onDailymotionStateChange = IriSP.wrap(this, this.stateHandler);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2543
    window.onDailymotionVideoProgress = IriSP.wrap(this, this.progressHandler);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2544
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2545
    var params = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2546
        "allowScriptAccess" : "always",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2547
        "wmode": "opaque"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2548
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2549
    var atts = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2550
        id : this.container
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2551
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2552
    swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2553
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2554
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2555
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2556
IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2557
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2558
IriSP.PopcornReplacement.dailymotion.prototype.ready = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2559
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2560
    this.player = document.getElementById(this.container);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2561
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2562
    this.player.addEventListener("onStateChange", "onDailymotionStateChange");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2563
    this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2564
    this.player.cueVideoByUrl(this._options.video);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2565
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2566
    this.callbacks.onReady();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2567
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2568
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2569
IriSP.PopcornReplacement.dailymotion.prototype.progressHandler = function(progressInfo) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2570
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2571
    this.callbacks.onTime({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2572
        position: progressInfo.mediaTime
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2573
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2574
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2575
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2576
IriSP.PopcornReplacement.dailymotion.prototype.stateHandler = function(state) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2577
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2578
    switch(state) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2579
        case 1:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2580
            this.callbacks.onPlay();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2581
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2582
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2583
        case 2:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2584
            this.callbacks.onPause();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2585
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2586
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2587
        case 3:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2588
            this.callbacks.onSeek({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2589
                position: this.player.getCurrentTime()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2590
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2591
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2592
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2593
        /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2594
        case 5:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2595
            this.callbacks.onReady();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2596
            break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2597
        */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2598
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2599
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2600
};/* To wrap a player the develop should create a new class derived from 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2601
   the IriSP.PopcornReplacement.player and defining the correct functions */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2602
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2603
/** jwplayer player wrapper */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2604
IriSP.PopcornReplacement.jwplayer = function(container, options) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2605
  /* appel du parent pour initialiser les structures communes à tous les players */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2606
  IriSP.PopcornReplacement.player.call(this, container, options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2607
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2608
  this.media.duration = options.duration; /* optional */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2609
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2610
  /* Définition des fonctions de l'API -  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2611
  this.playerFns = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2612
    play: function() { return jwplayer(this.container).play(); },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2613
    pause: function() { return jwplayer(this.container).pause(); },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2614
    getPosition: function() { return jwplayer(this.container).getPosition(); },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2615
    seek: function(pos) { return jwplayer(this.container).seek(pos); },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2616
    getMute: function() { return jwplayer(this.container).getMute() },
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2617
    setMute: function(p) { return jwplayer(this.container).setMute(p); },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2618
    getVolume: function() { return jwplayer(this.container).getVolume() / 100; },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2619
    setVolume: function(p) { return jwplayer(this.container).setVolume(Math.floor(100*p)); }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2620
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2621
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2622
  options.events = this.callbacks;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2623
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2624
  jwplayer(this.container).setup(options);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2625
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2626
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2627
IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2628
/* embed module - listens and relay hash changes to a parent window. */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2629
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2630
IriSP.EmbedModule = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2631
  IriSP.Module.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2632
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2633
  window.addEventListener('message', IriSP.wrap(this, this.handleMessages), false);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2634
  this._Popcorn.listen("IriSP.Mediafragment.hashchange", IriSP.wrap(this, this.relayChanges));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2635
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2636
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2637
IriSP.EmbedModule.prototype = new IriSP.Module();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2638
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2639
IriSP.EmbedModule.prototype.handleMessages = function(e) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2640
  if (e.data.type === "hashchange") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2641
    window.location.hash = e.data.value;    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2642
  }  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2643
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2644
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2645
IriSP.EmbedModule.prototype.relayChanges = function(newHash) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2646
  window.parent.postMessage({type: "hashchange", value: newHash}, "*"); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2647
  return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2648
};/* mediafragment module */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2649
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2650
IriSP.MediaFragment = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2651
  IriSP.Module.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2652
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2653
  this.mutex = false; /* a mutex because we access the url from two different functions */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2654
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2655
  this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this,this.advanceTime));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2656
  this._Popcorn.listen( "pause", IriSP.wrap(this,this.updateTime));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2657
  this._Popcorn.listen( "seeked", IriSP.wrap(this,this.updateTime));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2658
  this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this,this.updateAnnotation));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2659
  this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this,this.updateAnnotation));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2660
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2661
  window.onhashchange = IriSP.wrap(this, this.advanceTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2662
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2663
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2664
IriSP.MediaFragment.prototype = new IriSP.Module();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2665
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2666
IriSP.MediaFragment.prototype.advanceTime = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2667
             var url = window.location.href;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2668
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2669
              if ( url.split( "#" )[ 1 ] != null ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2670
                  pageoffset = url.split( "#" )[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2671
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2672
                  if ( pageoffset.substring(0, 2) === "t=") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2673
                    // timecode 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2674
                    if ( pageoffset.substring( 2 ) != null ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2675
                    var offsettime = pageoffset.substring( 2 );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2676
                    this._Popcorn.currentTime( parseFloat(offsettime) );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2677
                    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2678
                    /* we have to trigger this signal manually because of a
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2679
                     bug in the jwplayer */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2680
                    this._Popcorn.trigger("seeked", parseFloat(offsettime));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2681
                    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2682
                  } else if ( pageoffset.substring(0, 3) === "id=") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2683
                    // annotation
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2684
                    var annotationId = pageoffset.substring( 3 );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2685
                    // there's no better way than that because
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2686
                    // of possible race conditions
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2687
                    this._serializer.sync(IriSP.wrap(this, function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2688
                          this.lookupAnnotation.call(this, annotationId); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2689
                          }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2690
                  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2691
              }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2692
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2693
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2694
/** handler for the seeked signal. It may have or may have not an argument.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2695
    @param time if not undefined, the time we're seeking to 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2696
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2697
IriSP.MediaFragment.prototype.updateTime = function(time) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2698
  if (this.mutex === true) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2699
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2700
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2701
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2702
  var history = window.history;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2703
  if ( !history.pushState ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2704
    return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2705
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2706
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2707
  if (IriSP.null_or_undefined(time) || typeof(time) != "number") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2708
    var ntime = this._Popcorn.currentTime().toFixed(2)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2709
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2710
    var ntime = time.toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2711
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2712
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2713
  // used to relay the new hash to the embedder
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2714
  this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#t=" + ntime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2715
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2716
  splitArr = window.location.href.split( "#" )
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2717
  history.replaceState( {}, "", splitArr[0] + "#t=" + ntime );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2718
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2719
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2720
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2721
IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2722
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2723
  this.mutex = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2724
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2725
  var history = window.history;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2726
  if ( !history.pushState ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2727
    return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2728
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2729
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2730
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2731
  // used to relay the new hash to the embedder
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2732
  this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#id=" + annotationId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2733
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2734
  splitArr = window.location.href.split( "#" )
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2735
  history.replaceState( {}, "", splitArr[0] + "#id=" + annotationId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2736
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2737
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2738
  // reset the mutex afterwards to prevent the module from reacting to his own changes.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2739
  window.setTimeout(function() { _this.mutex = false }, 50);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2740
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2741
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2742
// lookup and seek to the beginning of an annotation
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2743
IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2744
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2745
  this.mutex = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2746
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2747
  var annotation = undefined;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2748
  var annotations = this._serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2749
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2750
  var i;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2751
  for (i = 0; i < annotations.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2752
      if (annotations[i].id === annotationId) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2753
        annotation = annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2754
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2755
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2756
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2757
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2758
  if (typeof(annotation) !== "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2759
    this._Popcorn.currentTime(annotation.begin / 1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2760
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2761
    /* we have to trigger this signal manually because of a
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2762
     bug in the jwplayer */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2763
    this._Popcorn.trigger("seeked", annotation.begin / 1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2764
    this._Popcorn.trigger("IriSP.Mediafragment.showAnnotation", annotationId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2765
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2766
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2767
  window.setTimeout(function() { _this.mutex = false }, 50);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2768
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2769
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2770
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2771
  this.__counter = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2772
  this.__oldList = [];
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2773
 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2774
  this.checkOption('ajax_mode');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2775
  this.checkOption('project_url');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2776
  this.checkOption('default_thumbnail');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2777
  this.checkOption("cinecast_version", false);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2778
  this.searchRe = null;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2779
  this._ajax_cache = [];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2780
  var _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2781
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2782
  this._Popcorn.listen("IriSP.search", function(searchString) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2783
      _this.searchHandler(searchString);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2784
  });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2785
  this._Popcorn.listen("IriSP.search.closed", function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2786
      _this.searchHandler(false);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2787
  });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2788
  this._Popcorn.listen("IriSP.search.cleared", function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2789
      _this.searchHandler(false);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2790
  });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2791
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2792
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2793
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2794
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2795
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2796
IriSP.AnnotationsListWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2797
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2798
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2799
IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2800
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2801
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2802
IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2803
  this.searchRe = (searchString && searchString.length) ? IriSP.regexpFromText(searchString) : null;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2804
  if (this.ajax_mode) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2805
      var _this = this,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2806
        _annotations = (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2807
            this.searchRe === null
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2808
            ? this._ajax_cache
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2809
            : IriSP.underscore.filter(this._ajax_cache, function(_a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2810
               return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2811
            })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2812
        );
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2813
    this.do_redraw(_annotations);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2814
    if (_annotations.length) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2815
        this._Popcorn.trigger("IriSP.search.matchFound");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2816
      } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2817
        this._Popcorn.trigger("IriSP.search.noMatchFound");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2818
      }    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2819
  } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2820
      this.drawList();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2821
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2822
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2823
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2824
/** effectively redraw the widget - called by drawList */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2825
IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2826
    var _html = IriSP.templToHTML(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2827
        IriSP.annotationsListWidget_template, {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2828
            annotations: list
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2829
        }),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2830
        _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2831
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2832
    this.selector.html(_html);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2833
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2834
    if (this.searchRe !== null) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2835
        this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description")
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2836
            .each(function()  {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2837
                var _$ = IriSP.jQuery(this);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2838
                _$.html(_$.text().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2839
            })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2840
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2841
};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2842
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2843
IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2844
    var _this = this
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2845
    return {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2846
        "id" : a.id,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2847
        "title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2848
        "desc" : this.cinecast_version ? a.content.data : a.content.description,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2849
        "begin": IriSP.msToTime(a.begin),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2850
        "end" : IriSP.msToTime(a.end),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2851
        "thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2852
        "url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2853
        "tags": typeof a.tags == "object"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2854
            ? IriSP.underscore(a.tags)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2855
                .chain()
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2856
                .map(function(_t) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2857
                    if (typeof _t == "string") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2858
                        return _t.replace(/^.*:/,'#');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2859
                    } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2860
                        if (typeof _t['id-ref'] != "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2861
                            var _f = IriSP.underscore.find(_this._serializer._data.tags, function(_tag) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2862
                                return _tag.id == _t['id-ref'];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2863
                            });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2864
                            if (typeof _f != "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2865
                                return IriSP.get_aliased(_f.meta, ['dc:title', 'title']);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2866
                            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2867
                        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2868
                    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2869
                    return null;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2870
                })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2871
                .filter(function(_t) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2872
                    return _t !== null && _t !== ""
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2873
                })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2874
                .value()
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2875
            : []
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2876
    }    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2877
}
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2878
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2879
/** draw the annotation list */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2880
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2881
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2882
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2883
//  var view_type = this._serializer.getContributions();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2884
  var annotations = this._serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2885
  var currentTime = this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2886
  var list = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2887
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2888
/*  if (typeof(view_type) === "undefined") {    
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2889
    return;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2890
} */
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2891
  for (i = 0; i < annotations.length; i++) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2892
    var obj = this.transformAnnotation(annotations[i]);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2893
    obj.iterator = i;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2894
    obj.distance = Math.abs((annotations[i].end + annotations[i].begin) / 2000 - currentTime);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2895
    if (!this.cinecast_version || annotations[i].type == "cinecast:UserAnnotation") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2896
        list.push(obj);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2897
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2898
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2899
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2900
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2901
    if (this.searchRe !== null) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2902
        list = list.filter(function(_a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2903
            return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2904
        });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2905
        if (list.length) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2906
            this._Popcorn.trigger("IriSP.search.matchFound");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2907
          } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2908
            this._Popcorn.trigger("IriSP.search.noMatchFound");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2909
          }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2910
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2911
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2912
  list = IriSP.underscore(list)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2913
    .chain()
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2914
    .sortBy(function(_o) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2915
        return _o.distance;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2916
    })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2917
    .first(10)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2918
    .sortBy(function(_o) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2919
        return _o.iterator;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2920
    })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2921
    .value();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2922
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2923
  var idList = IriSP.underscore.pluck(list, "id").sort();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2924
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2925
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2926
  if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2927
    this.do_redraw(list);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2928
    this.__oldList = idList;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2929
  }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2930
   /* save for next call */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2931
  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2932
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2933
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2934
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2935
IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2936
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2937
  /* the seeked signal sometimes passes an argument - depending on if we're using
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2938
     our popcorn lookalike or the real thing - if it's the case, use it as it's
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2939
     more precise than currentTime which sometimes contains the place we where at */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2940
  if (IriSP.null_or_undefined(timecode) || typeof(timecode) != "number") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2941
     var tcode = this._Popcorn.currentTime();     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2942
   } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2943
     var tcode = timecode;     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2944
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2945
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2946
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2947
  /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2948
     we double the braces using regexps and we feed it to mustache to build the correct url
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2949
     we have to do that because the platform only knows at run time what view it's displaying.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2950
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2951
     
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2952
  var platf_url = IriSP.widgetsDefaults.AnnotationsListWidget.ajax_url
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2953
                                      .replace(/\{/g, '{{').replace(/\}/g, '}}');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2954
  var media_id = this._serializer.currentMedia()["id"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2955
  var duration = this._serializer.getDuration();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2956
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2957
  var begin_timecode = (Math.floor(tcode) - 300) * 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2958
  if (begin_timecode < 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2959
    begin_timecode = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2960
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2961
  var end_timecode = (Math.floor(tcode) + 300) * 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2962
  if (end_timecode > duration)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2963
    end_timecode = duration;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2964
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2965
  var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2966
                                 end: end_timecode});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2967
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2968
  /* we create on the fly a serializer to get the ajax */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2969
  var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2970
  serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) }));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2971
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2972
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2973
/** process the received json - it's a bit hackish */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2974
IriSP.AnnotationsListWidget.prototype.processJson = function(json, serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2975
  /* FIXME: DRY the whole thing */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2976
  var annotations = serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2977
  if (IriSP.null_or_undefined(annotations))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2978
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2979
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2980
  /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2981
  commented in case we wanted to discriminate against some annotation types.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2982
  var view_types = serializer.getIds("Contributions");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2983
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2984
  var l = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2985
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2986
  var media = this._serializer.currentMedia()["id"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2987
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  2988
  for (i = 0; i < annotations.length; i++) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2989
    var obj = this.transformAnnotation(annotations[i])
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2990
      if (typeof obj.url == "undefined" || !obj.url) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2991
          /* only if the annotation isn't present in the document create an
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2992
             external link */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2993
          if (this.annotations_ids.indexOf(obj.id.toLowerCase()) == -1) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2994
            // braindead url; jacques didn't want to create a new one in the platform,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2995
            // so we append the cutting id to the url.
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2996
            obj.url = this.project_url + "/" + media + "/" + 
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2997
                         annotations[i].meta.project + "/" +
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2998
                         annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  2999
                         
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3000
            // obj.url = document.location.href.split("#")[0] + "/" + annotation.meta.project;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3001
          }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3002
          }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3003
      l.push(obj);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3004
  }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3005
  this._ajax_cache = l;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3006
  this.do_redraw(l);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3007
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3008
IriSP.AnnotationsListWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3009
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3010
  /* build a table of the annotations present in the document for faster 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3011
     lookup
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3012
  */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3013
  this.annotations_ids = IriSP.underscore(this._serializer._data.annotations).map(function(_a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3014
    return _a.id.toLowerCase();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3015
  });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3016
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3017
  var _this = this;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3018
    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3019
    if (!this.ajax_mode) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3020
        var _throttled = IriSP.underscore.throttle(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3021
            _this.drawList();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3022
        }, 1500);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3023
        _throttled();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3024
        this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3025
        this._Popcorn.listen("timeupdate", _throttled);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3026
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3027
    /* update the widget when the video has finished loading and when it's seeked and paused */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3028
    this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3029
    this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3030
    this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3031
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3032
    this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.ajaxRedraw));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3033
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3034
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3035
};/* Internationalization for this widget */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3036
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3037
IriSP.i18n.addMessages(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3038
    {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3039
        "fr": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3040
            "keywords": "Mots-clés"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3041
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3042
        "en": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3043
            "keywords": "Keywords"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3044
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3045
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3046
);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3047
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3048
IriSP.AnnotationsWidget = function(Popcorn, config, Serializer) {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3049
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3050
  /* flag used when we're creating an annotation */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3051
  this._hidden = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3052
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3053
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3054
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3055
IriSP.AnnotationsWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3056
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3057
IriSP.AnnotationsWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3058
    this.selector.find(".Ldt-SaTitle").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3059
    this.selector.find(".Ldt-SaDescription").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3060
    this.selector.find(".Ldt-SaKeywordText").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3061
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3062
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3063
IriSP.AnnotationsWidget.prototype.displayAnnotation = function(annotation) {       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3064
    var title = annotation.content.title;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3065
    var description = annotation.content.description;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3066
    var keywords =  "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3067
    var begin = +annotation.begin / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3068
    var end = +annotation.end / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3069
    var duration = this._serializer.getDuration();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3070
    var tags = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3071
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3072
    var title_templ = "{{title}} - ( {{begin}} - {{end}} )";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3073
    var endstr = Mustache.to_html(title_templ, {title: title, begin: IriSP.secondsToTime(begin), end: IriSP.secondsToTime(end)});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3074
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3075
    this.selector.find(".Ldt-SaTitle").text(endstr);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3076
    this.selector.find(".Ldt-SaDescription").text(description);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3077
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3078
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3079
    if (!IriSP.null_or_undefined(annotation.tags) && !IriSP.null_or_undefined(this._serializer._data.tags)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3080
      /* save the tag id and keywords in a unique structure */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3081
      var tag_list = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3082
      for (var i = 0; i < this._serializer._data.tags.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3083
        var id = this._serializer._data.tags[i]["id"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3084
        var keyword = IriSP.get_aliased(this._serializer._data.tags[i]["meta"], ["dc:title", "title"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3085
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3086
        tag_list[id] = keyword;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3087
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3088
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3089
      /* then browse the list of defined tags for the current annotation */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3090
      for (var i = 0; i < annotation.tags.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3091
        if (tag_list.hasOwnProperty(annotation.tags[i]["id-ref"]))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3092
          tags += tag_list[annotation.tags[i]["id-ref"]] + ", ";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3093
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3094
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3095
    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3096
    tags = IriSP.i18n.getMessage("keywords") + ": " + tags.slice(0, tags.length - 2);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3097
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3098
    this.selector.find(".Ldt-SaKeywords").text(tags);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3099
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3100
    // update sharing buttons
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3101
    var defaults = IriSP.widgetsDefaults.AnnotationsWidget;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3102
    var text = defaults.share_text;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3103
    var fb_link = defaults.fb_link;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3104
    var tw_link = defaults.tw_link;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3105
    var gplus_link = defaults.gplus_link;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3106
    var url = document.location.href + "#id=" + annotation.id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3107
    this.selector.find(".Ldt-fbShare").attr("href", IriSP.mkFbUrl(url, text));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3108
    this.selector.find(".Ldt-TwShare").attr("href", IriSP.mkTweetUrl(url, text));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3109
    this.selector.find(".Ldt-GplusShare").attr("href", IriSP.mkGplusUrl(url, text));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3110
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3111
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3112
IriSP.AnnotationsWidget.prototype.clearWidget = function() {   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3113
    /* retract the pane between two annotations */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3114
    this.selector.find(".Ldt-SaTitle").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3115
    this.selector.find(".Ldt-SaDescription").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3116
    this.selector.find(".Ldt-SaKeywordText").html("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3117
    this.selector.find(".Ldt-ShowAnnotation").slideUp();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3118
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3119
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3120
IriSP.AnnotationsWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3121
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3122
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3123
  var annotationMarkup = IriSP.templToHTML(IriSP.annotationWidget_template);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3124
	this.selector.append(annotationMarkup);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3125
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3126
  this._Popcorn.listen("IriSP.AnnotationsWidget.show", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3127
                        IriSP.wrap(this, this.show));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3128
  this._Popcorn.listen("IriSP.AnnotationsWidget.hide", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3129
                        IriSP.wrap(this, this.hide));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3130
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3131
  var legal_ids = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3132
  if (typeof(this._serializer.getChapitrage()) !== "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3133
    legal_ids.push(this._serializer.getChapitrage());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3134
  else 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3135
    legal_ids = this._serializer.getNonTweetIds();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3136
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3137
  var annotations = this._serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3138
  var i;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3139
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3140
	for (i in annotations) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3141
    var annotation = annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3142
    var begin = Math.round((+ annotation.begin) / 1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3143
    var end = Math.round((+ annotation.end) / 1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3144
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3145
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3146
          && !IriSP.underscore.include(legal_ids, annotation.meta["id-ref"])) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3147
        continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3148
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3149
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3150
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3151
    var conf = {start: begin, end: end, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3152
                onStart: 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3153
                       function(annotation) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3154
                        return function() { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3155
                            _this.displayAnnotation(annotation); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3156
                          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3157
                        } }(annotation),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3158
                onEnd: 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3159
                       function() { _this.clearWidget.call(_this); }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3160
                };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3161
    this._Popcorn = this._Popcorn.code(conf);                                             
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3162
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3163
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3164
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3165
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3166
IriSP.AnnotationsWidget.prototype.hide = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3167
  if (this._hidden == false) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3168
    this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3169
    this._hidden = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3170
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3171
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3172
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3173
IriSP.AnnotationsWidget.prototype.show = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3174
  if (this._hidden == true) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3175
    this.selector.show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3176
    this._hidden = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3177
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3178
};IriSP.ArrowWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3179
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3180
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3181
  this._oldAnnotation = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3182
  this._blockArrow = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3183
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3184
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3185
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3186
IriSP.ArrowWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3187
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3188
IriSP.ArrowWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3189
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3190
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3191
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3192
IriSP.ArrowWidget.prototype.clearWidget = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3193
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3194
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3195
IriSP.ArrowWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3196
  var templ = Mustache.to_html(IriSP.arrowWidget_template, {});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3197
  this.selector.append(templ);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3198
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3199
  this._Popcorn.listen("IriSP.ArrowWidget.blockArrow", IriSP.wrap(this, this.blockArrow));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3200
  this._Popcorn.listen("IriSP.ArrowWidget.releaseArrow", IriSP.wrap(this, this.releaseArrow));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3201
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3202
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3203
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3204
IriSP.ArrowWidget.prototype.timeUpdateHandler = function(percents) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3205
  if (this._blockArrow)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3206
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3207
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3208
  var currentTime = this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3209
  var currentAnnotation = this._serializer.currentChapitre(currentTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3210
  if (IriSP.null_or_undefined(currentAnnotation)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3211
    var c_annots = this._serializer.currentAnnotation(currentTime)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3212
    if (c_annots.length != 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3213
      var currentAnnotation = c_annots[0]; // FIXME : use the others ?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3214
    else
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3215
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3216
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3217
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3218
  /* move the arrow only if the current annotation changes */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3219
  if (currentAnnotation != this._oldAnnotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3220
    var begin = (+ currentAnnotation.begin) / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3221
    var end = (+ currentAnnotation.end) / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3222
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3223
    var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3224
    var middle_time = (begin + end) / 2;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3225
    var percents = middle_time / duration;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3226
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3227
    // we need to apply a fix because the arrow has a certain length
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3228
    // it's half the length of the arrow (27 / 2). We need to convert
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3229
    // it in percents though.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3230
    var totalWidth = this.selector.width();    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3231
    var pixels = percents * totalWidth;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3232
    var correction = (27 / 2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3233
    var corrected_pixels = pixels - correction;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3234
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3235
    /* make sure that the arrow is aligned with the pattern
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3236
       of the widget under it */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3237
    if (corrected_pixels % 3 != 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3238
      corrected_pixels -= (corrected_pixels % 3 - 1);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3239
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3240
    /* don't move out of the screen */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3241
    if (corrected_pixels <= 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3242
      corrected_pixels = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3243
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3244
    if (corrected_pixels <= 15) {      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3245
      this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3246
                                                .addClass("Ldt-arrowLeftEdge"); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3247
    } else if (corrected_pixels >= totalWidth - 25) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3248
           this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3249
                                                .addClass("Ldt-arrowRightEdge"); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3250
    } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3251
      this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3252
                                                .addClass("Ldt-arrowCenter"); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3253
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3254
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3255
    this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_pixels + "px"});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3256
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3257
    this._oldAnnotation = currentAnnotation;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3258
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3259
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3260
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3261
/** Block the arrow for instance when the user is annotating */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3262
IriSP.ArrowWidget.prototype.blockArrow = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3263
  this._blockArrow = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3264
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3265
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3266
IriSP.ArrowWidget.prototype.releaseArrow = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3267
  this._blockArrow = false;   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3268
};
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3269
/* Internationalization for this widget */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3270
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3271
IriSP.i18n.addMessages(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3272
    {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3273
        "en": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3274
            "submit": "Submit",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3275
            "add_keywords": "Add keywords",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3276
            "add_polemic_keywords": "Add polemic keywords",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3277
            "your_name": "Your name",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3278
            "type_here": "Type your annotation here.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3279
            "wait_while_processed": "Please wait while your request is being processed...",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3280
            "error_while_contacting": "An error happened while contacting the server. Your annotation has not been saved.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3281
            "empty_annotation": "Your annotation is empty. Please write something before submitting.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3282
            "annotation_saved": "Thank you, your annotation has been saved.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3283
            "share_annotation": "Would you like to share it on social networks ?",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3284
            "share_on": "Share on"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3285
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3286
        "fr": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3287
            "submit": "Envoyer",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3288
            "add_keywords": "Ajouter des mots-clés",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3289
            "add_polemic_keywords": "Ajouter des mots-clés polémiques",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3290
            "your_name": "Votre nom",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3291
            "type_here": "Rédigez votre annotation ici.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3292
            "wait_while_processed": "Veuillez patienter pendant le traitement de votre requête...",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3293
            "error_while_contacting": "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3294
            "empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3295
            "annotation_saved": "Merci, votre annotation a été enregistrée.",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3296
            "share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3297
            "share_on": "Partager sur"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3298
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3299
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3300
);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3301
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3302
IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3303
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3304
  this._hidden = true;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3305
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3306
  this.checkOption("keywords");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3307
  this.checkOption("polemic_mode", true);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3308
  this.checkOption("polemics");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3309
  this.checkOption("cinecast_version", false);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3310
  this.checkOption("api_endpoint_template");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3311
  this.checkOption("show_from_field", true);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3312
  this.checkOption("api_method");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3313
                         
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3314
  if (!IriSP.null_or_undefined(IriSP.user)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3315
      if (!IriSP.null_or_undefined(IriSP.user.avatar)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3316
        this.user_avatar = IriSP.user.avatar;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3317
      }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3318
      if (!IriSP.null_or_undefined(IriSP.user.name)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3319
        this.user_name = IriSP.user.name;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3320
      }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3321
  }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3322
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3323
  /* variables to save the current position of the slicer */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3324
  if (this.cinecast_version) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3325
    this.sliceLeft = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3326
    this.sliceWidth = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3327
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3328
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3329
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3330
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3331
IriSP.createAnnotationWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3332
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3333
IriSP.createAnnotationWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3334
    this.selector.find(".Ldt-SaTitle").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3335
    this.selector.find(".Ldt-SaDescription").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3336
    this.selector.find(".Ldt-SaKeywordText").text("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3337
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3338
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3339
IriSP.createAnnotationWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3340
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3341
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3342
  var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3343
                                           this);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3344
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3345
	this.selector.append(annotationMarkup);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3346
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3347
  if (!this.cinecast_version)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3348
    this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3349
  else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3350
    this.showStartScreen();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3351
  }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3352
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3353
  // Add onclick event to both polemic and keywords buttons
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3354
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3355
  this.selector.find(".Ldt-createAnnotation-btnblock button").click(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3356
      _this.addKeyword(IriSP.jQuery(this).text());
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3357
  });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3358
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3359
  // js_mod is a custom event because there's no simple way to test for a js
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3360
  // change in a textfield.                    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3361
  this.selector.find(".Ldt-createAnnotation-Description")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3362
               .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3363
               
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3364
  /* the cinecast version of the player is supposed to pause when the user clicks on the button */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3365
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3366
  /* the cinecast version expects the user to comment on a defined segment.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3367
     As the widget is always shown, we need a way to update it's content as
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3368
     time passes. We do this like we did with the annotationsWidget : we schedule
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3369
     a .code start function which will be called at the right time.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3370
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3371
  if (this.cinecast_version) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3372
    var legal_ids;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3373
    if (typeof(this._serializer.getChapitrage()) !== "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3374
      legal_id = this._serializer.getChapitrage();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3375
    else 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3376
      legal_id = this._serializer.getNonTweetIds()[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3377
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3378
    var annotations = this._serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3379
    var i;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3380
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3381
    for (i in annotations) {     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3382
      var annotation = annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3383
      if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3384
            && legal_id !== annotation.meta["id-ref"]) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3385
          continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3386
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3387
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3388
      code = {start: annotation.begin / 1000, end: annotation.end / 1000,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3389
              onStart: function(annotation) { return function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3390
                      if (typeof(annotation.content) !== "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3391
                        _this.selector.find(".Ldt-createAnnotation-Title").html(annotation.content.title);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3392
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3393
                      _this._currentAnnotation = annotation;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3394
                      var beginTime = IriSP.msToTime(annotation.begin);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3395
                      var endTime = IriSP.msToTime(annotation.end);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3396
                      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3397
                      _this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3398
              } }(annotation)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3399
            };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3400
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3401
      this._Popcorn.code(code);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3402
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3403
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3404
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3405
  this.selector.find(".Ldt-createAnnotation-submitButton").click(IriSP.wrap(this, this.handleButtonClick));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3406
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3407
  if (!this.cinecast_version) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3408
    this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3409
                          IriSP.wrap(this, this.handleAnnotateSignal));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3410
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3411
    // handle clicks on the cancel button too.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3412
    this.selector.find(".Ldt-createAnnotation-Minimize").click(IriSP.wrap(this, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3413
      function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3414
        // we've got to simulate the pressing of the button because there's no
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3415
        // other way to minimize the widget and show the widgets that were hidden
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3416
        // same time
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3417
        this._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3418
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3419
    ));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3420
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3421
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3422
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3423
/* Handles adding keywords and polemics */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3424
IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3425
    var _field = this.selector.find(".Ldt-createAnnotation-Description"),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3426
        _rx = IriSP.regexpFromText(_keyword),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3427
        _contents = _field.val();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3428
    _contents = ( _rx.test(_contents)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3429
        ? _contents.replace(_rx,"").replace("  "," ").trim()
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3430
        : _contents.trim() + " " + _keyword
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3431
    );
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3432
    _field.val(_contents);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3433
    _field.trigger("js_mod");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3434
}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3435
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3436
/** handles clicks on the annotate button. Works only for the non-cinecast version */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3437
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3438
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3439
  if (this._hidden == false && this._state == 'startScreen') {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3440
    this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3441
    this._hidden = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3442
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3443
    // free the arrow.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3444
    this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3445
    this._Popcorn.trigger("IriSP.SliceWidget.hide");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3446
    this._Popcorn.trigger("IriSP.AnnotationsWidget.show");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3447
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3448
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3449
    this._Popcorn.trigger("IriSP.AnnotationsWidget.hide");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3450
    this.showStartScreen();    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3451
    this.selector.show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3452
    this._hidden = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3453
    var currentTime = this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3454
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3455
    // block the arrow.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3456
    this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3457
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3458
    var duration = this._serializer.getDuration();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3459
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3460
    var currentChapter = this._serializer.currentChapitre(currentTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3461
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3462
    if (IriSP.null_or_undefined(currentChapter)) {      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3463
      var left = this.selector.width() / 2;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3464
      var width = this.selector.width() / 10;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3465
    } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3466
      var left = (currentChapter.begin / duration) * this.selector.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3467
      var width = (currentChapter.end / duration) * this.selector.width() - left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3468
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3469
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3470
    // slider position and length is kept in percents.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3471
    this.sliceLeft = (left / this.selector.width()) * 100;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3472
    this.sliceWidth = (width / this.selector.width()) * 100;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3473
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3474
    this._Popcorn.trigger("IriSP.SliceWidget.position", [left, width]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3475
    this._Popcorn.listen("IriSP.SliceWidget.zoneChange", IriSP.wrap(this, this.handleSliderChanges));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3476
    this._Popcorn.trigger("IriSP.SliceWidget.show");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3477
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3478
    if (!IriSP.null_or_undefined(currentChapter)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3479
      this.selector.find(".Ldt-createAnnotation-Title").html(currentChapter.content.title);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3480
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3481
      this._currentcurrentChapter = currentChapter;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3482
      var beginTime = IriSP.msToTime(currentChapter.begin);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3483
      var endTime = IriSP.msToTime(currentChapter.end);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3484
      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3485
      this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3486
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3487
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3488
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3489
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3490
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3491
/** watch for changes in the textfield and change the buttons accordingly */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3492
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3493
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3494
  if (this.cinecast_version && !this._Popcorn.media.paused) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3495
      this._Popcorn.pause();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3496
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3497
  this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3498
      var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text());
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3499
      if (_rx.test(contents)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3500
          IriSP.jQuery(this).parent().addClass("Ldt-createAnnotation-active-button");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3501
      } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3502
          IriSP.jQuery(this).parent().removeClass("Ldt-createAnnotation-active-button");
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3503
      }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3504
  });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3505
  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3506
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3507
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3508
IriSP.createAnnotationWidget.prototype.showStartScreen = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3509
  this.selector.find(".Ldt-createAnnotation-screen").hide();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3510
  this.selector.find(".Ldt-createAnnotation-startScreen").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3511
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3512
  var jqTextfield = this.selector.find(".Ldt-createAnnotation-Description"); // handle on the textfield. used for the closure
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3513
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3514
  /* test if the browser supports the placeholder attribute */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3515
  if (!IriSP.null_or_undefined(jqTextfield.get(0).placeholder)) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3516
    jqTextfield.attr("placeholder", IriSP.i18n.getMessage('type_here')); 
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3517
  } else {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3518
    jqTextfield.val(IriSP.i18n.getMessage('type_here'));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3519
    jqTextfield.one("click", IriSP.wrap(this, function() { jqTextfield.val(""); }));    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3520
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3521
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3522
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3523
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3524
  this._state = "startScreen";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3525
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3526
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3527
IriSP.createAnnotationWidget.prototype.showWaitScreen = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3528
  this.selector.find(".Ldt-createAnnotation-screen").hide();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3529
  this.selector.find(".Ldt-createAnnotation-waitScreen").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3530
  this._state = "waitScreen";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3531
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3532
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3533
IriSP.createAnnotationWidget.prototype.showErrorScreen = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3534
  this.selector.find(".Ldt-createAnnotation-screen").hide();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3535
  this.selector.find(".Ldt-createAnnotation-errorScreen").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3536
  this._state = "errorScreen";
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3537
  var _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3538
  window.setTimeout(function() { _this.showStartScreen(); }, 2000);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3539
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3540
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3541
/** update show the final screen with links to share the created annotation */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3542
IriSP.createAnnotationWidget.prototype.showEndScreen = function(annotation) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3543
  this.selector.find(".Ldt-createAnnotation-screen").hide();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3544
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3545
  if (this.cinecast_version) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3546
    this.selector.find(".Ldt-createAnnotation-Title").parent().show();      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3547
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3548
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3549
  var url = ( (typeof annotation.meta == "object" && typeof annotation.meta.url == "string" && annotation.meta.url.length)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3550
    ? annotation.meta.url
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3551
    : ( document.location.href + "#id=" + annotation.id ) );
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3552
  var twStatus = IriSP.mkTweetUrl(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3553
  var gpStatus = IriSP.mkGplusUrl(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3554
  var fbStatus = IriSP.mkFbUrl(url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3555
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3556
  this.selector.find(".Ldt-createAnnotation-endScreen-TweetLink").attr("href", twStatus);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3557
  this.selector.find(".Ldt-createAnnotation-endScreen-FbLink").attr("href", fbStatus);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3558
  this.selector.find(".Ldt-createAnnotation-endScreen-GplusLink").attr("href", gpStatus);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3559
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3560
  this.selector.find(".Ldt-createAnnotation-endScreen").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3561
  this._state = "endScreen";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3562
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3563
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3564
/** handle clicks on "send annotation" button */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3565
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3566
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3567
  var textfield = this.selector.find(".Ldt-createAnnotation-Description");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3568
  var contents = textfield.val();
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3569
  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3570
  if (contents === "") {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3571
    if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3572
      this.selector.find(".Ldt-createAnnotation-Container")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3573
                   .after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3574
      textfield.css("background-color", "#d93c71");      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3575
    } else {      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3576
      this.selector.find(".Ldt-createAnnotation-errorMessage").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3577
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3578
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3579
      textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3580
                      var contents = textfield.val();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3581
                      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3582
                      if (contents !== "") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3583
                        this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3584
                        textfield.css("background-color", "");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3585
                      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3586
                   }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3587
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3588
    this.showWaitScreen();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3589
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3590
    this.sendLdtData(contents, function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3591
                      if (_this.cinecast_version) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3592
                          if (_this._Popcorn.media.paused)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3593
                            _this._Popcorn.play();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3594
                      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3595
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3596
                      if (_this._state == "waitScreen") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3597
                        _this.showEndScreen(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3598
                        if (_this.cinecast_version) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3599
                          window.setTimeout(function() { _this.showStartScreen(); }, 5000);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3600
                        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3601
                      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3602
                      // hide the slicer widget
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3603
                      if (!_this.cinecast_version) {                      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3604
                        _this._Popcorn.trigger("IriSP.SliceWidget.hide");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3605
                      }           
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3606
                    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3607
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3608
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3609
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3610
IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3611
  this.sliceLeft = params[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3612
  this.sliceWidth = params[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3613
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3614
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3615
IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3616
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3617
  var apiJson = {annotations : [{}], meta: {}};
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3618
  var annotation = apiJson.annotations[0];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3619
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3620
  annotation.media = this._serializer.currentMedia()["id"];
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3621
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3622
  if (this.cinecast_version) {   
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3623
      annotation.begin = Math.round(this._Popcorn.currentTime() * 1000);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3624
      annotation.end = annotation.begin;      
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3625
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3626
    var duration = this._serializer.getDuration();    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3627
    annotation.begin = +((duration * (this.sliceLeft / 100)).toFixed(0));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3628
    annotation.end = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3629
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3630
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3631
  // boundary checks
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3632
  annotation.begin = Math.max(0, annotation.begin);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3633
  annotation.end = Math.min(this._serializer.getDuration(), annotation.end);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3634
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3635
  annotation.type = ( this.cinecast_version ? "cinecast:UserAnnotation" : ( this._serializer.getContributions() || "" ));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3636
  if (typeof(annotation.type) === "undefined")
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3637
    annotation.type = "";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3638
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3639
  annotation.type_title = "Contributions";
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3640
  annotation.content = {};
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3641
  annotation.content.data = contents;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3642
  if (this.cinecast_version) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3643
      var _extract = IriSP.underscore(this._serializer._data.annotations)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3644
          .filter(function(_a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3645
              return (_a.begin <= annotation.begin && _a.end >= annotation.begin && _a.type == "cinecast:MovieExtract");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3646
          })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3647
      if (_extract.length) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3648
          annotation.extract = _extract[0].id;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3649
      }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3650
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3651
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3652
  var meta = apiJson.meta;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3653
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3654
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3655
  var _username = this.selector.find(".Ldt-createAnnotation-userName").val();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3656
  meta.creator = (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3657
      (_username && _username.length)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3658
      ? _username
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3659
      : (
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3660
          (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.name))
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3661
          ? IriSP.user.name
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3662
          : "Anonymous user"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3663
      )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3664
  );
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3665
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3666
  meta.created = Date().toString();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3667
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3668
  // All #hashtags are added to tags
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3669
  annotation.tags = contents.match(/#[^#\s]+\b/gim) || [];
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3670
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3671
  var jsonString = JSON.stringify(apiJson);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3672
  var project_id = this._serializer._data.meta.id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3673
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3674
  //TODO: extract magic url
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3675
  var url = Mustache.to_html(this.api_endpoint_template,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3676
                              {id: project_id});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3677
                          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3678
  IriSP.jQuery.ajax({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3679
      url: url,
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3680
      type: this.api_method,
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3681
      contentType: 'application/json',
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3682
      data: jsonString,               
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3683
      //dataType: 'json',
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3684
      success: IriSP.wrap(this, function(json, textStatus, XMLHttpRequest) {                   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3685
                    /* add the annotation to the annotation and tell the world */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3686
                    if (this.cinecast_version) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3687
                        var annotation = json.annotations[0];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3688
                    } else {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3689
                    /* if the media doesn't have a contributions line, we need to add one */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3690
                        if (typeof(this._serializer.getContributions()) === "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3691
                          /* set up a basic view */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3692
                          var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3693
                                          "id": json.annotations[0].type}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3694
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3695
                          
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3696
                            IriSP.get_aliased(this._serializer._data, ["annotation_types", "annotation-types"]).push(tmp_view);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3697
                        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3698
                        
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3699
                        delete annotation.tags;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3700
                        annotation.content.description = annotation.content.data;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3701
                        annotation.content.title = "";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3702
                        delete annotation.content.data;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3703
                        annotation.id = json.annotations[0].id;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3704
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3705
                        annotation.meta = meta;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3706
                        annotation.meta["id-ref"] = json.annotations[0]["type"];
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3707
                    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3708
                        
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3709
                    // everything is shared so there's no need to propagate the change
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3710
                    _this._serializer._data.annotations.push(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3711
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3712
                    _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3713
                    callback(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3714
      }), 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3715
      error: 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3716
              function(jqXHR, textStatus, errorThrown) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3717
                            console.log("an error occured while contacting " 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3718
                            + url + " and sending " + jsonString + textStatus ); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3719
                            _this.showErrorScreen(); } });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3720
};IriSP.HelloWorldWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3721
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3722
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3723
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3724
IriSP.HelloWorldWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3725
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3726
IriSP.HelloWorldWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3727
    this.selector
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3728
        .html('Hello, world')
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3729
        .css({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3730
            "text-align" : "center",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3731
            "padding": "10px 0",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3732
            "font-size" : "14px"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3733
        });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3734
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3735
    console.log(this);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3736
}
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3737
/* Internationalization for this widget */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3738
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3739
IriSP.i18n.addMessages(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3740
    {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3741
        "en": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3742
            "play_pause": "Play/Pause",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3743
            "mute_unmute": "Mute/Unmute",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3744
            "play": "Play",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3745
            "pause": "Pause",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3746
            "mute": "Mute",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3747
            "unmute": "Unmute",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3748
            "annotate": "Annotate",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3749
            "search": "Search",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3750
            "elapsed_time": "Elapsed time",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3751
            "total_time": "Total time",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3752
            "volume": "Volume",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3753
            "volume_control": "Volume control"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3754
        },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3755
        "fr": {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3756
            "play_pause": "Lecture/Pause",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3757
            "mute_unmute": "Couper/Activer le son",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3758
            "play": "Lecture",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3759
            "pause": "Pause",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3760
            "mute": "Couper le son",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3761
            "unmute": "Activer le son",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3762
            "annotate": "Annoter",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3763
            "search": "Rechercher",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3764
            "elapsed_time": "Durée écoulée",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3765
            "total_time": "Durée totale",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3766
            "volume": "Niveau sonore",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3767
            "volume_control": "Réglage du niveau sonore"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3768
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3769
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3770
);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3771
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3772
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3773
IriSP.PlayerWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3774
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3775
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3776
  this._searchBlockOpen = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3777
  this._searchLastValue = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3778
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3779
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3780
IriSP.PlayerWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3781
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3782
IriSP.PlayerWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3783
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3784
  var width = this.width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3785
	var height = this.height;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3786
	var heightS = this.height-20;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3787
	  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3788
	var playerTempl = IriSP.templToHTML(IriSP.player_template, this._config);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3789
  this.selector.append(playerTempl);		
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3790
	
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3791
  this.selector.children(".Ldt-controler").show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3792
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3793
  // handle clicks by the user on the video.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3794
  this._Popcorn.listen("play", IriSP.wrap(this, this.playButtonUpdater));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3795
  this._Popcorn.listen("pause", IriSP.wrap(this, this.playButtonUpdater));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3796
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3797
  this._Popcorn.listen("volumechange", IriSP.wrap(this, this.volumeUpdater));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3798
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3799
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeDisplayUpdater));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3800
  // update the time display for the first time.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3801
  this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.timeDisplayUpdater));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3802
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3803
  this._Popcorn.listen("IriSP.search.matchFound", IriSP.wrap(this, this.searchMatch));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3804
  this._Popcorn.listen("IriSP.search.noMatchFound", IriSP.wrap(this, this.searchNoMatch));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3805
  this._Popcorn.listen("IriSP.search.triggeredSearch", IriSP.wrap(this, this.triggeredSearch));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3806
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3807
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3808
  this.selector.find(".Ldt-CtrlPlay").click(function() { self.playHandler.call(self); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3809
  this.selector.find(".Ldt-CtrlAnnotate").click(function() 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3810
                                            { self._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked"); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3811
  this.selector.find(".Ldt-CtrlSearch").click(function() { self.searchButtonHandler.call(self); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3812
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3813
	var _volctrl = this.selector.find(".Ldt-Ctrl-Volume-Control");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3814
    this.selector.find('.Ldt-CtrlSound')
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3815
        .click(function() { self.muteHandler.call(self); } )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3816
        .mouseover(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3817
            _volctrl.show();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3818
        })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3819
        .mouseout(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3820
            _volctrl.hide();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3821
        });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3822
    _volctrl.mouseover(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3823
        _volctrl.show();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3824
    }).mouseout(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3825
        _volctrl.hide();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3826
    });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3827
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3828
  /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3829
  var searchButtonPos = this.selector.find(".Ldt-CtrlSearch").position();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3830
  var searchBox = Mustache.to_html(IriSP.search_template, {margin_left : searchButtonPos.left + "px"});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3831
  this.selector.find(".Ldt-CtrlSearch").after(searchBox);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3832
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3833
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3834
  // trigger an IriSP.PlayerWidget.MouseOver to the widgets that are interested (i.e : sliderWidget)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3835
  this.selector.hover(function() { self._Popcorn.trigger("IriSP.PlayerWidget.MouseOver"); }, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3836
                      function() { self._Popcorn.trigger("IriSP.PlayerWidget.MouseOut"); });
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3837
  this.selector.find(".Ldt-Ctrl-Volume-Cursor").draggable({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3838
      axis: "x",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3839
      drag: function(event, ui) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3840
          var _vol = Math.max(0, Math.min( 1, ui.position.left / (ui.helper.parent().width() - ui.helper.outerWidth())));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3841
          ui.helper.attr("title",IriSP.i18n.getMessage('volume')+': ' + Math.floor(100*_vol) + '%');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3842
          self._Popcorn.volume(_vol);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3843
      },
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3844
      containment: "parent"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3845
  });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3846
 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3847
 setTimeout(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3848
     self.volumeUpdater();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3849
 }, 1000); /* some player - jwplayer notable - save the state of the mute button between sessions */
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3850
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3851
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3852
/* Update the elasped time div */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3853
IriSP.PlayerWidget.prototype.timeDisplayUpdater = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3854
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3855
  if (this._previousSecond === undefined) {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3856
    this._previousSecond = this._Popcorn.roundTime();
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3857
  }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3858
  else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3859
    /* we're still in the same second, so it's not necessary to update time */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3860
    if (this._Popcorn.roundTime() == this._previousSecond)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3861
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3862
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3863
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3864
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3865
  // we get it at each call because it may change.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3866
  var duration = this._serializer.getDuration() / 1000; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3867
  var totalTime = IriSP.secondsToTime(duration);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3868
  var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3869
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3870
  this.selector.find(".Ldt-ElapsedTime").html(elapsedTime.toString());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3871
  this.selector.find(".Ldt-TotalTime").html(totalTime.toString());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3872
  this._previousSecond = this._Popcorn.roundTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3873
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3874
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3875
/* update the icon of the button - separate function from playHandler
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3876
   because in some cases (for instance, when the user directly clicks on
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3877
   the jwplayer window) we have to change the icon without playing/pausing
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3878
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3879
IriSP.PlayerWidget.prototype.playButtonUpdater = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3880
  var status = this._Popcorn.media.paused;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3881
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3882
  if ( status == true ){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3883
    /* the background sprite is changed by adding/removing the correct classes */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3884
    this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('play'));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3885
    this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PauseState").addClass("Ldt-CtrlPlay-PlayState");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3886
  } else {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3887
    this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('pause'));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3888
    this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PlayState").addClass("Ldt-CtrlPlay-PauseState");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3889
  }  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3890
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3891
  return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3892
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3893
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3894
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3895
IriSP.PlayerWidget.prototype.playHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3896
  var status = this._Popcorn.media.paused;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3897
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3898
  if ( status == true ){        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3899
    this._Popcorn.play();   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3900
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3901
    this._Popcorn.pause();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3902
  }  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3903
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3904
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3905
IriSP.PlayerWidget.prototype.muteHandler = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3906
  this._Popcorn.mute(!this._Popcorn.muted());
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3907
};
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3908
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3909
IriSP.PlayerWidget.prototype.volumeUpdater = function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3910
    var _muted = this._Popcorn.muted(),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3911
        _vol = this._Popcorn.volume();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3912
    if (_vol === false) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3913
        _vol = .5;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3914
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3915
    var _soundCtl = this.selector.find(".Ldt-CtrlSound");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3916
    _soundCtl.removeClass("Ldt-CtrlSound-Mute Ldt-CtrlSound-Half Ldt-CtrlSound-Full");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3917
    if (_muted) {        
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3918
        _soundCtl.attr("title", IriSP.i18n.getMessage('unmute'))
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3919
            .addClass("Ldt-CtrlSound-Mute");    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3920
    } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3921
        _soundCtl.attr("title", IriSP.i18n.getMessage('mute'))
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3922
            .addClass(_vol < .5 ? "Ldt-CtrlSound-Half" : "Ldt-CtrlSound-Full" )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3923
    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3924
    var _cursor = this.selector.find(".Ldt-Ctrl-Volume-Cursor");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3925
    _cursor.css({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3926
        "left": ( _muted ? 0 : Math.floor(_vol * (_cursor.parent().width() - _cursor.outerWidth())) ) + "px"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  3927
    })
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3928
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3929
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3930
IriSP.PlayerWidget.prototype.showSearchBlock = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3931
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3932
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3933
  if (this._searchBlockOpen == false) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3934
    this.selector.find(".LdtSearch").show("blind", { direction: "horizontal"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3935
    this.selector.find(".LdtSearchInput").css('background-color','#fff');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3936
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3937
    this._searchBlockOpen = true;           
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3938
    this.selector.find(".LdtSearchInput").bind('keyup', null, function() { self.searchHandler.call(self); } );
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3939
    this.selector.find(".LdtSearchInput").focus();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3940
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3941
    // we need this variable because some widget can find a match in
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3942
    // their data while at the same time other's don't. As we want the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3943
    // search field to become green when there's a match, we need a 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3944
    // variable to remember that we had one.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3945
    this._positiveMatch = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3946
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3947
    // tell the world the field is open
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3948
    this._Popcorn.trigger("IriSP.search.open");     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3949
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3950
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3951
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3952
IriSP.PlayerWidget.prototype.hideSearchBlock = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3953
 if (this._searchBlockOpen == true) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3954
    this._searchLastValue = this.selector.find(".LdtSearchInput").attr('value');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3955
    this.selector.find(".LdtSearchInput").attr('value','');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3956
    this.selector.find(".LdtSearch").hide("blind", { direction: "horizontal"}, 75);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3957
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3958
    // unbind the watcher event.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3959
    this.selector.find(".LdtSearchInput").unbind('keypress set');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3960
    this._searchBlockOpen = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3961
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3962
    this._positiveMatch = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3963
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3964
    this._Popcorn.trigger("IriSP.search.closed");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3965
	}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3966
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3967
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3968
/** react to clicks on the search button */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3969
IriSP.PlayerWidget.prototype.searchButtonHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3970
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3971
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3972
  /* show the search field if it is not shown */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3973
  if ( this._searchBlockOpen == false ) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3974
    this.showSearchBlock();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3975
    this.selector.find(".LdtSearchInput").attr('value', this._searchLastValue);      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3976
    this._Popcorn.trigger("IriSP.search", this._searchLastValue); // trigger the search to make it more natural.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3977
	} else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3978
    this.hideSearchBlock();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3979
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3980
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3981
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3982
/** this handler is called whenever the content of the search
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3983
   field changes */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3984
IriSP.PlayerWidget.prototype.searchHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3985
  this._searchLastValue = this.selector.find(".LdtSearchInput").attr('value');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3986
  this._positiveMatch = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3987
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3988
  // do nothing if the search field is empty, instead of highlighting everything.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3989
  if (this._searchLastValue == "") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3990
    this._Popcorn.trigger("IriSP.search.cleared");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3991
    this.selector.find(".LdtSearchInput").css('background-color','');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3992
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3993
    this._Popcorn.trigger("IriSP.search", this._searchLastValue);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3994
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3995
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3996
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3997
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3998
  handler for the IriSP.search.found message, which is sent by some views when they
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  3999
  highlight a match.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4000
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4001
IriSP.PlayerWidget.prototype.searchMatch = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4002
  this._positiveMatch = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4003
  this.selector.find(".LdtSearchInput").css('background-color','#e1ffe1');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4004
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4005
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4006
/** the same, except that no value could be found */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4007
IriSP.PlayerWidget.prototype.searchNoMatch = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4008
  if (this._positiveMatch !== true)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4009
    this.selector.find(".LdtSearchInput").css('background-color', "#d62e3a");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4010
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4011
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4012
/** react to an IriSP.Player.triggeredSearch - that is, when
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4013
    a widget ask the PlayerWidget to do a search on his behalf */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4014
IriSP.PlayerWidget.prototype.triggeredSearch = function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4015
  this.showSearchBlock();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4016
  this.selector.find(".LdtSearchInput").attr('value', searchString);      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4017
  this._Popcorn.trigger("IriSP.search", searchString); // trigger the search to make it more natural.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4018
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4019
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4020
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4021
/* 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4022
 *   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4023
 *  Copyright 2010 Institut de recherche et d'innovation 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4024
 *  contributor(s) : Samuel Huron 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4025
 *   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4026
 *  contact@iri.centrepompidou.fr
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4027
 *  http://www.iri.centrepompidou.fr 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4028
 *   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4029
 *  This software is a computer program whose purpose is to show and add annotations on a video .
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4030
 *  This software is governed by the CeCILL-C license under French law and
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4031
 *  abiding by the rules of distribution of free software. You can  use, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4032
 *  modify and/ or redistribute the software under the terms of the CeCILL-C
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4033
 *  license as circulated by CEA, CNRS and INRIA at the following URL
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4034
 *  "http://www.cecill.info". 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4035
 *  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4036
 *  The fact that you are presently reading this means that you have had
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4037
 *  knowledge of the CeCILL-C license and that you accept its terms.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4038
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4039
// CHART TIMELINE / VERSION PROTOTYPE  ::
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4040
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4041
/** the polemic widget */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4042
IriSP.PolemicWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4043
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4044
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4045
  this.userPol    = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4046
  this.userNoPol  = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4047
  this.userst      = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4048
  this.numberOfTweet = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4049
  this.Users;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4050
  this.TweetPolemic;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4051
  this.yMax        = this.height; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4052
  this.PaperSlider;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4053
  this.heightOfChart;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4054
  this.tweets  = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4055
  this.svgElements = {};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4056
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4057
  this.oldSearchMatches = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4058
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4059
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4060
IriSP.PolemicWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4061
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4062
IriSP.PolemicWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4063
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4064
    // variable 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4065
    // yMax
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4066
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4067
    var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4068
    var yCoef        = 2;             // coef for height of 1 tweet 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4069
    var frameSize     = 5;             // frame size 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4070
    var margin         = 1;            // marge between frame
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4071
    var lineSize      = this.width;        // timeline pixel width 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4072
    var nbrframes     = lineSize/frameSize;     // frame numbers
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4073
    var numberOfTweet   = 0;            // number of tweet overide later 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4074
    var duration      = this._serializer.getDuration();      // timescale width 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4075
    var frameLength   = lineSize / frameSize;    // frame timescale  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4076
    var timeline;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4077
    var colors  = new Array("","#1D973D","#036AAE","#CE0A15","#C5A62D","#585858");
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4078
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4079
    // array 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4080
    //var tweets  = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4081
    var element = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4082
    var cluster = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4083
    var frames  = new Array(frameLength);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4084
    var slices  = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4085
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4086
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4087
    // Classes =======================================================================
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4088
    var Frames = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4089
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4090
      var Myclusters;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4091
      var x;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4092
      var y;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4093
      var width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4094
      var height;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4095
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4096
    Frames = function(json){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4097
      // make my clusters
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4098
      // ou Frame vide 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4099
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4100
    Frames.prototype.draw = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4101
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4102
    Frames.prototype.zoom = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4103
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4104
    Frames.prototype.inside = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4105
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4106
    var Clusters = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4107
      var Object;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4108
      var yDist;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4109
      var x;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4110
      var y;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4111
      var width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4112
      var height;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4113
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4114
    Clusters = function(json){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4115
      // make my object
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4116
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4117
    var Tweet = function(){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4118
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4119
    // Classes =======================================================================
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4120
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4121
    // Refactoring (parametere) ************************************************************
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4122
    // color translastion
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4123
    var qTweet_0  =0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4124
    var qTweet_Q  =0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4125
    var qTweet_REF=0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4126
    var qTweet_OK =0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4127
    var qTweet_KO =0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4128
    function colorTranslation(value){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4129
      if(value == "Q"){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4130
        qTweet_Q+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4131
        return 2;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4132
      }else if(value =="REF"){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4133
        qTweet_REF+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4134
        return 4;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4135
      }else if(value =="OK"){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4136
        qTweet_OK+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4137
        return 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4138
      }else if(value =="KO"){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4139
        qTweet_KO+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4140
        return 3;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4141
      }else if(value ==""){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4142
        qTweet_0+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4143
        return 5;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4144
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4145
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4146
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4147
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4148
      this._serializer.sync(function(data) { loaded_callback.call(self, data); return; });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4149
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4150
      function loaded_callback (json) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4151
      var view_type = this._serializer.getTweets();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4152
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4153
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4154
      if (typeof(view_type) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4155
        var view_type = this._serializer.getTweetIds()[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4156
        if (typeof(view_type) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4157
          // default to guessing if nothing else works.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4158
          var view = json.views[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4159
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4160
          if(typeof(view.annotation_types) !== "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4161
            /* we need to be backward compatible with the old files which used to
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4162
               feature only two lines : Chapitrage and Tweets. We've added a
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4163
               "Contributions" line so we need to discriminate against that */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4164
            if (view.annotation_types.length === 2 && typeof(this._serializer.getContributions()) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4165
              var view_type = view.annotation_types[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4166
            } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4167
              console.log("PolemicWidget: invalid file - minimizing");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4168
              return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4169
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4170
          }      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4171
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4172
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4173
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4174
      // Make and define the Raphael area
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4175
      this.paper = Raphael(document.getElementById(this._id), this._config.width, this._config.height);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4176
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4177
      // event handlers
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4178
      this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) { this.searchHandler(searchString); }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4179
      this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.searchFieldClosedHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4180
      this._Popcorn.listen("IriSP.search.cleared", IriSP.wrap(this, this.searchFieldClearedHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4181
      this.selector.mouseleave(IriSP.wrap(this, function() { self.TooltipWidget.hide.call(self.TooltipWidget); }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4182
      this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4183
      this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", IriSP.wrap(this, this.showAnnotation));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4184
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4185
      for(var i = 0; i < json.annotations.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4186
        var item = json.annotations[i];        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4187
        var MyTime  = Math.floor(item.begin/duration*lineSize);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4188
        var Myframe = Math.floor(MyTime/lineSize*frameLength);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4189
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4190
        if (typeof(item.meta) !== "undefined" 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4191
          && typeof(item.meta["id-ref"]) !== "undefined"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4192
          && item.meta["id-ref"] === view_type) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4193
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4194
            var MyTJson = {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4195
                _source = IriSP.get_aliased(item.meta, ['dc:source', 'source']);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4196
            if (_source !== null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4197
              var MyTJson = JSON.parse(_source['content']);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4198
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4199
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4200
            if (item.content['polemics'] != undefined 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4201
            && item.content['polemics'][0] != null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4202
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4203
              // a tweet can have many polemics at the same time.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4204
              for(var j=0; j<item.content['polemics'].length; j++){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4205
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4206
                  this.tweets[numberOfTweet] = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4207
                        id:i,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4208
                        qualification:colorTranslation(item.content['polemics'][j]),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4209
                        yIndicator:MyTime,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4210
                        yframe:Myframe,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4211
                        title:item.content['title'],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4212
                        timeframe:item.begin,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4213
                        userId: MyTJson.id,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4214
                        userScreenName: MyTJson.screen_name,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4215
                        tsource:MyTJson,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4216
                        cinecast_id: item.id
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4217
                        };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4218
                  numberOfTweet+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4219
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4220
              }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4221
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4222
          else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4223
            this.tweets[numberOfTweet] = {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4224
                  id:i,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4225
                  qualification:colorTranslation(""),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4226
                  yIndicator:MyTime,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4227
                  yframe:Myframe,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4228
                  title:item.content['title'],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4229
                  timeframe:item.begin,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4230
                  userId: MyTJson.id,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4231
                  userScreenName: MyTJson.screen_name,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4232
                  tsource:MyTJson,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4233
                  cinecast_id: item.id
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4234
            };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4235
            numberOfTweet+=1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4236
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4237
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4238
        } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4239
      };  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4240
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4241
       DrawTweets.call (this); // FIXME: ugly.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4242
       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4243
      };      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4244
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4245
    // tweet Drawing (in raphael) 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4246
    function DrawTweets (){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4247
    // GROUPES TWEET ============================================
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4248
    // Count nbr of cluster and tweet in a frame an save int in "frames"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4249
      numberOfTweet = this.tweets.length;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4250
      for(var i=0; i<nbrframes; i++) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4251
        for(var j=0; j<numberOfTweet; j++) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4252
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4253
          if (i==this.tweets[j].yframe){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4254
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4255
            var k = this.tweets[j].qualification;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4256
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4257
            // make array for frame cluster
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4258
            if(frames[i]==undefined){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4259
              frames[i] = {id:i,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4260
                     qualifVol:new Array(),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4261
                     mytweetsID:new Array()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4262
                    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4263
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4264
            // add my tweet to frame
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4265
            frames[i].mytweetsID.push(this.tweets[j]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4266
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4267
            // count opinion by frame
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4268
            if( frames[i].qualifVol[k] == undefined){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4269
              frames[i].qualifVol[k] = 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4270
            }else{
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4271
              frames[i].qualifVol[k] += 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4272
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4273
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4274
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4275
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4276
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4277
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4278
    // GROUPES TWEET ============================================    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4279
    // max of tweet by Frame 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4280
      var max = 0; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4281
      for(var i = 0; i < nbrframes; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4282
        var moy  = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4283
        for (var j = 0; j < 6; j++) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4284
          if (frames[i] != undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4285
            if (frames[i].qualifVol[j] != undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4286
              moy += frames[i].qualifVol[j];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4287
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4288
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4289
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4290
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4291
        if (moy > max) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4292
          max = moy;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4293
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4294
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4295
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4296
      var tweetDrawed = new Array();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4297
      var TweetHeight = 5;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4298
      var newHeight = TweetHeight * max + 10;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4299
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4300
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4301
      if (newHeight > this.height) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4302
        this.paper.setSize(this.width, newHeight);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4303
        this.height = newHeight;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4304
        console.log("resizeing");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4305
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4306
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4307
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4308
      // DRAW  TWEETS ============================================
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4309
      for(var i = 0; i < nbrframes; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4310
        var addEheight = 5;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4311
        if (frames[i] != undefined){                
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4312
          // by type 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4313
          
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4314
          for (var j = 6; j > -1; j--) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4315
            if (frames[i].qualifVol[j] != undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4316
              // show tweet by type 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4317
              for (var k = 0; k < frames[i].mytweetsID.length; k++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4318
              
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4319
                if (frames[i].mytweetsID[k].qualification == j) {                
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4320
                  var x = i * frameSize;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4321
                  var y = this.height - addEheight;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4322
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4323
                  if (this.yMax > y) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4324
                    this.yMax = y;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4325
                  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4326
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4327
                  /* some tweets seem to be duplicated - so we make a check before
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4328
                     creating a new rect */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4329
                  if (this.svgElements.hasOwnProperty(frames[i].mytweetsID[k].cinecast_id))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4330
                    continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4331
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4332
                  var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4333
                                    .attr({stroke:"#00","stroke-width":0.1,  fill: colors[j]});  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4334
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4335
                  addEheight += TweetHeight;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4336
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4337
                  /* stick a lot of things into e because that's the easiest way
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4338
                     to do it */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4339
                  e.color = colors[j];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4340
                  e.time = frames[i].mytweetsID[k].timeframe;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4341
                  e.title = frames[i].mytweetsID[k].title;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4342
                  e.id = frames[i].mytweetsID[k].cinecast_id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4343
                  this.svgElements[e.id] = e;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4344
                  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4345
                  IriSP.jQuery(e.node).mouseenter(function(element) { return function (_e) {                    
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4346
                        self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), element.attrs.x + element.attrs.width / 2, element.attrs.y - 2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4347
                        element.displayed = true;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4348
                        self._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4349
                            "widget" : "StackGraphWidget",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4350
                            "type": "mousemove",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4351
                            "x": _e.pageX,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4352
                            "y": _e.pageY,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4353
                            "annotation_id": element.id
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4354
                        });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4355
                  }}(e)).mousedown(function(element) { return function () {                    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4356
                    self._Popcorn.currentTime(element.time/1000);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4357
                    self._Popcorn.trigger("IriSP.PolemicTweet.click", element.id); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4358
                    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4359
                  }(e));                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4360
                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4361
                  IriSP.jQuery(e.node).attr('id', 't' + k + '');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4362
                  IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4363
                  IriSP.jQuery(e.node).attr('begin',  frames[i].mytweetsID[k].timeframe);                  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4364
                }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4365
              }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4366
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4367
          }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4368
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4369
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4370
      }    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4371
      // DRAW UI :: resize border and bgd      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4372
      this.paperBackground = this.paper.rect(0, 0, this.width, this.height).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1});  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4373
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4374
      // outer borders
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4375
      this.outerBorders   = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4376
      this.outerBorders.push(this.paper.rect(0, this.height - 1, this.width, 1).attr({fill:"#ababab",stroke: "none",opacity: 1}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4377
      this.outerBorders.push(this.paper.rect(0, 0, this.width, 1).attr({fill:"#ababab",stroke: "none",opacity: 1}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4378
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4379
      // inner borders
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4380
      this.innerBorders   = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4381
      this.innerBorders.push(this.paper.rect(1, this.height - 2, this.width, 1).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4382
      this.innerBorders.push(this.paper.rect(1, 1, this.width, 1).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4383
      this.innerBorders.push(this.paper.rect(1, 1, 1, this.height - 2).attr({fill:"#d0d1d1",stroke: "none",opacity: 0.8}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4384
      this.innerBorders.push(this.paper.rect(this.width - 2, 1, 1, this.height - 2).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4385
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4386
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4387
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4388
      this.paperSlider   = this.paper.rect(0, 0, 0, this.height).attr({fill:"#D4D5D5", stroke: "none", opacity: 1});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4389
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4390
      // the small white line displayed over the slider.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4391
      this.sliderTip = this.paper.rect(0, 0, 1, this.height).attr({fill:"#fc00ff", stroke: "none", opacity: 1});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4392
      // decalage 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4393
      // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1});  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4394
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4395
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4396
      this.paperSlider.toBack();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4397
      this.paperBackground.toBack();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4398
      this.sliderTip.toFront();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4399
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4400
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4401
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4402
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4403
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4404
/** update the positionMarker as time passes */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4405
IriSP.PolemicWidget.prototype.sliderUpdater = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4406
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4407
    var time = +this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4408
    var duration = this._serializer.getDuration();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4409
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4410
    this.paperSlider.attr("width", time * (this.width / (duration / 1000)));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4411
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4412
    this.sliderTip.attr("x", time * (this.width / (duration / 1000)));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4413
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4414
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4415
/** reacts to IriSP.search events */    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4416
IriSP.PolemicWidget.prototype.searchHandler = function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4417
  if (searchString == "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4418
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4419
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4420
  var matches = this._serializer.searchTweetsOccurences(searchString);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4421
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4422
  if (IriSP.countProperties(matches) > 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4423
    this._Popcorn.trigger("IriSP.search.matchFound");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4424
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4425
    this._Popcorn.trigger("IriSP.search.noMatchFound");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4426
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4427
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4428
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4429
  // decrease the opacity of the other elements.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4430
  for (var id in this.svgElements) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4431
    var e = this.svgElements[id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4432
    e.attr({fill: e.color, opacity: 0.4});   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4433
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4434
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4435
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4436
  for (var id in matches) {    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4437
    if (this.svgElements.hasOwnProperty(id)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4438
      var e = this.svgElements[id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4439
      this.svgElements[id].attr({fill: "#fc00ff", opacity: 1});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4440
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4441
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4442
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4443
  this.oldSearchMatches = matches;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4444
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4445
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4446
/** reacts to IriSP.search.cleared messages */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4447
IriSP.PolemicWidget.prototype.searchFieldClearedHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4448
  for (var id in this.svgElements) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4449
    var e = this.svgElements[id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4450
    e.attr({fill: e.color, opacity: 1});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4451
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4452
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4453
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4454
/** reacts to IriSP.search.closed messages by clearing the highlighted elements */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4455
IriSP.PolemicWidget.prototype.searchFieldClosedHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4456
  for (var id in this.svgElements) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4457
    var e = this.svgElements[id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4458
    e.attr({fill: e.color, opacity: 1});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4459
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4460
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4461
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4462
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4463
IriSP.PolemicWidget.prototype.showAnnotation = function(id) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4464
  if (this.svgElements.hasOwnProperty(id)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4465
    var e = this.svgElements[id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4466
    this.TooltipWidget.show(e.title, e.attr("fill"), e.x - 103, e.y - 160);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4467
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4468
};   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4469
IriSP.SegmentsWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4470
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4471
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4472
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4473
  this.oldSearchMatches = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4474
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4475
  // event handlers
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4476
  this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4477
  this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4478
  this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); });
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4479
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4480
  this.checkOption("cinecast_version");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4481
  this.defaultColors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"]
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4482
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4483
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4484
IriSP.SegmentsWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4485
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4486
IriSP.SegmentsWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4487
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4488
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4489
  var annotations = this._serializer._data.annotations;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4490
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4491
  this.selector.addClass("Ldt-SegmentsWidget");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4492
  this.selector.append(Mustache.to_html(IriSP.overlay_marker_template));
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4493
  
535
8276f3ff7a3f Added new player in player_embed
Raphael Velt <raph.velt@gmail.com>
parents: 534
diff changeset
  4494
  this.positionMarker = this.selector.find(".Ldt-SegmentPositionMarker");
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4495
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4496
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater));
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4497
  var duration = this._serializer.getDuration();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4498
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4499
  if (this.cinecast_version) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4500
      var segments_annotations = IriSP.underscore.filter(
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4501
          this._serializer._data.annotations,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4502
          function(_a) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4503
              return _a.type == "cinecast:MovieExtract";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4504
          }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4505
      );
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4506
  }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4507
  else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4508
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4509
      var view_type = this._serializer.getChapitrage();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4510
      if (typeof(view_type) === "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4511
        view_type = this._serializer.getNonTweetIds()[0];  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4512
      }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4513
    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4514
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4515
      var i = 0;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4516
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4517
      var segments_annotations = [];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4518
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4519
      for (i = 0; i < annotations.length; i++) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4520
        var annotation = annotations[i];
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4521
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4522
        /* filter the annotations whose type is not the one we want */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4523
        if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4524
              && annotation.meta["id-ref"] != view_type) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4525
            continue;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4526
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4527
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4528
        segments_annotations.push(annotation);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4529
      }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4530
}    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4531
    var _w = this.selector.width();
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4532
  var lastSegment = IriSP.underscore.max(segments_annotations, function(annotation) { return annotation.end; });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4533
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4534
  for (i = 0; i < segments_annotations.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4535
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4536
    var annotation = segments_annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4537
    var begin = (+ annotation.begin);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4538
    var end = (+ annotation.end);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4539
    var id = annotation.id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4540
        
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4541
    var startPixel = Math.floor(_w * (begin / duration));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4542
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4543
    var endPixel = Math.floor(_w * (end / duration));
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4544
    if (annotation.id !== lastSegment.id) 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4545
      var pxWidth = endPixel - startPixel -1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4546
    else
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4547
      /* the last segment has no segment following it */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4548
      var pxWidth = endPixel - startPixel;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4549
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4550
    var divTitle = this.cinecast_version
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4551
        ? annotation.content.data
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4552
        : annotation.content.title + ( annotation.content.title ? "<br />" : "" ) + annotation.content.description.replace(/(^.{120,140})[\s].+$/,'$1&hellip;');
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4553
    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4554
    var thumbUrl = annotation.meta.thumbnail || '';
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4555
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4556
    var hexa_color = typeof(annotation.content.color) !== "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4557
        ? '#' + IriSP.DEC_HEXA_COLOR(annotation.content.color)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4558
        : typeof(annotation.color) !== "undefined"
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4559
            ? '#' + IriSP.DEC_HEXA_COLOR(annotation.color)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4560
            : this.defaultColors[i % this.defaultColors.length];
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4561
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4562
    /*
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4563
    if (hexa_color === "FFCC00")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4564
      hexa_color = "333";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4565
    */
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4566
    if (hexa_color.length == 5)
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4567
      hexa_color = hexa_color + '00';
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4568
    
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4569
    
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4570
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4571
        {"divTitle" : divTitle, "id" : id, "startPixel" : startPixel,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4572
        "pxWidth" : pxWidth, "hexa_color" : hexa_color,
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4573
        "seekPlace" : Math.round(begin/1000), "thumbnailUrl": thumbUrl});
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4574
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4575
        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4576
    this.selector.append(annotationTemplate);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4577
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4578
    /* add a special class to the last segment and change its border */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4579
    if (annotation.id === lastSegment.id) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4580
        IriSP.jqId(id).addClass("Ldt-lastSegment").css("border-color", hexa_color);  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4581
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4582
   }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4583
    // react to mediafragment messages.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4584
    this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", 
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4585
        function(id, divTitle) {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4586
        
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4587
            var divObject = IriSP.jqId(id);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4588
            if (divObject.length) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4589
            divObject.fadeTo(0,1);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4590
            var offset_x = divObject.position().left + divObject.outerWidth() / 2;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4591
            self.TooltipWidget.show(divObject.attr("title"), IriSP.jQuery(this).css("background-color"), offset_x, 0);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4592
            IriSP.jQuery(document).one("mousemove", function() { divObject.fadeTo(0,.5);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4593
                                                                self.TooltipWidget.hide(); });
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4594
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4595
      });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4596
      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4597
    this.selector.find(".Ldt-iri-chapter")
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4598
        .fadeTo(0, .5)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4599
        .click(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4600
            self._Popcorn.trigger("IriSP.SegmentsWidget.click", this.id);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4601
            self._Popcorn.currentTime(IriSP.jQuery(this).attr("data-seek"));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4602
        })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4603
        .mouseover( function(event) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4604
            var divObject = IriSP.jQuery(this);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4605
            divObject.fadeTo(0,1);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4606
            var offset_x = divObject.position().left + divObject.outerWidth() / 2;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4607
            var thumb = divObject.attr("thumbnail-url");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4608
            var txt = divObject.attr("title") + (thumb && thumb.length ? '<br /><img src="' + thumb + '" />' : '');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4609
            self.TooltipWidget.show(txt, IriSP.jQuery(this).css("background-color"), offset_x, 0);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4610
        })
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4611
        .mouseout(function(){
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4612
            IriSP.jQuery(this).fadeTo(0,.5);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4613
            self.TooltipWidget.hide();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4614
        });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4615
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4616
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4617
/* restores the view after a search */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4618
IriSP.SegmentsWidget.prototype.clear = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4619
  this.selector.children(".Ldt-iri-chapter").fadeTo(0,.5);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4620
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4621
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4622
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4623
  this._Popcorn.trigger("IriSP.SegmentsWidget.click", annotation.id);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4624
  var begin = (+ annotation.begin) / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4625
  this._Popcorn.currentTime(Math.round(begin));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4626
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4627
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4628
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4629
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4630
  if (searchString == "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4631
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4632
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4633
  var matches = this._serializer.searchOccurences(searchString);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4634
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4635
  if (IriSP.countProperties(matches) > 0) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4636
    this._Popcorn.trigger("IriSP.search.matchFound");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4637
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4638
    this._Popcorn.trigger("IriSP.search.noMatchFound");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4639
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4640
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4641
  // un-highlight all the blocks
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4642
  this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4643
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4644
  // then highlight the ones with matches.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4645
  for (var id in matches) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4646
    var factor = 0.5 + matches[id] * 0.2;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4647
    this.selector.find("#"+id).dequeue();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4648
    this.selector.find("#"+id).animate({opacity:factor}, 200);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4649
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4650
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4651
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4652
  this.oldSearchMatches = matches;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4653
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4654
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4655
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4656
  this.clear();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4657
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4658
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4659
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4660
  this.clear();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4661
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4662
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4663
IriSP.SegmentsWidget.prototype.positionUpdater = function() {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4664
  var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4665
  var time = this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4666
  //var position 	= ((time / duration) * 100).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4667
  var position 	= ((time / duration) * 100).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4668
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4669
  this.positionMarker.css("left", position + "%");  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4670
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4671
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4672
IriSP.SegmentsWidget.prototype.showAnnotation = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4673
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4674
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4675
/** A widget to create a new segment */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4676
IriSP.SliceWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4677
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4678
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4679
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4680
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4681
IriSP.SliceWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4682
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4683
IriSP.SliceWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4684
  var templ = Mustache.to_html(IriSP.sliceWidget_template);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4685
  this.selector.append(templ);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4686
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4687
  this.sliceZone = this.selector.find(".Ldt-sliceZone");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4688
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4689
  /* global variables used to keep the position and width
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4690
     of the zone.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4691
  */  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4692
  this.zoneLeft = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4693
  this.zoneWidth = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4694
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4695
  this.leftHandle = this.selector.find(".Ldt-sliceLeftHandle");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4696
  this.rightHandle = this.selector.find(".Ldt-sliceRightHandle");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4697
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4698
  var left = this.selector.offset().left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4699
  var top = this.selector.offset().top;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4700
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4701
  // a bug in firefox makes it use the wrong format
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4702
  if (!IriSP.jQuery.browser.mozilla) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4703
    // contain the handles correctly - we cannot set
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4704
    // containment: parent because it wouldn't allow to select the 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4705
    // whole slice, so we have to compute a box in which the slice is
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4706
    // allowed to move.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4707
    var containment = [left - 8, top, this.selector.width() + left, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4708
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4709
    // var containment = [left - 16, top, this.selector.width() + left - 8, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4710
    this.leftHandle.draggable({axis: "x",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4711
    drag: IriSP.wrap(this, this.leftHandleDragged),  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4712
    containment: containment
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4713
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4714
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4715
    containment = [left, top, this.selector.width() + left, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4716
    // containment = [left, top, this.selector.width() + left - 8, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4717
    this.rightHandle.draggable({axis: "x",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4718
    drag: IriSP.wrap(this, this.rightHandleDragged),    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4719
    containment: containment
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4720
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4721
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4722
  } else { // firefox
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4723
    // we need to define a containment specific to firefox.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4724
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4725
    var containment = [left - 16, top, this.selector.width() + left - 8, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4726
    this.leftHandle.draggable({axis: "x",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4727
    drag: IriSP.wrap(this, this.leftHandleDragged),  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4728
    containment: containment
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4729
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4730
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4731
    containment = [left, top, this.selector.width() + left - 8, top];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4732
    this.rightHandle.draggable({axis: "x",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4733
    drag: IriSP.wrap(this, this.rightHandleDragged),    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4734
    containment: containment
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4735
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4736
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4737
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4738
  this.leftHandle.css("position", "absolute");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4739
  this.rightHandle.css("position", "absolute");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4740
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4741
  this._Popcorn.listen("IriSP.SliceWidget.position", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4742
                        IriSP.wrap(this, this.positionSliceHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4743
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4744
  this._Popcorn.listen("IriSP.SliceWidget.show", IriSP.wrap(this, this.show));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4745
  this._Popcorn.listen("IriSP.SliceWidget.hide", IriSP.wrap(this, this.hide));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4746
  this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4747
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4748
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4749
/** responds to an "IriSP.SliceWidget.position" message
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4750
    @param params an array with the first element being the left distance in
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4751
           percents and the second element the width of the slice in pixels
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4752
*/        
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4753
IriSP.SliceWidget.prototype.positionSliceHandler = function(params) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4754
  left = params[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4755
  width = params[1];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4756
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4757
  this.zoneLeft = left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4758
  this.zoneWidth = width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4759
  this.sliceZone.css("left", left + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4760
  this.sliceZone.css("width", width + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4761
  this.leftHandle.css("left", (left - 7) + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4762
  this.rightHandle.css("left", left + width + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4763
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4764
  this._leftHandleOldLeft = left - 7;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4765
  this._rightHandleOldLeft = left + width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4766
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4767
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4768
/** handle a dragging of the left handle */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4769
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4770
  /* we have a special variable, this._leftHandleOldLeft, to keep the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4771
     previous position of the handle. We do that to know in what direction
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4772
     is the handle being dragged
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4773
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4774
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4775
  var currentX = this.leftHandle.offset().left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4776
  var rightHandleX = Math.floor(this.rightHandle.position()["left"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4777
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4778
  var container_offset = this.selector.offset().left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4779
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4780
  if (Math.floor(ui.position.left) >= rightHandleX - 7) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4781
    /* prevent the handle from moving past the right handle */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4782
    ui.position.left = rightHandleX - 7;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4783
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4784
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4785
  this.zoneWidth = rightHandleX - Math.floor(ui.position.left) - 7;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4786
  this.zoneLeft = Math.floor(ui.position.left) + 8;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4787
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4788
  this.sliceZone.css("width", this.zoneWidth);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4789
  this.sliceZone.css("left", this.zoneLeft + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4790
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4791
  this._leftHandleOldLeft = ui.position.left;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4792
  this.broadcastChanges();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4793
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4794
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4795
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4796
/** handle a dragging of the right handle */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4797
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4798
  /* we have a special variable, this._leftHandleOldLeft, to keep the
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4799
     previous position of the handle. We do that to know in what direction
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4800
     is the handle being dragged
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4801
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4802
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4803
  var currentX = this.leftHandle.position()["left"];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4804
  var leftHandleX = Math.floor(this.leftHandle.position()["left"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4805
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4806
  var container_offset = this.selector.offset().left + this.selector.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4807
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4808
  if (Math.floor(ui.position.left) < leftHandleX + 7) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4809
    /* prevent the handle from moving past the left handle */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4810
    ui.position.left = leftHandleX + 7;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4811
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4812
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4813
  this.zoneWidth = Math.floor(ui.position.left) - (leftHandleX + 7);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4814
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4815
  this.sliceZone.css("width", this.zoneWidth);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4816
  //this.sliceZone.css("left", this.zoneLeft + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4817
  this._rightHandleOldLeft = Math.floor(this._rightHandleOldLeft);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4818
  this.broadcastChanges();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4819
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4820
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4821
/** tell to the world that the coordinates of the slice have
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4822
    changed 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4823
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4824
IriSP.SliceWidget.prototype.broadcastChanges = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4825
  var leftPercent = (this.zoneLeft / this.selector.width()) * 100;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4826
  var zonePercent = (this.zoneWidth / this.selector.width()) * 100;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4827
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4828
  this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4829
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4830
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4831
IriSP.SliceWidget.prototype.show = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4832
  this.selector.show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4833
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4834
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4835
IriSP.SliceWidget.prototype.hide = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4836
  this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4837
};IriSP.SliderWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4838
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4839
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4840
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4841
IriSP.SliderWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4842
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4843
IriSP.SliderWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4844
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4845
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4846
  this.selector.append(Mustache.to_html(IriSP.sliderWidget_template, {}));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4847
  this.selector.addClass("Ldt-SliderMinimized");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4848
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4849
  this.sliderBackground = this.selector.find(".Ldt-sliderBackground");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4850
  this.sliderForeground = this.selector.find(".Ldt-sliderForeground");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4851
  this.positionMarker = this.selector.find(".Ldt-sliderPositionMarker");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4852
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4853
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4854
  // a special variable to stop methods from tinkering
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4855
  // with the positionMarker when the user is dragging it
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4856
  this.draggingOngoing = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4857
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4858
  // another special variable used by the timeout handler to
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4859
  // open or close the slider.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4860
  this.sliderMaximized = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4861
  this.timeOutId = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4862
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4863
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4864
  this.positionMarker.draggable({axis: "x",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4865
  start: IriSP.wrap(this, this.positionMarkerDraggingStartedHandler),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4866
  stop: IriSP.wrap(this, this.positionMarkerDraggedHandler),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4867
  containment: "parent"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4868
  });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4869
  this.positionMarker.css("position", "absolute");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4870
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4871
  this.sliderBackground.click(function(event) { self.backgroundClickHandler.call(self, event); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4872
  this.sliderForeground.click(function(event) { self.foregroundClickHandler.call(self, event); });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4873
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4874
  this.selector.hover(IriSP.wrap(this, this.mouseOverHandler), IriSP.wrap(this, this.mouseOutHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4875
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4876
  // update the positions
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4877
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4878
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4879
  // special messages :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4880
  this._Popcorn.listen("IriSP.PlayerWidget.MouseOver", IriSP.wrap(this, this.mouseOverHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4881
  this._Popcorn.listen("IriSP.PlayerWidget.MouseOut", IriSP.wrap(this, this.mouseOutHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4882
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4883
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4884
/* update the slider and the position marker as time passes */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4885
IriSP.SliderWidget.prototype.sliderUpdater = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4886
  if(this.draggingOngoing || this._disableUpdate)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4887
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4888
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4889
  var time = this._Popcorn.currentTime();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4890
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4891
  var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4892
  var percents = time / duration;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4893
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4894
  /* we do these complicated calculations to center exactly
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4895
     the position Marker */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4896
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4897
  var divWidth = this.selector.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4898
  var pixels = Math.floor(this.selector.width() * percents);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4899
  var positionMarker_width = this.positionMarker.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4900
  var correction = (positionMarker_width / 2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4901
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4902
  /* check that we don't leave the left side */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4903
  var newPos = pixels - correction;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4904
  if (newPos <= 0)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4905
    newPos = 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4906
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4907
  /* check that we don't leave the right side */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4908
  var rightEdgePos = pixels + 1 * correction;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4909
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4910
  if (rightEdgePos >= divWidth)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4911
    newPos = divWidth - 1 * correction - 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4912
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4913
  this.sliderForeground.css("width", pixels + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4914
  this.positionMarker.css("left", newPos + "px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4915
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4916
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4917
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4918
IriSP.SliderWidget.prototype.backgroundClickHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4919
  /* this piece of code is a little bit convoluted - here's how it works :
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4920
     we want to handle clicks on the progress bar and convert those to seeks in the media.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4921
     However, jquery only gives us a global position, and we want a number of pixels relative
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4922
     to our container div, so we get the parent position, and compute an offset to this position,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4923
     and finally compute the progress ratio in the media.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4924
     Finally we multiply this ratio with the duration to get the correct time
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4925
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4926
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4927
  var parentOffset = this.sliderBackground.parent().offset();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4928
  var width = this.sliderBackground.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4929
  var relX = event.pageX - parentOffset.left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4930
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4931
  var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4932
  var newTime = ((relX / width) * duration).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4933
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4934
  this._Popcorn.currentTime(newTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4935
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4936
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4937
/* same function as the previous one, except that it handles clicks
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4938
   on the foreground element */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4939
IriSP.SliderWidget.prototype.foregroundClickHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4940
  var parentOffset = this.sliderForeground.parent().offset();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4941
  var width = this.sliderBackground.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4942
  var relX = event.pageX - parentOffset.left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4943
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4944
  var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4945
  var newTime = ((relX / width) * duration).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4946
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4947
  this._Popcorn.currentTime(newTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4948
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4949
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4950
/* handles mouse over the slider */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4951
IriSP.SliderWidget.prototype.mouseOverHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4952
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4953
  if (this.timeOutId !== null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4954
    window.clearTimeout(this.timeOutId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4955
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4956
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4957
  this.sliderMaximized = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4958
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4959
  this.sliderBackground.animate({"height": "9px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4960
  this.sliderForeground.animate({"height": "9px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4961
  this.positionMarker.animate({"height": "9px", "width": "9px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4962
  //this.positionMarker.css("margin-top", "-4px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4963
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4964
//  this.selector.removeClass("Ldt-SliderMinimized");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4965
//  this.selector.addClass("Ldt-SliderMaximized");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4966
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4967
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4968
/* handles when the mouse leaves the slider */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4969
IriSP.SliderWidget.prototype.mouseOutHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4970
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4971
  this.timeOutId = window.setTimeout(IriSP.wrap(this, this.minimizeOnTimeout),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4972
                                     IriSP.widgetsDefaults.SliderWidget.minimize_period);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4973
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4974
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4975
IriSP.SliderWidget.prototype.minimizeOnTimeout = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4976
  this.sliderBackground.animate({"height": "5px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4977
  this.sliderForeground.animate({"height": "5px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4978
  this.positionMarker.animate({"height": "5px", "width": "5px"}, 100);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4979
  this.positionMarker.css("margin-top", "0px");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4980
  this.sliderMinimized = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4981
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4982
//  this.selector.removeClass("Ldt-SliderMaximized");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4983
//  this.selector.addClass("Ldt-SliderMinimized");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4984
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4985
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4986
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4987
// called when the user starts dragging the position indicator
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4988
IriSP.SliderWidget.prototype.positionMarkerDraggingStartedHandler = function(event, ui) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4989
  this.draggingOngoing = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4990
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4991
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4992
IriSP.SliderWidget.prototype.positionMarkerDraggedHandler = function(event, ui) {   
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4993
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4994
/*  this._disableUpdate = true; // disable slider position updates while dragging is ongoing.
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4995
  window.setTimeout(IriSP.wrap(this, function() { this._disableUpdate = false; }), 500);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4996
*/
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4997
  var parentOffset = this.sliderForeground.parent().offset();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  4998
  var width = this.sliderBackground.width();
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  4999
  var relX = event.originalEvent.pageX - parentOffset.left;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5000
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5001
  var duration = this._serializer.getDuration() / 1000;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5002
  var newTime = ((relX / width) * duration).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5003
  this._Popcorn.currentTime(newTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5004
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5005
  this.draggingOngoing = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5006
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5007
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5008
/** @class The constructor for the sparkline widget */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5009
IriSP.SparklineWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5010
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5011
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5012
  this._oldAnnotation = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5013
  this._results = [];
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5014
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5015
  this.lineColor = this._config.lineColor || "#7492b4";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5016
  this.fillColor = this._config.fillColor || "#aeaeb8";
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5017
  this.lineWidth = this._config.lineWidth || 2;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5018
  this.slices = this._config.slices || Math.floor(this.width/20);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5019
  if (!this.width) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5020
      this.width = this.selector.width();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5021
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5022
  if (!this.height) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5023
      this.height = 40;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5024
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5025
  this.selector.css("height", this.height + "px");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5026
  if (this._config.background) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5027
      this.selector.css("background", this._config.background);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5028
  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5029
  this.checkOption('cinecast_version');
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5030
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5031
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5032
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5033
IriSP.SparklineWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5034
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5035
IriSP.SparklineWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5036
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5037
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5038
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5039
/** draw the sparkline using jquery sparkline */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5040
IriSP.SparklineWidget.prototype.draw = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5041
    this.duration = this._serializer.getDuration();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5042
    this.paper = new Raphael(this.selector[0], this.width, this.height);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5043
    var _this = this;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5044
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5045
  var views = this._serializer._data.views;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5046
  var stat_view;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5047
  if (!IriSP.null_or_undefined(views)) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5048
    for (var i = 0; i < views.length; i++) {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5049
      var view = views[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5050
      if (view.id === "stat") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5051
          stat_view = view;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5052
          break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5053
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5054
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5055
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5056
  
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5057
    var _ = IriSP.underscore;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5058
  // If we've found the correct view, feed the directly the data from the view
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5059
  // to jquery sparkline. Otherwise, compute it ourselves.
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5060
    if (!IriSP.null_or_undefined(stat_view)) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5061
        //console.log("sparklinewidget : using stats embedded in the json");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5062
        var _results = stat_view.meta.stat.split(",");      
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5063
    } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5064
        var _annotations = this._serializer._data.annotations,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5065
            _sliceDuration = Math.floor( this.duration / this.slices),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5066
            _results = _(_.range(this.slices)).map(function(_i) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5067
                return _(_annotations).filter(function(_a){
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5068
                    return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) && (!_this.cinecast_version || _a.type == "cinecast:UserAnnotation")
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5069
                }).length;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5070
            });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5071
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5072
    var _max = Math.max(1, _(_results).max()),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5073
        _h = this.height,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5074
        _scale = (_h - this.lineWidth) / _max,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5075
        _width = this.width / this.slices,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5076
        _y = _(_results).map(function(_v) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5077
            return _h - (_scale * _v);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5078
        }),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5079
        _d = _(_y).reduce(function(_memo, _v, _k) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5080
               return _memo + ( _k
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5081
                   ? 'C' + (_k * _width) + ' ' + _y[_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5082
                   : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v )
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5083
            },'') + 'L' + this.width + ' ' + _y[_y.length - 1],
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5084
        _d2 = _d + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5085
    this.paper.path(_d2).attr({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5086
        "stroke" : "none",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5087
        "fill" : this.fillColor
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5088
    });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5089
         
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5090
    this.paper.path(_d).attr({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5091
        "fill" : "none",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5092
        "stroke" : this.lineColor,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5093
        "stroke-width" : this.lineWidth
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5094
    });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5095
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5096
    this.rectangleProgress = this.paper.rect(0,0,0,this.height)
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5097
        .attr({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5098
            "stroke" : "none",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5099
            "fill" : "#808080",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5100
            "opacity" : .3
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5101
        });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5102
    this.ligneProgress = this.paper.path("M0 0L0 "+this.height).attr({"stroke":"#ff00ff", "line-width" : 2});
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5103
  // save the results in an array so that we can re-use them when a new annotation
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5104
  // is added.
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5105
  this._results = _results;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5106
  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5107
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5108
//  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.handleNewAnnotation));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5109
  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5110
  this.selector.click(IriSP.wrap(this, this.clickHandler));  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5111
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5112
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5113
/** react to a timeupdate event */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5114
IriSP.SparklineWidget.prototype.timeUpdateHandler = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5115
    var _currentTime = this._Popcorn.currentTime(),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5116
        _x = (1000 * _currentTime / this.duration) * this.width;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5117
    this.rectangleProgress.attr({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5118
        "width" : _x
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5119
    });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5120
    this.ligneProgress.attr({
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5121
        "path" : "M" + _x + " 0L" + _x + " " + this.height
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5122
    });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5123
                                  
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5124
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5125
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5126
/** handle clicks on the widget */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5127
IriSP.SparklineWidget.prototype.clickHandler = function(event) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5128
  var relX = event.pageX - this.selector.offset().left;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5129
  var newTime = ((relX / this.width) * this.duration/1000).toFixed(2);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5130
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5131
  this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5132
  this._Popcorn.currentTime(newTime);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5133
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5134
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5135
/** react when a new annotation is added */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5136
IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5137
//  var num_columns = this._results.length;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5138
//  var duration = this._serializer.getDuration();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5139
//  var time_step = Math.round(duration / num_columns); /* the time interval between two columns */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5140
//  var begin = +annotation.begin;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5141
//  var end = +annotation.end;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5142
//  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5143
//  /* increment all the values between the beginning and the end of the annotation */
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5144
//  var index_begin = Math.floor(begin / time_step);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5145
//  var index_end = Math.floor(end / time_step);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5146
//  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5147
//  for (var i = index_begin; i < Math.min(index_end, this._results.length); i++) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5148
//    this._results[i]++;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5149
//  }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5150
//  
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5151
//  this.selector.find(".Ldt-sparkLine").sparkline(this._results, {lineColor: "#7492b4", fillColor: "#aeaeb8",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5152
//                                                           spotColor: "#b70056",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5153
//                                                           width: this.width, height: this.height});
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5154
};IriSP.StackGraphWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5155
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5156
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5157
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5158
IriSP.StackGraphWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5159
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5160
IriSP.StackGraphWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5161
    var _ = IriSP._,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5162
        _defaultTags = [
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5163
            {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5164
                "keywords" : [ "++" ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5165
                "description" : "positif",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5166
                "color" : "#1D973D"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5167
            },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5168
            {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5169
                "keywords" : [ "--" ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5170
                "description" : "negatif",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5171
                "color" : "#CE0A15"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5172
            },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5173
            {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5174
                "keywords" : [ "==" ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5175
                "description" : "reference",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5176
                "color" : "#C5A62D"  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5177
            },
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5178
            {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5179
                "keywords" : [ "??" ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5180
                "description" : "question",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5181
                "color" : "#036AAE"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5182
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5183
        ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5184
        _defaultDefColor = "#585858";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5185
    this.height =  this._config.height || 50;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5186
    this.width = this.selector.width();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5187
    this.isStreamGraph = this._config.streamgraph || false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5188
    this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5189
    this.tagconf = (this._config.tags
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5190
        ? this._config.tags
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5191
        : _defaultTags);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5192
    IriSP._(this.tagconf).each(function(_a) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5193
        _a.regexp = new RegExp(_(_a.keywords).map(function(_k) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5194
            return _k.replace(/([\W])/gm,'\\$1');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5195
        }).join("|"),"im")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5196
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5197
    this.defaultcolorconf = (this._config.defaultcolor
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5198
        ? this._config.defaultcolor
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5199
        : _defaultDefColor);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5200
    this.paper = new Raphael(this.selector[0], this.width, this.height);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5201
    this.groups = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5202
    this.duration = this._serializer.getDuration();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5203
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5204
    var _annotationType = this._serializer.getTweets(),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5205
        _sliceDuration = ~~ ( this.duration / this.sliceCount),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5206
        _annotations = this._serializer._data.annotations,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5207
        _groupedAnnotations = _(_.range(this.sliceCount)).map(function(_i) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5208
            return _(_annotations).filter(function(_a){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5209
                return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5210
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5211
        }),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5212
        _max = IriSP._(_groupedAnnotations).max(function(_g) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5213
            return _g.length
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5214
        }).length,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5215
        _scale = this.height / _max,
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5216
        _width = this.width / this.sliceCount,
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5217
        _showTitle = !this._config.excludeTitle,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5218
        _showDescription = !this._config.excludeDescription;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5219
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5220
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5221
    var _paths = _(this.tagconf).map(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5222
        return [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5223
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5224
    _paths.push([]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5225
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5226
    for (var i = 0; i < this.sliceCount; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5227
        var _group = _groupedAnnotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5228
        if (_group) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5229
            var _vol = _(this.tagconf).map(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5230
                return 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5231
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5232
            for (var j = 0; j < _group.length; j++){
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5233
           var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '')
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5234
                var _tags = _(this.tagconf).map(function(_tag) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5235
                        return (_txt.search(_tag.regexp) == -1 ? 0 : 1)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5236
                    }),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5237
                    _nbtags = _(_tags).reduce(function(_a,_b) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5238
                        return _a + _b;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5239
                    }, 0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5240
                if (_nbtags) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5241
                    IriSP._(_tags).each(function(_v, _k) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5242
                        _vol[_k] += (_v / _nbtags);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5243
                    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5244
                }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5245
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5246
            var _nbtags = _(_vol).reduce(function(_a,_b) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5247
                    return _a + _b;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5248
                }, 0),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5249
                _nbneutre = _group.length - _nbtags,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5250
                _h = _nbneutre * _scale,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5251
                _base = this.height - _h;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5252
            if (!this.isStreamGraph) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5253
                this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5254
                    "stroke" : "none",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5255
                    "fill" : this.defaultcolorconf
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5256
                });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5257
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5258
           _paths[0].push(_base);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5259
            for (var j = 0; j < this.tagconf.length; j++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5260
                _h = _vol[j] * _scale;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5261
                _base = _base - _h;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5262
                if (!this.isStreamGraph) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5263
                    this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5264
                        "stroke" : "none",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5265
                        "fill" : this.tagconf[j].color
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5266
                    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5267
                }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5268
                _paths[j+1].push(_base);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5269
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5270
            this.groups.push(_(_vol).map(function(_v) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5271
                return _v / _group.length;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5272
            }))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5273
        } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5274
            for (var j = 0; j < _paths.length; j++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5275
                _paths[j].push(this.height);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5276
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5277
            this.groups.push(_(this.tagconf).map(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5278
                return 0;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5279
            }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5280
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5281
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5282
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5283
    if (this.isStreamGraph) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5284
        for (var j = _paths.length - 1; j >= 0; j--) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5285
            var _d = _(_paths[j]).reduce(function(_memo, _v, _k) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5286
               return _memo + ( _k
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5287
                   ? 'C' + (_k * _width) + ' ' + _paths[j][_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5288
                   : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v )
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5289
            },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5290
            this.paper.path(_d).attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5291
                "stroke" : "none",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5292
                "fill" : (j ? this.tagconf[j-1].color : this.defaultcolorconf)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5293
            });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5294
        }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5295
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5296
    this.rectangleFocus = this.paper.rect(0,0,_width,this.height)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5297
        .attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5298
            "stroke" : "none",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5299
            "fill" : "#ff00ff",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5300
            "opacity" : 0
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5301
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5302
    this.rectangleProgress = this.paper.rect(0,0,0,this.height)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5303
        .attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5304
            "stroke" : "none",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5305
            "fill" : "#808080",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5306
            "opacity" : .3
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5307
        });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5308
    this.ligneProgress = this.paper.path("M0 0L0 "+this.height).attr({"stroke":"#ff00ff", "line-width" : 2})
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5309
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5310
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5311
    var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5312
    this.selector
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5313
        .click(IriSP.wrap(this, this.clickHandler))
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5314
        .mousemove(function(_e) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5315
            _this.updateTooltip(_e);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5316
            // Trace
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5317
            var relX = _e.pageX - _this.selector.offset().left;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5318
            var _duration = _this._serializer.getDuration();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5319
            var _time = parseInt((relX / _this.width) * _duration);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5320
            _this._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5321
                "widget" : "StackGraphWidget",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5322
                "type": "mousemove",
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5323
                "x": _e.pageX,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5324
                "y": _e.pageY,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5325
                "time": _time
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5326
            });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5327
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5328
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5329
        .mouseout(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5330
            _this.TooltipWidget.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5331
            _this.rectangleFocus.attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5332
                "opacity" : 0
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5333
            })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5334
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5335
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5336
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5337
IriSP.StackGraphWidget.prototype.timeUpdateHandler = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5338
    var _currentTime = this._Popcorn.currentTime(),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5339
        _x = (1000 * _currentTime / this.duration) * this.width;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5340
    this.rectangleProgress.attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5341
        "width" : _x
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5342
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5343
    this.ligneProgress.attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5344
        "path" : "M" + _x + " 0L" + _x + " " + this.height
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5345
    })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5346
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5347
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5348
IriSP.StackGraphWidget.prototype.clickHandler = function(event) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5349
  /* Ctrl-C Ctrl-V'ed from another widget
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5350
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5351
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5352
  var relX = event.pageX - this.selector.offset().left;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5353
  var newTime = ((relX / this.width) * this.duration/1000).toFixed(2);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5354
  this._Popcorn.trigger("IriSP.StackGraphWidget.clicked", newTime);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5355
  this._Popcorn.currentTime(newTime);                                 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5356
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5357
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5358
IriSP.StackGraphWidget.prototype.updateTooltip = function(event) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5359
    var _segment = Math.max(0,Math.min(this.groups.length - 1, Math.floor(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width))),
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5360
        _valeurs = this.groups[_segment],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5361
        _width = this.width / this.sliceCount,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5362
        _html = '<ul style="list-style: none; margin: 0; padding: 0;">' + IriSP._(this.tagconf).map(function(_tag, _i) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5363
            return '<li style="clear: both;"><span style="float: left; width: 10px; height: 10px; margin: 2px; background: '
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5364
                + _tag.color
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5365
                + ';"></span>'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5366
                + ~~(100 * _valeurs[_i])
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5367
                + '% de '
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5368
                + _tag.description
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5369
                + '</li>';
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5370
        }).join('') + '</ul>';
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5371
    this.TooltipWidget._shown = false; // Vraiment, on ne peut pas ouvrir le widget s'il n'est pas encore ouvert ?
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5372
    this.TooltipWidget.show('','',(_segment + .5)* this.width / this.sliceCount, 0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5373
    this.TooltipWidget.selector.find(".tip").html(_html);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5374
    this.rectangleFocus.attr({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5375
        "x" : _segment * _width,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5376
        "opacity" : .4
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5377
    })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5378
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5379
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5380
IriSP.TagCloudWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5381
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5382
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5383
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5384
IriSP.TagCloudWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5385
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5386
IriSP.TagCloudWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5387
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5388
    var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5389
        _stopWords = [
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5390
            'aussi', 'and', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'donc', 'des', 'elle', 'encore', 'entre', 'est',
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5391
            'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre',
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5392
            'non', 'nos', 'nous', 'ont', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'sans', 'ses' ,'son', 'sont', 'sur',
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5393
            'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' ],
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5394
        _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5395
        _words = {},
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5396
        _showTitle = !this._config.excludeTitle,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5397
        _showDescription = !this._config.excludeDescription,
535
8276f3ff7a3f Added new player in player_embed
Raphael Velt <raph.velt@gmail.com>
parents: 534
diff changeset
  5398
        _excludePattern = this._config.excludePattern || null,
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5399
        _tagCount = this._config.tagCount || 30;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5400
    if (typeof this._config.excludeWords !== "undefined" && this._config.excludeWords.length) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5401
        IriSP._(this._config.excludeWords).each(function(_w) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5402
            _stopWords.push(_w.toLowerCase());
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5403
        });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5404
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5405
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5406
    IriSP._(this._serializer._data.annotations).each(function(_annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5407
       if (_annotation.content && _annotation.content.description) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5408
           var _txt = (_showTitle ? _annotation.content.title : '') + ' ' + (_showDescription ? _annotation.content.description : '')
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5409
           IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_mot) {
535
8276f3ff7a3f Added new player in player_embed
Raphael Velt <raph.velt@gmail.com>
parents: 534
diff changeset
  5410
               if (_stopWords.indexOf(_mot) == -1 && (_excludePattern == null || !_excludePattern.test(_mot))) {
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5411
                   _words[_mot] = 1 + (_words[_mot] || 0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5412
               }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5413
           })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5414
       } 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5415
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5416
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5417
    _words = IriSP._(_words)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5418
        .chain()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5419
        .map(function(_v, _k) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5420
            return {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5421
                "word" : _k,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5422
                "count" : _v
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5423
            }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5424
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5425
        .filter(function(_v) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5426
            return _v.count > 2;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5427
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5428
        .sortBy(function(_v) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5429
            return - _v.count;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5430
        })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5431
        .first(_tagCount)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5432
        .value();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5433
    var _max = _words[0].count,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5434
        _min = Math.min(_words[_words.length - 1].count, _max - 1),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5435
        _scale = 16 / Math.sqrt(_max - _min),
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5436
        _this = this,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5437
        _html = '<ul>'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5438
            + IriSP._(_words)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5439
                .chain()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5440
                .shuffle()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5441
                .map(function(_word) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5442
                    var _size = 10 + _scale * Math.sqrt(_word.count - _min);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5443
                    return '<li class="Ldt-TraceMe" style="font-size:'
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5444
                        + _size
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5445
                        + 'px;">'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5446
                        + _word.word
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5447
                        + '</li>'
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5448
                })
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5449
                .value()
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5450
                .join("")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5451
            + '</ul>';
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5452
    this.selector
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5453
        .addClass("Ldt-TagCloud")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5454
        .html(_html);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5455
    this.selector.find("li").click(function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5456
        var _txt = this.textContent.replace(/(^[\s]+|[\s]+$)/g,'');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5457
        _this._Popcorn.trigger("IriSP.search.triggeredSearch", _txt);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5458
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5459
    this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5460
        var _rgxp = new RegExp("(" + searchString.replace(/(\W)/g,'\\$1') + ")","gi");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5461
        this.selector.find("li").each(function(_i, _e) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5462
            _e.innerHTML = searchString.length ?
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5463
                _e.textContent.replace(_rgxp,'<span class="Ldt-TagCloud-actif Ldt-TraceMe">$1</span>')
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5464
                : _e.textContent;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5465
        });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5466
    }));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5467
    this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.endsearch));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5468
    this._Popcorn.listen("IriSP.search.cleared", IriSP.wrap(this, this.endsearch));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5469
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5470
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5471
IriSP.TagCloudWidget.prototype.endsearch = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5472
    this.selector.find("li").each(function(_i, _e) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5473
        _e.innerHTML = _e.textContent;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5474
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5475
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5476
/* this widget displays a small tooltip */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5477
IriSP.TooltipWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5478
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5479
  this._shown = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5480
  this._displayedText = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5481
  this._hideTimeout = -1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5482
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5483
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5484
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5485
IriSP.TooltipWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5486
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5487
IriSP.TooltipWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5488
  var templ = Mustache.to_html(IriSP.tooltipWidget_template);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5489
  // position the widget absolutely relative to document. --- NOOOO !!!!
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5490
  this.selector.css({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5491
      "position": "absolute",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5492
      "top": 0,
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5493
      "left": 0
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5494
  });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5495
  this.selector.parent().css({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5496
      "position": "relative"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5497
  });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5498
  this.selector.append(templ);
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5499
  var _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5500
  this.selector.mouseover(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5501
      _this.hide();
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5502
  });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5503
  this.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5504
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5505
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5506
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5507
IriSP.TooltipWidget.prototype.clear = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5508
	this.selector.find(".tiptext").html("");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5509
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5510
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5511
IriSP.TooltipWidget.prototype.show = function(text, color, x, y) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5512
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5513
  if (this._displayedText == text && this._shown)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5514
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5515
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5516
  this.selector.find(".tipcolor").css("background-color", color);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5517
  this._displayedText = text;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5518
  this.selector.find(".tiptext").html(text);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5519
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5520
  var _tip = this.selector.find(".tip");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5521
  _tip.show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5522
  _tip.css({
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5523
      "left": Math.floor(x - _tip.outerWidth() / 2)+"px",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5524
      "top": Math.floor(y - _tip.outerHeight())+"px"
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5525
  });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5526
  this._shown = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5527
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5528
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5529
IriSP.TooltipWidget.prototype.hide = function() {                                                   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5530
  this.selector.find(".tip").hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5531
  this._shown = false;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5532
};IriSP.TraceWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5533
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5534
  this.lastEvent = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5535
  var _this = this,
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5536
    _listeners = {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5537
        "IriSP.createAnnotationWidget.addedAnnotation" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5538
        "IriSP.search.open" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5539
        "IriSP.search.closed" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5540
        "IriSP.search" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5541
        "IriSP.search.cleared" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5542
        "IriSP.search.matchFound" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5543
        "IriSP.search.noMatchFound" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5544
        "IriSP.search.triggeredSearch" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5545
        "IriSP.TraceWidget.MouseEvents" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5546
        "play" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5547
        "pause" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5548
        "volumechange" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5549
        "seeked" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5550
        "play" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5551
        "pause" : 0,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5552
        "timeupdate" : 2000
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5553
    };
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5554
    IriSP._(_listeners).each(function(_ms, _listener) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5555
        var _f = function(_arg) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5556
            _this.eventHandler(_listener, _arg);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5557
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5558
        if (_ms) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5559
            _f = IriSP.underscore.throttle(_f, _ms);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5560
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5561
        _this._Popcorn.listen(_listener, _f);
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5562
    });
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5563
    this._Popcorn.listen("timeupdate", IriSP.underscore.throttle(function(_arg) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5564
        _this.eventHandler(_listener, _arg);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5565
    }));
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5566
    
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5567
    this.tracer = IriSP.TraceManager(IriSP.jQuery).init_trace("test", this._config);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5568
    this.tracer.set_default_subject("default_subject");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5569
    this.tracer.trace("StartTracing", { "hello": "world" });
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5570
    
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5571
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5572
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5573
IriSP.TraceWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5574
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5575
IriSP.TraceWidget.prototype.draw = function() {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5576
    this.mouseLocation = '';
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5577
    var _this = this;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5578
    IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5579
        var _widget = IriSP.jQuery(this).attr("widget-type"),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5580
            _class = _e.target.className;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5581
        var _data = {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5582
            "type": _e.type,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5583
            "x": _e.clientX,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5584
            "y": _e.clientY,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5585
            "widget": _widget
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5586
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5587
        if (typeof _class == "string" && _class.indexOf('Ldt-TraceMe') != -1) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5588
            var _name = _e.target.localName,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5589
                _id = _e.target.id,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5590
                _text = _e.target.textContent.trim(),
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5591
                _title = _e.target.title,
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5592
                _value = _e.target.value;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5593
            _data.target = _name + (_id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : '');
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5594
            if (typeof _title == "string" && _title.length && _title.length < 140) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5595
                _data.title = _title;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5596
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5597
            if (typeof _text == "string" && _text.length && _text.length < 140) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5598
                _data.text = _text;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5599
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5600
            if (typeof _value == "string" && _value.length) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5601
                _data.value = _value;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5602
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5603
            _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5604
        } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5605
            //console.log(_e.type+','+_this.mouseLocation+','+_widget);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5606
            if (_e.type == "mouseover") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5607
                if (_this.mouseLocation != _widget) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5608
                    _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5609
                } else {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5610
                    if (typeof _this.moTimeout != "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5611
                        clearTimeout(_this.moTimeout);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5612
                        delete _this.moTimeout;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5613
                    }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5614
                }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5615
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5616
            if (_e.type == "click") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5617
                _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5618
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5619
            if (_e.type == "mouseout") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5620
                if (typeof _this.moTimeout != "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5621
                    clearTimeout(_this.moTimeout);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5622
                }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5623
                _this.moTimeout = setTimeout(function() {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5624
                   if (_data.widget != _this.mouseLocation) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5625
                       _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5626
                   }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5627
                },100);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5628
            }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5629
        }
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5630
        _this.mouseLocation = _widget;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5631
    });
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5632
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5633
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5634
IriSP.TraceWidget.prototype.eventHandler = function(_listener, _arg) {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5635
    var _traceName = 'Mdp_';
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5636
    if (typeof _arg == "string" || typeof _arg == "number") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5637
        _arg = { "value" : _arg }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5638
    }
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5639
    if (typeof _arg == "undefined") {
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5640
        _arg = {}
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5641
    }
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5642
    switch(_listener) {
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5643
        case 'IriSP.TraceWidget.MouseEvents':
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5644
            _traceName += _arg.widget + '_' + _arg.type;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5645
            delete _arg.widget;
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5646
            delete _arg.type;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5647
        break;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5648
        case 'timeupdate':
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5649
        case 'play':
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5650
        case 'pause':
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5651
            _arg.time = this._Popcorn.currentTime() * 1000;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5652
        case 'seeked':
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5653
        case 'volumechange':
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5654
            _traceName += 'Popcorn_' + _listener;
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5655
        break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5656
        default:
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5657
            _traceName += _listener.replace('IriSP.','').replace('.','_');
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5658
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5659
    this.lastEvent = _traceName;
573
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5660
    this.tracer.trace(_traceName, _arg);
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5661
    console.log("trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
6ec62b3610c8 Update metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 535
diff changeset
  5662
    
534
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5663
}
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5664
/* a widget that displays tweet - used in conjunction with the polemicWidget */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5665
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5666
IriSP.TweetsWidget = function(Popcorn, config, Serializer) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5667
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5668
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5669
  this._displayingTweet = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5670
  this._timeoutId = undefined; 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5671
  this._hidden = false; /* hidden means that the createAnnotationWidget is shown */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5672
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5673
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5674
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5675
IriSP.TweetsWidget.prototype = new IriSP.Widget();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5676
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5677
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5678
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5679
    if (this._hidden)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5680
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5681
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5682
    var title = IriSP.formatTweet(annotation.content.title);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5683
    var img = annotation.content.img.src;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5684
    if (typeof(img) === "undefined" || img === "" || img === "None") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5685
      img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5686
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5687
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5688
    var imageMarkup = IriSP.templToHTML("<img src='{{src}}' alt='user image'></img>", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5689
                                       {src : img});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5690
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5691
    if (typeof(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content) !== "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5692
      var tweetContents = JSON.parse(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5693
      var creator = tweetContents.user.screen_name;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5694
      var real_name = tweetContents.user.name;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5695
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5696
      imageMarkup = IriSP.templToHTML("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5697
                                       {src : img, creator: creator});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5698
            
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5699
      var formatted_date = new Date(tweetContents.created_at).toLocaleDateString();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5700
      title = IriSP.templToHTML("<a class='Ldt-tweet_userHandle' href='http://twitter.com/{{creator}}'>@{{creator}}</a> - " + 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5701
                                "<div class='Ldt-tweet_realName'>{{real_name}}</div>" +
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5702
                                "<div class='Ldt-tweet_tweetContents'>{{{ contents }}}</div>" +
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5703
                                "<div class='Ldt-tweet_date'>{{ date }}</div>", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5704
                                {creator: creator, real_name: real_name, contents : title, date : formatted_date});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5705
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5706
      this.selector.find(".Ldt-TweetReply").attr("href", "http://twitter.com/home?status=@" + creator + ":%20");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5707
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5708
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5709
      var rtText = Mustache.to_html("http://twitter.com/home?status=RT @{{creator}}: {{text}}",
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5710
                                    {creator: creator, text: IriSP.encodeURI(annotation.content.title)});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5711
      this.selector.find(".Ldt-Retweet").attr("href", rtText);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5712
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5713
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5714
    this.selector.find(".Ldt-tweetContents").html(title);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5715
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5716
    this.selector.show("blind", 250); 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5717
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5718
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5719
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5720
  if (this._displayingTweet === false) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5721
    this._displayingTweet = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5722
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5723
    window.clearTimeout(this._timeoutId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5724
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5725
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5726
  this.drawTweet(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5727
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5728
  var time = this._Popcorn.currentTime();  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5729
  this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5730
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5731
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5732
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5733
IriSP.TweetsWidget.prototype.clearPanel = function() {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5734
    this._displayingTweet = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5735
    this._timeoutId = undefined;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5736
    this.closePanel();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5737
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5738
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5739
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5740
IriSP.TweetsWidget.prototype.closePanel = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5741
    if (this._timeoutId != undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5742
      /* we're called from the "close window" link */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5743
      /* cancel the timeout */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5744
      window.clearTimeout(this._timeoutId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5745
      this._timeoutId = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5746
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5747
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5748
    this.selector.hide("blind", 400);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5749
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5750
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5751
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5752
/* cancel the timeout if the user clicks on the keep panel open button */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5753
IriSP.TweetsWidget.prototype.keepPanel = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5754
    if (this._timeoutId != undefined) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5755
      /* we're called from the "close window" link */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5756
      /* cancel the timeout */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5757
      window.clearTimeout(this._timeoutId);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5758
      this._timeoutId = null;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5759
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5760
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5761
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5762
IriSP.TweetsWidget.prototype.draw = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5763
  var _this = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5764
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5765
  var tweetMarkup = IriSP.templToHTML(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template});
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5766
  this.selector.append(tweetMarkup);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5767
  this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5768
  this.selector.find(".Ldt-tweetWidgetMinimize").click(IriSP.wrap(this, this.closePanel));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5769
  this.selector.find(".Ldt-tweetWidgetKeepOpen").click(IriSP.wrap(this, this.keepPanel));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5770
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5771
  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5772
  this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5773
                        IriSP.wrap(this, this.handleAnnotateSignal));  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5774
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5775
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5776
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5777
  var index, annotation;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5778
  for (index in this._serializer._data.annotations) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5779
    annotation = this._serializer._data.annotations[index];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5780
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5781
    if (annotation.id === tweet_id)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5782
      break;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5783
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5784
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5785
  if (annotation.id !== tweet_id)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5786
      /* we haven't found it */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5787
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5788
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5789
  this.displayTweet(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5790
  return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5791
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5792
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5793
/** handle clicks on the annotate button by hiding/showing itself */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5794
IriSP.TweetsWidget.prototype.handleAnnotateSignal = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5795
  if (this._hidden == false) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5796
    this.selector.hide();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5797
    this._hidden = true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5798
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5799
    if (this._displayingTweet !== false)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5800
      this.selector.show();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5801
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5802
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5803
    this._hidden = false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5804
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5805
};/** @class This class implement a serializer for the JSON-Cinelab format
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5806
    @params DataLoader a dataloader reference
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5807
    @url the url from which to get our cinelab
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5808
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5809
IriSP.JSONSerializer = function(DataLoader, url) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5810
  IriSP.Serializer.call(this, DataLoader, url);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5811
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5812
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5813
IriSP.JSONSerializer.prototype = new IriSP.Serializer();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5814
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5815
/** serialize data */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5816
IriSP.JSONSerializer.prototype.serialize = function(data) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5817
  return JSON.stringify(data);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5818
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5819
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5820
/** deserialize data */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5821
IriSP.JSONSerializer.prototype.deserialize = function(data) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5822
  return JSON.parse(data);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5823
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5824
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5825
/** load JSON-cinelab data and also sort the annotations by start time
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5826
    @param callback function to call when the data is ready.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5827
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5828
IriSP.JSONSerializer.prototype.sync = function(callback) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5829
  /* we don't have to do much because jQuery handles json for us */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5830
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5831
  var self = this;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5832
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5833
  var fn = function(data) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5834
	  //TODO: seems taht data can be null here
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5835
	  if (data !== null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5836
		  self._data = data;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5837
	      if (typeof(self._data["annotations"]) === "undefined" ||
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5838
	          self._data["annotations"] === null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5839
	          self._data["annotations"] = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5840
	      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5841
	      // sort the data too       
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5842
	      self._data["annotations"].sort(function(a, b) 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5843
	          { var a_begin = +a.begin;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5844
	            var b_begin = +b.begin;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5845
	            return a_begin - b_begin;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5846
	          });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5847
	  }     
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5848
      callback(data);      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5849
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5850
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5851
  this._DataLoader.get(this._url, fn);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5852
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5853
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5854
/** @return the metadata about the media being read FIXME: always return the first media. */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5855
IriSP.JSONSerializer.prototype.currentMedia = function() {  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5856
  return this._data.medias[0]; /* FIXME: don't hardcode it */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5857
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5858
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5859
/** searches for an annotation which matches title, description and keyword 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5860
   "" matches any field. 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5861
   Note: it ignores tweets.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5862
   @return a list of matching ids.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5863
*/    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5864
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5865
    /* we can have many types of annotations. We want search to only look for regular segments */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5866
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5867
       null or undefined.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5868
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5869
    var view;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5870
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5871
    if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5872
       view = this._data.views[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5873
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5874
    var searchViewType = "";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5875
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5876
    if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5877
            searchViewType = view.annotation_types[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5878
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5879
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5880
    var filterfn = function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5881
      if( searchViewType  != "" && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5882
          typeof(annotation.meta) !== "undefined" && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5883
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5884
          annotation.meta["id-ref"] !== searchViewType) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5885
        return true; // don't pass
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5886
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5887
          return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5888
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5889
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5890
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5891
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5892
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5893
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5894
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5895
/* only look for tweets */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5896
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5897
    /* we can have many types of annotations. We want search to only look for regular segments */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5898
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5899
       null or undefined.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5900
    */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5901
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5902
    var searchViewType = this.getTweets();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5903
    if (typeof(searchViewType) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5904
      var view;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5905
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5906
      if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5907
         view = this._data.views[0];    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5908
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5909
      if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5910
              searchViewType = view.annotation_types[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5911
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5912
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5913
    var filterfn = function(annotation) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5914
      if( searchViewType  != "" && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5915
          typeof(annotation.meta) !== "undefined" && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5916
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5917
          annotation.meta["id-ref"] === searchViewType) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5918
        return false; // pass
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5919
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5920
          return true;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5921
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5922
    };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5923
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5924
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5925
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5926
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5927
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5928
/**
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5929
  search an annotation according to its title, description and keyword
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5930
  @param filter a function to filter the results with. Used to select between annotation types.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5931
 */    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5932
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5933
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5934
    var rTitle;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5935
    var rDescription;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5936
    var rKeyword;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5937
    /* match anything if given the empty string */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5938
    if (title == "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5939
      title = ".*";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5940
    if (description == "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5941
      description = ".*";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5942
    if (keyword == "")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5943
      keyword = ".*";
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5944
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5945
    rTitle = new RegExp(title, "i");  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5946
    rDescription = new RegExp(description, "i");  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5947
    rKeyword = new RegExp(keyword, "i");  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5948
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5949
    var ret_array = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5950
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5951
    var i;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5952
    for (i in this._data.annotations) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5953
      var annotation = this._data.annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5954
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5955
      /* filter the annotations whose type is not the one we want */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5956
      if (filter(annotation)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5957
          continue;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5958
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5959
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5960
      if (rTitle.test(annotation.content.title) && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5961
          rDescription.test(annotation.content.description)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5962
          /* FIXME : implement keyword support */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5963
          ret_array.push(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5964
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5965
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5966
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5967
    return ret_array;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5968
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5969
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5970
/** breaks a string in words and searches each of these words. Returns an array
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5971
   of objects with the id of the annotation and its number of occurences.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5972
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5973
   @param searchString a string of words.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5974
   FIXME: optimize ? seems to be n^2 in the worst case.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5975
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5976
IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5977
  var ret = { };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5978
  var keywords = searchString.split(/\s+/);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5979
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5980
  for (var i in keywords) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5981
    var keyword = keywords[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5982
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5983
    // search this keyword in descriptions and title
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5984
    var found_annotations = []
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5985
    found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", ""));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5986
    found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, ""));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5987
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5988
    for (var j in found_annotations) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5989
      var current_annotation = found_annotations[j];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5990
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5991
      if (!ret.hasOwnProperty(current_annotation.id)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5992
        ret[current_annotation.id] = 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5993
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5994
        ret[current_annotation.id] += 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5995
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5996
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5997
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5998
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  5999
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6000
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6001
  return ret;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6002
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6003
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6004
/** breaks a string in words and searches each of these words. Returns an array
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6005
   of objects with the id of the annotation and its number of occurences.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6006
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6007
   FIXME: optimize ? seems to be n^2 in the worst case.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6008
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6009
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6010
  var ret = { };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6011
  var keywords = searchString.split(/\s+/);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6012
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6013
  for (var i in keywords) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6014
    var keyword = keywords[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6015
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6016
    // search this keyword in descriptions and title
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6017
    var found_annotations = []
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6018
    found_annotations = found_annotations.concat(this.searchTweets(keyword, "", ""));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6019
    found_annotations = found_annotations.concat(this.searchTweets("", keyword, ""));
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6020
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6021
    for (var j in found_annotations) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6022
      var current_annotation = found_annotations[j];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6023
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6024
      if (!ret.hasOwnProperty(current_annotation.id)) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6025
        ret[current_annotation.id] = 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6026
      } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6027
        ret[current_annotation.id] += 1;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6028
      }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6029
      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6030
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6031
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6032
  };
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6033
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6034
  return ret;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6035
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6036
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6037
/** returns all the annotations that are displayable at the moment 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6038
   NB: only takes account the first type of annotations - ignores tweets 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6039
   currentTime is in seconds.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6040
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6041
   @param currentTime the time at which we search.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6042
   @param (optional) the if of the type of the annotations we want to get.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6043
 */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6044
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6045
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime, id) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6046
  var view;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6047
  var currentTimeMs = 1000 * currentTime;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6048
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6049
  if (typeof(id) === "undefined") {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6050
      var legal_ids = this.getNonTweetIds();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6051
  } else {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6052
      legal_ids = [id];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6053
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6054
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6055
  var ret_array = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6056
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6057
  var i;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6058
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6059
  for (i in this._data.annotations) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6060
    var annotation = this._data.annotations[i];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6061
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6062
    if (IriSP.underscore.include(legal_ids, annotation.meta["id-ref"]) && 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6063
        annotation.begin <= currentTimeMs &&
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6064
        annotation.end >= currentTimeMs)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6065
          ret_array.push(annotation);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6066
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6067
 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6068
  if (ret_array == []) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6069
    console.log("ret_array empty, ", legal_ids);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6070
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6071
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6072
  return ret_array;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6073
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6074
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6075
/** return the current chapitre
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6076
    @param currentTime the current time, in seconds.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6077
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6078
IriSP.JSONSerializer.prototype.currentChapitre = function(currentTime) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6079
  return this.currentAnnotations(currentTime, this.getChapitrage())[0];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6080
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6081
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6082
/** returns a list of ids of tweet lines (aka: groups in cinelab) */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6083
IriSP.JSONSerializer.prototype.getTweetIds = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6084
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6085
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6086
    return [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6087
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6088
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6089
  /* Get the displayable types
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6090
     We've got to jump through a few hoops because the json sometimes defines
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6091
     fields with underscores and sometimes with dashes
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6092
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6093
  var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6094
  if (annotation_types === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6095
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6096
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6097
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6098
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6099
  var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6100
  if (available_types === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6101
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6102
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6103
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6104
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6105
  var potential_types = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6106
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6107
  // Get the list of types which contain "Tw" in their content
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6108
  for (var i = 0; i < available_types.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6109
    if (/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title']))) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6110
      potential_types.push(available_types[i].id);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6111
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6112
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6113
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6114
  // Get the intersection of both.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6115
  var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6116
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6117
  return tweetsId;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6118
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6119
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6120
/** this function returns a list of lines which are not tweet lines */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6121
IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6122
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6123
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6124
    return [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6125
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6126
  /* Get the displayable types
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6127
     We've got to jump through a few hoops because the json sometimes defines
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6128
     fields with underscores and sometimes with dashes
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6129
  */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6130
  var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6131
  if (annotation_types === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6132
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6133
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6134
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6135
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6136
  var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6137
  if (available_types === null) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6138
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6139
      return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6140
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6141
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6142
  var potential_types = [];
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6143
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6144
  // Get the list of types which do not contain "Tw" in their content
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6145
  for (var i = 0; i < available_types.length; i++) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6146
    if (!(/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title'])))) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6147
      potential_types.push(available_types[i].id);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6148
    }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6149
  }
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6150
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6151
  // Get the intersection of both.
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6152
  var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6153
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6154
  return nonTweetsId;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6155
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6156
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6157
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6158
/** return the id of the ligne de temps which contains name
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6159
    @param name of the ligne de temps
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6160
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6161
IriSP.JSONSerializer.prototype.getId = function(name) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6162
   var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6163
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6164
  if (available_types == null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6165
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6166
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6167
  name = name.toUpperCase();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6168
  var e;  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6169
  e = IriSP.underscore.find(available_types, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6170
    function(entry) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6171
        if (IriSP.get_aliased(entry, ['dc:title', 'title']) === null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6172
          return false;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6173
        return (entry["dc:title"].toUpperCase().indexOf(name) !== -1);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6174
    });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6175
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6176
  if (typeof(e) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6177
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6178
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6179
  var id = e.id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6180
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6181
  return id;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6182
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6183
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6184
/** return the list of id's of the ligne de temps which contains name
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6185
    @param name of the ligne de temps
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6186
*/
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6187
IriSP.JSONSerializer.prototype.getIds = function(name) {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6188
   var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6189
   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6190
  if (available_types == null)
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6191
    return;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6192
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6193
  name = name.toUpperCase();
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6194
  var e = [];  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6195
  e = IriSP.underscore.filter(available_types, 
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6196
                                  function(entry) { return (IriSP.get_aliased(entry, ['dc:title', 'title']).toUpperCase().indexOf(name) !== -1) });
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6197
  return IriSP.underscore.pluck(e, "id");  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6198
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6199
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6200
/** return the id of the ligne de temps named "Chapitrage" */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6201
IriSP.JSONSerializer.prototype.getChapitrage = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6202
  var val = this.getId("Chapitrage");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6203
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6204
    val = this.getId("Chapter");   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6205
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6206
    val = this.getId("Chapit");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6207
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6208
    val = this.getId("Chap");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6209
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6210
  return val;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6211
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6212
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6213
/** return the id of the ligne de temps named "Tweets" */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6214
IriSP.JSONSerializer.prototype.getTweets = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6215
  var val = this.getId("Tweets");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6216
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6217
    val = this.getId("Tweet");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6218
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6219
    val = this.getId("Twitter");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6220
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6221
    val = this.getId("twit");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6222
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6223
    val = this.getId("Polemic");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6224
  
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6225
  return val;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6226
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6227
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6228
/** return the id of the ligne de temps named "Contributions" */
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6229
IriSP.JSONSerializer.prototype.getContributions = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6230
  var val = this.getId("Contribution");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6231
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6232
    val = this.getId("Particip");   
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6233
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6234
    val = this.getId("Contr");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6235
  if (typeof(val) === "undefined")
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6236
    val = this.getId("Publ");
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6237
    
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6238
  return val;
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6239
};
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6240
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6241
IriSP.JSONSerializer.prototype.getDuration = function() {
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6242
    return +(IriSP.get_aliased(this.currentMedia().meta, ["dc:duration", "duration"]) || 0);
0a2505c3b547 New metadata player and big directory reorganization
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
  6243
}