test/integration/allocine_dossier_independant/js/LdtPlayer-release.js
author veltr
Mon, 26 Mar 2012 19:18:04 +0200
branchpopcorn-port
changeset 838 03b03865eb9b
parent 837 353a78021ebc
child 841 8da49ff273e0
permissions -rw-r--r--
Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     1
/* 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     2
 * 	
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     3
 *	Copyright 2010-2012 Institut de recherche et d'innovation 
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
     4
 *	contributor(s) : Karim Hamidou, Samuel Huron, Raphael Velt, Thibaut Cavalie
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     5
 *	 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     6
 *	contact@iri.centrepompidou.fr
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     7
 *	http://www.iri.centrepompidou.fr 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     8
 *	 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     9
 *	This software is a computer program whose purpose is to show and add annotations on a video .
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    10
 *	This software is governed by the CeCILL-C license under French law and
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    11
 *	abiding by the rules of distribution of free software. You can  use, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    12
 *	modify and/ or redistribute the software under the terms of the CeCILL-C
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    13
 *	license as circulated by CEA, CNRS and INRIA at the following URL
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    14
 *	"http://www.cecill.info". 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    15
 *	
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    16
 *	The fact that you are presently reading this means that you have had
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    17
 *	knowledge of the CeCILL-C license and that you accept its terms.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    18
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    19
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    20
    v2.0.3 (c) Kyle Simpson
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    21
    MIT License
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    22
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    23
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    24
(function(global){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    25
	var _$LAB = global.$LAB,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    26
	
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    27
		// constants for the valid keys of the options object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    28
		_UseLocalXHR = "UseLocalXHR",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    29
		_AlwaysPreserveOrder = "AlwaysPreserveOrder",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    30
		_AllowDuplicates = "AllowDuplicates",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    31
		_CacheBust = "CacheBust",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    32
		/*!START_DEBUG*/_Debug = "Debug",/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    33
		_BasePath = "BasePath",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    34
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    35
		// stateless variables used across all $LAB instances
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    36
		root_page = /^[^?#]*\//.exec(location.href)[0],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    37
		root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    38
		append_to = document.head || document.getElementsByTagName("head"),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    39
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    40
		// inferences... ick, but still necessary
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    41
		opera_or_gecko = (global.opera && Object.prototype.toString.call(global.opera) == "[object Opera]") || ("MozAppearance" in document.documentElement.style),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    42
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    43
/*!START_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    44
		// console.log() and console.error() wrappers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    45
		log_msg = function(){}, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    46
		log_error = log_msg,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    47
/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    48
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    49
		// feature sniffs (yay!)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    50
		test_script_elem = document.createElement("script"),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    53
		script_ordered_async = !real_preloading && test_script_elem.async === true, // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    54
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    55
		// XHR preloading (same-domain) and cache-preloading (remote-domain) are the fallbacks (for some browsers)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    56
		xhr_or_cache_preloading = !real_preloading && !script_ordered_async && !opera_or_gecko
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    57
	;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    58
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    59
/*!START_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    60
	// define console wrapper functions if applicable
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    61
	if (global.console && global.console.log) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    62
		if (!global.console.error) global.console.error = global.console.log;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    63
		log_msg = function(msg) { global.console.log(msg); };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    64
		log_error = function(msg,err) { global.console.error(msg,err); };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    65
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    66
/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    67
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    68
	// test for function
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    69
	function is_func(func) { return Object.prototype.toString.call(func) == "[object Function]"; }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    70
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    71
	// test for array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    72
	function is_array(arr) { return Object.prototype.toString.call(arr) == "[object Array]"; }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    73
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    74
	// make script URL absolute/canonical
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    75
	function canonical_uri(src,base_path) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    76
		var absolute_regex = /^\w+\:\/\//;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    77
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    78
		// is `src` is protocol-relative (begins with // or ///), prepend protocol
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    79
		if (/^\/\/\/?/.test(src)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    80
			src = location.protocol + src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    81
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    82
		// is `src` page-relative? (not an absolute URL, and not a domain-relative path, beginning with /)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    83
		else if (!absolute_regex.test(src) && src.charAt(0) != "/") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    84
			// prepend `base_path`, if any
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    85
			src = (base_path || "") + src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    86
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    87
		// make sure to return `src` as absolute
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    88
		return absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    89
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    90
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    91
	// merge `source` into `target`
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    92
	function merge_objs(source,target) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    93
		for (var k in source) { if (source.hasOwnProperty(k)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    94
			target[k] = source[k]; // TODO: does this need to be recursive for our purposes?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    95
		}}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    96
		return target;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    97
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    98
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    99
	// does the chain group have any ready-to-execute scripts?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   100
	function check_chain_group_scripts_ready(chain_group) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   101
		var any_scripts_ready = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   102
		for (var i=0; i<chain_group.scripts.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   103
			if (chain_group.scripts[i].ready && chain_group.scripts[i].exec_trigger) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   104
				any_scripts_ready = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   105
				chain_group.scripts[i].exec_trigger();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   106
				chain_group.scripts[i].exec_trigger = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   107
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   108
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   109
		return any_scripts_ready;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   110
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   111
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   112
	// creates a script load listener
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   113
	function create_script_load_listener(elem,registry_item,flag,onload) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   114
		elem.onload = elem.onreadystatechange = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   115
			if ((elem.readyState && elem.readyState != "complete" && elem.readyState != "loaded") || registry_item[flag]) return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   116
			elem.onload = elem.onreadystatechange = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   117
			onload();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   118
		};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   119
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   120
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   121
	// script executed handler
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   122
	function script_executed(registry_item) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   123
		registry_item.ready = registry_item.finished = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   124
		for (var i=0; i<registry_item.finished_listeners.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   125
			registry_item.finished_listeners[i]();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   126
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   127
		registry_item.ready_listeners = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   128
		registry_item.finished_listeners = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   129
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   130
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   131
	// make the request for a scriptha
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   132
	function request_script(chain_opts,script_obj,registry_item,onload,preload_this_script) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   133
		// setTimeout() "yielding" prevents some weird race/crash conditions in older browsers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   134
		setTimeout(function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   135
			var script, src = script_obj.real_src, xhr;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   136
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   137
			// don't proceed until `append_to` is ready to append to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   138
			if ("item" in append_to) { // check if `append_to` ref is still a live node list
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   139
				if (!append_to[0]) { // `append_to` node not yet ready
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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()`
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   141
					setTimeout(arguments.callee,25);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   142
					return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   143
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   145
				append_to = append_to[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   146
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   147
			script = document.createElement("script");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   148
			if (script_obj.type) script.type = script_obj.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   149
			if (script_obj.charset) script.charset = script_obj.charset;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   150
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   151
			// should preloading be used for this script?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   152
			if (preload_this_script) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   153
				// real script preloading?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   154
				if (real_preloading) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   155
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload: "+src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   156
					registry_item.elem = script;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   157
					if (explicit_preloading) { // explicit preloading (aka, Zakas' proposal)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   158
						script.preload = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   159
						script.onpreload = onload;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   160
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   161
					else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   162
						script.onreadystatechange = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   163
							if (script.readyState == "loaded") onload();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   164
						};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   165
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   166
					script.src = src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   167
					// NOTE: no append to DOM yet, appending will happen when ready to execute
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   168
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   169
				// same-domain and XHR allowed? use XHR preloading
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   170
				else if (preload_this_script && src.indexOf(root_domain) == 0 && chain_opts[_UseLocalXHR]) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   172
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload (xhr): "+src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   173
					xhr.onreadystatechange = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   174
						if (xhr.readyState == 4) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   175
							xhr.onreadystatechange = function(){}; // fix a memory leak in IE
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   177
							onload();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   178
						}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   179
					};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   180
					xhr.open("GET",src);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   181
					xhr.send();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   182
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   183
				// as a last resort, use cache-preloading
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   184
				else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   185
					/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script preload (cache): "+src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   186
					script.type = "text/cache-script";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   187
					create_script_load_listener(script,registry_item,"ready",function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   188
						append_to.removeChild(script);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   189
						onload();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   190
					});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   191
					script.src = src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   192
					append_to.insertBefore(script,append_to.firstChild);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   193
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   194
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   195
			// use async=false for ordered async? parallel-load-serial-execute http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   196
			else if (script_ordered_async) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   197
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script load (ordered async): "+src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   198
				script.async = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   199
				create_script_load_listener(script,registry_item,"finished",onload);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   200
				script.src = src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   201
				append_to.insertBefore(script,append_to.firstChild);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   202
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   203
			// otherwise, just a normal script element
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   204
			else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   205
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("start script load: "+src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   206
				create_script_load_listener(script,registry_item,"finished",onload);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   207
				script.src = src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   208
				append_to.insertBefore(script,append_to.firstChild);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   209
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   210
		},0);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   211
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   212
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   213
	// create a clean instance of $LAB
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   214
	function create_sandbox() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   215
		var global_defaults = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   216
			can_use_preloading = real_preloading || xhr_or_cache_preloading,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   217
			queue = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   218
			registry = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   219
			instanceAPI
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   220
		;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   221
		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   222
		// global defaults
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   223
		global_defaults[_UseLocalXHR] = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   224
		global_defaults[_AlwaysPreserveOrder] = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   225
		global_defaults[_AllowDuplicates] = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   226
		global_defaults[_CacheBust] = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   227
		/*!START_DEBUG*/global_defaults[_Debug] = false;/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   228
		global_defaults[_BasePath] = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   229
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   230
		// execute a script that has been preloaded already
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   231
		function execute_preloaded_script(chain_opts,script_obj,registry_item) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   232
			var script;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   233
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   234
			function preload_execute_finished() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   235
				if (script != null) { // make sure this only ever fires once
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   236
					script = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   237
					script_executed(registry_item);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   238
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   239
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   240
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   241
			if (registry[script_obj.src].finished) return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   242
			if (!chain_opts[_AllowDuplicates]) registry[script_obj.src].finished = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   243
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   244
			script = registry_item.elem || document.createElement("script");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   245
			if (script_obj.type) script.type = script_obj.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   246
			if (script_obj.charset) script.charset = script_obj.charset;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   247
			create_script_load_listener(script,registry_item,"finished",preload_execute_finished);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   248
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   249
			// script elem was real-preloaded
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   250
			if (registry_item.elem) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   251
				registry_item.elem = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   252
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   253
			// script was XHR preloaded
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   254
			else if (registry_item.text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   255
				script.onload = script.onreadystatechange = null;	// script injection doesn't fire these events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   256
				script.text = registry_item.text;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   257
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   258
			// script was cache-preloaded
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   259
			else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   260
				script.src = script_obj.real_src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   261
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   262
			append_to.insertBefore(script,append_to.firstChild);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   263
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   264
			// manually fire execution callback for injected scripts, since events don't fire
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   265
			if (registry_item.text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   266
				preload_execute_finished();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   267
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   268
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   269
	
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   270
		// process the script request setup
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   271
		function do_script(chain_opts,script_obj,chain_group,preload_this_script) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   272
			var registry_item,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   273
				registry_items,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   274
				ready_cb = function(){ script_obj.ready_cb(script_obj,function(){ execute_preloaded_script(chain_opts,script_obj,registry_item); }); },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   275
				finished_cb = function(){ script_obj.finished_cb(script_obj,chain_group); }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   276
			;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   277
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   278
			script_obj.src = canonical_uri(script_obj.src,chain_opts[_BasePath]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   279
			script_obj.real_src = script_obj.src + 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   280
				// append cache-bust param to URL?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   281
				(chain_opts[_CacheBust] ? ((/\?.*$/.test(script_obj.src) ? "&_" : "?_") + ~~(Math.random()*1E9) + "=") : "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   282
			;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   283
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   284
			if (!registry[script_obj.src]) registry[script_obj.src] = {items:[],finished:false};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   285
			registry_items = registry[script_obj.src].items;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   286
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   287
			// allowing duplicates, or is this the first recorded load of this script?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   288
			if (chain_opts[_AllowDuplicates] || registry_items.length == 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   289
				registry_item = registry_items[registry_items.length] = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   290
					ready:false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   291
					finished:false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   292
					ready_listeners:[ready_cb],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   293
					finished_listeners:[finished_cb]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   294
				};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   295
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   296
				request_script(chain_opts,script_obj,registry_item,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   297
					// which callback type to pass?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   298
					(
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   299
					 	(preload_this_script) ? // depends on script-preloading
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   300
						function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   301
							registry_item.ready = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   302
							for (var i=0; i<registry_item.ready_listeners.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   303
								registry_item.ready_listeners[i]();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   304
							}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   305
							registry_item.ready_listeners = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   306
						} :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   307
						function(){ script_executed(registry_item); }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   308
					),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   309
					// signal if script-preloading should be used or not
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   310
					preload_this_script
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   311
				);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   312
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   313
			else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   314
				registry_item = registry_items[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   315
				if (registry_item.finished) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   316
					finished_cb();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   317
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   318
				else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   319
					registry_item.finished_listeners.push(finished_cb);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   320
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   321
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   322
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   323
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   324
		// creates a closure for each separate chain spawned from this $LAB instance, to keep state cleanly separated between chains
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   325
		function create_chain() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   326
			var chainedAPI,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   327
				chain_opts = merge_objs(global_defaults,{}),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   328
				chain = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   329
				exec_cursor = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   330
				scripts_currently_loading = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   331
				group
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   332
			;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   333
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   334
			// called when a script has finished preloading
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   335
			function chain_script_ready(script_obj,exec_trigger) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   336
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("script preload finished: "+script_obj.real_src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   337
				script_obj.ready = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   338
				script_obj.exec_trigger = exec_trigger;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   339
				advance_exec_cursor(); // will only check for 'ready' scripts to be executed
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   340
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   341
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   342
			// called when a script has finished executing
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   343
			function chain_script_executed(script_obj,chain_group) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   344
				/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("script execution finished: "+script_obj.real_src);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   345
				script_obj.ready = script_obj.finished = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   346
				script_obj.exec_trigger = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   347
				// check if chain group is all finished
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   348
				for (var i=0; i<chain_group.scripts.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   349
					if (!chain_group.scripts[i].finished) return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   350
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   351
				// chain_group is all finished if we get this far
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   352
				chain_group.finished = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   353
				advance_exec_cursor();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   354
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   355
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   356
			// main driver for executing each part of the chain
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   357
			function advance_exec_cursor() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   358
				while (exec_cursor < chain.length) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   359
					if (is_func(chain[exec_cursor])) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   360
						/*!START_DEBUG*/if (chain_opts[_Debug]) log_msg("$LAB.wait() executing: "+chain[exec_cursor]);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   361
						try { chain[exec_cursor++](); } catch (err) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   362
							/*!START_DEBUG*/if (chain_opts[_Debug]) log_error("$LAB.wait() error caught: ",err);/*!END_DEBUG*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   363
						}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   364
						continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   365
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   366
					else if (!chain[exec_cursor].finished) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   367
						if (check_chain_group_scripts_ready(chain[exec_cursor])) continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   368
						break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   369
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   370
					exec_cursor++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   371
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   372
				// we've reached the end of the chain (so far)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   373
				if (exec_cursor == chain.length) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   374
					scripts_currently_loading = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   375
					group = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   376
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   377
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   378
			
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   379
			// setup next chain script group
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   380
			function init_script_chain_group() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   381
				if (!group || !group.scripts) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   382
					chain.push(group = {scripts:[],finished:true});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   383
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   384
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   385
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   386
			// API for $LAB chains
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   387
			chainedAPI = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   388
				// start loading one or more scripts
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   389
				script:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   390
					for (var i=0; i<arguments.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   391
						(function(script_obj,script_list){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   392
							var splice_args;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   393
							
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   394
							if (!is_array(script_obj)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   395
								script_list = [script_obj];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   396
							}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   397
							for (var j=0; j<script_list.length; j++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   398
								init_script_chain_group();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   399
								script_obj = script_list[j];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   400
								
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   401
								if (is_func(script_obj)) script_obj = script_obj();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   402
								if (!script_obj) continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   403
								if (is_array(script_obj)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   404
									// set up an array of arguments to pass to splice()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   405
									splice_args = [].slice.call(script_obj); // first include the actual array elements we want to splice in
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   406
									splice_args.unshift(j,1); // next, put the `index` and `howMany` parameters onto the beginning of the splice-arguments array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   407
									[].splice.apply(script_list,splice_args); // use the splice-arguments array as arguments for splice()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   409
									continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   410
								}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   411
								if (typeof script_obj == "string") script_obj = {src:script_obj};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   412
								script_obj = merge_objs(script_obj,{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   413
									ready:false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   414
									ready_cb:chain_script_ready,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   415
									finished:false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   416
									finished_cb:chain_script_executed
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   417
								});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   418
								group.finished = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   419
								group.scripts.push(script_obj);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   420
								
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   421
								do_script(chain_opts,script_obj,group,(can_use_preloading && scripts_currently_loading));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   422
								scripts_currently_loading = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   423
								
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   424
								if (chain_opts[_AlwaysPreserveOrder]) chainedAPI.wait();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   425
							}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   426
						})(arguments[i],arguments[i]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   427
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   428
					return chainedAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   429
				},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   430
				// force LABjs to pause in execution at this point in the chain, until the execution thus far finishes, before proceeding
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   431
				wait:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   432
					if (arguments.length > 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   433
						for (var i=0; i<arguments.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   434
							chain.push(arguments[i]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   435
						}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   436
						group = chain[chain.length-1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   437
					}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   438
					else group = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   439
					
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   440
					advance_exec_cursor();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   441
					
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   442
					return chainedAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   443
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   444
			};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   445
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   446
			// the first chain link API (includes `setOptions` only this first time)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   447
			return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   448
				script:chainedAPI.script, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   449
				wait:chainedAPI.wait, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   450
				setOptions:function(opts){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   451
					merge_objs(opts,chain_opts);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   452
					return chainedAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   453
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   454
			};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   455
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   456
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   457
		// API for each initial $LAB instance (before chaining starts)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   458
		instanceAPI = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   459
			// main API functions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   460
			setGlobalDefaults:function(opts){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   461
				merge_objs(opts,global_defaults);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   462
				return instanceAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   463
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   464
			setOptions:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   465
				return create_chain().setOptions.apply(null,arguments);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   466
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   467
			script:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   468
				return create_chain().script.apply(null,arguments);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   469
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   470
			wait:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   471
				return create_chain().wait.apply(null,arguments);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   472
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   473
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   474
			// built-in queuing for $LAB `script()` and `wait()` calls
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   475
			// useful for building up a chain programmatically across various script locations, and simulating
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   476
			// execution of the chain
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   477
			queueScript:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   478
				queue[queue.length] = {type:"script", args:[].slice.call(arguments)};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   479
				return instanceAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   480
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   481
			queueWait:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   482
				queue[queue.length] = {type:"wait", args:[].slice.call(arguments)};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   483
				return instanceAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   484
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   485
			runQueue:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   486
				var $L = instanceAPI, len=queue.length, i=len, val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   487
				for (;--i>=0;) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   488
					val = queue.shift();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   489
					$L = $L[val.type].apply(null,val.args);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   490
				}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   491
				return $L;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   492
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   493
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   494
			// rollback `[global].$LAB` to what it was before this file was loaded, the return this current instance of $LAB
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   495
			noConflict:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   496
				global.$LAB = _$LAB;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   497
				return instanceAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   498
			},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   499
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   500
			// create another clean instance of $LAB
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   501
			sandbox:function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   502
				return create_sandbox();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   503
			}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   504
		};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   505
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   506
		return instanceAPI;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   507
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   508
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   509
	// create the main instance of $LAB
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   510
	global.$LAB = create_sandbox();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   511
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   512
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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?).
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   515
	   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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. 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   520
	   fixed by this hack, and should therefore **not** be lazy-loaded by script loader tools such as LABjs.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   521
	*/ 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   522
	(function(addEvent,domLoaded,handler){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   523
		if (document.readyState == null && document[addEvent]){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   524
			document.readyState = "loading";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   525
			document[addEvent](domLoaded,handler = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   526
				document.removeEventListener(domLoaded,handler,false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   527
				document.readyState = "complete";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   528
			},false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   529
		}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   530
	})("addEventListener","DOMContentLoaded");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   531
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   532
})(this);/*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   533
  mustache.js — Logic-less templates in JavaScript
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   534
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   535
  See http://mustache.github.com/ for more info.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   536
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   537
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   538
var Mustache = function () {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   539
  var _toString = Object.prototype.toString;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   540
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   541
  Array.isArray = Array.isArray || function (obj) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   542
    return _toString.call(obj) == "[object Array]";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   543
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   544
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   545
  var _trim = String.prototype.trim, trim;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   546
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   547
  if (_trim) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   548
    trim = function (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   549
      return text == null ? "" : _trim.call(text);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   550
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   551
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   552
    var trimLeft, trimRight;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   553
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   554
    // IE doesn't match non-breaking spaces with \s.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   555
    if ((/\S/).test("\xA0")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   556
      trimLeft = /^[\s\xA0]+/;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   557
      trimRight = /[\s\xA0]+$/;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   558
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   559
      trimLeft = /^\s+/;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   560
      trimRight = /\s+$/;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   561
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   562
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   563
    trim = function (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   564
      return text == null ? "" :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   565
        text.toString().replace(trimLeft, "").replace(trimRight, "");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   566
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   567
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   568
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   569
  var escapeMap = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   570
    "&": "&amp;",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   571
    "<": "&lt;",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   572
    ">": "&gt;",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   573
    '"': '&quot;',
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   574
    "'": '&#39;'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   575
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   576
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   577
  function escapeHTML(string) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   578
    return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   579
      return escapeMap[s] || s;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   580
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   581
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   582
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   583
  var regexCache = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   584
  var Renderer = function () {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   585
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   586
  Renderer.prototype = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   587
    otag: "{{",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   588
    ctag: "}}",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   589
    pragmas: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   590
    buffer: [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   591
    pragmas_implemented: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   592
      "IMPLICIT-ITERATOR": true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   593
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   594
    context: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   595
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   596
    render: function (template, context, partials, in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   597
      // reset buffer & set context
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   598
      if (!in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   599
        this.context = context;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   600
        this.buffer = []; // TODO: make this non-lazy
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   601
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   602
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   603
      // fail fast
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   604
      if (!this.includes("", template)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   605
        if (in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   606
          return template;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   607
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   608
          this.send(template);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   609
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   610
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   611
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   612
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   613
      // get the pragmas together
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   614
      template = this.render_pragmas(template);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   615
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   616
      // render the template
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   617
      var html = this.render_section(template, context, partials);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   618
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   619
      // render_section did not find any sections, we still need to render the tags
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   620
      if (html === false) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   621
        html = this.render_tags(template, context, partials, in_recursion);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   622
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   623
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   624
      if (in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   625
        return html;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   626
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   627
        this.sendLines(html);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   628
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   629
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   630
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   631
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   632
      Sends parsed lines
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   633
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   634
    send: function (line) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   635
      if (line !== "") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   636
        this.buffer.push(line);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   637
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   638
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   639
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   640
    sendLines: function (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   641
      if (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   642
        var lines = text.split("\n");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   643
        for (var i = 0; i < lines.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   644
          this.send(lines[i]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   645
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   646
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   647
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   648
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   649
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   650
      Looks for %PRAGMAS
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   651
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   652
    render_pragmas: function (template) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   653
      // no pragmas
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   654
      if (!this.includes("%", template)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   655
        return template;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   656
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   657
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   658
      var that = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   659
      var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   660
        return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   661
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   662
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   663
      return template.replace(regex, function (match, pragma, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   664
        if (!that.pragmas_implemented[pragma]) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   665
          throw({message:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   666
            "This implementation of mustache doesn't understand the '" +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   667
            pragma + "' pragma"});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   668
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   669
        that.pragmas[pragma] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   670
        if (options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   671
          var opts = options.split("=");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   672
          that.pragmas[pragma][opts[0]] = opts[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   673
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   674
        return "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   675
        // ignore unknown pragmas silently
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   676
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   677
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   678
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   679
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   680
      Tries to find a partial in the curent scope and render it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   681
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   682
    render_partial: function (name, context, partials) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   683
      name = trim(name);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   684
      if (!partials || partials[name] === undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   685
        throw({message: "unknown_partial '" + name + "'"});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   686
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   687
      if (!context || typeof context[name] != "object") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   688
        return this.render(partials[name], context, partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   689
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   690
      return this.render(partials[name], context[name], partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   691
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   692
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   693
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   694
      Renders inverted (^) and normal (#) sections
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   695
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   696
    render_section: function (template, context, partials) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   697
      if (!this.includes("#", template) && !this.includes("^", template)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   698
        // did not render anything, there were no sections
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   699
        return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   700
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   701
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   702
      var that = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   703
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   704
      var regex = this.getCachedRegex("render_section", function (otag, ctag) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   705
        // This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   706
        return new RegExp(
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   707
          "^([\\s\\S]*?)" +         // all the crap at the beginning that is not {{*}} ($1)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   708
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   709
          otag +                    // {{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   710
          "(\\^|\\#)\\s*(.+)\\s*" + //  #foo (# == $2, foo == $3)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   711
          ctag +                    // }}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   712
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   713
          "\n*([\\s\\S]*?)" +       // between the tag ($2). leading newlines are dropped
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   714
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   715
          otag +                    // {{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   716
          "\\/\\s*\\3\\s*" +        //  /foo (backreference to the opening tag).
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   717
          ctag +                    // }}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   718
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   719
          "\\s*([\\s\\S]*)$",       // everything else in the string ($4). leading whitespace is dropped.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   720
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   721
        "g");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   722
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   723
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   724
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   725
      // for each {{#foo}}{{/foo}} section do...
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   726
      return template.replace(regex, function (match, before, type, name, content, after) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   727
        // before contains only tags, no sections
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   728
        var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   729
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   730
        // after may contain both sections and tags, so use full rendering function
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   731
            renderedAfter = after ? that.render(after, context, partials, true) : "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   732
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   733
        // will be computed below
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   734
            renderedContent,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   735
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   736
            value = that.find(name, context);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   737
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   738
        if (type === "^") { // inverted section
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   739
          if (!value || Array.isArray(value) && value.length === 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   740
            // false or empty list, render it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   741
            renderedContent = that.render(content, context, partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   742
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   743
            renderedContent = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   744
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   745
        } else if (type === "#") { // normal section
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   746
          if (Array.isArray(value)) { // Enumerable, Let's loop!
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   747
            renderedContent = that.map(value, function (row) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   748
              return that.render(content, that.create_context(row), partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   749
            }).join("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   750
          } else if (that.is_object(value)) { // Object, Use it as subcontext!
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   751
            renderedContent = that.render(content, that.create_context(value),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   752
              partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   753
          } else if (typeof value == "function") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   754
            // higher order section
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   755
            renderedContent = value.call(context, content, function (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   756
              return that.render(text, context, partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   757
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   758
          } else if (value) { // boolean section
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   759
            renderedContent = that.render(content, context, partials, true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   760
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   761
            renderedContent = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   762
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   763
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   764
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   765
        return renderedBefore + renderedContent + renderedAfter;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   766
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   767
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   768
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   769
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   770
      Replace {{foo}} and friends with values from our view
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   771
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   772
    render_tags: function (template, context, partials, in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   773
      // tit for tat
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   774
      var that = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   775
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   776
      var new_regex = function () {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   777
        return that.getCachedRegex("render_tags", function (otag, ctag) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   778
          return new RegExp(otag + "(=|!|>|&|\\{|%)?([^#\\^]+?)\\1?" + ctag + "+", "g");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   779
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   780
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   781
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   782
      var regex = new_regex();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   783
      var tag_replace_callback = function (match, operator, name) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   784
        switch(operator) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   785
        case "!": // ignore comments
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   786
          return "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   787
        case "=": // set new delimiters, rebuild the replace regexp
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   788
          that.set_delimiters(name);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   789
          regex = new_regex();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   790
          return "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   791
        case ">": // render partial
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   792
          return that.render_partial(name, context, partials);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   793
        case "{": // the triple mustache is unescaped
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   794
        case "&": // & operator is an alternative unescape method
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   795
          return that.find(name, context);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   796
        default: // escape the value
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   797
          return escapeHTML(that.find(name, context));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   798
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   799
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   800
      var lines = template.split("\n");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   801
      for(var i = 0; i < lines.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   802
        lines[i] = lines[i].replace(regex, tag_replace_callback, this);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   803
        if (!in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   804
          this.send(lines[i]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   805
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   806
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   807
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   808
      if (in_recursion) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   809
        return lines.join("\n");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   810
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   811
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   812
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   813
    set_delimiters: function (delimiters) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   814
      var dels = delimiters.split(" ");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   815
      this.otag = this.escape_regex(dels[0]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   816
      this.ctag = this.escape_regex(dels[1]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   817
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   818
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   819
    escape_regex: function (text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   820
      // thank you Simon Willison
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   821
      if (!arguments.callee.sRE) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   822
        var specials = [
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   823
          '/', '.', '*', '+', '?', '|',
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   824
          '(', ')', '[', ']', '{', '}', '\\'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   825
        ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   826
        arguments.callee.sRE = new RegExp(
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   827
          '(\\' + specials.join('|\\') + ')', 'g'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   828
        );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   829
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   830
      return text.replace(arguments.callee.sRE, '\\$1');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   831
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   832
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   833
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   834
      find `name` in current `context`. That is find me a value
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   835
      from the view object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   836
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   837
    find: function (name, context) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   838
      name = trim(name);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   839
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   840
      // Checks whether a value is thruthy or false or 0
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   841
      function is_kinda_truthy(bool) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   842
        return bool === false || bool === 0 || bool;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   843
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   844
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   845
      var value;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   846
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   847
      // check for dot notation eg. foo.bar
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   848
      if (name.match(/([a-z_]+)\./ig)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   849
        var childValue = this.walk_context(name, context);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   850
        if (is_kinda_truthy(childValue)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   851
          value = childValue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   852
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   853
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   854
        if (is_kinda_truthy(context[name])) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   855
          value = context[name];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   856
        } else if (is_kinda_truthy(this.context[name])) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   857
          value = this.context[name];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   858
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   859
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   860
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   861
      if (typeof value == "function") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   862
        return value.apply(context);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   863
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   864
      if (value !== undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   865
        return value;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   866
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   867
      // silently ignore unkown variables
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   868
      return "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   869
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   870
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   871
    walk_context: function (name, context) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   872
      var path = name.split('.');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   873
      // if the var doesn't exist in current context, check the top level context
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   874
      var value_context = (context[path[0]] != undefined) ? context : this.context;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   875
      var value = value_context[path.shift()];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   876
      while (value != undefined && path.length > 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   877
        value_context = value;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   878
        value = value[path.shift()];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   879
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   880
      // if the value is a function, call it, binding the correct context
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   881
      if (typeof value == "function") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   882
        return value.apply(value_context);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   883
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   884
      return value;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   885
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   886
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   887
    // Utility methods
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   888
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   889
    /* includes tag */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   890
    includes: function (needle, haystack) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   891
      return haystack.indexOf(this.otag + needle) != -1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   892
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   893
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   894
    // by @langalex, support for arrays of strings
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   895
    create_context: function (_context) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   896
      if (this.is_object(_context)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   897
        return _context;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   898
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   899
        var iterator = ".";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   900
        if (this.pragmas["IMPLICIT-ITERATOR"]) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   901
          iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   902
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   903
        var ctx = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   904
        ctx[iterator] = _context;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   905
        return ctx;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   906
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   907
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   908
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   909
    is_object: function (a) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   910
      return a && typeof a == "object";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   911
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   912
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   913
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   914
      Why, why, why? Because IE. Cry, cry cry.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   915
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   916
    map: function (array, fn) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   917
      if (typeof array.map == "function") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   918
        return array.map(fn);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   919
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   920
        var r = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   921
        var l = array.length;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   922
        for(var i = 0; i < l; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   923
          r.push(fn(array[i]));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   924
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   925
        return r;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   926
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   927
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   928
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   929
    getCachedRegex: function (name, generator) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   930
      var byOtag = regexCache[this.otag];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   931
      if (!byOtag) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   932
        byOtag = regexCache[this.otag] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   933
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   934
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   935
      var byCtag = byOtag[this.ctag];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   936
      if (!byCtag) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   937
        byCtag = byOtag[this.ctag] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   938
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   939
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   940
      var regex = byCtag[name];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   941
      if (!regex) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   942
        regex = byCtag[name] = generator(this.otag, this.ctag);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   943
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   944
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   945
      return regex;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   946
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   947
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   948
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   949
  return({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   950
    name: "mustache.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   951
    version: "0.5.0-dev",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   952
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   953
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   954
      Turns a template and view into HTML
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   955
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   956
    to_html: function (template, view, partials, send_fun) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   957
      var renderer = new Renderer();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   958
      if (send_fun) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   959
        renderer.send = send_fun;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   960
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   961
      renderer.render(template, view || {}, partials);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   962
      if (!send_fun) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   963
        return renderer.buffer.join("\n");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   964
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   965
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   966
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   967
}();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   968
// Underscore.js 1.2.3
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   969
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   970
// Underscore is freely distributable under the MIT license.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   971
// Portions of Underscore are inspired or borrowed from Prototype,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   972
// Oliver Steele's Functional, and John Resig's Micro-Templating.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   973
// For all details and documentation:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   974
// http://documentcloud.github.com/underscore
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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==
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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"&&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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=
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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-
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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=
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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===
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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)==
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   998
/* main file */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   999
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1000
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1001
if ( window.IriSP === undefined && window.__IriSP === undefined ) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1002
  /**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1003
    @class
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1004
    the object under which everything goes.        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1005
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1006
	IriSP = {}; 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1007
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1008
  /** Alias to IriSP for backward compatibility */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1009
	__IriSP = IriSP;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1010
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1011
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1012
/* underscore comes bundled with the player and we need 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1013
   it ASAP, so load it that way
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1014
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1015
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1016
IriSP._ = window._.noConflict();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1017
IriSP.underscore = IriSP._;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1018
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1019
IriSP.loadLibs = function( libs, config, metadata_url, callback ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1020
    // Localize jQuery variable
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1021
		IriSP.jQuery = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1022
    var $L = $LAB.script(libs.jQuery).script(libs.swfObject).wait()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1023
                .script(libs.jQueryUI);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1024
                                   
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1025
    if (config.player.type === "jwplayer" || config.player.type === "allocine") {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1026
      // load our popcorn.js lookalike
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1027
      $L.script(libs.jwplayer);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1028
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1029
      // load the real popcorn
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1030
      $L.script(libs.popcorn).script(libs["popcorn.code"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1031
      if (config.player.type === "youtube") {
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1032
        $L.script(libs["popcorn.youtube"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1033
      } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1034
      if (config.player.type === "vimeo")
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1035
        $L.script(libs["popcorn.vimeo"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1036
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1037
      /* do nothing for html5 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1038
    }       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1039
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1040
    /* widget specific requirements */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1041
    for (var idx in config.gui.widgets) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1042
      if (config.gui.widgets[idx].type === "PolemicWidget" ||
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1043
          config.gui.widgets[idx].type === "StackGraphWidget" ||
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1044
          config.gui.widgets[idx].type === "SparklineWidget") {        
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1045
        $L.script(libs.raphael);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1046
      }
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1047
      if (config.gui.widgets[idx].type === "TraceWidget") {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1048
          $L.script(libs.tracemanager)
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1049
      }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1050
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1051
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1052
    // same for modules
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1053
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1054
    for (var idx in config.modules) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1055
      if (config.modules[idx].type === "PolemicWidget")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1056
        $L.script(libs.raphaelJs);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1057
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1058
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1059
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1060
    $L.wait(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1061
      IriSP.jQuery = window.jQuery.noConflict( true );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1062
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1063
      var css_link_jquery = IriSP.jQuery( "<link>", { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1064
        rel: "stylesheet", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1065
        type: "text/css", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1066
        href: libs.cssjQueryUI,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1067
        'class': "dynamic_css"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1068
      } );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1069
      var css_link_custom = IriSP.jQuery( "<link>", { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1070
        rel: "stylesheet", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1071
        type: "text/css", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1072
        href: config.gui.css,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1073
        'class': "dynamic_css"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1074
      } );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1075
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1076
      css_link_jquery.appendTo('head');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1077
      css_link_custom.appendTo('head');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1078
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1079
      IriSP.setupDataLoader();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1080
      IriSP.__dataloader.get(metadata_url, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1081
          function(data) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1082
            /* save the data so that we could re-use it to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1083
               configure the video
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1084
            */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1085
            IriSP.__jsonMetadata = data;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1086
            callback.call(window) });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1087
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1088
};
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
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>";
837
353a78021ebc Added Internationalization
veltr
parents: 836
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>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
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>";
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
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>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1093
IriSP.arrowWidget_template = "<div class='Ldt-arrowWidget Ldt-arrowLeftEdge'></div>";
837
353a78021ebc Added Internationalization
veltr
parents: 836
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>";
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1095
IriSP.createAnnotation_errorMessage_template = "<p class='Ldt-createAnnotation-errorMessage'>  {{l10n.empty_annotation}}</p>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1096
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>";
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1097
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-MuteState Ldt-TraceMe' title='{{l10n.mute_unmute}}'></div>	</div></div>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1098
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>";
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1099
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>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1100
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>";
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1101
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>";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1102
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>";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1103
IriSP.tooltipWidget_template = "{{! template for the tooltip widget }}<div class='tip'>	<div class='tipcolor' style='height:10px;width:10px'></div>	<div class='tiptext'></div>";
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1104
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 */
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1105
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1106
/* trace function, for debugging */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1107
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1108
IriSP.traceNum = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1109
IriSP.trace = function( msg, value ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1110
/*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1111
	if( IriSP.config.gui.debug === true ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1112
		IriSP.traceNum += 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1113
		IriSP.jQuery( "<div>"+IriSP.traceNum+" - "+msg+" : "+value+"</div>" ).appendTo( "#Ldt-output" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1114
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1115
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1116
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1117
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1118
/* used in callbacks - because in callbacks we lose "this",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1119
   we need to have a special function which wraps "this" in 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1120
   a closure. This way, the 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1121
*/   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1122
IriSP.wrap = function (obj, fn) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1123
  return function() {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1124
    var args = Array.prototype.slice.call(arguments, 0);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1125
    return fn.apply(obj, args);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1126
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1127
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1128
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1129
/* convert a time to a percentage in the media */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1130
IriSP.timeToPourcent = function(time, timetotal){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1131
	var time = Math.abs(time);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1132
  var timetotal = Math.abs(timetotal);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1133
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1134
	return Math.floor((time/timetotal) * 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1135
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1136
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1137
IriSP.padWithZeros = function(num) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1138
  if (Math.abs(num) < 10) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1139
    return "0" + num.toString();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1140
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1141
    return num.toString();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1142
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1143
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1144
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1145
/* convert a number of milliseconds to a tuple of the form 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1146
   [hours, minutes, seconds]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1147
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1148
IriSP.msToTime = function(ms) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1149
  return IriSP.secondsToTime(ms / 1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1150
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1151
/* convert a number of seconds to a tuple of the form 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1152
   [hours, minutes, seconds]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1153
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1154
IriSP.secondsToTime = function(secs) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1155
  var hours = Math.abs(parseInt( secs / 3600 ) % 24);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1156
  var minutes = Math.abs(parseInt( secs / 60 ) % 60);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1157
  var seconds = parseFloat(Math.abs(secs % 60).toFixed(0));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1158
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1159
  var toString_fn = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1160
    var ret = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1161
    if (hours > 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1162
       ret = IriSP.padWithZeros(this.hours) + ":";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1163
    ret += IriSP.padWithZeros(this.minutes) + ":" + IriSP.padWithZeros(this.seconds);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1164
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1165
    return ret;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1166
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1167
  return {"hours" : hours, "minutes" : minutes, "seconds" : seconds, toString: toString_fn};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1168
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1169
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1170
/* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1171
IriSP.formatTweet = function(tweet) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1172
  /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1173
    an array of arrays which hold a regexp and its replacement.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1174
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1175
  var regExps = [
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1176
    /* copied from http://codegolf.stackexchange.com/questions/464/shortest-url-regex-match-in-javascript/480#480 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1177
    [/((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi, "<a href='$1'>$1</a>"],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1178
    [/@(\w+)/gi, "<a href='http://twitter.com/$1'>@$1</a>"], // matches a @handle
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1179
    [/#(\w+)/gi, "<a href='http://twitter.com/search?q=%23$1'>#$1</a>"],// matches a hashtag
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1180
    [/(\+\+)/gi, "<span class='Ldt-PolemicPlusPlus'>$1</span>"],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1181
    [/(--)/gi, "<span class='Ldt-PolemicMinusMinus'>$1</span>"],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1182
    [/(==)/gi, "<span class='Ldt-PolemicEqualEqual'>$1</span>"],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1183
    [/(\?\?)/gi, "<span class='Ldt-PolemicQuestion'>$1</span>"]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1184
  ]; 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1185
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1186
  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1187
  for(i = 0; i < regExps.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1188
     tweet = tweet.replace(regExps[i][0], regExps[i][1]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1189
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1190
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1191
  return tweet;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1192
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1193
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1194
IriSP.countProperties = function(obj) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1195
    var count = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1196
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1197
    for(var prop in obj) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1198
        if(obj.hasOwnProperty(prop))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1199
                ++count;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1200
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1201
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1202
    return count;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1203
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1204
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1205
// conversion de couleur Decimal vers HexaDecimal || 000 si fff
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1206
IriSP.DEC_HEXA_COLOR = function (dec) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1207
  var val = +dec;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1208
  var str = val.toString(16);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1209
  var zeroes = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1210
  if (str.length < 6) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1211
    for (var i = 0; i < 6 - str.length; i++)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1212
      zeroes += "0";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1213
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1214
  return zeroes + str;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1215
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1216
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1217
/* shortcut to have global variables in templates */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1218
IriSP.templToHTML = function(template, values) {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1219
  var params = IriSP.jQuery.extend(
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1220
      { "defaults" : IriSP.default_templates_vars,
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1221
        "l10n" : IriSP.i18n.getMessages()
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1222
        },
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1223
      values);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1224
  return Mustache.to_html(template, params);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1225
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1226
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1227
/* we need to be stricter than encodeURIComponent,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1228
   because of twitter
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1229
*/  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1230
IriSP.encodeURI = function(str) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1231
  return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1232
                                 replace(/\)/g, '%29').replace(/\*/g, '%2A');  
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1233
}
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1234
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1235
IriSP.jqEscape = function(text) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1236
   return text.replace(/(:|\.)/g,'\\$1')
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1237
}
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1238
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1239
IriSP.jqId = function (text) { 
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1240
   return IriSP.jQuery('#' + IriSP.jqEscape(text));
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1241
 }  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1242
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1243
IriSP.__guidCounter = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1244
IriSP.guid = function(prefix) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1245
  IriSP.__guidCounter += 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1246
  return prefix + IriSP.__guidCounter;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1247
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1248
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1249
/** returns an url to share on facebook */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1250
IriSP.mkFbUrl = function(url, text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1251
  if (typeof(text) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1252
    text = "I'm watching ";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1253
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1254
  return "http://www.facebook.com/share.php?u=" + IriSP.encodeURI(text) + IriSP.shorten_url(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1255
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1256
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1257
/** returns an url to share on twitter */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1258
IriSP.mkTweetUrl = function(url, text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1259
  if (typeof(text) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1260
    text = "I'm watching ";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1261
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1262
  return "http://twitter.com/home?status=" + IriSP.encodeURI(text) + IriSP.shorten_url(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1263
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1264
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1265
/** returns an url to share on google + */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1266
IriSP.mkGplusUrl = function(url, text) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1267
  return "https://plusone.google.com/_/+1/confirm?hl=en&url=" + IriSP.shorten_url(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1268
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1269
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1270
/** test if a value is null or undefined */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1271
IriSP.null_or_undefined = function(val) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1272
  return (typeof(val) === "undefined" || val === null);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1273
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1274
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1275
/** get a property that can have multiple names **/
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1276
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1277
IriSP.get_aliased = function(_obj, _aliases) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1278
    for (var _i = 0; _i < _aliases.length; _i++) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1279
        if (typeof _obj[_aliases[_i]] !== "undefined") {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1280
            return _obj[_aliases[_i]];
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1281
        }
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1282
    }
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1283
    return null;
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1284
}
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1285
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1286
/** issue a call to an url shortener and return the shortened url */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1287
IriSP.shorten_url = function(url) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1288
  if (IriSP.config.shortener.hasOwnProperty("shortening_function"))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1289
    return IriSP.config.shortener.shortening_function(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1290
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1291
  return url;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1292
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1293
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1294
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1295
/* for ie compatibility
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1296
if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1297
   Object.defineProperty=function(obj,prop,desc) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1298
      if ("get" in desc) obj.__defineGetter__(prop,desc.get);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1299
      if ("set" in desc) obj.__defineSetter__(prop,desc.set);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1300
   }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1301
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1302
*/
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1303
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1304
/* Creates regexps from text */
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1305
IriSP.regexpFromText = function(_text) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1306
    return new RegExp('(' + _text.replace(/(\W)/gim,'\\$1') + ')','gim');
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1307
}
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1308
/* wrapper that simulates popcorn.js because
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1309
   popcorn is a bit unstable at the time */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1310
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1311
IriSP.PopcornReplacement = {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1312
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1313
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1314
/** base class for our popcorn-compatible players.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1315
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1316
IriSP.PopcornReplacement.player = function(container, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1317
  /* the jwplayer calls the callbacks in the global space so we need to 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1318
     preserve them using IriSP.wrap */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1319
  this.callbacks = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1320
      onReady:  IriSP.wrap(this, this.__initApi),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1321
      onTime:   IriSP.wrap(this, this.__timeHandler),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1322
      onPlay:   IriSP.wrap(this, this.__playHandler),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1323
      onPause:  IriSP.wrap(this, this.__pauseHandler),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1324
      onSeek:   IriSP.wrap(this, this.__seekHandler) 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1325
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1326
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1327
  this.media = { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1328
    "paused": true,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1329
    "muted": false
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1330
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1331
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1332
  this.container = container.slice(1); //eschew the '#'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1333
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1334
  this.msgPump = {}; /* dictionnary used to receive and send messages */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1335
  this.__codes = []; /* used to schedule the execution of a piece of code in 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1336
                        a segment (similar to the popcorn.code plugin). */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1337
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1338
  this._options = options;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1339
                          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1340
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1341
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1342
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1343
  if (!this.msgPump.hasOwnProperty(msg))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1344
    this.msgPump[msg] = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1345
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1346
  this.msgPump[msg].push(callback);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1347
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1348
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1349
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1350
  if (!this.msgPump.hasOwnProperty(msg))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1351
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1352
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1353
  var d = this.msgPump[msg];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1354
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1355
  for(var i = 0; i < d.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1356
    d[i].call(window, params);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1357
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1358
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1359
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1360
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1361
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1362
  var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1363
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1364
      return v.toString(16);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1365
   });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1366
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1367
  return prefix + str;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1368
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1369
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1370
/** init the api after that flash player has been setup - called by the callback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1371
    defined by the embedded flash player 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1372
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1373
IriSP.PopcornReplacement.player.prototype.__initApi = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1374
  this.trigger("loadedmetadata"); // we've done more than loading metadata of course,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1375
                                                      // but popcorn doesn't need to know more.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1376
  this.media.muted = this.playerFns.getMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1377
  /* some programmed segments are supposed to be run at the beginning */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1378
  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1379
  for(i = 0; i < this.__codes.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1380
    var c = this.__codes[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1381
    if (0 == c.start) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1382
      c.onStart();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1383
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1384
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1385
    if (0 == c.end) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1386
      c.onEnd();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1387
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1388
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1389
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1390
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1391
/*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1392
IriSP.PopcornReplacement.jwplayer = function(container, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1393
  IriSP.PopcornReplacement._container = container.slice(1); //eschew the '#'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1394
  options.events = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1395
      onReady: IriSP.PopcornReplacement.__initApi,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1396
      onTime: IriSP.PopcornReplacement.__timeHandler,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1397
      onPlay: IriSP.PopcornReplacement.__playHandler,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1398
      onPause: IriSP.PopcornReplacement.__pauseHandler,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1399
      onSeek: IriSP.PopcornReplacement.__seekHandler 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1400
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1401
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1402
  jwplayer(IriSP.PopcornReplacement._container).setup(options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1403
  IriSP.PopcornReplacement.media.duration = options.duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1404
  return IriSP.PopcornReplacement;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1405
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1406
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1407
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1408
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1409
  if (typeof(time) === "undefined") {        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1410
      return this.playerFns.getPosition();            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1411
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1412
     var currentTime = +time;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1413
     this.playerFns.seek(currentTime);              
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1414
     return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1415
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1416
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1417
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1418
IriSP.PopcornReplacement.player.prototype.play = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1419
  this.media.paused = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1420
  this.trigger("play");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1421
  //IriSP.PopcornReplacement.trigger("playing");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1422
  this.playerFns.play();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1423
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1424
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1425
IriSP.PopcornReplacement.player.prototype.pause = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1426
  if ( !this.media.paused ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1427
    this.media.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1428
    this.trigger( "pause" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1429
    this.playerFns.pause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1430
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1431
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1432
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1433
IriSP.PopcornReplacement.player.prototype.muted = function(val) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1434
  if (typeof(val) !== "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1435
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1436
    if (this.playerFns.getMute() !== val) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1437
      if (val) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1438
        this.playerFns.setMute(true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1439
        this.media.muted = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1440
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1441
        this.playerFns.setMute(false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1442
        this.media.muted = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1443
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1444
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1445
      this.trigger( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1446
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1447
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1448
    return this.playerFns.getMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1449
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1450
    return this.playerFns.getMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1451
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1452
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1453
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1454
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1455
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1456
IriSP.PopcornReplacement.player.prototype.code = function(options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1457
  this.__codes.push(options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1458
  return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1459
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1460
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1461
/* called everytime the player updates itself 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1462
   (onTime event)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1463
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1464
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1465
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1466
  var pos = event.position;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1467
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1468
  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1469
  for(i = 0; i < this.__codes.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1470
     var c = this.__codes[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1471
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1472
     if (pos >= c.start && pos < c.end && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1473
         pos - 1 <= c.start) {       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1474
        c.onStart();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1475
     }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1476
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1477
     if (pos > c.start && pos > c.end && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1478
         pos - 1 <= c.end) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1479
         c.onEnd();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1480
     }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1481
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1482
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1483
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1484
  this.trigger("timeupdate");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1485
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1486
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1487
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1488
  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1489
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1490
  for(i = 0; i < this.__codes.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1491
     var c = this.__codes[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1492
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1493
     if (event.position >= c.start && event.position < c.end) {        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1494
        c.onEnd();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1495
     }         
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1496
   }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1497
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1498
   for(i = 0; i < this.__codes.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1499
     var c = this.__codes[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1500
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1501
     if (typeof(event.offset) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1502
       event.offset = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1503
           
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1504
     if (event.offset >= c.start && event.offset < c.end) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1505
       c.onStart();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1506
     }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1507
     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1508
   }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1509
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1510
  /* this signal sends as an extra argument the position in the video.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1511
     As far as I know, this argument is not provided by popcorn */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1512
  this.trigger("seeked", event.offset);  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1513
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1514
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1515
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1516
  this.media.paused = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1517
  this.trigger("play");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1518
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1519
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1520
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1521
  this.media.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1522
  this.trigger("pause");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1523
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1524
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1525
IriSP.PopcornReplacement.player.prototype.roundTime = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1526
  var currentTime = this.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1527
  return Math.round(currentTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1528
};/* data.js - this file deals with how the players gets and sends data */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1529
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1530
IriSP.DataLoader = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1531
  this._cache = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1532
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1533
  /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1534
    A structure to hold callbacks for specific urls. We need it because
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1535
    ajax calls are asynchronous, so it means that sometimes we ask
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1536
    multiple times for a ressource because the first call hasn't been
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1537
    received yet.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1538
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1539
  this._callbacks = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1540
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1541
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1542
IriSP.DataLoader.prototype.get = function(url, callback) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1543
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1544
  var base_url = url.split("&")[0]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1545
  if (this._cache.hasOwnProperty(base_url)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1546
    callback(this._cache[base_url]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1547
  } else {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1548
    if (!this._callbacks.hasOwnProperty(base_url)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1549
      this._callbacks[base_url] = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1550
      this._callbacks[base_url].push(callback);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1551
      /* we need a closure because this gets lost when it's called back */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1552
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1553
      // uncomment you don't want to use caching.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1554
      // IriSP.jQuery.get(url, callback);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1555
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1556
      var func = function(data) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1557
                  this._cache[base_url] = data;                                
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1558
                  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1559
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1560
                  for (i = 0; i < this._callbacks[base_url].length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1561
                    this._callbacks[base_url][i](this._cache[base_url]);                                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1562
                  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1563
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1564
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1565
      /* automagically choose between json and jsonp */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1566
      if (url.indexOf(document.location.hostname) === -1 &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1567
          url.indexOf("http://") !== -1 /* not a relative url */ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1568
        // we contacting a foreign domain, use JSONP
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1569
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1570
        IriSP.jQuery.get(url, {}, IriSP.wrap(this, func), "jsonp");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1571
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1572
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1573
        // otherwise, hey, whatever rows your boat
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1574
        IriSP.jQuery.get(url, IriSP.wrap(this, func));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1575
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1576
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1577
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1578
      /* simply push the callback - it'll get called when the ressource
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1579
         has been received */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1580
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1581
      this._callbacks[base_url].push(callback);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1582
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1583
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1584
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1585
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1586
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1587
/* the base abstract "class" */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1588
IriSP.Serializer = function(DataLoader, url) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1589
  this._DataLoader = DataLoader;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1590
  this._url = url;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1591
  this._data = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1592
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1593
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1594
IriSP.Serializer.prototype.serialize = function(data) { };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1595
IriSP.Serializer.prototype.deserialize = function(data) {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1596
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1597
IriSP.Serializer.prototype.currentMedia = function() {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1598
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1599
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1600
IriSP.Serializer.prototype.sync = function(callback) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1601
  callback.call(this, this._data);  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1602
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1603
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1604
IriSP.SerializerFactory = function(DataLoader) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1605
  this._dataloader = DataLoader;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1606
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1607
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1608
IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1609
  /* This function returns serializer set-up with the correct
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1610
     configuration - takes a metadata struct describing the metadata source
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1611
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1612
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1613
  if (metadataOptions === undefined)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1614
    /* return an empty serializer */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1615
    return IriSP.Serializer("", "");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1616
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1617
  switch(metadataOptions.type) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1618
    case "json":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1619
      return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1620
      break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1621
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1622
    case "dummy": /* only used for unit testing - not defined in production */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1623
      return new IriSP.MockSerializer(this._dataloader, metadataOptions.src);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1624
      break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1625
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1626
    case "empty":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1627
      return new IriSP.Serializer("", "empty");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1628
      break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1629
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1630
    default:      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1631
      return undefined;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1632
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1633
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1634
/* site.js - all our site-dependent config : player chrome, cdn locations, etc...*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1635
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1636
IriSP.defaults = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1637
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1638
/* these objects are filled by configureDefaults. The function doesn't overwrite 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1639
   defaults that were originally defined by the user.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1640
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1641
IriSP.lib = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1642
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1643
/* We need to define those so that the individual settings can be overwritten */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1644
IriSP.widgetsDefaults = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1645
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1646
IriSP.paths = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1647
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1648
IriSP.libdir = "/metadataplayer/src/js/libs/";
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1649
IriSP.jwplayer_swf_path = "../test/libs/player.swf";
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1650
IriSP.platform_url = "http://192.168.56.101/pf";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1651
IriSP.default_templates_vars = { };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1652
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1653
IriSP.language = 'fr';
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1654
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1655
/** ugly ugly ugly ugly - returns an object defining 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1656
    the paths to the libs
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1657
    We need it that way cause it's called at runtime by
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1658
    IriSP.configureDefaults.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1659
*/   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1660
IriSP.defaults.lib = function(libdir) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1661
  if (IriSP.null_or_undefined(libdir))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1662
    libdir = IriSP.libdir;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1663
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1664
  return { 
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1665
//      jQuery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1666
    jQuery : libdir + "jquery.min.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1667
//      jQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1668
    jQueryUI : libdir + "jquery-ui.min.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1669
//      jQueryToolTip : "http://cdn.jquerytools.org/1.2.4/all/jquery.tools.min.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1670
    jQueryToolTip : libdir + "jquery.tools.min.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1671
//      swfObject : "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1672
    swfObject : libdir + "swfobject.js",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1673
//      cssjQueryUI : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css",
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  1674
    cssjQueryUI : libdir + "jquery-ui.css",
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1675
      popcorn : libdir + "popcorn.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1676
      jwplayer : libdir + "jwplayer.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1677
      popcornReplacement: libdir + "pop.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1678
      raphael: libdir + "raphael.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1679
      jquery_sparkline: libdir + "jquery.sparkline.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1680
      "popcorn.mediafragment" : libdir + "popcorn.mediafragment.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1681
      "popcorn.code" : libdir + "popcorn.code.js",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1682
      "popcorn.jwplayer": libdir + "popcorn.jwplayer.js",
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1683
      "popcorn.youtube": libdir + "popcorn.youtube.js",
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1684
      "tracemanager": libdir + "tracemanager.js"
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1685
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1686
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1687
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1688
//Configuration for the player and utility functions.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1689
// No need to have them configured at runtime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1690
IriSP.config = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1691
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1692
IriSP.config.shortener = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1693
  // function to call to shorten an url.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1694
  //shortening_function : IriSP.platform_shorten_url
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1695
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1696
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1697
IriSP.defaults.widgetsDefaults = function(platform_url) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1698
  if (IriSP.null_or_undefined(platform_url))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1699
    platform_url = IriSP.platform_url;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1700
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1701
  return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1702
    "LayoutManager" : {spacer_div_height : "0px" },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1703
    "PlayerWidget" : {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1704
    "AnnotationsWidget": {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1705
      "share_text" : "I'm watching ",     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1706
      "fb_link" : "http://www.facebook.com/share.php?u=",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1707
      "tw_link" : "http://twitter.com/home?status=",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1708
      "gplus_link" : ""
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1709
      },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1710
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1711
    "TweetsWidget" : {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1712
        default_profile_picture : "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1713
        tweet_display_period: 10000 // how long do we show a tweet ?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1714
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1715
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1716
    "SliderWidget" : {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1717
        minimize_period: 850 // how long does the slider stays maximized after the user leaves the zone ?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1718
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1719
    "createAnnotationWidget" : {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1720
        keywords: ["#amateur", "#digital-studies"],
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1721
        polemic_mode: true, /* enable polemics ? */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1722
        /* polemics - the corresponding class names defined in the css should be for instance :
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1723
           Ldt-createAnnotation-polemic-positive for positive
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1724
           Ldt-createAnnotation-polemic-equalequal for equalequal, etc.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1725
        */
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1726
        polemics: [ { "className" : "positive", "keyword" : "++" }, { "className" : "negative", "keyword" : "--" }, { "className" : "reference", "keyword" : "==" }, { "className" : "question", "keyword" : "??" } ], 
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1727
        cinecast_version: false, /* put to false to enable the platform version, true for the festival cinecast one. */
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1728
        
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1729
        /* where does the widget PUT the annotations - this is a mustache template. id refers to the id of the media ans is filled
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1730
           by the widget. 
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1731
        */
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1732
        api_endpoint_template: platform_url + "/ldtplatform/api/ldt/annotations/{{id}}.json",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1733
        api_method: "PUT"
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1734
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1735
    "SparklineWidget" : {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1736
        column_width: 10 // the width of a column in pixels.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1737
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1738
    "Main" : {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1739
        autoplay: true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1740
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1741
    "AnnotationsListWidget" : {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1742
        ajax_mode: true, /* use ajax to get information about the annotations.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1743
                           if set to false, only search in the annotations for the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1744
                           current project. */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1745
        /* the platform generates some funky urls. We replace them afterwards to point to the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1746
           correct place - this setting will probably be overwritten by the platform 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1747
           implementers.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1748
           Note that the player has to replace the variables between {{ and }} by its own values.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1749
        */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1750
        ajax_url: platform_url + "/ldtplatform/api/ldt/segments/{media}/{begin}/{end}", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1751
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1752
        ajax_granularity: 10000, /* how much ms should we look before and after the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1753
                                   current timecode */
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1754
      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  1755
        default_thumbnail: "/metadataplayer/src/css/imgs/video_sequence.png",
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1756
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1757
        project_url: platform_url + "/ldtplatform/ldt/front/player/" /* the beginning 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1758
                                                                        of a link to the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1759
                                                                        new front */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1760
    } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1761
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1762
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1763
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1764
/*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1765
Override this if you want to change the info the player receives about the user.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1766
It's typically overrided in server-side templates with user-specific data.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1767
*/
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1768
IriSP.defaults.user = function() { return {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1769
      "name" : "Anonymous user",
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1770
      "avatar" : IriSP.paths.imgs + "/user_default_icon.png"
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1771
    }
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1772
};
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  1773
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1774
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1775
IriSP.defaults.paths = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1776
//  "imgs": "/tweetlive/res/metadataplayer/src/css/imgs"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1777
  "imgs": "/metadataplayer/src/css/imgs"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1778
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1779
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1780
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1781
IriSP.defaults.default_templates_vars = function() { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1782
  return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1783
  "img_dir" : IriSP.paths.imgs 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1784
  };
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  1785
}/* the widget classes and definitions */
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1786
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1787
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1788
  * @class Widget is an "abstract" class. It's mostly used to define some properties common to every widget.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1789
  *
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1790
  *  Note that widget constructors are never called directly by the user. Instead, the widgets are instantiated by functions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1791
  *  defined in init.js
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1792
  *  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1793
  * @constructor
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1794
  * @param Popcorn a reference to the popcorn Object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1795
  * @param config configuration options for the widget
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1796
  * @param Serializer a serializer instance from which the widget reads data fromCharCode  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1797
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1798
IriSP.Widget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1799
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1800
  if (config === undefined || config === null) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1801
    config = {}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1802
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1803
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1804
  this._Popcorn = Popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1805
  this._config = config;  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1806
  this._serializer = Serializer;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1807
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1808
  if (config.hasOwnProperty("container")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1809
     this._id = config.container;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1810
     this.selector = IriSP.jQuery("#" + this._id);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1811
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1812
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1813
  if (config.hasOwnProperty("spacer")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1814
     this._spacerId = config.spacer;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1815
     this.spacer = IriSP.jQuery("#" + this._spacerId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1816
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1817
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1818
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1819
  if (config.hasOwnProperty("width")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1820
     // this.width and not this._width because we consider it public.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1821
     this.width = config.width;     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1822
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1823
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1824
  if (config.hasOwnProperty("height")) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1825
     this.height = config.height;     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1826
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1827
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1828
  if (config.hasOwnProperty("heightmax")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1829
     this.heightmax = config.heightmax;     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1830
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1831
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1832
  if (config.hasOwnProperty("widthmax")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1833
     this.widthmax = config.widthmax;     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1834
  } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1835
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1836
  if (config.hasOwnProperty("layoutManager")) {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1837
     this.layoutManager = config.layoutManager;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1838
  }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1839
  if (typeof this.selector != "undefined") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1840
      this.selector.addClass("Ldt-TraceMe").addClass("Ldt-Widget");
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  1841
      this.selector.attr("widget-type", this._config.type);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1842
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1843
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1844
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1845
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1846
// This functions checks for configuration options
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1847
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1848
IriSP.Widget.prototype.checkOption = function(_name, _default) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1849
    this[_name] = (
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1850
        typeof this._config[_name] != "undefined"
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1851
        ? this._config[_name]
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1852
        : (
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1853
            (typeof IriSP.widgetsDefaults[this._config.type] != "undefined" && IriSP.widgetsDefaults[this._config.type][_name] != "undefined")
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1854
            ? IriSP.widgetsDefaults[this._config.type][_name]
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1855
            : (
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1856
                typeof _default != "undefined"
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1857
                ? _default
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1858
                : null
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1859
            )
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1860
        )
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1861
    )
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1862
}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  1863
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1864
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1865
  * This method responsible of drawing a widget on screen.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1866
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1867
IriSP.Widget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1868
  /* implemented by "sub-classes" */  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1869
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1870
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1871
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1872
  * Optional method if you want your widget to support redraws.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1873
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1874
IriSP.Widget.prototype.redraw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1875
  /* implemented by "sub-classes" */  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1876
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1877
/* modules are non-graphical entities, similar to widgets */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1878
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1879
IriSP.Module = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1880
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1881
  if (config === undefined || config === null) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1882
    config = {}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1883
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1884
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1885
  this._Popcorn = Popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1886
  this._config = config;  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1887
  this._serializer = Serializer;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1888
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1889
/* layout.js - very basic layout management */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1890
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1891
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1892
  @class a layout manager manages a div and the layout of objects
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1893
  inside it.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1894
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1895
IriSP.LayoutManager = function(options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1896
    this._Popcorn = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1897
    this._widgets = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1898
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1899
    this._div = "LdtPlayer";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1900
    this._width = 640;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1901
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1902
    if (options === undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1903
      options = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1904
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1905
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1906
    if (options.hasOwnProperty('container')) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1907
      this._div = options.container;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1908
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1909
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1910
    if (options.hasOwnProperty('width')) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1911
      this._width = options.width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1912
    }    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1913
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1914
    if (options.hasOwnProperty('height')) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1915
      this._height = options.height;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1916
    } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1917
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1918
    /* this is a shortcut */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1919
    this.selector = IriSP.jQuery("#" + this._div);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1920
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1921
    this.selector.css("width", this._width);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1922
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1923
    if (this._height !== undefined)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1924
      this.selector.css("height", this._height);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1925
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1926
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1927
/** 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1928
   Set the popcorn instance used by the manager.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1929
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1930
   we need this special setter because of a chicken and egg problem :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1931
   we want the manager to use popcorn but the popcorn div will be managed
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1932
   by the manager. So we need a way to set the instance the manager uses
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1933
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1934
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1935
IriSP.LayoutManager.prototype.setPopcornInstance = function(popcorn) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1936
    this._Popcorn = popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1937
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1938
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1939
/** create a subdiv with an unique id, and a spacer div as well.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1940
    @param widgetName the name of the widget.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1941
    @return an array of the form [createdivId, spacerdivId].
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1942
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1943
IriSP.LayoutManager.prototype.createDiv = function(widgetName) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1944
    if (typeof(widgetName) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1945
       widgetName = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1946
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1947
    var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1948
    var spacerDiv = IriSP.guid("LdtPlayer_spacer_");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1949
    this._widgets.push([widgetName, newDiv]);    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1950
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1951
    var divTempl = "<div id='{{id}}' style='width: {{width}}px; position: relative;'></div";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1952
    var spacerTempl = "<div id='{{spacer_id}}' style='width: {{width}}px; position: relative; height: {{spacer_div_height}};'></div";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1953
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1954
    var divCode = Mustache.to_html(divTempl, {id: newDiv, width: this._width});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1955
    var spacerCode = Mustache.to_html(spacerTempl, {spacer_id: spacerDiv, width: this._width,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1956
                                                    spacer_div_height: IriSP.widgetsDefaults.LayoutManager.spacer_div_height });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1957
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1958
    this.selector.append(divCode);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1959
    this.selector.append(spacerCode);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1960
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1961
    return [newDiv, spacerDiv];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1962
};/* init.js - initialization and configuration of Popcorn and the widgets
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1963
exemple json configuration:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1964
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1965
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1966
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1967
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1968
    set up the IriSP.__dataloader instance - 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1969
    we need it because we have to get the metadata
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1970
    about the video before that the widget have even
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1971
    loaded.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1972
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1973
IriSP.setupDataLoader = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1974
  /* we set it up separately because we need to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1975
     get data at the very beginning, for instance when
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1976
     setting up the video */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1977
  IriSP.__dataloader = new IriSP.DataLoader();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1978
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1979
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1980
/** do some magic to configure popcorn according to the options object passed.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1981
    Works for html5, jwplayer and youtube videos 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1982
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1983
IriSP.configurePopcorn = function (layoutManager, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1984
    var pop;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1985
    var ret = layoutManager.createDiv(); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1986
    var containerDiv = ret[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1987
    var spacerDiv = ret[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1988
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1989
    /* insert one pixel of margin between the video and the first widget, using the 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1990
       spacer.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1991
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1992
    IriSP.jQuery("#" + spacerDiv).css("height", "1px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1993
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1994
    switch(options.type) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1995
      /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1996
        todo : dynamically create the div/video tag which
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1997
        will contain the video.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1998
      */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1999
      case "html5":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2000
           var tmpId = Popcorn.guid("video"); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2001
           IriSP.jQuery("#" + containerDiv).append("<video src='" + options.file + "' id='" + tmpId + "'></video>");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2002
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2003
           if (options.hasOwnProperty("width"))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2004
             IriSP.jQuery("#" + containerDiv).css("width", options.width);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2005
           
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2006
           if (options.hasOwnProperty("height"))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2007
             IriSP.jQuery("#" + containerDiv).css("height", options.height);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2008
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2009
           pop = Popcorn("#" + tmpId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2010
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2011
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2012
      case "jwplayer":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2013
          var opts = IriSP.jQuery.extend({}, options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2014
          delete opts.container;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2015
          delete opts.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2016
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2017
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2018
          /* Try to guess options.file and options.streamer only if file and streamer
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2019
             are not already defined in the configuration */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2020
          if (options.provider === "rtmp" && !opts.hasOwnProperty("file") && !opts.hasOwnProperty("streamer")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2021
            /* exit if we can't access the metadata */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2022
            if (typeof(IriSP.__jsonMetadata) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2023
                break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2024
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2025
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2026
            // the json format is totally illogical
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2027
            //opts.streamer = IriSP.__jsonMetadata["medias"][0]["meta"]["item"]["value"];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2028
            //var source = IriSP.__jsonMetadata["medias"][0]["href"];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2029
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2030
            // the source if a full url but jwplayer wants an url relative to the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2031
            // streamer url, so we've got to remove the common part.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2032
            //opts.file = source.slice(opts.streamer.length);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2033
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2034
            /* sometimes we get served a file with a wrong path and streamer.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2035
               as a streamer is of the form rtmp://domain/path/ and the media is
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2036
               the rest, we uglily do this :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2037
            */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2038
            opts.file = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2039
            opts.streamer = "";
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2040
            var fullPath = IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2041
            
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2042
            if (fullPath === null) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2043
              console.log("no url or href field defined in the metadata.");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2044
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2045
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2046
            var pathSplit = fullPath.split('/');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2047
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2048
            for (var i = 0; i < pathSplit.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2049
              if (i < 4) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2050
                 opts.streamer += pathSplit[i] + "/";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2051
              } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2052
                 opts.file += pathSplit[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2053
                 /* omit the last slash if we're on the last element */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2054
                 if (i < pathSplit.length - 1)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2055
                  opts.file += "/";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2056
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2057
            }            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2058
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2059
            /* other providers type, video for instance -
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2060
               pass everything as is */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2061
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2062
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2063
          if (!options.hasOwnProperty("flashplayer")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2064
            opts.flashplayer = IriSP.jwplayer_swf_path;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2065
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2066
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2067
          if (!options.hasOwnProperty("controlbar.position")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2068
            opts["controlbar.position"] = "none";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2069
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2070
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2071
          pop = new IriSP.PopcornReplacement.jwplayer("#" + containerDiv, opts);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2072
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2073
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2074
      case "youtube":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2075
          var opts = IriSP.jQuery.extend({}, options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2076
          delete opts.container;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2077
          opts.controls = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2078
          opts.autostart = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2079
          templ = "width: {{width}}px; height: {{height}}px;";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2080
          var str = Mustache.to_html(templ, {width: opts.width, height: opts.height});    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2081
          // Popcorn.youtube wants us to specify the size of the player in the style attribute of its container div.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2082
          IriSP.jQuery("#" + containerDiv).attr("style", str);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2083
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2084
          pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2085
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2086
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2087
    case "dailymotion":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2088
        pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2089
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2090
             
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2091
      case "allocine":
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2092
          /* pass the options as-is to the allocine player and let it handle everything */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2093
          pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2094
          break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2095
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2096
      default:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2097
        pop = undefined;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2098
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2099
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2100
    return pop;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2101
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2102
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2103
/** Configure the gui and instantiate the widgets passed as parameters
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2104
    @param guiOptions the gui object as seen in the examples.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2105
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2106
IriSP.configureWidgets = function (popcornInstance, layoutManager, guiOptions) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2107
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2108
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2109
  var params = {width: guiOptions.width, height: guiOptions.height};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2110
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2111
  var default_options = guiOptions.default_options;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2112
  if (IriSP.null_or_undefined(default_options))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2113
    default_options = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2114
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2115
  var ret_widgets = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2116
  var index;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2117
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2118
  for (index = 0; index < guiOptions.widgets.length; index++) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2119
    var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, guiOptions.widgets[index], default_options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2120
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2121
    ret_widgets.push(widget);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2122
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2123
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2124
  return ret_widgets;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2125
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2126
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2127
/** configure modules. @see configureWidgets */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2128
IriSP.configureModules = function (popcornInstance, modulesList) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2129
  if (IriSP.null_or_undefined(modulesList))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2130
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2131
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2132
  var serialFactory = new IriSP.SerializerFactory(IriSP.__dataloader);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2133
  var ret_modules = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2134
  var index;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2135
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2136
  for (index = 0; index < modulesList.length; index++) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2137
    var moduleConfig = modulesList[index];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2138
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2139
    var serializer = serialFactory.getSerializer(moduleConfig.metadata);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2140
    var module = new IriSP[moduleConfig.type](popcornInstance, moduleConfig, serializer);    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2141
    ret_modules.push(module);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2142
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2143
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2144
  return ret_modules;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2145
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2146
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2147
/** instantiate a widget - only called by configureWidgets, never by the user. Handles widget 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2148
    dependencies.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2149
    @param popcornInstance popcorn instance the widget will user
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2150
    @param serialFactory serializer factory to instantiate the widget with
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2151
    @param layoutManager layout manager
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2152
    @param widgetConfig configuration options for the widget
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2153
    @param defaultOptions a dictionnary with some options defined for every widget.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2154
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2155
IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig, defaultOptions) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2156
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2157
    if (IriSP.null_or_undefined(defaultOptions))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2158
      defaultOptions = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2159
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2160
    widgetConfig = IriSP.underscore.defaults(widgetConfig, defaultOptions);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2161
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2162
    var arr = IriSP.jQuery.extend({}, widgetConfig);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2163
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2164
    /* create a div for those widgets who didn't already specify a container; */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2165
    if (!arr.hasOwnProperty("container")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2166
      /* create div returns us a container for the widget and a spacer */    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2167
      var ret = layoutManager.createDiv(widgetConfig.type);        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2168
      var container = ret[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2169
      var spacer = ret[1];           
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2170
      arr.container = container;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2171
      arr.spacer = spacer;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2172
      arr.layoutManager = layoutManager;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2173
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2174
    var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2175
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2176
    if (typeof serializer == "undefined")   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2177
      debugger;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2178
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2179
    // instantiate the object passed as a string
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2180
    var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer);    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2181
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2182
    if (widgetConfig.hasOwnProperty("requires")) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2183
      // also create the widgets this one depends on.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2184
      // the dependency widget is available in the parent widget context as
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2185
      // this.WidgetName (for instance, this.TipWidget);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2186
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2187
      var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2188
      for(i = 0; i < widgetConfig.requires.length; i++) {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2189
        var widgetName = widgetConfig.requires[i]["type"],
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2190
            _configobj = IriSP.jQuery.extend({}, widgetConfig.requires[i]),
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2191
            _div = document.createElement('div'),
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2192
            _container = IriSP.guid(arr.container + '_' + widgetName + '_');
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2193
        _configobj.container = _container;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2194
        _div.id = _container;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2195
        widget.selector.append(_div);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  2196
        widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, _configobj, defaultOptions);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2197
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2198
    }       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2199
     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2200
    serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2201
    return widget;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2202
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2203
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2204
/** Go through the defaults to set a reasonable value */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2205
IriSP.configureDefaults = function(libdir, platform_url) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2206
  /* the defaults configuration is messy and complicated. There are two things to know :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2207
     - we want to allow overwriting of defaults - that's why we have IriSP.widgetDefaults
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2208
       and IriSP.defaults.widgetDefaults. The first is filled by the embedder and then fleshed out
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2209
       with the contents of the first. We use underscore.defaults for that, but there's one problem with
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2210
       this function : it doesn't work recursively.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2211
     - we need to compute some values at runtime instead of at compile time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2212
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2213
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2214
  IriSP.lib = IriSP.underscore.defaults(IriSP.lib, IriSP.defaults.lib(libdir));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2215
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2216
  /* get the factory defaults for the widgets and merge them with the default the user
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2217
     may have defined 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2218
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2219
  var factory_defaults = IriSP.defaults.widgetsDefaults(platform_url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2220
  for(var widget in factory_defaults) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2221
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2222
      /* create the object if it doesn't exists */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2223
      if (IriSP.null_or_undefined(IriSP.widgetsDefaults[widget]))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2224
        IriSP.widgetsDefaults[widget] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2225
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2226
      IriSP.widgetsDefaults[widget] = IriSP.underscore.defaults(IriSP.widgetsDefaults[widget], factory_defaults[widget]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2227
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2228
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2229
  IriSP.paths = IriSP.underscore.defaults(IriSP.paths, IriSP.defaults.paths);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2230
  IriSP.default_templates_vars = IriSP.underscore.defaults(IriSP.default_templates_vars, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2231
                                       IriSP.defaults.default_templates_vars());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2232
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2233
  if (IriSP.null_or_undefined(IriSP.user))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2234
    IriSP.user = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2235
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2236
  IriSP.user = IriSP.underscore.defaults(IriSP.user, IriSP.defaults.user());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2237
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2238
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2239
/** single point of entry for the metadataplayer */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2240
IriSP.initPlayer = function(config, metadata_url, libdir, platform_url) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2241
    IriSP.configureDefaults(libdir, platform_url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2242
    IriSP.loadLibs(IriSP.lib, config, metadata_url,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2243
      function() {   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2244
              
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2245
              var layoutManager = new IriSP.LayoutManager(config.gui);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2246
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2247
              var pop = IriSP.configurePopcorn(layoutManager, config.player);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2248
              
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2249
              var widgets = IriSP.configureWidgets(pop, layoutManager, config.gui); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2250
              var modules = IriSP.configureModules(pop, config.modules); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2251
      });
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2252
};IriSP.i18n_factory = function() {
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2253
    this.messages = {};
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2254
    this.base_lang = 'en';
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2255
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2256
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2257
IriSP.i18n_factory.prototype.getLanguage = function(lang) {
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2258
    var _lang = (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2259
        typeof lang != "undefined"
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2260
        ? lang
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2261
        : (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2262
            typeof IriSP.language != "undefined"
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2263
            ? IriSP.language
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2264
            : this.base_lang
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2265
        )
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2266
    );
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2267
    return (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2268
        typeof this.messages[_lang] == "object"
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2269
        ? _lang
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2270
        : (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2271
            typeof this.messages[this.base_lang] == "object"
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2272
            ? this.base_lang
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2273
            : null
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2274
        )
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2275
    )
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2276
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2277
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2278
IriSP.i18n_factory.prototype.getMessages = function(lang) {
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2279
    var _lang = this.getLanguage(lang);
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2280
    return (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2281
        _lang != null
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2282
        ? this.messages[_lang]
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2283
        : {}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2284
    );
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2285
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2286
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2287
IriSP.i18n_factory.prototype.getMessage = function(message, lang) {
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2288
    var _msgs = this.getMessages(lang);
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2289
    return (
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2290
        typeof _msgs[message] != "undefined"
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2291
        ? _msgs[message]
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2292
        : message
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2293
    )
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2294
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2295
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2296
IriSP.i18n_factory.prototype.addMessage = function(lang, messagekey, messagevalue) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2297
    if (typeof this.messages[lang] == "undefined") {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2298
        this.messages[lang] = {};
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2299
    }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2300
    this.messages[lang][messagekey] = messagevalue;
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2301
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2302
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2303
IriSP.i18n_factory.prototype.addMessages = function(messagesObj) {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2304
    var _this = this;
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2305
    IriSP.underscore(messagesObj).each(function(_messages, _lang) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2306
        IriSP.underscore(_messages).each(function(_value, _key) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2307
            _this.addMessage(_lang, _key, _value);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2308
        })
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2309
    });
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2310
}
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2311
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2312
IriSP.i18n = new IriSP.i18n_factory();
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  2313
/* To wrap a player the develop should create a new class derived from
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2314
the IriSP.PopcornReplacement.player and defining the correct functions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2315
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2316
/** allocine player wrapper */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2317
IriSP.PopcornReplacement.allocine = function(container, options) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2318
//    console.log("Calling allocine player");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2319
    /* appel du parent pour initialiser les structures communes à tous les players */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2320
    IriSP.PopcornReplacement.player.call(this, container, options);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2321
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2322
    var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2323
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2324
    /* Définition des fonctions de l'API -  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2325
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2326
    this.playerFns = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2327
        play : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2328
            if (_this.player) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2329
            //    console.log("ask play _this.player = " + _this.player);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2330
                return _this.player.sendToActionScript("play");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2331
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2332
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2333
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2334
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2335
        pause : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2336
            if (_this.player) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2337
            //    console.log("ask pause _this.player = " + _this.player);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2338
                return _this.player.sendToActionScript("pause");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2339
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2340
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2341
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2342
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2343
        getPosition : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2344
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2345
                return _this.player.sendToActionScript("getSeek","return");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2346
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2347
                return 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2348
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2349
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2350
        seek : function(pos) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2351
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2352
                return _this.player.sendToActionScript("seek",pos);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2353
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2354
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2355
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2356
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2357
        getMute : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2358
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2359
                return _this.player.sendToActionScript("getMute","return");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2360
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2361
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2362
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2363
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2364
        setMute : function(p) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2365
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2366
                //return p ? _this.player.sendToActionScript("setMute") : _this.player.sendToActionScript("setMute");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2367
            	_this.player.sendToActionScript("setMute");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2368
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2369
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2370
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2371
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2372
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2373
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2374
    window.onReady = IriSP.wrap(this, this.ready);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2375
    //NOT CALLED window.onAllocineStateChange = IriSP.wrap(this, this.stateHandler);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2376
    window.onTime = IriSP.wrap(this, this.progressHandler);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2377
    
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2378
    var _videoUrl = (
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2379
        typeof options.directVideoPath == "string"
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2380
        ? options.directVideoPath
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2381
        : IriSP.get_aliased(IriSP.__jsonMetadata["medias"][0], ["href","url"])
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2382
    );
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2383
    
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2384
    var fv = "streamFMS=true&adVast=false&lg=fr_cinecast&autoPlay=" + options.autoPlay + "&directVideoTitle=&urlAcData=" + options.urlAcData + "&directVideoPath=" + _videoUrl + "&host=http://allocine.fr";
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2385
//    console.log("fv = " + fv);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2386
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2387
    var params = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2388
        "allowScriptAccess" : "always",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2389
        "wmode": "opaque",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2390
        "flashvars" : fv
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2391
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2392
    var atts = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2393
        id : this.container
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2394
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2395
    swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "8", null, null, params, atts);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2396
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2397
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2398
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2399
IriSP.PopcornReplacement.allocine.prototype = new IriSP.PopcornReplacement.player("", {});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2400
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2401
IriSP.PopcornReplacement.allocine.prototype.ready = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2402
    this.player = document.getElementById(this.container);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2403
    this.player.addEventListener("onStateChange", "onAllocineStateChange");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2404
    this.player.addEventListener("onVideoProgress", "onAllocineVideoProgress");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2405
    this.player.cueVideoByUrl(this._options.video);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2406
    this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2407
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2408
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2409
IriSP.PopcornReplacement.allocine.prototype.progressHandler = function(progressInfo) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2410
    this.callbacks.onTime({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2411
        position: progressInfo.mediaTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2412
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2413
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2414
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2415
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2416
IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2417
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2418
    switch(state) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2419
        case 1:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2420
            this.callbacks.onPlay();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2421
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2422
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2423
        case 2:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2424
            this.callbacks.onPause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2425
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2426
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2427
        case 3:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2428
            this.callbacks.onSeek({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2429
                position: this.player.getCurrentTime()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2430
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2431
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2432
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2433
        /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2434
        case 5:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2435
            this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2436
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2437
        */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2438
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2439
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2440
};/* To wrap a player the develop should create a new class derived from
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2441
the IriSP.PopcornReplacement.player and defining the correct functions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2442
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2443
/** jwplayer player wrapper */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2444
IriSP.PopcornReplacement.dailymotion = function(container, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2445
    console.log("Calling");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2446
    /* appel du parent pour initialiser les structures communes à tous les players */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2447
    IriSP.PopcornReplacement.player.call(this, container, options);   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2448
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2449
    var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2450
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2451
    /* Définition des fonctions de l'API -  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2452
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2453
    this.playerFns = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2454
        play : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2455
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2456
                return _this.player.playVideo();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2457
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2458
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2459
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2460
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2461
        pause : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2462
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2463
                return _this.player.pauseVideo();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2464
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2465
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2466
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2467
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2468
        getPosition : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2469
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2470
                return _this.player.getCurrentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2471
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2472
                return 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2473
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2474
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2475
        seek : function(pos) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2476
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2477
                return _this.player.seekTo(pos);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2478
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2479
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2480
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2481
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2482
        getMute : function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2483
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2484
                return _this.player.isMuted();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2485
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2486
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2487
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2488
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2489
        setMute : function(p) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2490
            if (_this.player) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2491
                return p ? _this.player.mute() : _this.player.unMute();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2492
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2493
                return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2494
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2495
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2496
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2497
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2498
    window.onDailymotionPlayerReady = IriSP.wrap(this, this.ready);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2499
    window.onDailymotionStateChange = IriSP.wrap(this, this.stateHandler);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2500
    window.onDailymotionVideoProgress = IriSP.wrap(this, this.progressHandler);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2501
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2502
    var params = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2503
        "allowScriptAccess" : "always",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2504
        "wmode": "opaque"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2505
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2506
    var atts = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2507
        id : this.container
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2508
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2509
    swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2510
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2511
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2512
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2513
IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2514
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2515
IriSP.PopcornReplacement.dailymotion.prototype.ready = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2516
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2517
    this.player = document.getElementById(this.container);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2518
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2519
    this.player.addEventListener("onStateChange", "onDailymotionStateChange");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2520
    this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2521
    this.player.cueVideoByUrl(this._options.video);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2522
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2523
    this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2524
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2525
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2526
IriSP.PopcornReplacement.dailymotion.prototype.progressHandler = function(progressInfo) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2527
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2528
    this.callbacks.onTime({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2529
        position: progressInfo.mediaTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2530
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2531
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2532
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2533
IriSP.PopcornReplacement.dailymotion.prototype.stateHandler = function(state) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2534
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2535
    switch(state) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2536
        case 1:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2537
            this.callbacks.onPlay();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2538
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2539
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2540
        case 2:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2541
            this.callbacks.onPause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2542
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2543
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2544
        case 3:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2545
            this.callbacks.onSeek({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2546
                position: this.player.getCurrentTime()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2547
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2548
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2549
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2550
        /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2551
        case 5:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2552
            this.callbacks.onReady();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2553
            break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2554
        */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2555
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2556
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2557
};/* To wrap a player the develop should create a new class derived from 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2558
   the IriSP.PopcornReplacement.player and defining the correct functions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2559
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2560
/** jwplayer player wrapper */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2561
IriSP.PopcornReplacement.jwplayer = function(container, options) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2562
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2563
  /* appel du parent pour initialiser les structures communes à tous les players */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2564
  IriSP.PopcornReplacement.player.call(this, container, options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2565
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2566
  this.media.duration = options.duration; /* optional */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2567
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2568
  /* Définition des fonctions de l'API -  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2569
  this.playerFns = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2570
    play: function() { return jwplayer(this.container).play(); },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2571
    pause: function() { return jwplayer(this.container).pause(); },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2572
    getPosition: function() { return jwplayer(this.container).getPosition(); },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2573
    seek: function(pos) { return jwplayer(this.container).seek(pos); },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2574
    getMute: function() { return jwplayer(this.container).getMute() },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2575
    setMute: function(p) { return jwplayer(this.container).setMute(p); }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2576
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2577
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2578
  options.events = this.callbacks;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2579
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2580
  jwplayer(this.container).setup(options);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2581
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2582
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2583
IriSP.PopcornReplacement.jwplayer.prototype = new IriSP.PopcornReplacement.player("", {});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2584
/* embed module - listens and relay hash changes to a parent window. */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2585
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2586
IriSP.EmbedModule = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2587
  IriSP.Module.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2588
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2589
  window.addEventListener('message', IriSP.wrap(this, this.handleMessages), false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2590
  this._Popcorn.listen("IriSP.Mediafragment.hashchange", IriSP.wrap(this, this.relayChanges));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2591
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2592
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2593
IriSP.EmbedModule.prototype = new IriSP.Module();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2594
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2595
IriSP.EmbedModule.prototype.handleMessages = function(e) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2596
  if (e.data.type === "hashchange") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2597
    window.location.hash = e.data.value;    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2598
  }  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2599
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2600
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2601
IriSP.EmbedModule.prototype.relayChanges = function(newHash) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2602
  window.parent.postMessage({type: "hashchange", value: newHash}, "*"); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2603
  return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2604
};/* mediafragment module */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2605
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2606
IriSP.MediaFragment = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2607
  IriSP.Module.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2608
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2609
  this.mutex = false; /* a mutex because we access the url from two different functions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2610
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2611
  this._Popcorn.listen( "loadedmetadata", IriSP.wrap(this,this.advanceTime));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2612
  this._Popcorn.listen( "pause", IriSP.wrap(this,this.updateTime));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2613
  this._Popcorn.listen( "seeked", IriSP.wrap(this,this.updateTime));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2614
  this._Popcorn.listen( "IriSP.PolemicTweet.click", IriSP.wrap(this,this.updateAnnotation));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2615
  this._Popcorn.listen( "IriSP.SegmentsWidget.click", IriSP.wrap(this,this.updateAnnotation));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2616
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2617
  window.onhashchange = IriSP.wrap(this, this.advanceTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2618
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2619
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2620
IriSP.MediaFragment.prototype = new IriSP.Module();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2621
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2622
IriSP.MediaFragment.prototype.advanceTime = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2623
             var url = window.location.href;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2624
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2625
              if ( url.split( "#" )[ 1 ] != null ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2626
                  pageoffset = url.split( "#" )[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2627
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2628
                  if ( pageoffset.substring(0, 2) === "t=") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2629
                    // timecode 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2630
                    if ( pageoffset.substring( 2 ) != null ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2631
                    var offsettime = pageoffset.substring( 2 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2632
                    this._Popcorn.currentTime( parseFloat(offsettime) );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2633
                    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2634
                    /* we have to trigger this signal manually because of a
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2635
                     bug in the jwplayer */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2636
                    this._Popcorn.trigger("seeked", parseFloat(offsettime));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2637
                    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2638
                  } else if ( pageoffset.substring(0, 3) === "id=") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2639
                    // annotation
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2640
                    var annotationId = pageoffset.substring( 3 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2641
                    // there's no better way than that because
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2642
                    // of possible race conditions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2643
                    this._serializer.sync(IriSP.wrap(this, function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2644
                          this.lookupAnnotation.call(this, annotationId); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2645
                          }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2646
                  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2647
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2648
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2649
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2650
/** handler for the seeked signal. It may have or may have not an argument.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2651
    @param time if not undefined, the time we're seeking to 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2652
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2653
IriSP.MediaFragment.prototype.updateTime = function(time) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2654
  if (this.mutex === true) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2655
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2656
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2657
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2658
  var history = window.history;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2659
  if ( !history.pushState ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2660
    return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2661
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2662
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2663
  if (IriSP.null_or_undefined(time) || typeof(time) != "number") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2664
    var ntime = this._Popcorn.currentTime().toFixed(2)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2665
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2666
    var ntime = time.toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2667
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2668
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2669
  // used to relay the new hash to the embedder
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2670
  this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#t=" + ntime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2671
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2672
  splitArr = window.location.href.split( "#" )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2673
  history.replaceState( {}, "", splitArr[0] + "#t=" + ntime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2674
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2675
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2676
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2677
IriSP.MediaFragment.prototype.updateAnnotation = function(annotationId) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2678
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2679
  this.mutex = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2680
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2681
  var history = window.history;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2682
  if ( !history.pushState ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2683
    return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2684
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2685
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2686
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2687
  // used to relay the new hash to the embedder
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2688
  this._Popcorn.trigger("IriSP.Mediafragment.hashchange", "#id=" + annotationId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2689
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2690
  splitArr = window.location.href.split( "#" )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2691
  history.replaceState( {}, "", splitArr[0] + "#id=" + annotationId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2692
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2693
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2694
  // reset the mutex afterwards to prevent the module from reacting to his own changes.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2695
  window.setTimeout(function() { _this.mutex = false }, 50);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2696
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2697
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2698
// lookup and seek to the beginning of an annotation
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2699
IriSP.MediaFragment.prototype.lookupAnnotation = function(annotationId) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2700
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2701
  this.mutex = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2702
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2703
  var annotation = undefined;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2704
  var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2705
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2706
  var i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2707
  for (i = 0; i < annotations.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2708
      if (annotations[i].id === annotationId) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2709
        annotation = annotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2710
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2711
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2712
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2713
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2714
  if (typeof(annotation) !== "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2715
    this._Popcorn.currentTime(annotation.begin / 1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2716
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2717
    /* we have to trigger this signal manually because of a
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2718
     bug in the jwplayer */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2719
    this._Popcorn.trigger("seeked", annotation.begin / 1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2720
    this._Popcorn.trigger("IriSP.Mediafragment.showAnnotation", annotationId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2721
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2722
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2723
  window.setTimeout(function() { _this.mutex = false }, 50);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2724
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2725
IriSP.AnnotationsListWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2726
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2727
  this.__counter = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2728
  this.__oldList = [];
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2729
 
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2730
  this.checkOption('ajax_mode');
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2731
  this.checkOption('project_url');
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2732
  this.checkOption('default_thumbnail');
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2733
  this.checkOption("cinecast_version", false);
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2734
  this.searchRe = null;
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2735
  this._ajax_cache = [];
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2736
  var _this = this;
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2737
  
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2738
  this._Popcorn.listen("IriSP.search", function(searchString) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2739
      _this.searchHandler(searchString);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2740
  });
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2741
  this._Popcorn.listen("IriSP.search.closed", function() {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2742
      _this.searchHandler(false);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2743
  });
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2744
  this._Popcorn.listen("IriSP.search.cleared", function() {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2745
      _this.searchHandler(false);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2746
  });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2747
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2748
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2749
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2750
IriSP.AnnotationsListWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2751
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2752
IriSP.AnnotationsListWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2753
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2754
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2755
IriSP.AnnotationsListWidget.prototype.clearWidget = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2756
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2757
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2758
IriSP.AnnotationsListWidget.prototype.searchHandler = function(searchString) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2759
  this.searchRe = (searchString && searchString.length) ? IriSP.regexpFromText(searchString) : null;
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2760
  if (this.ajax_mode) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2761
      var _this = this,
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2762
        _annotations = (
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2763
            this.searchRe === null
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2764
            ? this._ajax_cache
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2765
            : IriSP.underscore.filter(this._ajax_cache, function(_a) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2766
               return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2767
            })
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2768
        );
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2769
    this.do_redraw(_annotations);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2770
    if (_annotations.length) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2771
        this._Popcorn.trigger("IriSP.search.matchFound");
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2772
      } else {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2773
        this._Popcorn.trigger("IriSP.search.noMatchFound");
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2774
      }    
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2775
  } else {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2776
      this.drawList();
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2777
  }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2778
}
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2779
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2780
/** effectively redraw the widget - called by drawList */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2781
IriSP.AnnotationsListWidget.prototype.do_redraw = function(list) {
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2782
    var _html = IriSP.templToHTML(
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2783
        IriSP.annotationsListWidget_template, {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2784
            annotations: list
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2785
        }),
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2786
        _this = this;
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2787
      
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2788
    this.selector.html(_html);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2789
    
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2790
    if (this.searchRe !== null) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2791
        this.selector.find(".Ldt-AnnotationsList-Title a, .Ldt-AnnotationsList-Description")
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2792
            .each(function()  {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2793
                var _$ = IriSP.jQuery(this);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2794
                _$.html(_$.text().replace(_this.searchRe, '<span class="Ldt-AnnotationsList-highlight">$1</span>'))
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2795
            })
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2796
    }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2797
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2798
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2799
IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2800
    var _this = this
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2801
    return {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2802
        "id" : a.id,
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2803
        "title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title,
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2804
        "desc" : this.cinecast_version ? a.content.data : a.content.description,
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2805
        "begin": IriSP.msToTime(a.begin),
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2806
        "end" : IriSP.msToTime(a.end),
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2807
        "thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2808
        "url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null,
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2809
        "tags": typeof a.tags == "object"
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2810
            ? IriSP.underscore(a.tags)
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2811
                .chain()
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2812
                .map(function(_t) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2813
                    if (typeof _t == "string") {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2814
                        return _t.replace(/^.*:/,'#');
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2815
                    } else {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2816
                        if (typeof _t['id-ref'] != "undefined") {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2817
                            var _f = IriSP.underscore.find(_this._serializer._data.tags, function(_tag) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2818
                                return _tag['id-ref'] == _t.id;
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2819
                            });
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2820
                            if (typeof _f != "undefined") {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2821
                                return IriSP.get_aliased(_f.meta, ['dc:title', 'title']);
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2822
                            }
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2823
                        }
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2824
                    }
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2825
                    return null;
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2826
                })
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2827
                .filter(function(_t) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2828
                    return _t !== null && _t !== ""
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2829
                })
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2830
                .value()
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2831
            : []
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2832
    }    
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2833
}
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2834
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2835
/** draw the annotation list */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2836
IriSP.AnnotationsListWidget.prototype.drawList = function(force_redraw) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2837
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2838
  
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2839
//  var view_type = this._serializer.getContributions();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2840
  var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2841
  var currentTime = this._Popcorn.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2842
  var list = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2843
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2844
/*  if (typeof(view_type) === "undefined") {    
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2845
    return;
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2846
} */
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2847
  for (i = 0; i < annotations.length; i++) {
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2848
    var obj = this.transformAnnotation(annotations[i]);
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2849
    obj.iterator = i;
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2850
    obj.distance = Math.abs((annotations[i].end + annotations[i].begin) / 2000 - currentTime);
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2851
    if (!this.cinecast_version || annotations[i].type == "cinecast:UserAnnotation") {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2852
        list.push(obj);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2853
    }
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2854
    
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2855
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2856
  
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2857
    if (this.searchRe !== null) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2858
        list = list.filter(function(_a) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2859
            return (_this.searchRe.test(_a.desc) || _this.searchRe.test(_a.title)); 
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2860
        });
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2861
        if (list.length) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2862
            this._Popcorn.trigger("IriSP.search.matchFound");
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2863
          } else {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2864
            this._Popcorn.trigger("IriSP.search.noMatchFound");
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2865
          }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2866
    }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2867
  
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2868
  list = IriSP.underscore(list)
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2869
    .chain()
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2870
    .sortBy(function(_o) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2871
        return _o.distance;
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2872
    })
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2873
    .first(10)
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2874
    .sortBy(function(_o) {
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2875
        return _o.iterator;
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2876
    })
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2877
    .value();
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2878
  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2879
  var idList = IriSP.underscore.pluck(list, "id").sort();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2880
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2881
  
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2882
  if (!IriSP.underscore.isEqual(this.__oldList, idList) || typeof(force_redraw) !== "undefined") {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2883
    this.do_redraw(list);
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2884
    this.__oldList = idList;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2885
  }
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2886
   /* save for next call */
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2887
  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2888
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2889
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2890
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2891
IriSP.AnnotationsListWidget.prototype.ajaxRedraw = function(timecode) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2892
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2893
  /* the seeked signal sometimes passes an argument - depending on if we're using
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2894
     our popcorn lookalike or the real thing - if it's the case, use it as it's
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2895
     more precise than currentTime which sometimes contains the place we where at */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2896
  if (IriSP.null_or_undefined(timecode) || typeof(timecode) != "number") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2897
     var tcode = this._Popcorn.currentTime();     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2898
   } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2899
     var tcode = timecode;     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2900
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2901
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2902
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2903
  /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2904
     we double the braces using regexps and we feed it to mustache to build the correct url
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2905
     we have to do that because the platform only knows at run time what view it's displaying.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2906
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2907
     
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2908
  var platf_url = IriSP.widgetsDefaults.AnnotationsListWidget.ajax_url
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2909
                                      .replace(/\{/g, '{{').replace(/\}/g, '}}');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2910
  var media_id = this._serializer.currentMedia()["id"];
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  2911
  var duration = this._serializer.getDuration();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2912
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2913
  var begin_timecode = (Math.floor(tcode) - 300) * 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2914
  if (begin_timecode < 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2915
    begin_timecode = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2916
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2917
  var end_timecode = (Math.floor(tcode) + 300) * 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2918
  if (end_timecode > duration)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2919
    end_timecode = duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2920
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2921
  var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2922
                                 end: end_timecode});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2923
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2924
  /* we create on the fly a serializer to get the ajax */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2925
  var serializer = new IriSP.JSONSerializer(IriSP.__dataloader, templ);
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2926
  serializer.sync(IriSP.wrap(this, function(json) { this.processJson(json, serializer) }));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2927
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2928
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2929
/** process the received json - it's a bit hackish */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2930
IriSP.AnnotationsListWidget.prototype.processJson = function(json, serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2931
  /* FIXME: DRY the whole thing */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2932
  var annotations = serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2933
  if (IriSP.null_or_undefined(annotations))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2934
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2935
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2936
  /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2937
  commented in case we wanted to discriminate against some annotation types.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2938
  var view_types = serializer.getIds("Contributions");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2939
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2940
  var l = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2941
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2942
  var media = this._serializer.currentMedia()["id"];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2943
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2944
  for (i = 0; i < annotations.length; i++) {
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2945
    var obj = this.transformAnnotation(annotations[i])
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2946
      if (typeof obj.url == "undefined" || !obj.url) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2947
          /* only if the annotation isn't present in the document create an
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2948
             external link */
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2949
          if (!this.annotations_ids.indexOf(obj.id) != -1) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2950
            // braindead url; jacques didn't want to create a new one in the platform,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2951
            // so we append the cutting id to the url.
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2952
            obj.url = this.project_url + "/" + media + "/" + 
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2953
                         annotations[i].meta.project + "/" +
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2954
                         annotations[i].meta["id-ref"] + '#id=' + annotations[i].id;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2955
            
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2956
            // obj.url = document.location.href.split("#")[0] + "/" + annotation.meta.project;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2957
          }
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  2958
          }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2959
      l.push(obj);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2960
  }
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2961
  this._ajax_cache = l;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2962
  this.do_redraw(l);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2963
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2964
IriSP.AnnotationsListWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2965
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2966
  /* build a table of the annotations present in the document for faster 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2967
     lookup
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2968
  */
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2969
  this.annotations_ids = [];
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2970
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2971
  var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2972
  var i = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2973
  for(i = 0; i < annotations.length; i++) {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  2974
    this.annotations_ids.push(annotations[i]["id"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2975
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2976
  
833
33a5d5882be4 Last commit before weekend
veltr
parents: 832
diff changeset
  2977
  var _this = this;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2978
    
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2979
    if (!this.ajax_mode) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2980
        var _throttled = IriSP.underscore.throttle(function() {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2981
            _this.drawList();
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2982
        }, 1500);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2983
        _throttled();
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2984
        this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", _throttled);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2985
        this._Popcorn.listen("timeupdate", _throttled);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2986
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2987
    /* update the widget when the video has finished loading and when it's seeked and paused */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2988
    this._Popcorn.listen("seeked", IriSP.wrap(this, this.ajaxRedraw));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2989
    this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.ajaxRedraw));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2990
    this._Popcorn.listen("paused", IriSP.wrap(this, this.ajaxRedraw));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2991
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2992
    this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.ajaxRedraw));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2993
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2994
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2995
};/* Internationalization for this widget */
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2996
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2997
IriSP.i18n.addMessages(
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2998
    {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  2999
        "fr": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3000
            "keywords": "Mots-clés"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3001
        },
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3002
        "en": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3003
            "keywords": "Keywords"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3004
        }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3005
    }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3006
);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3007
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3008
IriSP.AnnotationsWidget = function(Popcorn, config, Serializer) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3009
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3010
  /* flag used when we're creating an annotation */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3011
  this._hidden = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3012
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3013
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3014
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3015
IriSP.AnnotationsWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3016
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3017
IriSP.AnnotationsWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3018
    this.selector.find(".Ldt-SaTitle").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3019
    this.selector.find(".Ldt-SaDescription").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3020
    this.selector.find(".Ldt-SaKeywordText").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3021
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3022
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3023
IriSP.AnnotationsWidget.prototype.displayAnnotation = function(annotation) {       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3024
    var title = annotation.content.title;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3025
    var description = annotation.content.description;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3026
    var keywords =  "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3027
    var begin = +annotation.begin / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3028
    var end = +annotation.end / 1000;
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3029
    var duration = this._serializer.getDuration();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3030
    var tags = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3031
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3032
    var title_templ = "{{title}} - ( {{begin}} - {{end}} )";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3033
    var endstr = Mustache.to_html(title_templ, {title: title, begin: IriSP.secondsToTime(begin), end: IriSP.secondsToTime(end)});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3034
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3035
    this.selector.find(".Ldt-SaTitle").text(endstr);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3036
    this.selector.find(".Ldt-SaDescription").text(description);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3037
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3038
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3039
    if (!IriSP.null_or_undefined(annotation.tags) && !IriSP.null_or_undefined(this._serializer._data.tags)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3040
      /* save the tag id and keywords in a unique structure */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3041
      var tag_list = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3042
      for (var i = 0; i < this._serializer._data.tags.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3043
        var id = this._serializer._data.tags[i]["id"];
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3044
        var keyword = IriSP.get_aliased(this._serializer._data.tags[i]["meta"], ["dc:title", "title"]);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3045
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3046
        tag_list[id] = keyword;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3047
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3048
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3049
      /* then browse the list of defined tags for the current annotation */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3050
      for (var i = 0; i < annotation.tags.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3051
        if (tag_list.hasOwnProperty(annotation.tags[i]["id-ref"]))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3052
          tags += tag_list[annotation.tags[i]["id-ref"]] + ", ";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3053
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3054
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3055
    
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3056
    tags = IriSP.i18n.getMessage("keywords") + ": " + tags.slice(0, tags.length - 2);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3057
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3058
    this.selector.find(".Ldt-SaKeywords").text(tags);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3059
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3060
    // update sharing buttons
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3061
    var defaults = IriSP.widgetsDefaults.AnnotationsWidget;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3062
    var text = defaults.share_text;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3063
    var fb_link = defaults.fb_link;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3064
    var tw_link = defaults.tw_link;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3065
    var gplus_link = defaults.gplus_link;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3066
    var url = document.location.href + "#id=" + annotation.id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3067
    this.selector.find(".Ldt-fbShare").attr("href", IriSP.mkFbUrl(url, text));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3068
    this.selector.find(".Ldt-TwShare").attr("href", IriSP.mkTweetUrl(url, text));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3069
    this.selector.find(".Ldt-GplusShare").attr("href", IriSP.mkGplusUrl(url, text));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3070
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3071
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3072
IriSP.AnnotationsWidget.prototype.clearWidget = function() {   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3073
    /* retract the pane between two annotations */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3074
    this.selector.find(".Ldt-SaTitle").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3075
    this.selector.find(".Ldt-SaDescription").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3076
    this.selector.find(".Ldt-SaKeywordText").html("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3077
    this.selector.find(".Ldt-ShowAnnotation").slideUp();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3078
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3079
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3080
IriSP.AnnotationsWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3081
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3082
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3083
  var annotationMarkup = IriSP.templToHTML(IriSP.annotationWidget_template);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3084
	this.selector.append(annotationMarkup);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3085
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3086
  this._Popcorn.listen("IriSP.AnnotationsWidget.show", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3087
                        IriSP.wrap(this, this.show));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3088
  this._Popcorn.listen("IriSP.AnnotationsWidget.hide", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3089
                        IriSP.wrap(this, this.hide));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3090
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3091
  var legal_ids = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3092
  if (typeof(this._serializer.getChapitrage()) !== "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3093
    legal_ids.push(this._serializer.getChapitrage());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3094
  else 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3095
    legal_ids = this._serializer.getNonTweetIds();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3096
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3097
  var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3098
  var i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3099
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3100
	for (i in annotations) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3101
    var annotation = annotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3102
    var begin = Math.round((+ annotation.begin) / 1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3103
    var end = Math.round((+ annotation.end) / 1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3104
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3105
    if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3106
          && !IriSP.underscore.include(legal_ids, annotation.meta["id-ref"])) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3107
        continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3108
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3109
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3110
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3111
    var conf = {start: begin, end: end, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3112
                onStart: 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3113
                       function(annotation) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3114
                        return function() { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3115
                            _this.displayAnnotation(annotation); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3116
                          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3117
                        } }(annotation),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3118
                onEnd: 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3119
                       function() { _this.clearWidget.call(_this); }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3120
                };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3121
    this._Popcorn = this._Popcorn.code(conf);                                             
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3122
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3123
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3124
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3125
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3126
IriSP.AnnotationsWidget.prototype.hide = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3127
  if (this._hidden == false) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3128
    this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3129
    this._hidden = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3130
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3131
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3132
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3133
IriSP.AnnotationsWidget.prototype.show = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3134
  if (this._hidden == true) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3135
    this.selector.show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3136
    this._hidden = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3137
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3138
};IriSP.ArrowWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3139
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3140
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3141
  this._oldAnnotation = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3142
  this._blockArrow = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3143
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3144
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3145
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3146
IriSP.ArrowWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3147
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3148
IriSP.ArrowWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3149
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3150
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3151
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3152
IriSP.ArrowWidget.prototype.clearWidget = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3153
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3154
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3155
IriSP.ArrowWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3156
  var templ = Mustache.to_html(IriSP.arrowWidget_template, {});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3157
  this.selector.append(templ);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3158
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3159
  this._Popcorn.listen("IriSP.ArrowWidget.blockArrow", IriSP.wrap(this, this.blockArrow));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3160
  this._Popcorn.listen("IriSP.ArrowWidget.releaseArrow", IriSP.wrap(this, this.releaseArrow));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3161
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3162
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3163
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3164
IriSP.ArrowWidget.prototype.timeUpdateHandler = function(percents) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3165
  if (this._blockArrow)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3166
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3167
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3168
  var currentTime = this._Popcorn.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3169
  var currentAnnotation = this._serializer.currentChapitre(currentTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3170
  if (IriSP.null_or_undefined(currentAnnotation)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3171
    var c_annots = this._serializer.currentAnnotation(currentTime)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3172
    if (c_annots.length != 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3173
      var currentAnnotation = c_annots[0]; // FIXME : use the others ?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3174
    else
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3175
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3176
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3177
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3178
  /* move the arrow only if the current annotation changes */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3179
  if (currentAnnotation != this._oldAnnotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3180
    var begin = (+ currentAnnotation.begin) / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3181
    var end = (+ currentAnnotation.end) / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3182
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3183
    var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3184
    var middle_time = (begin + end) / 2;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3185
    var percents = middle_time / duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3186
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3187
    // we need to apply a fix because the arrow has a certain length
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3188
    // it's half the length of the arrow (27 / 2). We need to convert
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3189
    // it in percents though.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3190
    var totalWidth = this.selector.width();    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3191
    var pixels = percents * totalWidth;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3192
    var correction = (27 / 2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3193
    var corrected_pixels = pixels - correction;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3194
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3195
    /* make sure that the arrow is aligned with the pattern
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3196
       of the widget under it */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3197
    if (corrected_pixels % 3 != 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3198
      corrected_pixels -= (corrected_pixels % 3 - 1);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3199
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3200
    /* don't move out of the screen */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3201
    if (corrected_pixels <= 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3202
      corrected_pixels = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3203
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3204
    if (corrected_pixels <= 15) {      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3205
      this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3206
                                                .addClass("Ldt-arrowLeftEdge"); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3207
    } else if (corrected_pixels >= totalWidth - 25) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3208
           this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3209
                                                .addClass("Ldt-arrowRightEdge"); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3210
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3211
      this.selector.children(".Ldt-arrowWidget").removeClass("Ldt-arrowLeftEdge Ldt-arrowCenter Ldt-arrowRightEdge")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3212
                                                .addClass("Ldt-arrowCenter"); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3213
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3214
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3215
    this.selector.children(".Ldt-arrowWidget").animate({"left" : corrected_pixels + "px"});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3216
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3217
    this._oldAnnotation = currentAnnotation;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3218
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3219
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3220
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3221
/** Block the arrow for instance when the user is annotating */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3222
IriSP.ArrowWidget.prototype.blockArrow = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3223
  this._blockArrow = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3224
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3225
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3226
IriSP.ArrowWidget.prototype.releaseArrow = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3227
  this._blockArrow = false;   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3228
};
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3229
/* Internationalization for this widget */
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3230
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3231
IriSP.i18n.addMessages(
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3232
    {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3233
        "en": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3234
            "submit": "Submit",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3235
            "add_keywords": "Add keywords",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3236
            "add_polemic_keywords": "Add polemic keywords",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3237
            "your_name": "Your name",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3238
            "type_here": "Type your annotation here.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3239
            "wait_while_processed": "Please wait while your request is being processed...",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3240
            "error_while_contacting": "An error happened while contacting the server. Your annotation has not been saved.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3241
            "empty_annotation": "Your annotation is empty. Please write something before submitting.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3242
            "annotation_saved": "Thank you, your annotation has been saved.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3243
            "share_annotation": "Would you like to share it on social networks ?",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3244
            "share_on": "Share on"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3245
        },
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3246
        "fr": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3247
            "submit": "Envoyer",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3248
            "add_keywords": "Ajouter des mots-clés",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3249
            "add_polemic_keywords": "Ajouter des mots-clés polémiques",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3250
            "your_name": "Votre nom",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3251
            "type_here": "Rédigez votre annotation ici.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3252
            "wait_while_processed": "Veuillez patienter pendant le traitement de votre requête...",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3253
            "error_while_contacting": "Une erreur s'est produite en contactant le serveur. Votre annotation n'a pas été enregistrée",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3254
            "empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3255
            "annotation_saved": "Merci, votre annotation a été enregistrée.",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3256
            "share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3257
            "share_on": "Partager sur"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3258
        }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3259
    }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3260
);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3261
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3262
IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3263
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3264
  this._hidden = true;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3265
  
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3266
  this.checkOption("keywords");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3267
  this.checkOption("polemic_mode", true);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3268
  this.checkOption("polemics");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3269
  this.checkOption("cinecast_version", false);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3270
  this.checkOption("api_endpoint_template");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3271
  this.checkOption("show_from_field", true);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3272
  this.checkOption("api_method");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3273
                         
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3274
  if (!IriSP.null_or_undefined(IriSP.user)) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3275
      if (!IriSP.null_or_undefined(IriSP.user.avatar)) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3276
        this.user_avatar = IriSP.user.avatar;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3277
      }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3278
      if (!IriSP.null_or_undefined(IriSP.user.name)) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3279
        this.user_name = IriSP.user.name;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3280
      }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3281
  }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3282
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3283
  /* variables to save the current position of the slicer */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3284
  if (this.cinecast_version) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3285
    this.sliceLeft = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3286
    this.sliceWidth = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3287
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3288
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3289
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3290
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3291
IriSP.createAnnotationWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3292
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3293
IriSP.createAnnotationWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3294
    this.selector.find(".Ldt-SaTitle").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3295
    this.selector.find(".Ldt-SaDescription").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3296
    this.selector.find(".Ldt-SaKeywordText").text("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3297
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3298
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3299
IriSP.createAnnotationWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3300
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3301
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3302
  var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, 
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3303
                                           this);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3304
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3305
	this.selector.append(annotationMarkup);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3306
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3307
  if (!this.cinecast_version)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3308
    this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3309
  else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3310
    this.showStartScreen();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3311
  }
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3312
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3313
  // Add onclick event to both polemic and keywords buttons
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3314
  
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3315
  this.selector.find(".Ldt-createAnnotation-btnblock button").click(function() {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3316
      _this.addKeyword(IriSP.jQuery(this).text());
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3317
  });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3318
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3319
  // js_mod is a custom event because there's no simple way to test for a js
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3320
  // change in a textfield.                    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3321
  this.selector.find(".Ldt-createAnnotation-Description")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3322
               .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3323
               
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3324
  /* the cinecast version of the player is supposed to pause when the user clicks on the button */
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  3325
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3326
  /* the cinecast version expects the user to comment on a defined segment.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3327
     As the widget is always shown, we need a way to update it's content as
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3328
     time passes. We do this like we did with the annotationsWidget : we schedule
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3329
     a .code start function which will be called at the right time.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3330
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3331
  if (this.cinecast_version) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3332
    var legal_ids;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3333
    if (typeof(this._serializer.getChapitrage()) !== "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3334
      legal_id = this._serializer.getChapitrage();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3335
    else 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3336
      legal_id = this._serializer.getNonTweetIds()[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3337
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3338
    var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3339
    var i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3340
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3341
    for (i in annotations) {     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3342
      var annotation = annotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3343
      if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3344
            && legal_id !== annotation.meta["id-ref"]) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3345
          continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3346
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3347
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3348
      code = {start: annotation.begin / 1000, end: annotation.end / 1000,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3349
              onStart: function(annotation) { return function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3350
                      if (typeof(annotation.content) !== "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3351
                        _this.selector.find(".Ldt-createAnnotation-Title").html(annotation.content.title);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3352
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3353
                      _this._currentAnnotation = annotation;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3354
                      var beginTime = IriSP.msToTime(annotation.begin);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3355
                      var endTime = IriSP.msToTime(annotation.end);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3356
                      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3357
                      _this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3358
              } }(annotation)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3359
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3360
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3361
      this._Popcorn.code(code);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3362
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3363
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3364
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3365
  this.selector.find(".Ldt-createAnnotation-submitButton").click(IriSP.wrap(this, this.handleButtonClick));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3366
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3367
  if (!this.cinecast_version) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3368
    this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3369
                          IriSP.wrap(this, this.handleAnnotateSignal));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3370
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3371
    // handle clicks on the cancel button too.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3372
    this.selector.find(".Ldt-createAnnotation-Minimize").click(IriSP.wrap(this, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3373
      function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3374
        // we've got to simulate the pressing of the button because there's no
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3375
        // other way to minimize the widget and show the widgets that were hidden
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3376
        // same time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3377
        this._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3378
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3379
    ));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3380
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3381
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3382
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3383
/* Handles adding keywords and polemics */
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3384
IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3385
    var _field = this.selector.find(".Ldt-createAnnotation-Description"),
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3386
        _rx = IriSP.regexpFromText(_keyword),
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3387
        _contents = _field.val();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3388
    _contents = ( _rx.test(_contents)
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3389
        ? _contents.replace(_rx,"").replace("  "," ").trim()
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3390
        : _contents.trim() + " " + _keyword
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3391
    );
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3392
    _field.val(_contents);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3393
    _field.trigger("js_mod");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3394
}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3395
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3396
/** handles clicks on the annotate button. Works only for the non-cinecast version */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3397
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3398
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3399
  if (this._hidden == false && this._state == 'startScreen') {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3400
    this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3401
    this._hidden = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3402
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3403
    // free the arrow.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3404
    this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3405
    this._Popcorn.trigger("IriSP.SliceWidget.hide");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3406
    this._Popcorn.trigger("IriSP.AnnotationsWidget.show");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3407
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3408
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3409
    this._Popcorn.trigger("IriSP.AnnotationsWidget.hide");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3410
    this.showStartScreen();    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3411
    this.selector.show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3412
    this._hidden = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3413
    var currentTime = this._Popcorn.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3414
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3415
    // block the arrow.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3416
    this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3417
    
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3418
    var duration = this._serializer.getDuration();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3419
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3420
    var currentChapter = this._serializer.currentChapitre(currentTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3421
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3422
    if (IriSP.null_or_undefined(currentChapter)) {      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3423
      var left = this.selector.width() / 2;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3424
      var width = this.selector.width() / 10;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3425
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3426
      var left = (currentChapter.begin / duration) * this.selector.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3427
      var width = (currentChapter.end / duration) * this.selector.width() - left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3428
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3429
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3430
    // slider position and length is kept in percents.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3431
    this.sliceLeft = (left / this.selector.width()) * 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3432
    this.sliceWidth = (width / this.selector.width()) * 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3433
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3434
    this._Popcorn.trigger("IriSP.SliceWidget.position", [left, width]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3435
    this._Popcorn.listen("IriSP.SliceWidget.zoneChange", IriSP.wrap(this, this.handleSliderChanges));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3436
    this._Popcorn.trigger("IriSP.SliceWidget.show");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3437
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3438
    if (!IriSP.null_or_undefined(currentChapter)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3439
      this.selector.find(".Ldt-createAnnotation-Title").html(currentChapter.content.title);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3440
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3441
      this._currentcurrentChapter = currentChapter;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3442
      var beginTime = IriSP.msToTime(currentChapter.begin);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3443
      var endTime = IriSP.msToTime(currentChapter.end);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3444
      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3445
      this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3446
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3447
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3448
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3449
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3450
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3451
/** watch for changes in the textfield and change the buttons accordingly */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3452
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3453
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  3454
  if (this.cinecast_version && !this._Popcorn.media.paused) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  3455
      this._Popcorn.pause();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  3456
  }
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3457
  this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3458
      var _rx = IriSP.regexpFromText(IriSP.jQuery(this).text());
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3459
      if (_rx.test(contents)) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3460
          IriSP.jQuery(this).parent().addClass("Ldt-createAnnotation-active-button");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3461
      } else {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3462
          IriSP.jQuery(this).parent().removeClass("Ldt-createAnnotation-active-button");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3463
      }
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3464
  });
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3465
  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3466
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3467
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3468
IriSP.createAnnotationWidget.prototype.showStartScreen = function() {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3469
  this.selector.find(".Ldt-createAnnotation-screen").hide();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3470
  this.selector.find(".Ldt-createAnnotation-startScreen").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3471
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3472
  var jqTextfield = this.selector.find(".Ldt-createAnnotation-Description"); // handle on the textfield. used for the closure
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3473
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3474
  /* test if the browser supports the placeholder attribute */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3475
  if (!IriSP.null_or_undefined(jqTextfield.get(0).placeholder)) {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3476
    jqTextfield.attr("placeholder", IriSP.i18n.getMessage('type_here')); 
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3477
  } else {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3478
    jqTextfield.val(IriSP.i18n.getMessage('type_here'));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3479
    jqTextfield.one("click", IriSP.wrap(this, function() { jqTextfield.val(""); }));    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3480
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3481
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3482
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3483
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3484
  this._state = "startScreen";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3485
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3486
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3487
IriSP.createAnnotationWidget.prototype.showWaitScreen = function() {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3488
  this.selector.find(".Ldt-createAnnotation-screen").hide();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3489
  this.selector.find(".Ldt-createAnnotation-waitScreen").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3490
  this._state = "waitScreen";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3491
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3492
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3493
IriSP.createAnnotationWidget.prototype.showErrorScreen = function() {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3494
  this.selector.find(".Ldt-createAnnotation-screen").hide();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3495
  this.selector.find(".Ldt-createAnnotation-errorScreen").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3496
  this._state = "errorScreen";
832
6397a2ca3a67 corrections
veltr
parents: 831
diff changeset
  3497
  var _this = this;
6397a2ca3a67 corrections
veltr
parents: 831
diff changeset
  3498
  window.setTimeout(function() { _this.showStartScreen(); }, 2000);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3499
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3500
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3501
/** update show the final screen with links to share the created annotation */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3502
IriSP.createAnnotationWidget.prototype.showEndScreen = function(annotation) {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3503
  this.selector.find(".Ldt-createAnnotation-screen").hide();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3504
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3505
  if (this.cinecast_version) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3506
    this.selector.find(".Ldt-createAnnotation-Title").parent().show();      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3507
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3508
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3509
  var url = ( (typeof annotation.meta == "object" && typeof annotation.meta.url == "string" && annotation.meta.url.length)
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3510
    ? annotation.meta.url
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3511
    : ( document.location.href + "#id=" + annotation.id ) );
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3512
  var twStatus = IriSP.mkTweetUrl(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3513
  var gpStatus = IriSP.mkGplusUrl(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3514
  var fbStatus = IriSP.mkFbUrl(url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3515
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3516
  this.selector.find(".Ldt-createAnnotation-endScreen-TweetLink").attr("href", twStatus);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3517
  this.selector.find(".Ldt-createAnnotation-endScreen-FbLink").attr("href", fbStatus);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3518
  this.selector.find(".Ldt-createAnnotation-endScreen-GplusLink").attr("href", gpStatus);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3519
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3520
  this.selector.find(".Ldt-createAnnotation-endScreen").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3521
  this._state = "endScreen";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3522
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3523
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3524
/** handle clicks on "send annotation" button */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3525
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3526
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3527
  var textfield = this.selector.find(".Ldt-createAnnotation-Description");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3528
  var contents = textfield.val();
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3529
  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3530
  if (contents === "") {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3531
    if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3532
      this.selector.find(".Ldt-createAnnotation-Container")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3533
                   .after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3534
      textfield.css("background-color", "#d93c71");      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3535
    } else {      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3536
      this.selector.find(".Ldt-createAnnotation-errorMessage").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3537
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3538
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3539
      textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3540
                      var contents = textfield.val();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3541
                      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3542
                      if (contents !== "") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3543
                        this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3544
                        textfield.css("background-color", "");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3545
                      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3546
                   }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3547
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3548
    this.showWaitScreen();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3549
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3550
    this.sendLdtData(contents, function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3551
                      if (_this.cinecast_version) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3552
                          if (_this._Popcorn.media.paused)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3553
                            _this._Popcorn.play();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3554
                      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3555
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3556
                      if (_this._state == "waitScreen") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3557
                        _this.showEndScreen(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3558
                        if (_this.cinecast_version) {
832
6397a2ca3a67 corrections
veltr
parents: 831
diff changeset
  3559
                          window.setTimeout(function() { _this.showStartScreen(); }, 5000);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3560
                        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3561
                      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3562
                      // hide the slicer widget
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3563
                      if (!_this.cinecast_version) {                      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3564
                        _this._Popcorn.trigger("IriSP.SliceWidget.hide");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3565
                      }           
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3566
                    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3567
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3568
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3569
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3570
IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3571
  this.sliceLeft = params[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3572
  this.sliceWidth = params[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3573
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3574
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3575
IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3576
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3577
  var apiJson = {annotations : [{}], meta: {}};
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3578
  var annotation = apiJson.annotations[0];
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3579
  
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3580
  annotation.media = this._serializer.currentMedia()["id"];
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3581
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3582
  if (this.cinecast_version) {   
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3583
      annotation.begin = Math.round(this._Popcorn.currentTime() * 1000);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3584
      annotation.end = annotation.begin;      
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3585
  } else {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3586
    var duration = this._serializer.getDuration();    
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3587
    annotation.begin = +((duration * (this.sliceLeft / 100)).toFixed(0));
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3588
    annotation.end = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3589
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3590
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3591
  // boundary checks
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3592
  annotation.begin = Math.max(0, annotation.begin);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3593
  annotation.end = Math.min(this._serializer.getDuration(), annotation.end);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3594
  
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3595
  annotation.type = ( this.cinecast_version ? "cinecast:UserAnnotation" : ( this._serializer.getContributions() || "" ));
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3596
  if (typeof(annotation.type) === "undefined")
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3597
    annotation.type = "";
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3598
  
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3599
  annotation.type_title = "Contributions";
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3600
  annotation.content = {};
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3601
  annotation.content.data = contents;
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3602
  if (this.cinecast_version) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3603
      var _extract = IriSP.underscore(this._serializer._data.annotations)
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3604
          .filter(function(_a) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3605
              return (_a.begin <= annotation.begin && _a.end >= annotation.begin && _a.type == "cinecast:MovieExtract");
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3606
          })
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3607
      if (_extract.length) {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3608
          annotation.extract = _extract[0].id;
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3609
      }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3610
  }
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3611
  
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3612
  var meta = apiJson.meta;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3613
  
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3614
  
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3615
  var _username = this.selector.find(".Ldt-createAnnotation-userName").val();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3616
  meta.creator = (
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3617
      (_username && _username.length)
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3618
      ? _username
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3619
      : (
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3620
          (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.name))
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3621
          ? IriSP.user.name
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3622
          : "Anonymous user"
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3623
      )
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3624
  );
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3625
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3626
  meta.created = Date().toString();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3627
  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3628
  // All #hashtags are added to tags
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3629
  annotation.tags = contents.match(/#[^#\s]+\b/gim) || [];
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3630
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3631
  var jsonString = JSON.stringify(apiJson);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3632
  var project_id = this._serializer._data.meta.id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3633
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3634
  //TODO: extract magic url
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3635
  var url = Mustache.to_html(this.api_endpoint_template,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3636
                              {id: project_id});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3637
                          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3638
  IriSP.jQuery.ajax({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3639
      url: url,
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3640
      type: this.api_method,
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3641
      contentType: 'application/json',
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3642
      data: jsonString,               
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3643
      //dataType: 'json',
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3644
      success: IriSP.wrap(this, function(json, textStatus, XMLHttpRequest) {                   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3645
                    /* add the annotation to the annotation and tell the world */
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3646
                    if (this.cinecast_version) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3647
                        var annotation = json.annotations[0];
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3648
                    } else {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3649
                    /* if the media doesn't have a contributions line, we need to add one */
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3650
                        if (typeof(this._serializer.getContributions()) === "undefined") {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3651
                          /* set up a basic view */
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3652
                          var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions",
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3653
                                          "id": json.annotations[0].type}
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3654
    
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3655
                          
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3656
                            IriSP.get_aliased(this._serializer._data, ["annotation_types", "annotation-types"]).push(tmp_view);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3657
                        }
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3658
                        
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3659
                        delete annotation.tags;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3660
                        annotation.content.description = annotation.content.data;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3661
                        annotation.content.title = "";
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3662
                        delete annotation.content.data;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3663
                        annotation.id = json.annotations[0].id;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3664
    
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3665
                        annotation.meta = meta;
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3666
                        annotation.meta["id-ref"] = json.annotations[0]["type"];
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3667
                    }
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  3668
                        
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3669
                    // everything is shared so there's no need to propagate the change
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3670
                    _this._serializer._data.annotations.push(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3671
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3672
                    _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3673
                    callback(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3674
      }), 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3675
      error: 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3676
              function(jqXHR, textStatus, errorThrown) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3677
                            console.log("an error occured while contacting " 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3678
                            + url + " and sending " + jsonString + textStatus ); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3679
                            _this.showErrorScreen(); } });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3680
};IriSP.HelloWorldWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3681
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3682
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3683
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3684
IriSP.HelloWorldWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3685
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3686
IriSP.HelloWorldWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3687
    this.selector
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3688
        .html('Hello, world')
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3689
        .css({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3690
            "text-align" : "center",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3691
            "padding": "10px 0",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3692
            "font-size" : "14px"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3693
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3694
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3695
    console.log(this);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3696
}
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3697
/* Internationalization for this widget */
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3698
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3699
IriSP.i18n.addMessages(
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3700
    {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3701
        "en": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3702
            "play_pause": "Play/Pause",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3703
            "mute_unmute": "Mute/Unmute",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3704
            "play": "Play",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3705
            "pause": "Pause",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3706
            "mute": "Mute",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3707
            "unmute": "Unmute",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3708
            "annotate": "Annotate",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3709
            "search": "Search",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3710
            "elapsed_time": "Elapsed time",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3711
            "total_time": "Total time"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3712
        },
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3713
        "fr": {
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3714
            "play_pause": "Lecture/Pause",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3715
            "mute_unmute": "Couper/Activer le son",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3716
            "play": "Lecture",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3717
            "pause": "Pause",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3718
            "mute": "Couper le son",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3719
            "unmute": "Activer le son",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3720
            "annotate": "Annoter",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3721
            "search": "Rechercher",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3722
            "elapsed_time": "Durée écoulée",
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3723
            "total_time": "Durée totale"
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3724
        }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3725
    }
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3726
);
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3727
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  3728
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3729
IriSP.PlayerWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3730
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3731
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3732
  this._searchBlockOpen = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3733
  this._searchLastValue = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3734
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3735
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3736
IriSP.PlayerWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3737
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3738
IriSP.PlayerWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3739
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3740
  var width = this.width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3741
	var height = this.height;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3742
	var heightS = this.height-20;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3743
	  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3744
	var playerTempl = IriSP.templToHTML(IriSP.player_template, this._config);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3745
  this.selector.append(playerTempl);		
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3746
	
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3747
  this.selector.children(".Ldt-controler").show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3748
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3749
  // handle clicks by the user on the video.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3750
  this._Popcorn.listen("play", IriSP.wrap(this, this.playButtonUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3751
  this._Popcorn.listen("pause", IriSP.wrap(this, this.playButtonUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3752
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3753
  this._Popcorn.listen("volumechange", IriSP.wrap(this, this.muteButtonUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3754
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3755
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeDisplayUpdater));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3756
  // update the time display for the first time.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3757
  this._Popcorn.listen("loadedmetadata", IriSP.wrap(this, this.timeDisplayUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3758
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3759
  this._Popcorn.listen("IriSP.search.matchFound", IriSP.wrap(this, this.searchMatch));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3760
  this._Popcorn.listen("IriSP.search.noMatchFound", IriSP.wrap(this, this.searchNoMatch));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3761
  this._Popcorn.listen("IriSP.search.triggeredSearch", IriSP.wrap(this, this.triggeredSearch));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3762
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3763
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3764
  this.selector.find(".Ldt-CtrlPlay").click(function() { self.playHandler.call(self); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3765
  this.selector.find(".Ldt-CtrlAnnotate").click(function() 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3766
                                            { self._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked"); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3767
  this.selector.find(".Ldt-CtrlSearch").click(function() { self.searchButtonHandler.call(self); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3768
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3769
  this.selector.find('.Ldt-CtrlSound').click(function() { self.muteHandler.call(self); } );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3770
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3771
  /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3772
  var searchButtonPos = this.selector.find(".Ldt-CtrlSearch").position();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3773
  var searchBox = Mustache.to_html(IriSP.search_template, {margin_left : searchButtonPos.left + "px"});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3774
  this.selector.find(".Ldt-CtrlSearch").after(searchBox);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3775
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3776
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3777
  // trigger an IriSP.PlayerWidget.MouseOver to the widgets that are interested (i.e : sliderWidget)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3778
  this.selector.hover(function() { self._Popcorn.trigger("IriSP.PlayerWidget.MouseOver"); }, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3779
                      function() { self._Popcorn.trigger("IriSP.PlayerWidget.MouseOut"); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3780
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3781
  this.muteButtonUpdater(); /* some player - jwplayer notable - save the state of the mute button between sessions */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3782
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3783
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3784
/* Update the elasped time div */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3785
IriSP.PlayerWidget.prototype.timeDisplayUpdater = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3786
  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3787
  if (this._previousSecond === undefined) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3788
    this._previousSecond = this._Popcorn.roundTime();
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  3789
  }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3790
  else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3791
    /* we're still in the same second, so it's not necessary to update time */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3792
    if (this._Popcorn.roundTime() == this._previousSecond)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3793
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3794
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3795
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3796
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3797
  // we get it at each call because it may change.
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  3798
  var duration = this._serializer.getDuration() / 1000; 
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3799
  var totalTime = IriSP.secondsToTime(duration);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3800
  var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3801
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3802
  this.selector.find(".Ldt-ElapsedTime").html(elapsedTime.toString());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3803
  this.selector.find(".Ldt-TotalTime").html(totalTime.toString());
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3804
  this._previousSecond = this._Popcorn.roundTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3805
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3806
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3807
/* update the icon of the button - separate function from playHandler
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3808
   because in some cases (for instance, when the user directly clicks on
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3809
   the jwplayer window) we have to change the icon without playing/pausing
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3810
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3811
IriSP.PlayerWidget.prototype.playButtonUpdater = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3812
  var status = this._Popcorn.media.paused;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3813
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3814
  if ( status == true ){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3815
    /* the background sprite is changed by adding/removing the correct classes */
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3816
    this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('play'));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3817
    this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PauseState").addClass("Ldt-CtrlPlay-PlayState");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3818
  } else {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3819
    this.selector.find(".Ldt-CtrlPlay").attr("title", IriSP.i18n.getMessage('pause'));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3820
    this.selector.find(".Ldt-CtrlPlay").removeClass("Ldt-CtrlPlay-PlayState").addClass("Ldt-CtrlPlay-PauseState");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3821
  }  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3822
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3823
  return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3824
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3825
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3826
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3827
IriSP.PlayerWidget.prototype.playHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3828
  var status = this._Popcorn.media.paused;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3829
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3830
  if ( status == true ){        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3831
    this._Popcorn.play();   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3832
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3833
    this._Popcorn.pause();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3834
  }  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3835
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3836
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3837
IriSP.PlayerWidget.prototype.muteHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3838
  if (!this._Popcorn.muted()) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3839
      this._Popcorn.mute(true);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3840
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3841
      this._Popcorn.mute(false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3842
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3843
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3844
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3845
IriSP.PlayerWidget.prototype.muteButtonUpdater = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3846
  var status = this._Popcorn.media.muted;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3847
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3848
  if ( status == true ){        
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3849
    this.selector.find(".Ldt-CtrlSound").attr("title", IriSP.i18n.getMessage('unmute'));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3850
    this.selector.find(".Ldt-CtrlSound").removeClass("Ldt-CtrlSound-MuteState").addClass("Ldt-CtrlSound-SoundState");    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3851
  } else {
837
353a78021ebc Added Internationalization
veltr
parents: 836
diff changeset
  3852
    this.selector.find(".Ldt-CtrlSound").attr("title", IriSP.i18n.getMessage('mute'));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3853
    this.selector.find(".Ldt-CtrlSound").removeClass("Ldt-CtrlSound-SoundState").addClass("Ldt-CtrlSound-MuteState");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3854
  }  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3855
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3856
  return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3857
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3858
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3859
IriSP.PlayerWidget.prototype.showSearchBlock = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3860
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3861
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3862
  if (this._searchBlockOpen == false) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3863
    this.selector.find(".LdtSearch").show("blind", { direction: "horizontal"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3864
    this.selector.find(".LdtSearchInput").css('background-color','#fff');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3865
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3866
    this._searchBlockOpen = true;           
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3867
    this.selector.find(".LdtSearchInput").bind('keyup', null, function() { self.searchHandler.call(self); } );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3868
    this.selector.find(".LdtSearchInput").focus();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3869
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3870
    // we need this variable because some widget can find a match in
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3871
    // their data while at the same time other's don't. As we want the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3872
    // search field to become green when there's a match, we need a 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3873
    // variable to remember that we had one.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3874
    this._positiveMatch = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3875
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3876
    // tell the world the field is open
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3877
    this._Popcorn.trigger("IriSP.search.open");     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3878
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3879
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3880
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3881
IriSP.PlayerWidget.prototype.hideSearchBlock = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3882
 if (this._searchBlockOpen == true) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3883
    this._searchLastValue = this.selector.find(".LdtSearchInput").attr('value');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3884
    this.selector.find(".LdtSearchInput").attr('value','');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3885
    this.selector.find(".LdtSearch").hide("blind", { direction: "horizontal"}, 75);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3886
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3887
    // unbind the watcher event.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3888
    this.selector.find(".LdtSearchInput").unbind('keypress set');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3889
    this._searchBlockOpen = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3890
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3891
    this._positiveMatch = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3892
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3893
    this._Popcorn.trigger("IriSP.search.closed");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3894
	}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3895
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3896
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3897
/** react to clicks on the search button */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3898
IriSP.PlayerWidget.prototype.searchButtonHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3899
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3900
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3901
  /* show the search field if it is not shown */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3902
  if ( this._searchBlockOpen == false ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3903
    this.showSearchBlock();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3904
    this.selector.find(".LdtSearchInput").attr('value', this._searchLastValue);      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3905
    this._Popcorn.trigger("IriSP.search", this._searchLastValue); // trigger the search to make it more natural.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3906
	} else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3907
    this.hideSearchBlock();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3908
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3909
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3910
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3911
/** this handler is called whenever the content of the search
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3912
   field changes */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3913
IriSP.PlayerWidget.prototype.searchHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3914
  this._searchLastValue = this.selector.find(".LdtSearchInput").attr('value');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3915
  this._positiveMatch = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3916
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3917
  // do nothing if the search field is empty, instead of highlighting everything.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3918
  if (this._searchLastValue == "") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3919
    this._Popcorn.trigger("IriSP.search.cleared");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3920
    this.selector.find(".LdtSearchInput").css('background-color','');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3921
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3922
    this._Popcorn.trigger("IriSP.search", this._searchLastValue);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3923
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3924
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3925
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3926
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3927
  handler for the IriSP.search.found message, which is sent by some views when they
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3928
  highlight a match.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3929
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3930
IriSP.PlayerWidget.prototype.searchMatch = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3931
  this._positiveMatch = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3932
  this.selector.find(".LdtSearchInput").css('background-color','#e1ffe1');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3933
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3934
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3935
/** the same, except that no value could be found */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3936
IriSP.PlayerWidget.prototype.searchNoMatch = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3937
  if (this._positiveMatch !== true)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3938
    this.selector.find(".LdtSearchInput").css('background-color', "#d62e3a");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3939
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3940
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3941
/** react to an IriSP.Player.triggeredSearch - that is, when
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3942
    a widget ask the PlayerWidget to do a search on his behalf */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3943
IriSP.PlayerWidget.prototype.triggeredSearch = function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3944
  this.showSearchBlock();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3945
  this.selector.find(".LdtSearchInput").attr('value', searchString);      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3946
  this._Popcorn.trigger("IriSP.search", searchString); // trigger the search to make it more natural.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3947
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3948
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3949
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3950
/* 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3951
 *   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3952
 *  Copyright 2010 Institut de recherche et d'innovation 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3953
 *  contributor(s) : Samuel Huron 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3954
 *   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3955
 *  contact@iri.centrepompidou.fr
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3956
 *  http://www.iri.centrepompidou.fr 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3957
 *   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3958
 *  This software is a computer program whose purpose is to show and add annotations on a video .
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3959
 *  This software is governed by the CeCILL-C license under French law and
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3960
 *  abiding by the rules of distribution of free software. You can  use, 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3961
 *  modify and/ or redistribute the software under the terms of the CeCILL-C
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3962
 *  license as circulated by CEA, CNRS and INRIA at the following URL
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3963
 *  "http://www.cecill.info". 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3964
 *  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3965
 *  The fact that you are presently reading this means that you have had
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3966
 *  knowledge of the CeCILL-C license and that you accept its terms.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3967
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3968
// CHART TIMELINE / VERSION PROTOTYPE  ::
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3969
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3970
/** the polemic widget */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3971
IriSP.PolemicWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3972
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3973
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3974
  this.userPol    = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3975
  this.userNoPol  = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3976
  this.userst      = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3977
  this.numberOfTweet = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3978
  this.Users;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3979
  this.TweetPolemic;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3980
  this.yMax        = this.height; 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3981
  this.PaperSlider;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3982
  this.heightOfChart;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3983
  this.tweets  = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3984
  this.svgElements = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3985
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3986
  this.oldSearchMatches = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3987
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3988
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3989
IriSP.PolemicWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3990
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3991
IriSP.PolemicWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3992
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3993
    // variable 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3994
    // yMax
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3995
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3996
    var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3997
    var yCoef        = 2;             // coef for height of 1 tweet 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3998
    var frameSize     = 5;             // frame size 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  3999
    var margin         = 1;            // marge between frame
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4000
    var lineSize      = this.width;        // timeline pixel width 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4001
    var nbrframes     = lineSize/frameSize;     // frame numbers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4002
    var numberOfTweet   = 0;            // number of tweet overide later 
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4003
    var duration      = this._serializer.getDuration();      // timescale width 
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4004
    var frameLength   = lineSize / frameSize;    // frame timescale  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4005
    var timeline;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4006
    var colors  = new Array("","#1D973D","#036AAE","#CE0A15","#C5A62D","#585858");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4007
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4008
    // array 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4009
    //var tweets  = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4010
    var element = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4011
    var cluster = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4012
    var frames  = new Array(frameLength);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4013
    var slices  = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4014
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4015
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4016
    // Classes =======================================================================
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4017
    var Frames = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4018
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4019
      var Myclusters;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4020
      var x;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4021
      var y;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4022
      var width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4023
      var height;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4024
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4025
    Frames = function(json){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4026
      // make my clusters
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4027
      // ou Frame vide 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4028
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4029
    Frames.prototype.draw = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4030
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4031
    Frames.prototype.zoom = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4032
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4033
    Frames.prototype.inside = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4034
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4035
    var Clusters = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4036
      var Object;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4037
      var yDist;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4038
      var x;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4039
      var y;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4040
      var width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4041
      var height;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4042
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4043
    Clusters = function(json){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4044
      // make my object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4045
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4046
    var Tweet = function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4047
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4048
    // Classes =======================================================================
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4049
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4050
    // Refactoring (parametere) ************************************************************
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4051
    // color translastion
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4052
    var qTweet_0  =0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4053
    var qTweet_Q  =0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4054
    var qTweet_REF=0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4055
    var qTweet_OK =0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4056
    var qTweet_KO =0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4057
    function colorTranslation(value){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4058
      if(value == "Q"){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4059
        qTweet_Q+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4060
        return 2;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4061
      }else if(value =="REF"){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4062
        qTweet_REF+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4063
        return 4;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4064
      }else if(value =="OK"){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4065
        qTweet_OK+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4066
        return 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4067
      }else if(value =="KO"){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4068
        qTweet_KO+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4069
        return 3;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4070
      }else if(value ==""){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4071
        qTweet_0+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4072
        return 5;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4073
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4074
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4075
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4076
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4077
      this._serializer.sync(function(data) { loaded_callback.call(self, data); return; });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4078
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4079
      function loaded_callback (json) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4080
      var view_type = this._serializer.getTweets();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4081
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4082
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4083
      if (typeof(view_type) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4084
        var view_type = this._serializer.getTweetIds()[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4085
        if (typeof(view_type) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4086
          // default to guessing if nothing else works.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4087
          var view = json.views[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4088
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4089
          if(typeof(view.annotation_types) !== "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4090
            /* we need to be backward compatible with the old files which used to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4091
               feature only two lines : Chapitrage and Tweets. We've added a
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4092
               "Contributions" line so we need to discriminate against that */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4093
            if (view.annotation_types.length === 2 && typeof(this._serializer.getContributions()) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4094
              var view_type = view.annotation_types[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4095
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4096
              console.log("PolemicWidget: invalid file - minimizing");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4097
              return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4098
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4099
          }      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4100
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4101
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4102
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4103
      // Make and define the Raphael area
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4104
      this.paper = Raphael(document.getElementById(this._id), this._config.width, this._config.height);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4105
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4106
      // event handlers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4107
      this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) { this.searchHandler(searchString); }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4108
      this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.searchFieldClosedHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4109
      this._Popcorn.listen("IriSP.search.cleared", IriSP.wrap(this, this.searchFieldClearedHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4110
      this.selector.mouseleave(IriSP.wrap(this, function() { self.TooltipWidget.hide.call(self.TooltipWidget); }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4111
      this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4112
      this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", IriSP.wrap(this, this.showAnnotation));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4113
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4114
      for(var i = 0; i < json.annotations.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4115
        var item = json.annotations[i];        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4116
        var MyTime  = Math.floor(item.begin/duration*lineSize);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4117
        var Myframe = Math.floor(MyTime/lineSize*frameLength);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4118
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4119
        if (typeof(item.meta) !== "undefined" 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4120
          && typeof(item.meta["id-ref"]) !== "undefined"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4121
          && item.meta["id-ref"] === view_type) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4122
            
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4123
            var MyTJson = {},
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4124
                _source = IriSP.get_aliased(item.meta, ['dc:source', 'source']);
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4125
            if (_source !== null) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4126
              var MyTJson = JSON.parse(_source['content']);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4127
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4128
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4129
            if (item.content['polemics'] != undefined 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4130
            && item.content['polemics'][0] != null) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4131
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4132
              // a tweet can have many polemics at the same time.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4133
              for(var j=0; j<item.content['polemics'].length; j++){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4134
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4135
                  this.tweets[numberOfTweet] = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4136
                        id:i,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4137
                        qualification:colorTranslation(item.content['polemics'][j]),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4138
                        yIndicator:MyTime,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4139
                        yframe:Myframe,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4140
                        title:item.content['title'],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4141
                        timeframe:item.begin,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4142
                        userId: MyTJson.id,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4143
                        userScreenName: MyTJson.screen_name,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4144
                        tsource:MyTJson,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4145
                        cinecast_id: item.id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4146
                        };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4147
                  numberOfTweet+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4148
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4149
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4150
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4151
          else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4152
            this.tweets[numberOfTweet] = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4153
                  id:i,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4154
                  qualification:colorTranslation(""),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4155
                  yIndicator:MyTime,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4156
                  yframe:Myframe,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4157
                  title:item.content['title'],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4158
                  timeframe:item.begin,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4159
                  userId: MyTJson.id,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4160
                  userScreenName: MyTJson.screen_name,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4161
                  tsource:MyTJson,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4162
                  cinecast_id: item.id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4163
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4164
            numberOfTweet+=1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4165
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4166
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4167
        } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4168
      };  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4169
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4170
       DrawTweets.call (this); // FIXME: ugly.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4171
       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4172
      };      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4173
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4174
    // tweet Drawing (in raphael) 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4175
    function DrawTweets (){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4176
    // GROUPES TWEET ============================================
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4177
    // Count nbr of cluster and tweet in a frame an save int in "frames"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4178
      numberOfTweet = this.tweets.length;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4179
      for(var i=0; i<nbrframes; i++) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4180
        for(var j=0; j<numberOfTweet; j++) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4181
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4182
          if (i==this.tweets[j].yframe){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4183
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4184
            var k = this.tweets[j].qualification;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4185
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4186
            // make array for frame cluster
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4187
            if(frames[i]==undefined){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4188
              frames[i] = {id:i,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4189
                     qualifVol:new Array(),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4190
                     mytweetsID:new Array()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4191
                    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4192
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4193
            // add my tweet to frame
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4194
            frames[i].mytweetsID.push(this.tweets[j]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4195
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4196
            // count opinion by frame
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4197
            if( frames[i].qualifVol[k] == undefined){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4198
              frames[i].qualifVol[k] = 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4199
            }else{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4200
              frames[i].qualifVol[k] += 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4201
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4202
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4203
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4204
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4205
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4206
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4207
    // GROUPES TWEET ============================================    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4208
    // max of tweet by Frame 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4209
      var max = 0; 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4210
      for(var i = 0; i < nbrframes; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4211
        var moy  = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4212
        for (var j = 0; j < 6; j++) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4213
          if (frames[i] != undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4214
            if (frames[i].qualifVol[j] != undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4215
              moy += frames[i].qualifVol[j];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4216
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4217
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4218
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4219
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4220
        if (moy > max) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4221
          max = moy;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4222
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4223
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4224
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4225
      var tweetDrawed = new Array();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4226
      var TweetHeight = 5;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4227
      var newHeight = TweetHeight * max + 10;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4228
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4229
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4230
      if (newHeight > this.height) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4231
        this.paper.setSize(this.width, newHeight);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4232
        this.height = newHeight;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4233
        console.log("resizeing");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4234
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4235
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4236
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4237
      // DRAW  TWEETS ============================================
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4238
      for(var i = 0; i < nbrframes; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4239
        var addEheight = 5;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4240
        if (frames[i] != undefined){                
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4241
          // by type 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4242
          
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4243
          for (var j = 6; j > -1; j--) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4244
            if (frames[i].qualifVol[j] != undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4245
              // show tweet by type 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4246
              for (var k = 0; k < frames[i].mytweetsID.length; k++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4247
              
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4248
                if (frames[i].mytweetsID[k].qualification == j) {                
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4249
                  var x = i * frameSize;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4250
                  var y = this.height - addEheight;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4251
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4252
                  if (this.yMax > y) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4253
                    this.yMax = y;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4254
                  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4255
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4256
                  /* some tweets seem to be duplicated - so we make a check before
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4257
                     creating a new rect */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4258
                  if (this.svgElements.hasOwnProperty(frames[i].mytweetsID[k].cinecast_id))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4259
                    continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4260
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4261
                  var e = this.paper.rect(x, y, frameSize - margin, TweetHeight /* height */)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4262
                                    .attr({stroke:"#00","stroke-width":0.1,  fill: colors[j]});  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4263
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4264
                  addEheight += TweetHeight;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4265
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4266
                  /* stick a lot of things into e because that's the easiest way
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4267
                     to do it */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4268
                  e.color = colors[j];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4269
                  e.time = frames[i].mytweetsID[k].timeframe;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4270
                  e.title = frames[i].mytweetsID[k].title;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4271
                  e.id = frames[i].mytweetsID[k].cinecast_id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4272
                  this.svgElements[e.id] = e;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4273
                  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4274
                  IriSP.jQuery(e.node).mouseenter(function(element) { return function (_e) {                    
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4275
                        self.TooltipWidget.show.call(self.TooltipWidget, element.title, element.attr("fill"), element.attrs.x + element.attrs.width / 2, element.attrs.y - 2);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4276
                        element.displayed = true;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4277
                        self._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4278
                            "widget" : "StackGraphWidget",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4279
                            "type": "mousemove",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4280
                            "x": _e.pageX,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4281
                            "y": _e.pageY,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4282
                            "annotation_id": element.id
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4283
                        });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4284
                  }}(e)).mousedown(function(element) { return function () {                    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4285
                    self._Popcorn.currentTime(element.time/1000);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4286
                    self._Popcorn.trigger("IriSP.PolemicTweet.click", element.id); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4287
                    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4288
                  }(e));                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4289
                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4290
                  IriSP.jQuery(e.node).attr('id', 't' + k + '');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4291
                  IriSP.jQuery(e.node).attr('title', frames[i].mytweetsID[k].title);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4292
                  IriSP.jQuery(e.node).attr('begin',  frames[i].mytweetsID[k].timeframe);                  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4293
                }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4294
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4295
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4296
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4297
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4298
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4299
      }    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4300
      // DRAW UI :: resize border and bgd      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4301
      this.paperBackground = this.paper.rect(0, 0, this.width, this.height).attr({fill:"#F8F8F8","stroke-width":0.1,opacity: 1});  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4302
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4303
      // outer borders
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4304
      this.outerBorders   = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4305
      this.outerBorders.push(this.paper.rect(0, this.height - 1, this.width, 1).attr({fill:"#ababab",stroke: "none",opacity: 1}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4306
      this.outerBorders.push(this.paper.rect(0, 0, this.width, 1).attr({fill:"#ababab",stroke: "none",opacity: 1}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4307
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4308
      // inner borders
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4309
      this.innerBorders   = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4310
      this.innerBorders.push(this.paper.rect(1, this.height - 2, this.width, 1).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4311
      this.innerBorders.push(this.paper.rect(1, 1, this.width, 1).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4312
      this.innerBorders.push(this.paper.rect(1, 1, 1, this.height - 2).attr({fill:"#d0d1d1",stroke: "none",opacity: 0.8}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4313
      this.innerBorders.push(this.paper.rect(this.width - 2, 1, 1, this.height - 2).attr({fill:"#efefef",stroke: "none",opacity: 1}));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4314
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4315
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4316
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4317
      this.paperSlider   = this.paper.rect(0, 0, 0, this.height).attr({fill:"#D4D5D5", stroke: "none", opacity: 1});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4318
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4319
      // the small white line displayed over the slider.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4320
      this.sliderTip = this.paper.rect(0, 0, 1, this.height).attr({fill:"#fc00ff", stroke: "none", opacity: 1});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4321
      // decalage 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4322
      // tweetSelection = this.paper.rect(-100,-100,5,5).attr({fill:"#fff",stroke: "none",opacity: 1});  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4323
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4324
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4325
      this.paperSlider.toBack();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4326
      this.paperBackground.toBack();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4327
      this.sliderTip.toFront();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4328
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4329
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4330
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4331
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4332
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4333
/** update the positionMarker as time passes */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4334
IriSP.PolemicWidget.prototype.sliderUpdater = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4335
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4336
    var time = +this._Popcorn.currentTime();
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4337
    var duration = this._serializer.getDuration();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4338
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4339
    this.paperSlider.attr("width", time * (this.width / (duration / 1000)));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4340
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4341
    this.sliderTip.attr("x", time * (this.width / (duration / 1000)));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4342
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4343
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4344
/** reacts to IriSP.search events */    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4345
IriSP.PolemicWidget.prototype.searchHandler = function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4346
  if (searchString == "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4347
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4348
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4349
  var matches = this._serializer.searchTweetsOccurences(searchString);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4350
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4351
  if (IriSP.countProperties(matches) > 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4352
    this._Popcorn.trigger("IriSP.search.matchFound");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4353
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4354
    this._Popcorn.trigger("IriSP.search.noMatchFound");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4355
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4356
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4357
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4358
  // decrease the opacity of the other elements.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4359
  for (var id in this.svgElements) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4360
    var e = this.svgElements[id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4361
    e.attr({fill: e.color, opacity: 0.4});   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4362
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4363
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4364
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4365
  for (var id in matches) {    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4366
    if (this.svgElements.hasOwnProperty(id)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4367
      var e = this.svgElements[id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4368
      this.svgElements[id].attr({fill: "#fc00ff", opacity: 1});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4369
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4370
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4371
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4372
  this.oldSearchMatches = matches;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4373
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4374
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4375
/** reacts to IriSP.search.cleared messages */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4376
IriSP.PolemicWidget.prototype.searchFieldClearedHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4377
  for (var id in this.svgElements) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4378
    var e = this.svgElements[id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4379
    e.attr({fill: e.color, opacity: 1});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4380
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4381
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4382
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4383
/** reacts to IriSP.search.closed messages by clearing the highlighted elements */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4384
IriSP.PolemicWidget.prototype.searchFieldClosedHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4385
  for (var id in this.svgElements) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4386
    var e = this.svgElements[id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4387
    e.attr({fill: e.color, opacity: 1});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4388
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4389
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4390
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4391
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4392
IriSP.PolemicWidget.prototype.showAnnotation = function(id) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4393
  if (this.svgElements.hasOwnProperty(id)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4394
    var e = this.svgElements[id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4395
    this.TooltipWidget.show(e.title, e.attr("fill"), e.x - 103, e.y - 160);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4396
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4397
};   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4398
IriSP.SegmentsWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4399
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4400
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4401
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4402
  this.oldSearchMatches = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4403
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4404
  // event handlers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4405
  this._Popcorn.listen("IriSP.search", function(searchString) { self.searchHandler.call(self, searchString); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4406
  this._Popcorn.listen("IriSP.search.closed", function() { self.searchFieldClosedHandler.call(self); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4407
  this._Popcorn.listen("IriSP.search.cleared", function() { self.searchFieldClearedHandler.call(self); });
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4408
  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4409
  this.checkOption("cinecast_version");
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4410
  this.defaultColors = ["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"]
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4411
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4412
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4413
IriSP.SegmentsWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4414
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4415
IriSP.SegmentsWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4416
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4417
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4418
  var annotations = this._serializer._data.annotations;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4419
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4420
  this.selector.addClass("Ldt-SegmentsWidget");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4421
  this.selector.append(Mustache.to_html(IriSP.overlay_marker_template));
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4422
  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  4423
  this.positionMarker = this.selector.find(".Ldt-SegmentPositionMarker");
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4424
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4425
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.positionUpdater));
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4426
  var duration = this._serializer.getDuration();
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4427
  
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4428
  if (this.cinecast_version) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4429
      var segments_annotations = IriSP.underscore.filter(
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4430
          this._serializer._data.annotations,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4431
          function(_a) {
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4432
              return _a.type == "cinecast:MovieExtract";
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4433
          }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4434
      );
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4435
  }
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4436
  else {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4437
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4438
      var view_type = this._serializer.getChapitrage();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4439
      if (typeof(view_type) === "undefined") {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4440
        view_type = this._serializer.getNonTweetIds()[0];  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4441
      }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4442
    
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4443
      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4444
      var i = 0;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4445
      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4446
      var segments_annotations = [];
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4447
      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4448
      for (i = 0; i < annotations.length; i++) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4449
        var annotation = annotations[i];
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4450
    
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4451
        /* filter the annotations whose type is not the one we want */
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4452
        if (view_type != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4453
              && annotation.meta["id-ref"] != view_type) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4454
            continue;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4455
        }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4456
    
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4457
        segments_annotations.push(annotation);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4458
      }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4459
}    
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4460
    var _w = this.selector.width();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4461
  var lastSegment = IriSP.underscore.max(segments_annotations, function(annotation) { return annotation.end; });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4462
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4463
  for (i = 0; i < segments_annotations.length; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4464
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4465
    var annotation = segments_annotations[i];
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4466
    var begin = (+ annotation.begin);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4467
    var end = (+ annotation.end);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4468
    var id = annotation.id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4469
        
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4470
    var startPixel = Math.floor(_w * (begin / duration));
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4471
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4472
    var endPixel = Math.floor(_w * (end / duration));
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4473
    if (annotation.id !== lastSegment.id) 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4474
      var pxWidth = endPixel - startPixel -1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4475
    else
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4476
      /* the last segment has no segment following it */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4477
      var pxWidth = endPixel - startPixel;
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4478
    
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4479
    var divTitle = this.cinecast_version
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4480
        ? annotation.content.data
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4481
        : annotation.content.title + ( annotation.content.title ? "<br />" : "" ) + annotation.content.description.replace(/(^.{120,140})[\s].+$/,'$1&hellip;');
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4482
    
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4483
    var thumbUrl = annotation.meta.thumbnail || '';
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4484
    
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4485
    var hexa_color = typeof(annotation.content.color) !== "undefined"
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4486
        ? '#' + IriSP.DEC_HEXA_COLOR(annotation.content.color)
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4487
        : typeof(annotation.color) !== "undefined"
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4488
            ? '#' + IriSP.DEC_HEXA_COLOR(annotation.color)
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4489
            : this.defaultColors[i % this.defaultColors.length];
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4490
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4491
    /*
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4492
    if (hexa_color === "FFCC00")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4493
      hexa_color = "333";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4494
    */
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4495
    if (hexa_color.length == 5)
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4496
      hexa_color = hexa_color + '00';
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4497
    
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4498
    
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4499
    var annotationTemplate = Mustache.to_html(IriSP.annotation_template,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4500
        {"divTitle" : divTitle, "id" : id, "startPixel" : startPixel,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4501
        "pxWidth" : pxWidth, "hexa_color" : hexa_color,
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4502
        "seekPlace" : Math.round(begin/1000), "thumbnailUrl": thumbUrl});
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4503
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4504
        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4505
    this.selector.append(annotationTemplate);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4506
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4507
    /* add a special class to the last segment and change its border */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4508
    if (annotation.id === lastSegment.id) {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4509
        IriSP.jqId(id).addClass("Ldt-lastSegment").css("border-color", hexa_color);  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4510
    }
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4511
   }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4512
    // react to mediafragment messages.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4513
    this._Popcorn.listen("IriSP.Mediafragment.showAnnotation", 
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4514
        function(id, divTitle) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4515
        
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4516
            var divObject = IriSP.jqId(id);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4517
            if (divObject.length) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4518
            divObject.fadeTo(0,1);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4519
            var offset_x = divObject.position().left + divObject.outerWidth() / 2;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4520
            self.TooltipWidget.show(divObject.attr("title"), IriSP.jQuery(this).css("background-color"), offset_x, 0);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4521
            IriSP.jQuery(document).one("mousemove", function() { divObject.fadeTo(0,.5);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4522
                                                                self.TooltipWidget.hide(); });
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4523
        }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4524
      });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4525
      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4526
    this.selector.find(".Ldt-iri-chapter")
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4527
        .fadeTo(0, .5)
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4528
        .click(function() {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4529
            self._Popcorn.trigger("IriSP.SegmentsWidget.click", this.id);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4530
            self._Popcorn.currentTime(IriSP.jQuery(this).attr("data-seek"));
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4531
        })
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4532
        .mouseover( function(event) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4533
            var divObject = IriSP.jQuery(this);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4534
            divObject.fadeTo(0,1);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4535
            var offset_x = divObject.position().left + divObject.outerWidth() / 2;
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4536
            var thumb = divObject.attr("thumbnail-url");
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4537
            var txt = divObject.attr("title") + (thumb && thumb.length ? '<br /><img src="' + thumb + '" />' : '');
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4538
            self.TooltipWidget.show(txt, IriSP.jQuery(this).css("background-color"), offset_x, 0);
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4539
        })
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4540
        .mouseout(function(){
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4541
            IriSP.jQuery(this).fadeTo(0,.5);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4542
            self.TooltipWidget.hide();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4543
        });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4544
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4545
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4546
/* restores the view after a search */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4547
IriSP.SegmentsWidget.prototype.clear = function() {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4548
  this.selector.children(".Ldt-iri-chapter").fadeTo(0,.5);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4549
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4550
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4551
IriSP.SegmentsWidget.prototype.clickHandler = function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4552
  this._Popcorn.trigger("IriSP.SegmentsWidget.click", annotation.id);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4553
  var begin = (+ annotation.begin) / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4554
  this._Popcorn.currentTime(Math.round(begin));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4555
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4556
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4557
IriSP.SegmentsWidget.prototype.searchHandler = function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4558
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4559
  if (searchString == "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4560
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4561
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4562
  var matches = this._serializer.searchOccurences(searchString);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4563
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4564
  if (IriSP.countProperties(matches) > 0) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4565
    this._Popcorn.trigger("IriSP.search.matchFound");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4566
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4567
    this._Popcorn.trigger("IriSP.search.noMatchFound");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4568
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4569
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4570
  // un-highlight all the blocks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4571
  this.selector.children(".Ldt-iri-chapter").css("opacity", 0.1);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4572
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4573
  // then highlight the ones with matches.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4574
  for (var id in matches) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4575
    var factor = 0.5 + matches[id] * 0.2;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4576
    this.selector.find("#"+id).dequeue();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4577
    this.selector.find("#"+id).animate({opacity:factor}, 200);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4578
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4579
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4580
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4581
  this.oldSearchMatches = matches;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4582
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4583
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4584
IriSP.SegmentsWidget.prototype.searchFieldClearedHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4585
  this.clear();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4586
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4587
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4588
IriSP.SegmentsWidget.prototype.searchFieldClosedHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4589
  this.clear();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4590
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4591
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4592
IriSP.SegmentsWidget.prototype.positionUpdater = function() {  
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4593
  var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4594
  var time = this._Popcorn.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4595
  //var position 	= ((time / duration) * 100).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4596
  var position 	= ((time / duration) * 100).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4597
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4598
  this.positionMarker.css("left", position + "%");  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4599
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4600
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4601
IriSP.SegmentsWidget.prototype.showAnnotation = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4602
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4603
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4604
/** A widget to create a new segment */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4605
IriSP.SliceWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4606
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4607
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4608
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4609
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4610
IriSP.SliceWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4611
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4612
IriSP.SliceWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4613
  var templ = Mustache.to_html(IriSP.sliceWidget_template);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4614
  this.selector.append(templ);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4615
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4616
  this.sliceZone = this.selector.find(".Ldt-sliceZone");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4617
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4618
  /* global variables used to keep the position and width
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4619
     of the zone.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4620
  */  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4621
  this.zoneLeft = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4622
  this.zoneWidth = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4623
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4624
  this.leftHandle = this.selector.find(".Ldt-sliceLeftHandle");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4625
  this.rightHandle = this.selector.find(".Ldt-sliceRightHandle");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4626
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4627
  var left = this.selector.offset().left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4628
  var top = this.selector.offset().top;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4629
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4630
  // a bug in firefox makes it use the wrong format
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4631
  if (!IriSP.jQuery.browser.mozilla) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4632
    // contain the handles correctly - we cannot set
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4633
    // containment: parent because it wouldn't allow to select the 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4634
    // whole slice, so we have to compute a box in which the slice is
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4635
    // allowed to move.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4636
    var containment = [left - 8, top, this.selector.width() + left, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4637
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4638
    // var containment = [left - 16, top, this.selector.width() + left - 8, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4639
    this.leftHandle.draggable({axis: "x",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4640
    drag: IriSP.wrap(this, this.leftHandleDragged),  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4641
    containment: containment
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4642
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4643
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4644
    containment = [left, top, this.selector.width() + left, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4645
    // containment = [left, top, this.selector.width() + left - 8, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4646
    this.rightHandle.draggable({axis: "x",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4647
    drag: IriSP.wrap(this, this.rightHandleDragged),    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4648
    containment: containment
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4649
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4650
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4651
  } else { // firefox
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4652
    // we need to define a containment specific to firefox.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4653
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4654
    var containment = [left - 16, top, this.selector.width() + left - 8, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4655
    this.leftHandle.draggable({axis: "x",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4656
    drag: IriSP.wrap(this, this.leftHandleDragged),  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4657
    containment: containment
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4658
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4659
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4660
    containment = [left, top, this.selector.width() + left - 8, top];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4661
    this.rightHandle.draggable({axis: "x",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4662
    drag: IriSP.wrap(this, this.rightHandleDragged),    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4663
    containment: containment
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4664
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4665
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4666
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4667
  this.leftHandle.css("position", "absolute");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4668
  this.rightHandle.css("position", "absolute");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4669
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4670
  this._Popcorn.listen("IriSP.SliceWidget.position", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4671
                        IriSP.wrap(this, this.positionSliceHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4672
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4673
  this._Popcorn.listen("IriSP.SliceWidget.show", IriSP.wrap(this, this.show));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4674
  this._Popcorn.listen("IriSP.SliceWidget.hide", IriSP.wrap(this, this.hide));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4675
  this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4676
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4677
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4678
/** responds to an "IriSP.SliceWidget.position" message
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4679
    @param params an array with the first element being the left distance in
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4680
           percents and the second element the width of the slice in pixels
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4681
*/        
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4682
IriSP.SliceWidget.prototype.positionSliceHandler = function(params) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4683
  left = params[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4684
  width = params[1];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4685
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4686
  this.zoneLeft = left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4687
  this.zoneWidth = width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4688
  this.sliceZone.css("left", left + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4689
  this.sliceZone.css("width", width + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4690
  this.leftHandle.css("left", (left - 7) + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4691
  this.rightHandle.css("left", left + width + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4692
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4693
  this._leftHandleOldLeft = left - 7;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4694
  this._rightHandleOldLeft = left + width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4695
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4696
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4697
/** handle a dragging of the left handle */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4698
IriSP.SliceWidget.prototype.leftHandleDragged = function(event, ui) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4699
  /* we have a special variable, this._leftHandleOldLeft, to keep the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4700
     previous position of the handle. We do that to know in what direction
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4701
     is the handle being dragged
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4702
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4703
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4704
  var currentX = this.leftHandle.offset().left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4705
  var rightHandleX = Math.floor(this.rightHandle.position()["left"]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4706
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4707
  var container_offset = this.selector.offset().left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4708
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4709
  if (Math.floor(ui.position.left) >= rightHandleX - 7) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4710
    /* prevent the handle from moving past the right handle */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4711
    ui.position.left = rightHandleX - 7;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4712
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4713
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4714
  this.zoneWidth = rightHandleX - Math.floor(ui.position.left) - 7;  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4715
  this.zoneLeft = Math.floor(ui.position.left) + 8;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4716
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4717
  this.sliceZone.css("width", this.zoneWidth);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4718
  this.sliceZone.css("left", this.zoneLeft + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4719
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4720
  this._leftHandleOldLeft = ui.position.left;  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4721
  this.broadcastChanges();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4722
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4723
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4724
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4725
/** handle a dragging of the right handle */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4726
IriSP.SliceWidget.prototype.rightHandleDragged = function(event, ui) { 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4727
  /* we have a special variable, this._leftHandleOldLeft, to keep the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4728
     previous position of the handle. We do that to know in what direction
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4729
     is the handle being dragged
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4730
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4731
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4732
  var currentX = this.leftHandle.position()["left"];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4733
  var leftHandleX = Math.floor(this.leftHandle.position()["left"]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4734
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4735
  var container_offset = this.selector.offset().left + this.selector.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4736
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4737
  if (Math.floor(ui.position.left) < leftHandleX + 7) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4738
    /* prevent the handle from moving past the left handle */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4739
    ui.position.left = leftHandleX + 7;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4740
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4741
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4742
  this.zoneWidth = Math.floor(ui.position.left) - (leftHandleX + 7);    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4743
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4744
  this.sliceZone.css("width", this.zoneWidth);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4745
  //this.sliceZone.css("left", this.zoneLeft + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4746
  this._rightHandleOldLeft = Math.floor(this._rightHandleOldLeft);  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4747
  this.broadcastChanges();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4748
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4749
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4750
/** tell to the world that the coordinates of the slice have
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4751
    changed 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4752
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4753
IriSP.SliceWidget.prototype.broadcastChanges = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4754
  var leftPercent = (this.zoneLeft / this.selector.width()) * 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4755
  var zonePercent = (this.zoneWidth / this.selector.width()) * 100;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4756
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4757
  this._Popcorn.trigger("IriSP.SliceWidget.zoneChange", [leftPercent, zonePercent]);  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4758
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4759
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4760
IriSP.SliceWidget.prototype.show = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4761
  this.selector.show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4762
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4763
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4764
IriSP.SliceWidget.prototype.hide = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4765
  this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4766
};IriSP.SliderWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4767
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4768
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4769
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4770
IriSP.SliderWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4771
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4772
IriSP.SliderWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4773
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4774
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4775
  this.selector.append(Mustache.to_html(IriSP.sliderWidget_template, {}));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4776
  this.selector.addClass("Ldt-SliderMinimized");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4777
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4778
  this.sliderBackground = this.selector.find(".Ldt-sliderBackground");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4779
  this.sliderForeground = this.selector.find(".Ldt-sliderForeground");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4780
  this.positionMarker = this.selector.find(".Ldt-sliderPositionMarker");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4781
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4782
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4783
  // a special variable to stop methods from tinkering
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4784
  // with the positionMarker when the user is dragging it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4785
  this.draggingOngoing = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4786
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4787
  // another special variable used by the timeout handler to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4788
  // open or close the slider.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4789
  this.sliderMaximized = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4790
  this.timeOutId = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4791
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4792
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4793
  this.positionMarker.draggable({axis: "x",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4794
  start: IriSP.wrap(this, this.positionMarkerDraggingStartedHandler),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4795
  stop: IriSP.wrap(this, this.positionMarkerDraggedHandler),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4796
  containment: "parent"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4797
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4798
  this.positionMarker.css("position", "absolute");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4799
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4800
  this.sliderBackground.click(function(event) { self.backgroundClickHandler.call(self, event); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4801
  this.sliderForeground.click(function(event) { self.foregroundClickHandler.call(self, event); });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4802
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4803
  this.selector.hover(IriSP.wrap(this, this.mouseOverHandler), IriSP.wrap(this, this.mouseOutHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4804
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4805
  // update the positions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4806
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.sliderUpdater));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4807
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4808
  // special messages :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4809
  this._Popcorn.listen("IriSP.PlayerWidget.MouseOver", IriSP.wrap(this, this.mouseOverHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4810
  this._Popcorn.listen("IriSP.PlayerWidget.MouseOut", IriSP.wrap(this, this.mouseOutHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4811
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4812
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4813
/* update the slider and the position marker as time passes */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4814
IriSP.SliderWidget.prototype.sliderUpdater = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4815
  if(this.draggingOngoing || this._disableUpdate)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4816
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4817
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4818
  var time = this._Popcorn.currentTime();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4819
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4820
  var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4821
  var percents = time / duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4822
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4823
  /* we do these complicated calculations to center exactly
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4824
     the position Marker */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4825
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4826
  var divWidth = this.selector.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4827
  var pixels = Math.floor(this.selector.width() * percents);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4828
  var positionMarker_width = this.positionMarker.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4829
  var correction = (positionMarker_width / 2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4830
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4831
  /* check that we don't leave the left side */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4832
  var newPos = pixels - correction;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4833
  if (newPos <= 0)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4834
    newPos = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4835
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4836
  /* check that we don't leave the right side */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4837
  var rightEdgePos = pixels + 1 * correction;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4838
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4839
  if (rightEdgePos >= divWidth)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4840
    newPos = divWidth - 1 * correction - 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4841
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4842
  this.sliderForeground.css("width", pixels + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4843
  this.positionMarker.css("left", newPos + "px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4844
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4845
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4846
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4847
IriSP.SliderWidget.prototype.backgroundClickHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4848
  /* this piece of code is a little bit convoluted - here's how it works :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4849
     we want to handle clicks on the progress bar and convert those to seeks in the media.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4850
     However, jquery only gives us a global position, and we want a number of pixels relative
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4851
     to our container div, so we get the parent position, and compute an offset to this position,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4852
     and finally compute the progress ratio in the media.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4853
     Finally we multiply this ratio with the duration to get the correct time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4854
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4855
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4856
  var parentOffset = this.sliderBackground.parent().offset();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4857
  var width = this.sliderBackground.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4858
  var relX = event.pageX - parentOffset.left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4859
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4860
  var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4861
  var newTime = ((relX / width) * duration).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4862
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4863
  this._Popcorn.currentTime(newTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4864
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4865
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4866
/* same function as the previous one, except that it handles clicks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4867
   on the foreground element */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4868
IriSP.SliderWidget.prototype.foregroundClickHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4869
  var parentOffset = this.sliderForeground.parent().offset();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4870
  var width = this.sliderBackground.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4871
  var relX = event.pageX - parentOffset.left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4872
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4873
  var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4874
  var newTime = ((relX / width) * duration).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4875
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4876
  this._Popcorn.currentTime(newTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4877
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4878
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4879
/* handles mouse over the slider */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4880
IriSP.SliderWidget.prototype.mouseOverHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4881
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4882
  if (this.timeOutId !== null) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4883
    window.clearTimeout(this.timeOutId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4884
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4885
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4886
  this.sliderMaximized = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4887
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4888
  this.sliderBackground.animate({"height": "9px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4889
  this.sliderForeground.animate({"height": "9px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4890
  this.positionMarker.animate({"height": "9px", "width": "9px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4891
  //this.positionMarker.css("margin-top", "-4px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4892
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4893
//  this.selector.removeClass("Ldt-SliderMinimized");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4894
//  this.selector.addClass("Ldt-SliderMaximized");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4895
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4896
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4897
/* handles when the mouse leaves the slider */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4898
IriSP.SliderWidget.prototype.mouseOutHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4899
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4900
  this.timeOutId = window.setTimeout(IriSP.wrap(this, this.minimizeOnTimeout),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4901
                                     IriSP.widgetsDefaults.SliderWidget.minimize_period);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4902
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4903
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4904
IriSP.SliderWidget.prototype.minimizeOnTimeout = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4905
  this.sliderBackground.animate({"height": "5px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4906
  this.sliderForeground.animate({"height": "5px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4907
  this.positionMarker.animate({"height": "5px", "width": "5px"}, 100);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4908
  this.positionMarker.css("margin-top", "0px");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4909
  this.sliderMinimized = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4910
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4911
//  this.selector.removeClass("Ldt-SliderMaximized");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4912
//  this.selector.addClass("Ldt-SliderMinimized");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4913
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4914
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4915
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4916
// called when the user starts dragging the position indicator
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4917
IriSP.SliderWidget.prototype.positionMarkerDraggingStartedHandler = function(event, ui) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4918
  this.draggingOngoing = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4919
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4920
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4921
IriSP.SliderWidget.prototype.positionMarkerDraggedHandler = function(event, ui) {   
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  4922
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  4923
/*  this._disableUpdate = true; // disable slider position updates while dragging is ongoing.
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4924
  window.setTimeout(IriSP.wrap(this, function() { this._disableUpdate = false; }), 500);
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  4925
*/
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4926
  var parentOffset = this.sliderForeground.parent().offset();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4927
  var width = this.sliderBackground.width();
838
03b03865eb9b Transferred i18n data to widgets, corrected slider bug, added search in annotationslist
veltr
parents: 837
diff changeset
  4928
  var relX = event.originalEvent.pageX - parentOffset.left;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4929
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  4930
  var duration = this._serializer.getDuration() / 1000;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4931
  var newTime = ((relX / width) * duration).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4932
  this._Popcorn.currentTime(newTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4933
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4934
  this.draggingOngoing = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4935
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4936
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4937
/** @class The constructor for the sparkline widget */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4938
IriSP.SparklineWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4939
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4940
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4941
  this._oldAnnotation = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4942
  this._results = [];
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4943
  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4944
  this.lineColor = this._config.lineColor || "#7492b4";
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4945
  this.fillColor = this._config.fillColor || "#aeaeb8";
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4946
  this.lineWidth = this._config.lineWidth || 2;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4947
  this.slices = this._config.slices || Math.floor(this.width/20);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4948
  if (!this.width) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4949
      this.width = this.selector.width();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4950
  }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4951
  if (!this.height) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4952
      this.height = 40;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4953
  }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4954
  this.selector.css("height", this.height + "px");
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4955
  if (this._config.background) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4956
      this.selector.css("background", this._config.background);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4957
  }
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4958
  this.checkOption('cinecast_version');
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4959
  console.log('Cinecast', this.cinecast_version);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4960
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4961
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4962
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4963
IriSP.SparklineWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4964
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4965
IriSP.SparklineWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4966
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4967
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4968
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4969
/** draw the sparkline using jquery sparkline */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4970
IriSP.SparklineWidget.prototype.draw = function() {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4971
    this.duration = this._serializer.getDuration();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4972
    this.paper = new Raphael(this.selector[0], this.width, this.height);
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4973
    var _this = this;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4974
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4975
  var views = this._serializer._data.views;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4976
  var stat_view;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4977
  if (!IriSP.null_or_undefined(views)) {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4978
    for (var i = 0; i < views.length; i++) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4979
      var view = views[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4980
      if (view.id === "stat") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4981
          stat_view = view;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4982
          break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4983
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4984
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4985
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4986
  
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4987
    var _ = IriSP.underscore;
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4988
  // If we've found the correct view, feed the directly the data from the view
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  4989
  // to jquery sparkline. Otherwise, compute it ourselves.
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4990
    if (!IriSP.null_or_undefined(stat_view)) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4991
        console.log("sparklinewidget : using stats embedded in the json");
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4992
        var _results = stat_view.meta.stat.split(",");      
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4993
    } else {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4994
        var _annotations = this._serializer._data.annotations,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4995
            _sliceDuration = Math.floor( this.duration / this.slices),
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4996
            _results = _(_.range(this.slices)).map(function(_i) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4997
                return _(_annotations).filter(function(_a){
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  4998
                    return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration) && (!_this.cinecast_version || _a.type == "cinecast:UserAnnotation")
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  4999
                }).length;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5000
            });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5001
    }
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5002
    var _max = Math.max(1, _(_results).max()),
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5003
        _h = this.height,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5004
        _scale = (_h - this.lineWidth) / _max,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5005
        _width = this.width / this.slices,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5006
        _y = _(_results).map(function(_v) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5007
            return _h - (_scale * _v);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5008
        }),
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5009
        _d = _(_y).reduce(function(_memo, _v, _k) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5010
               return _memo + ( _k
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5011
                   ? 'C' + (_k * _width) + ' ' + _y[_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5012
                   : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v )
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5013
            },'') + 'L' + this.width + ' ' + _y[_y.length - 1],
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5014
        _d2 = _d + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5015
    this.paper.path(_d2).attr({
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5016
        "stroke" : "none",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5017
        "fill" : this.fillColor
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5018
    });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5019
         
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5020
    this.paper.path(_d).attr({
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5021
        "fill" : "none",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5022
        "stroke" : this.lineColor,
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5023
        "stroke-width" : this.lineWidth
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5024
    });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5025
  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5026
    this.rectangleProgress = this.paper.rect(0,0,0,this.height)
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5027
        .attr({
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5028
            "stroke" : "none",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5029
            "fill" : "#808080",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5030
            "opacity" : .3
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5031
        });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5032
    this.ligneProgress = this.paper.path("M0 0L0 "+this.height).attr({"stroke":"#ff00ff", "line-width" : 2});
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5033
  // save the results in an array so that we can re-use them when a new annotation
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5034
  // is added.
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5035
  this._results = _results;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5036
  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5037
  this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5038
//  this._Popcorn.listen("IriSP.createAnnotationWidget.addedAnnotation", IriSP.wrap(this, this.handleNewAnnotation));
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5039
  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5040
  this.selector.click(IriSP.wrap(this, this.clickHandler));  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5041
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5042
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5043
/** react to a timeupdate event */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5044
IriSP.SparklineWidget.prototype.timeUpdateHandler = function() {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5045
    var _currentTime = this._Popcorn.currentTime(),
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5046
        _x = (1000 * _currentTime / this.duration) * this.width;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5047
    this.rectangleProgress.attr({
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5048
        "width" : _x
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5049
    });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5050
    this.ligneProgress.attr({
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5051
        "path" : "M" + _x + " 0L" + _x + " " + this.height
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5052
    });
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5053
                                  
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5054
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5055
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5056
/** handle clicks on the widget */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5057
IriSP.SparklineWidget.prototype.clickHandler = function(event) {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5058
  var relX = event.pageX - this.selector.offset().left;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5059
  var newTime = ((relX / this.width) * this.duration/1000).toFixed(2);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5060
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5061
  this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime);
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5062
  this._Popcorn.currentTime(newTime);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5063
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5064
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5065
/** react when a new annotation is added */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5066
IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) {
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5067
//  var num_columns = this._results.length;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5068
//  var duration = this._serializer.getDuration();
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5069
//  var time_step = Math.round(duration / num_columns); /* the time interval between two columns */
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5070
//  var begin = +annotation.begin;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5071
//  var end = +annotation.end;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5072
//  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5073
//  /* increment all the values between the beginning and the end of the annotation */
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5074
//  var index_begin = Math.floor(begin / time_step);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5075
//  var index_end = Math.floor(end / time_step);
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5076
//  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5077
//  for (var i = index_begin; i < Math.min(index_end, this._results.length); i++) {
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5078
//    this._results[i]++;
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5079
//  }
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5080
//  
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5081
//  this.selector.find(".Ldt-sparkLine").sparkline(this._results, {lineColor: "#7492b4", fillColor: "#aeaeb8",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5082
//                                                           spotColor: "#b70056",
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5083
//                                                           width: this.width, height: this.height});
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5084
};IriSP.StackGraphWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5085
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5086
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5087
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5088
IriSP.StackGraphWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5089
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5090
IriSP.StackGraphWidget.prototype.draw = function() {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5091
    var _ = IriSP._,
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5092
        _defaultTags = [
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5093
            {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5094
                "keywords" : [ "++" ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5095
                "description" : "positif",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5096
                "color" : "#1D973D"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5097
            },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5098
            {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5099
                "keywords" : [ "--" ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5100
                "description" : "negatif",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5101
                "color" : "#CE0A15"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5102
            },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5103
            {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5104
                "keywords" : [ "==" ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5105
                "description" : "reference",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5106
                "color" : "#C5A62D"  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5107
            },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5108
            {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5109
                "keywords" : [ "??" ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5110
                "description" : "question",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5111
                "color" : "#036AAE"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5112
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5113
        ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5114
        _defaultDefColor = "#585858";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5115
    this.height =  this._config.height || 50;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5116
    this.width = this.selector.width();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5117
    this.isStreamGraph = this._config.streamgraph || false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5118
    this.sliceCount = this._config.slices || ~~(this.width/(this.isStreamGraph ? 20 : 5));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5119
    this.tagconf = (this._config.tags
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5120
        ? this._config.tags
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5121
        : _defaultTags);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5122
    IriSP._(this.tagconf).each(function(_a) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5123
        _a.regexp = new RegExp(_(_a.keywords).map(function(_k) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5124
            return _k.replace(/([\W])/gm,'\\$1');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5125
        }).join("|"),"im")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5126
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5127
    this.defaultcolorconf = (this._config.defaultcolor
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5128
        ? this._config.defaultcolor
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5129
        : _defaultDefColor);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5130
    this.paper = new Raphael(this.selector[0], this.width, this.height);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5131
    this.groups = [];
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5132
    this.duration = this._serializer.getDuration();
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5133
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5134
    var _annotationType = this._serializer.getTweets(),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5135
        _sliceDuration = ~~ ( this.duration / this.sliceCount),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5136
        _annotations = this._serializer._data.annotations,
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5137
        _groupedAnnotations = _(_.range(this.sliceCount)).map(function(_i) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5138
            return _(_annotations).filter(function(_a){
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5139
                return (_a.begin <= (1 + _i) * _sliceDuration) && (_a.end >= _i * _sliceDuration)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5140
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5141
        }),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5142
        _max = IriSP._(_groupedAnnotations).max(function(_g) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5143
            return _g.length
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5144
        }).length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5145
        _scale = this.height / _max,
835
a8af9da7c622 Integrated trace manager
veltr
parents: 833
diff changeset
  5146
        _width = this.width / this.sliceCount,
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5147
        _showTitle = !this._config.excludeTitle,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5148
        _showDescription = !this._config.excludeDescription;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5149
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5150
    
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5151
    var _paths = _(this.tagconf).map(function() {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5152
        return [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5153
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5154
    _paths.push([]);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5155
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5156
    for (var i = 0; i < this.sliceCount; i++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5157
        var _group = _groupedAnnotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5158
        if (_group) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5159
            var _vol = _(this.tagconf).map(function() {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5160
                return 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5161
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5162
            for (var j = 0; j < _group.length; j++){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5163
           var _txt = (_showTitle ? _group[j].content.title : '') + ' ' + (_showDescription ? _group[j].content.description : '')
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5164
                var _tags = _(this.tagconf).map(function(_tag) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5165
                        return (_txt.search(_tag.regexp) == -1 ? 0 : 1)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5166
                    }),
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5167
                    _nbtags = _(_tags).reduce(function(_a,_b) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5168
                        return _a + _b;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5169
                    }, 0);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5170
                if (_nbtags) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5171
                    IriSP._(_tags).each(function(_v, _k) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5172
                        _vol[_k] += (_v / _nbtags);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5173
                    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5174
                }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5175
            }
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5176
            var _nbtags = _(_vol).reduce(function(_a,_b) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5177
                    return _a + _b;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5178
                }, 0),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5179
                _nbneutre = _group.length - _nbtags,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5180
                _h = _nbneutre * _scale,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5181
                _base = this.height - _h;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5182
            if (!this.isStreamGraph) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5183
                this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5184
                    "stroke" : "none",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5185
                    "fill" : this.defaultcolorconf
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5186
                });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5187
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5188
           _paths[0].push(_base);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5189
            for (var j = 0; j < this.tagconf.length; j++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5190
                _h = _vol[j] * _scale;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5191
                _base = _base - _h;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5192
                if (!this.isStreamGraph) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5193
                    this.paper.rect(i * _width, _base, _width - 1, _h ).attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5194
                        "stroke" : "none",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5195
                        "fill" : this.tagconf[j].color
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5196
                    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5197
                }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5198
                _paths[j+1].push(_base);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5199
            }
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5200
            this.groups.push(_(_vol).map(function(_v) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5201
                return _v / _group.length;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5202
            }))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5203
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5204
            for (var j = 0; j < _paths.length; j++) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5205
                _paths[j].push(this.height);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5206
            }
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5207
            this.groups.push(_(this.tagconf).map(function() {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5208
                return 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5209
            }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5210
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5211
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5212
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5213
    if (this.isStreamGraph) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5214
        for (var j = _paths.length - 1; j >= 0; j--) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5215
            var _d = _(_paths[j]).reduce(function(_memo, _v, _k) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5216
               return _memo + ( _k
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5217
                   ? 'C' + (_k * _width) + ' ' + _paths[j][_k - 1] + ' ' + (_k * _width) + ' ' + _v + ' ' + ((_k + .5) * _width) + ' ' + _v
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5218
                   : 'M0 ' + _v + 'L' + (.5*_width) + ' ' + _v )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5219
            },'') + 'L' + this.width + ' ' + _paths[j][_paths[j].length - 1] + 'L' + this.width + ' ' + this.height + 'L0 ' + this.height;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5220
            this.paper.path(_d).attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5221
                "stroke" : "none",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5222
                "fill" : (j ? this.tagconf[j-1].color : this.defaultcolorconf)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5223
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5224
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5225
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5226
    this.rectangleFocus = this.paper.rect(0,0,_width,this.height)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5227
        .attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5228
            "stroke" : "none",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5229
            "fill" : "#ff00ff",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5230
            "opacity" : 0
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5231
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5232
    this.rectangleProgress = this.paper.rect(0,0,0,this.height)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5233
        .attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5234
            "stroke" : "none",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5235
            "fill" : "#808080",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5236
            "opacity" : .3
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5237
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5238
    this.ligneProgress = this.paper.path("M0 0L0 "+this.height).attr({"stroke":"#ff00ff", "line-width" : 2})
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5239
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5240
    this._Popcorn.listen("timeupdate", IriSP.wrap(this, this.timeUpdateHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5241
    var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5242
    this.selector
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5243
        .click(IriSP.wrap(this, this.clickHandler))
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5244
        .mousemove(function(_e) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5245
            _this.updateTooltip(_e);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5246
            // Trace
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5247
            var relX = _e.pageX - _this.selector.offset().left;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5248
            var _duration = _this._serializer.getDuration();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5249
            var _time = parseInt((relX / _this.width) * _duration);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5250
            _this._Popcorn.trigger("IriSP.TraceWidget.MouseEvents", {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5251
                "widget" : "StackGraphWidget",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5252
                "type": "mousemove",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5253
                "x": _e.pageX,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5254
                "y": _e.pageY,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5255
                "time": _time
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5256
            });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5257
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5258
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5259
        .mouseout(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5260
            _this.TooltipWidget.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5261
            _this.rectangleFocus.attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5262
                "opacity" : 0
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5263
            })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5264
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5265
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5266
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5267
IriSP.StackGraphWidget.prototype.timeUpdateHandler = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5268
    var _currentTime = this._Popcorn.currentTime(),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5269
        _x = (1000 * _currentTime / this.duration) * this.width;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5270
    this.rectangleProgress.attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5271
        "width" : _x
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5272
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5273
    this.ligneProgress.attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5274
        "path" : "M" + _x + " 0L" + _x + " " + this.height
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5275
    })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5276
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5277
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5278
IriSP.StackGraphWidget.prototype.clickHandler = function(event) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5279
  /* Ctrl-C Ctrl-V'ed from another widget
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5280
  */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5281
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5282
  var relX = event.pageX - this.selector.offset().left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5283
  var newTime = ((relX / this.width) * this.duration/1000).toFixed(2);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5284
  this._Popcorn.trigger("IriSP.StackGraphWidget.clicked", newTime);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5285
  this._Popcorn.currentTime(newTime);                                 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5286
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5287
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5288
IriSP.StackGraphWidget.prototype.updateTooltip = function(event) {
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5289
    var _segment = Math.max(0,Math.min(this.groups.length - 1, Math.floor(this.sliceCount * (event.pageX - this.selector.offset().left)/this.width))),
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5290
        _valeurs = this.groups[_segment],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5291
        _width = this.width / this.sliceCount,
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5292
        _html = '<ul style="list-style: none; margin: 0; padding: 0;">' + IriSP._(this.tagconf).map(function(_tag, _i) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5293
            return '<li style="clear: both;"><span style="float: left; width: 10px; height: 10px; margin: 2px; background: '
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5294
                + _tag.color
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5295
                + ';"></span>'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5296
                + ~~(100 * _valeurs[_i])
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5297
                + '% de '
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5298
                + _tag.description
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5299
                + '</li>';
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5300
        }).join('') + '</ul>';
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5301
    this.TooltipWidget._shown = false; // Vraiment, on ne peut pas ouvrir le widget s'il n'est pas encore ouvert ?
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5302
    this.TooltipWidget.show('','',(_segment + .5)* this.width / this.sliceCount, 0);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5303
    this.TooltipWidget.selector.find(".tip").html(_html);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5304
    this.rectangleFocus.attr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5305
        "x" : _segment * _width,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5306
        "opacity" : .4
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5307
    })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5308
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5309
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5310
IriSP.TagCloudWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5311
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5312
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5313
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5314
IriSP.TagCloudWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5315
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5316
IriSP.TagCloudWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5317
    
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5318
    var _urlRegExp = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5319
        _stopWords = [
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5320
            'aussi', 'and', 'avec', 'aux', 'bien', 'car', 'cette', 'comme', 'dans', 'donc', 'des', 'elle', 'encore', 'entre', 'est',
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5321
            'être', 'eux', 'faire', 'fait', 'http', 'ici', 'ils', 'les', 'leur', 'leurs', 'mais', 'mes', 'même', 'mon', 'notre',
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5322
            'non', 'nos', 'nous', 'ont', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'sans', 'ses' ,'son', 'sont', 'sur',
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5323
            'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' ],
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5324
        _regexpword = /[^\s\.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5325
        _words = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5326
        _showTitle = !this._config.excludeTitle,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5327
        _showDescription = !this._config.excludeDescription,
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5328
        _excludePattern = this._config.excludePattern || null,
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5329
        _tagCount = this._config.tagCount || 30;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5330
    if (typeof this._config.excludeWords !== "undefined" && this._config.excludeWords.length) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5331
        IriSP._(this._config.excludeWords).each(function(_w) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5332
            _stopWords.push(_w.toLowerCase());
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5333
        });
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5334
    }
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5335
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5336
    IriSP._(this._serializer._data.annotations).each(function(_annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5337
       if (_annotation.content && _annotation.content.description) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5338
           var _txt = (_showTitle ? _annotation.content.title : '') + ' ' + (_showDescription ? _annotation.content.description : '')
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5339
           IriSP._(_txt.toLowerCase().replace(_urlRegExp, '').match(_regexpword)).each(function(_mot) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5340
               if (_stopWords.indexOf(_mot) == -1 && (_excludePattern == null || !_excludePattern.test(_mot))) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5341
                   _words[_mot] = 1 + (_words[_mot] || 0);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5342
               }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5343
           })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5344
       } 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5345
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5346
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5347
    _words = IriSP._(_words)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5348
        .chain()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5349
        .map(function(_v, _k) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5350
            return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5351
                "word" : _k,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5352
                "count" : _v
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5353
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5354
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5355
        .filter(function(_v) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5356
            return _v.count > 2;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5357
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5358
        .sortBy(function(_v) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5359
            return - _v.count;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5360
        })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5361
        .first(_tagCount)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5362
        .value();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5363
    var _max = _words[0].count,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5364
        _min = Math.min(_words[_words.length - 1].count, _max - 1),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5365
        _scale = 16 / Math.sqrt(_max - _min),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5366
        _this = this,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5367
        _html = '<ul>'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5368
            + IriSP._(_words)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5369
                .chain()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5370
                .shuffle()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5371
                .map(function(_word) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5372
                    var _size = 10 + _scale * Math.sqrt(_word.count - _min);
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5373
                    return '<li class="Ldt-TraceMe" style="font-size:'
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5374
                        + _size
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5375
                        + 'px;">'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5376
                        + _word.word
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5377
                        + '</li>'
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5378
                })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5379
                .value()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5380
                .join("")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5381
            + '</ul>';
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5382
    this.selector
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5383
        .addClass("Ldt-TagCloud")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5384
        .html(_html);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5385
    this.selector.find("li").click(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5386
        var _txt = this.textContent.replace(/(^[\s]+|[\s]+$)/g,'');
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5387
        _this._Popcorn.trigger("IriSP.search.triggeredSearch", _txt);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5388
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5389
    this._Popcorn.listen("IriSP.search", IriSP.wrap(this, function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5390
        var _rgxp = new RegExp("(" + searchString.replace(/(\W)/g,'\\$1') + ")","gi");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5391
        this.selector.find("li").each(function(_i, _e) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5392
            _e.innerHTML = searchString.length ?
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5393
                _e.textContent.replace(_rgxp,'<span class="Ldt-TagCloud-actif Ldt-TraceMe">$1</span>')
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5394
                : _e.textContent;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5395
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5396
    }));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5397
    this._Popcorn.listen("IriSP.search.closed", IriSP.wrap(this, this.endsearch));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5398
    this._Popcorn.listen("IriSP.search.cleared", IriSP.wrap(this, this.endsearch));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5399
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5400
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5401
IriSP.TagCloudWidget.prototype.endsearch = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5402
    this.selector.find("li").each(function(_i, _e) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5403
        _e.innerHTML = _e.textContent;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5404
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5405
}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5406
/* this widget displays a small tooltip */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5407
IriSP.TooltipWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5408
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5409
  this._shown = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5410
  this._displayedText = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5411
  this._hideTimeout = -1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5412
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5413
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5414
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5415
IriSP.TooltipWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5416
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5417
IriSP.TooltipWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5418
  var templ = Mustache.to_html(IriSP.tooltipWidget_template);
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5419
  // position the widget absolutely relative to document. --- NOOOO !!!!
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5420
  this.selector.css({
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5421
      "position": "absolute",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5422
      "top": 0,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5423
      "left": 0
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5424
  });
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5425
  this.selector.parent().css({
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5426
      "position": "relative"
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5427
  });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5428
  this.selector.append(templ);
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5429
  var _this = this;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5430
  this.selector.mouseover(function() {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5431
      _this.hide();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5432
  });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5433
  this.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5434
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5435
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5436
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5437
IriSP.TooltipWidget.prototype.clear = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5438
	this.selector.find(".tiptext").html("");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5439
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5440
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5441
IriSP.TooltipWidget.prototype.show = function(text, color, x, y) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5442
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5443
  if (this._displayedText == text && this._shown)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5444
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5445
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5446
  this.selector.find(".tipcolor").css("background-color", color);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5447
  this._displayedText = text;
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5448
  this.selector.find(".tiptext").html(text);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5449
  
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5450
  var _tip = this.selector.find(".tip");
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5451
  _tip.show();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5452
  _tip.css({
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5453
      "left": Math.floor(x - _tip.outerWidth() / 2)+"px",
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5454
      "top": Math.floor(y - _tip.outerHeight())+"px"
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5455
  });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5456
  this._shown = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5457
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5458
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5459
IriSP.TooltipWidget.prototype.hide = function() {                                                   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5460
  this.selector.find(".tip").hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5461
  this._shown = false;  
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5462
};IriSP.TraceWidget = function(Popcorn, config, Serializer) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5463
  IriSP.Widget.call(this, Popcorn, config, Serializer);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5464
  this.lastEvent = "";
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5465
  var _this = this,
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5466
    _listeners = {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5467
        "IriSP.createAnnotationWidget.addedAnnotation" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5468
        "IriSP.search.open" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5469
        "IriSP.search.closed" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5470
        "IriSP.search" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5471
        "IriSP.search.cleared" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5472
        "IriSP.search.matchFound" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5473
        "IriSP.search.noMatchFound" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5474
        "IriSP.search.triggeredSearch" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5475
        "IriSP.TraceWidget.MouseEvents" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5476
        "play" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5477
        "pause" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5478
        "volumechange" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5479
        "seeked" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5480
        "play" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5481
        "pause" : 0,
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5482
        "timeupdate" : 2000
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5483
    };
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5484
    IriSP._(_listeners).each(function(_ms, _listener) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5485
        var _f = function(_arg) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5486
            _this.eventHandler(_listener, _arg);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5487
        }
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5488
        if (_ms) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5489
            _f = IriSP.underscore.throttle(_f, _ms);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5490
        }
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5491
        _this._Popcorn.listen(_listener, _f);
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5492
    });
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5493
    this._Popcorn.listen("timeupdate", IriSP.underscore.throttle(function(_arg) {
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5494
        _this.eventHandler(_listener, _arg);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5495
    }));
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5496
    
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5497
    this.tracer = IriSP.TraceManager(IriSP.jQuery).init_trace("test", this._config);
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5498
    this.tracer.set_default_subject("default_subject");
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5499
    this.tracer.trace("StartTracing", { "hello": "world" });
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5500
    
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5501
}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5502
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5503
IriSP.TraceWidget.prototype = new IriSP.Widget();
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5504
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5505
IriSP.TraceWidget.prototype.draw = function() {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5506
    this.mouseLocation = '';
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5507
    var _this = this;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5508
    IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) {
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5509
        var _widget = IriSP.jQuery(this).attr("widget-type"),
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5510
            _class = _e.target.className;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5511
        var _data = {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5512
            "type": _e.type,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5513
            "x": _e.clientX,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5514
            "y": _e.clientY,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5515
            "widget": _widget
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5516
        }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5517
        if (typeof _class == "string" && _class.indexOf('Ldt-TraceMe') != -1) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5518
            var _name = _e.target.localName,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5519
                _id = _e.target.id,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5520
                _text = _e.target.textContent.trim(),
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5521
                _title = _e.target.title,
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5522
                _value = _e.target.value;
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5523
            _data.target = _name + (_id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : '');
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5524
            if (typeof _title == "string" && _title.length && _title.length < 140) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5525
                _data.title = _title;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5526
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5527
            if (typeof _text == "string" && _text.length && _text.length < 140) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5528
                _data.text = _text;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5529
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5530
            if (typeof _value == "string" && _value.length) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5531
                _data.value = _value;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5532
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5533
            _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5534
        } else {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5535
            //console.log(_e.type+','+_this.mouseLocation+','+_widget);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5536
            if (_e.type == "mouseover") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5537
                if (_this.mouseLocation != _widget) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5538
                    _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5539
                } else {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5540
                    if (typeof _this.moTimeout != "undefined") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5541
                        clearTimeout(_this.moTimeout);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5542
                        delete _this.moTimeout;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5543
                    }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5544
                }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5545
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5546
            if (_e.type == "click") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5547
                _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5548
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5549
            if (_e.type == "mouseout") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5550
                if (typeof _this.moTimeout != "undefined") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5551
                    clearTimeout(_this.moTimeout);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5552
                }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5553
                _this.moTimeout = setTimeout(function() {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5554
                   if (_data.widget != _this.mouseLocation) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5555
                       _this._Popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5556
                   }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5557
                },100);
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5558
            }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5559
        }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5560
        _this.mouseLocation = _widget;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5561
    });
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5562
}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5563
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5564
IriSP.TraceWidget.prototype.eventHandler = function(_listener, _arg) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5565
    var _traceName = 'Mdp_';
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5566
    if (typeof _arg == "string" || typeof _arg == "number") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5567
        _arg = { "value" : _arg }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5568
    }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5569
    if (typeof _arg == "undefined") {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5570
        _arg = {}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5571
    }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5572
    switch(_listener) {
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5573
        case 'IriSP.TraceWidget.MouseEvents':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5574
            _traceName += _arg.widget + '_' + _arg.type;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5575
            delete _arg.widget;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5576
            delete _arg.type;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5577
        break;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5578
        case 'timeupdate':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5579
        case 'play':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5580
        case 'pause':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5581
            _arg.time = this._Popcorn.currentTime() * 1000;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5582
        case 'seeked':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5583
        case 'volumechange':
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5584
            _traceName += 'Popcorn_' + _listener;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5585
        break;
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5586
        default:
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5587
            _traceName += _listener.replace('IriSP.','').replace('.','_');
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5588
    }
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5589
    this.lastEvent = _traceName;
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5590
    this.tracer.trace(_traceName, _arg);
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5591
    console.log("trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
836
526f91f5253e Changes for Cinecast
veltr
parents: 835
diff changeset
  5592
    
831
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5593
}
0dd21c298380 Integration pour cinecast
veltr
parents: 823
diff changeset
  5594
/* a widget that displays tweet - used in conjunction with the polemicWidget */
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5595
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5596
IriSP.TweetsWidget = function(Popcorn, config, Serializer) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5597
  IriSP.Widget.call(this, Popcorn, config, Serializer);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5598
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5599
  this._displayingTweet = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5600
  this._timeoutId = undefined; 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5601
  this._hidden = false; /* hidden means that the createAnnotationWidget is shown */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5602
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5603
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5604
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5605
IriSP.TweetsWidget.prototype = new IriSP.Widget();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5606
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5607
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5608
IriSP.TweetsWidget.prototype.drawTweet = function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5609
    if (this._hidden)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5610
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5611
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5612
    var title = IriSP.formatTweet(annotation.content.title);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5613
    var img = annotation.content.img.src;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5614
    if (typeof(img) === "undefined" || img === "" || img === "None") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5615
      img = IriSP.widgetsDefaults.TweetsWidget.default_profile_picture;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5616
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5617
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5618
    var imageMarkup = IriSP.templToHTML("<img src='{{src}}' alt='user image'></img>", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5619
                                       {src : img});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5620
    
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5621
    if (typeof(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content) !== "undefined") {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  5622
      var tweetContents = JSON.parse(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content);
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5623
      var creator = tweetContents.user.screen_name;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5624
      var real_name = tweetContents.user.name;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5625
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5626
      imageMarkup = IriSP.templToHTML("<a href='http://twitter.com/{{creator}}'><img src='{{src}}' alt='user image'></img></a>", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5627
                                       {src : img, creator: creator});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5628
            
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5629
      var formatted_date = new Date(tweetContents.created_at).toLocaleDateString();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5630
      title = IriSP.templToHTML("<a class='Ldt-tweet_userHandle' href='http://twitter.com/{{creator}}'>@{{creator}}</a> - " + 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5631
                                "<div class='Ldt-tweet_realName'>{{real_name}}</div>" +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5632
                                "<div class='Ldt-tweet_tweetContents'>{{{ contents }}}</div>" +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5633
                                "<div class='Ldt-tweet_date'>{{ date }}</div>", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5634
                                {creator: creator, real_name: real_name, contents : title, date : formatted_date});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5635
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5636
      this.selector.find(".Ldt-TweetReply").attr("href", "http://twitter.com/home?status=@" + creator + ":%20");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5637
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5638
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5639
      var rtText = Mustache.to_html("http://twitter.com/home?status=RT @{{creator}}: {{text}}",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5640
                                    {creator: creator, text: IriSP.encodeURI(annotation.content.title)});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5641
      this.selector.find(".Ldt-Retweet").attr("href", rtText);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5642
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5643
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5644
    this.selector.find(".Ldt-tweetContents").html(title);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5645
    this.selector.find(".Ldt-tweetAvatar").html(imageMarkup);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5646
    this.selector.show("blind", 250); 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5647
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5648
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5649
IriSP.TweetsWidget.prototype.displayTweet = function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5650
  if (this._displayingTweet === false) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5651
    this._displayingTweet = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5652
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5653
    window.clearTimeout(this._timeoutId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5654
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5655
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5656
  this.drawTweet(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5657
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5658
  var time = this._Popcorn.currentTime();  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5659
  this._timeoutId = window.setTimeout(IriSP.wrap(this, this.clearPanel), IriSP.widgetsDefaults.TweetsWidget.tweet_display_period);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5660
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5661
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5662
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5663
IriSP.TweetsWidget.prototype.clearPanel = function() {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5664
    this._displayingTweet = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5665
    this._timeoutId = undefined;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5666
    this.closePanel();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5667
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5668
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5669
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5670
IriSP.TweetsWidget.prototype.closePanel = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5671
    if (this._timeoutId != undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5672
      /* we're called from the "close window" link */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5673
      /* cancel the timeout */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5674
      window.clearTimeout(this._timeoutId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5675
      this._timeoutId = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5676
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5677
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5678
    this.selector.hide("blind", 400);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5679
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5680
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5681
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5682
/* cancel the timeout if the user clicks on the keep panel open button */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5683
IriSP.TweetsWidget.prototype.keepPanel = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5684
    if (this._timeoutId != undefined) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5685
      /* we're called from the "close window" link */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5686
      /* cancel the timeout */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5687
      window.clearTimeout(this._timeoutId);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5688
      this._timeoutId = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5689
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5690
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5691
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5692
IriSP.TweetsWidget.prototype.draw = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5693
  var _this = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5694
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5695
  var tweetMarkup = IriSP.templToHTML(IriSP.tweetWidget_template, {"share_template" : IriSP.share_template});
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5696
  this.selector.append(tweetMarkup);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5697
  this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5698
  this.selector.find(".Ldt-tweetWidgetMinimize").click(IriSP.wrap(this, this.closePanel));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5699
  this.selector.find(".Ldt-tweetWidgetKeepOpen").click(IriSP.wrap(this, this.keepPanel));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5700
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5701
  this._Popcorn.listen("IriSP.PolemicTweet.click", IriSP.wrap(this, this.PolemicTweetClickHandler));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5702
  this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5703
                        IriSP.wrap(this, this.handleAnnotateSignal));  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5704
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5705
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5706
IriSP.TweetsWidget.prototype.PolemicTweetClickHandler = function(tweet_id) {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5707
  var index, annotation;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5708
  for (index in this._serializer._data.annotations) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5709
    annotation = this._serializer._data.annotations[index];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5710
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5711
    if (annotation.id === tweet_id)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5712
      break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5713
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5714
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5715
  if (annotation.id !== tweet_id)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5716
      /* we haven't found it */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5717
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5718
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5719
  this.displayTweet(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5720
  return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5721
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5722
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5723
/** handle clicks on the annotate button by hiding/showing itself */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5724
IriSP.TweetsWidget.prototype.handleAnnotateSignal = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5725
  if (this._hidden == false) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5726
    this.selector.hide();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5727
    this._hidden = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5728
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5729
    if (this._displayingTweet !== false)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5730
      this.selector.show();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5731
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5732
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5733
    this._hidden = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5734
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5735
};/** @class This class implement a serializer for the JSON-Cinelab format
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5736
    @params DataLoader a dataloader reference
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5737
    @url the url from which to get our cinelab
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5738
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5739
IriSP.JSONSerializer = function(DataLoader, url) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5740
  IriSP.Serializer.call(this, DataLoader, url);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5741
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5742
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5743
IriSP.JSONSerializer.prototype = new IriSP.Serializer();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5744
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5745
/** serialize data */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5746
IriSP.JSONSerializer.prototype.serialize = function(data) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5747
  return JSON.stringify(data);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5748
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5749
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5750
/** deserialize data */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5751
IriSP.JSONSerializer.prototype.deserialize = function(data) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5752
  return JSON.parse(data);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5753
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5754
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5755
/** load JSON-cinelab data and also sort the annotations by start time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5756
    @param callback function to call when the data is ready.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5757
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5758
IriSP.JSONSerializer.prototype.sync = function(callback) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5759
  /* we don't have to do much because jQuery handles json for us */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5760
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5761
  var self = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5762
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5763
  var fn = function(data) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5764
	  //TODO: seems taht data can be null here
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5765
	  if (data !== null) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5766
		  self._data = data;  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5767
	      if (typeof(self._data["annotations"]) === "undefined" ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5768
	          self._data["annotations"] === null)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5769
	          self._data["annotations"] = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5770
	      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5771
	      // sort the data too       
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5772
	      self._data["annotations"].sort(function(a, b) 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5773
	          { var a_begin = +a.begin;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5774
	            var b_begin = +b.begin;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5775
	            return a_begin - b_begin;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5776
	          });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5777
	  }     
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5778
      callback(data);      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5779
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5780
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5781
  this._DataLoader.get(this._url, fn);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5782
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5783
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5784
/** @return the metadata about the media being read FIXME: always return the first media. */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5785
IriSP.JSONSerializer.prototype.currentMedia = function() {  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5786
  return this._data.medias[0]; /* FIXME: don't hardcode it */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5787
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5788
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5789
/** searches for an annotation which matches title, description and keyword 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5790
   "" matches any field. 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5791
   Note: it ignores tweets.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5792
   @return a list of matching ids.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5793
*/    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5794
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5795
    /* we can have many types of annotations. We want search to only look for regular segments */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5796
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5797
       null or undefined.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5798
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5799
    var view;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5800
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5801
    if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5802
       view = this._data.views[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5803
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5804
    var searchViewType = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5805
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5806
    if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5807
            searchViewType = view.annotation_types[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5808
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5809
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5810
    var filterfn = function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5811
      if( searchViewType  != "" && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5812
          typeof(annotation.meta) !== "undefined" && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5813
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5814
          annotation.meta["id-ref"] !== searchViewType) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5815
        return true; // don't pass
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5816
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5817
          return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5818
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5819
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5820
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5821
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5822
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5823
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5824
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5825
/* only look for tweets */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5826
IriSP.JSONSerializer.prototype.searchTweets = function(title, description, keyword) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5827
    /* we can have many types of annotations. We want search to only look for regular segments */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5828
    /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5829
       null or undefined.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5830
    */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5831
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5832
    var searchViewType = this.getTweets();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5833
    if (typeof(searchViewType) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5834
      var view;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5835
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5836
      if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5837
         view = this._data.views[0];    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5838
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5839
      if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5840
              searchViewType = view.annotation_types[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5841
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5842
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5843
    var filterfn = function(annotation) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5844
      if( searchViewType  != "" && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5845
          typeof(annotation.meta) !== "undefined" && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5846
          typeof(annotation.meta["id-ref"]) !== "undefined" &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5847
          annotation.meta["id-ref"] === searchViewType) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5848
        return false; // pass
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5849
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5850
          return true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5851
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5852
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5853
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5854
    return this.searchAnnotationsFilter(title, description, keyword, filterfn);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5855
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5856
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5857
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5858
/**
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5859
  search an annotation according to its title, description and keyword
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5860
  @param filter a function to filter the results with. Used to select between annotation types.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5861
 */    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5862
IriSP.JSONSerializer.prototype.searchAnnotationsFilter = function(title, description, keyword, filter) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5863
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5864
    var rTitle;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5865
    var rDescription;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5866
    var rKeyword;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5867
    /* match anything if given the empty string */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5868
    if (title == "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5869
      title = ".*";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5870
    if (description == "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5871
      description = ".*";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5872
    if (keyword == "")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5873
      keyword = ".*";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5874
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5875
    rTitle = new RegExp(title, "i");  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5876
    rDescription = new RegExp(description, "i");  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5877
    rKeyword = new RegExp(keyword, "i");  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5878
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5879
    var ret_array = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5880
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5881
    var i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5882
    for (i in this._data.annotations) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5883
      var annotation = this._data.annotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5884
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5885
      /* filter the annotations whose type is not the one we want */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5886
      if (filter(annotation)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5887
          continue;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5888
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5889
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5890
      if (rTitle.test(annotation.content.title) && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5891
          rDescription.test(annotation.content.description)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5892
          /* FIXME : implement keyword support */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5893
          ret_array.push(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5894
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5895
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5896
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5897
    return ret_array;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5898
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5899
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5900
/** breaks a string in words and searches each of these words. Returns an array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5901
   of objects with the id of the annotation and its number of occurences.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5902
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5903
   @param searchString a string of words.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5904
   FIXME: optimize ? seems to be n^2 in the worst case.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5905
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5906
IriSP.JSONSerializer.prototype.searchOccurences = function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5907
  var ret = { };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5908
  var keywords = searchString.split(/\s+/);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5909
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5910
  for (var i in keywords) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5911
    var keyword = keywords[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5912
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5913
    // search this keyword in descriptions and title
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5914
    var found_annotations = []
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5915
    found_annotations = found_annotations.concat(this.searchAnnotations(keyword, "", ""));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5916
    found_annotations = found_annotations.concat(this.searchAnnotations("", keyword, ""));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5917
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5918
    for (var j in found_annotations) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5919
      var current_annotation = found_annotations[j];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5920
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5921
      if (!ret.hasOwnProperty(current_annotation.id)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5922
        ret[current_annotation.id] = 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5923
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5924
        ret[current_annotation.id] += 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5925
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5926
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5927
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5928
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5929
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5930
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5931
  return ret;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5932
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5933
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5934
/** breaks a string in words and searches each of these words. Returns an array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5935
   of objects with the id of the annotation and its number of occurences.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5936
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5937
   FIXME: optimize ? seems to be n^2 in the worst case.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5938
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5939
IriSP.JSONSerializer.prototype.searchTweetsOccurences = function(searchString) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5940
  var ret = { };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5941
  var keywords = searchString.split(/\s+/);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5942
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5943
  for (var i in keywords) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5944
    var keyword = keywords[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5945
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5946
    // search this keyword in descriptions and title
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5947
    var found_annotations = []
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5948
    found_annotations = found_annotations.concat(this.searchTweets(keyword, "", ""));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5949
    found_annotations = found_annotations.concat(this.searchTweets("", keyword, ""));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5950
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5951
    for (var j in found_annotations) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5952
      var current_annotation = found_annotations[j];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5953
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5954
      if (!ret.hasOwnProperty(current_annotation.id)) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5955
        ret[current_annotation.id] = 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5956
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5957
        ret[current_annotation.id] += 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5958
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5959
      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5960
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5961
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5962
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5963
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5964
  return ret;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5965
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5966
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5967
/** returns all the annotations that are displayable at the moment 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5968
   NB: only takes account the first type of annotations - ignores tweets 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5969
   currentTime is in seconds.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5970
   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5971
   @param currentTime the time at which we search.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5972
   @param (optional) the if of the type of the annotations we want to get.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5973
 */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5974
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5975
IriSP.JSONSerializer.prototype.currentAnnotations = function(currentTime, id) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5976
  var view;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5977
  var currentTimeMs = 1000 * currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5978
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5979
  if (typeof(id) === "undefined") {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5980
      var legal_ids = this.getNonTweetIds();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5981
  } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5982
      legal_ids = [id];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5983
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5984
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5985
  var ret_array = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5986
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5987
  var i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5988
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5989
  for (i in this._data.annotations) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5990
    var annotation = this._data.annotations[i];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5991
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5992
    if (IriSP.underscore.include(legal_ids, annotation.meta["id-ref"]) && 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5993
        annotation.begin <= currentTimeMs &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5994
        annotation.end >= currentTimeMs)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5995
          ret_array.push(annotation);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5996
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5997
 
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5998
  if (ret_array == []) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  5999
    console.log("ret_array empty, ", legal_ids);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6000
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6001
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6002
  return ret_array;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6003
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6004
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6005
/** return the current chapitre
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6006
    @param currentTime the current time, in seconds.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6007
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6008
IriSP.JSONSerializer.prototype.currentChapitre = function(currentTime) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6009
  return this.currentAnnotations(currentTime, this.getChapitrage())[0];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6010
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6011
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6012
/** returns a list of ids of tweet lines (aka: groups in cinelab) */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6013
IriSP.JSONSerializer.prototype.getTweetIds = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6014
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6015
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6016
    return [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6017
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6018
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6019
  /* Get the displayable types
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6020
     We've got to jump through a few hoops because the json sometimes defines
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6021
     fields with underscores and sometimes with dashes
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6022
  */
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6023
  var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]);
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6024
  if (annotation_types === null) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6025
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6026
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6027
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6028
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6029
  var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);    
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6030
  if (available_types === null) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6031
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6032
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6033
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6034
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6035
  var potential_types = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6036
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6037
  // Get the list of types which contain "Tw" in their content
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6038
  for (var i = 0; i < available_types.length; i++) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6039
    if (/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title']))) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6040
      potential_types.push(available_types[i].id);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6041
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6042
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6043
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6044
  // Get the intersection of both.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6045
  var tweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6046
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6047
  return tweetsId;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6048
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6049
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6050
/** this function returns a list of lines which are not tweet lines */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6051
IriSP.JSONSerializer.prototype.getNonTweetIds = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6052
  if (IriSP.null_or_undefined(this._data.lists) || IriSP.null_or_undefined(this._data.lists) ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6053
      IriSP.null_or_undefined(this._data.views) || IriSP.null_or_undefined(this._data.views[0]))
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6054
    return [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6055
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6056
  /* Get the displayable types
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6057
     We've got to jump through a few hoops because the json sometimes defines
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6058
     fields with underscores and sometimes with dashes
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6059
  */
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6060
  var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]);
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6061
  if (annotation_types === null) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6062
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6063
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6064
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6065
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6066
  var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);    
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6067
  if (available_types === null) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6068
      console.log("neither view.annotation_types nor view.annotation-types are defined");      
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6069
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6070
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6071
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6072
  var potential_types = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6073
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6074
  // Get the list of types which do not contain "Tw" in their content
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6075
  for (var i = 0; i < available_types.length; i++) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6076
    if (!(/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title'])))) {
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6077
      potential_types.push(available_types[i].id);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6078
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6079
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6080
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6081
  // Get the intersection of both.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6082
  var nonTweetsId = IriSP.underscore.intersection(annotation_types, potential_types);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6083
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6084
  return nonTweetsId;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6085
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6086
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6087
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6088
/** return the id of the ligne de temps which contains name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6089
    @param name of the ligne de temps
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6090
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6091
IriSP.JSONSerializer.prototype.getId = function(name) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6092
   var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);  
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6093
   
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6094
  if (available_types == null)
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6095
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6096
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6097
  name = name.toUpperCase();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6098
  var e;  
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6099
  e = IriSP.underscore.find(available_types, 
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6100
    function(entry) {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6101
        if (IriSP.get_aliased(entry, ['dc:title', 'title']) === null)
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6102
          return false;
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6103
        return (entry["dc:title"].toUpperCase().indexOf(name) !== -1);
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6104
    });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6105
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6106
  if (typeof(e) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6107
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6108
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6109
  var id = e.id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6110
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6111
  return id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6112
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6113
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6114
/** return the list of id's of the ligne de temps which contains name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6115
    @param name of the ligne de temps
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6116
*/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6117
IriSP.JSONSerializer.prototype.getIds = function(name) {
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6118
   var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]);  
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6119
   
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6120
  if (available_types == null)
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6121
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6122
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6123
  name = name.toUpperCase();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6124
  var e = [];  
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6125
  e = IriSP.underscore.filter(available_types, 
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6126
                                  function(entry) { return (IriSP.get_aliased(entry, ['dc:title', 'title']).toUpperCase().indexOf(name) !== -1) });
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6127
  return IriSP.underscore.pluck(e, "id");  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6128
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6129
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6130
/** return the id of the ligne de temps named "Chapitrage" */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6131
IriSP.JSONSerializer.prototype.getChapitrage = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6132
  var val = this.getId("Chapitrage");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6133
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6134
    val = this.getId("Chapter");   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6135
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6136
    val = this.getId("Chapit");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6137
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6138
    val = this.getId("Chap");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6139
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6140
  return val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6141
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6142
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6143
/** return the id of the ligne de temps named "Tweets" */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6144
IriSP.JSONSerializer.prototype.getTweets = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6145
  var val = this.getId("Tweets");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6146
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6147
    val = this.getId("Tweet");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6148
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6149
    val = this.getId("Twitter");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6150
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6151
    val = this.getId("twit");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6152
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6153
    val = this.getId("Polemic");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6154
  
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6155
  return val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6156
};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6157
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6158
/** return the id of the ligne de temps named "Contributions" */
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6159
IriSP.JSONSerializer.prototype.getContributions = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6160
  var val = this.getId("Contribution");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6161
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6162
    val = this.getId("Particip");   
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6163
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6164
    val = this.getId("Contr");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6165
  if (typeof(val) === "undefined")
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6166
    val = this.getId("Publ");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6167
    
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  6168
  return val;
823
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6169
};
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6170
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6171
IriSP.JSONSerializer.prototype.getDuration = function() {
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6172
    return +(IriSP.get_aliased(this.currentMedia().meta, ["dc:duration", "duration"]) || 0);
1e7962e1d3ae Starting 'cinecast-traces' branch
veltr
parents: 819
diff changeset
  6173
}