5 init_player_listener();
6 init_menu_source("body");
10 // -----------------------------------------------------------------
14 var current_document = false;
15 var autoplay_next = false;
17 function init_players(target){
18 $(target == "*" ? "audio" : target + " audio").each
20 { var audio_elt = $(this).get(0);
22 var id_document = $(this).attr("id").substring(6);
24 if((k = id_document.indexOf("_")) != -1) id_source = id_document.substring(0, k);
26 $(this).find("source").each(
28 if(audio_elt.canPlayType($(this).attr("type"))) CAN_PLAY = true;
32 audio_elt.addEventListener("ended", track_ended, false);
33 $("#player_" + id_document + " .play").click(function() { play(id_document); return false; });
34 $("#player_" + id_document + " .play").css("display", "inline");
35 $("#player_" + id_document + " .pause").click(function() { pause(); return false; });
36 $("#player_" + id_document + " .pause").css("display", "none");
37 $("#player_" + id_document + " .stop").click(function() { stop(); return false; });
38 $("#player_" + id_document + " .stop").css("display", "none");
39 $("#document_" + id_document + " .no_player").remove();
42 if(!CAN_PLAY) $("#player_" + id_document).remove();
45 $(target == "*" ? ".track" : target + " .track").each(
47 if($(this).find(".player").size()){
48 var id_source = $(this).attr("id").substring(6);
49 $(this).find(".player_progress").first().click(
51 if((progress_width = $(this).width()) != 0){
52 play_source_from(id_source, (100 * (e.pageX - this.offsetLeft)) / progress_width);
57 else $(this).find(".player_progress").first().css("cursor", "default");
62 function init_player_listener(){
63 setInterval("player_listener_update()", 300);
66 function player_listener_update(){
68 (current_document != false)
69 && (source_id = get_current_source_id())
70 && (current_audio = $("#audio_" + current_document).get(0))
71 && ($("#track_" + source_id + " .player_progress").size())
73 $("#track_" + source_id + " .player_progress .position").not(
74 "#track_" + source_id + " .pistes .player_progress .position").not(
75 "#track_" + source_id + " .derivation .player_progress .position").css(
77 Math.round((100 * current_audio.currentTime) / current_audio.duration) + "%"
82 function get_current_source_id(){
83 if(current_document != false){
84 if($("#document_" + current_document).size()){
85 var source_document_id = $("#document_" + current_document).attr("id").substring(9);
86 if((k = source_document_id.indexOf("_")) != -1){
87 return source_document_id.substring(0, k);
95 autoplay_next = play_first_source();
98 function play_first_source(){
100 $(".track").not(".pistes .track").not(".derivation .track").each(
103 $(this).find(".documents li").not(".pistes .documents li").not(".derivation .documents li").each(
106 var source_document_id = $(this).attr("id").substring(9);
107 if(source_document_id.length > 0){
108 if($("#player_" + source_document_id).size()){
110 play(source_document_id);
122 function play_next_source(){
124 if(current_document != false){
125 if($("#document_" + current_document).size()){
126 var current_source_document_id = $("#document_" + current_document).attr("id");
127 var current_source_id = get_current_source_id();
128 if(current_source_id != false){
129 var CURRENT_FOUND = false;
130 $(".track").not(".pistes .track").not(".derivation .track").each(
134 $(this).find(".documents li").not(".pistes .documents li").not(".derivation .documents li").each(
137 var source_document_id = $(this).attr("id").substring(9);
138 if(source_document_id.length > 0){
139 if($("#player_" + source_document_id).size()){
141 play(source_document_id);
149 if(current_source_id == $(this).attr("id").substring("6")){
150 CURRENT_FOUND = true;
162 function play(id_document){
163 if(current_document == id_document){
164 if($("#audio_" + current_document).get(0).paused){
165 gui_state("playing");
166 $("#audio_" + current_document).get(0).play();
170 if(current_document != false){
171 var audio_elt = $("#audio_" + current_document).get(0);
173 audio_elt.currentTime = 0;
176 current_document = id_document;
181 function play_source_from(id_source, position){
183 (current_document != false)
184 && (current_source_id = get_current_source_id())
185 && (id_source == current_source_id)
192 $("#track_" + id_source + " .documents li").each(
195 var source_document_id = $(this).attr("id").substring(9);
196 if(source_document_id.length > 0){
197 if($("#player_" + source_document_id).size()){
199 current_document = source_document_id;
209 function _play(position){
210 if(current_document != false){
211 var audio_elt = $("#audio_" + current_document).get(0);
212 audio_elt.preload = "auto";
213 audio_elt.addEventListener("loadeddata", track_loadeddata, false);
214 audio_elt.addEventListener("canplaythrough", track_canplaythrough, false);
215 audio_elt.addEventListener("playing", track_playing, false);
216 gui_state("loading");
217 audio_elt.position = position;
222 function track_loadeddata(event){
223 var audio_elt = event.target;
224 audio_elt.removeEventListener("loadeddata", track_loadeddata, false);
225 if(current_document != false){
226 audio_elt.currentTime = audio_elt.position ? (audio_elt.position * audio_elt.duration) / 100 : 0;
230 function track_canplaythrough(event){
231 var audio_elt = event.target;
232 audio_elt.removeEventListener("canplaythrough", track_canplaythrough, false);
236 function track_playing(event){
237 var audio_elt = event.target;
238 audio_elt.removeEventListener("playing", track_playing, false);
239 gui_state("playing");
243 if(current_document != false){
244 var audio_elt = $("#audio_" + current_document).get(0);
251 if(current_document != false){
252 var audio_elt = $("#audio_" + current_document).get(0);
254 audio_elt.currentTime = 0;
256 current_document = false;
258 autoplay_next = false;
261 function track_ended(){
263 var current_audio = $("#audio_" + current_document).get(0);
264 current_audio.pause();
265 if(current_audio.currentTime) current_audio.currentTime = 0;
266 if(autoplay_next) autoplay_next = play_next_source();
269 function gui_state(state){
271 if(current_document != false){
272 var source_id = get_current_source_id();
273 $("#track_" + source_id).removeClass("loading_player");
274 if(state == "playing"){
275 $("#player_" + current_document).find(".play").css("display", "none");
276 $("#player_" + current_document).find(".pause").css("display", "inline");
277 $("#player_" + current_document).find(".stop").css("display", "inline");
278 // $("#track_" + source_id).removeClass("track");
279 $("#track_" + source_id).addClass("playing_track");
281 else if(state == "paused"){
282 $("#player_" + current_document).find(".play").get(0).style.display = "inline";
283 $("#player_" + current_document).find(".pause").get(0).style.display = "none";
284 $("#player_" + current_document).find(".stop").get(0).style.display = "inline";
285 // $("#track_" + source_id).removeClass("track");
286 $("#track_" + source_id).addClass("playing_track");
288 else if(state == "stoped"){
289 $("#player_" + current_document).find(".play").get(0).style.display = "inline";
290 $("#player_" + current_document).find(".pause").get(0).style.display = "none";
291 $("#player_" + current_document).find(".stop").get(0).style.display = "none";
292 $("#track_" + source_id).removeClass("playing_track");
293 // $("#track_" + source_id).addClass("track");
294 $("#track_" + source_id + " .player_progress .position").not(
295 "#track_" + source_id + " .pistes .player_progress .position").not(
296 "#track_" + source_id + " .derivation .player_progress .position").css("width", "0%");
298 else if(state == "loading"){
299 $("#track_" + source_id).addClass("loading_player");
305 if((current_document != false) && $("#player_" + current_document).size()){
306 $("#player_" + current_document).find(".play").get(0).blur();
307 $("#player_" + current_document).find(".pause").get(0).blur();
308 $("#player_" + current_document).find(".stop").get(0).blur();
312 // -----------------------------------------------------------------
317 var show_xml_links = {};
319 function show_xml(id){
320 alert(xml_contents[id]);
323 function init_show_xml_links(){
324 for(var i in show_xml_links){
325 $("#show_xml_" + i).colorbox();
330 function set_show_xml_links(i){
331 if(loaded) $("#show_xml_" + i).colorbox();
332 else show_xml_links[i] = true;
335 // -----------------------------------------------------------------
336 // sources / derivations
339 function toggle_source_list(id_block){
340 var content = $("#source_list_" + id_block + " .pistes").html();
341 if(content.length > 0){
342 $("#source_list_" + id_block).slideUp(200);
343 $("#source_list_" + id_block + " .pistes").empty();
344 $("#toggle_sources_list_" + id_block + ".block_list_toggle").html("[+]");
347 $("#source_list_" + id_block).slideDown(200);
348 $("#toggle_sources_list_" + id_block + ".block_list_toggle").html("[-]");
349 $("#source_list_" + id_block + " .pistes").html("<div class=\"loading\"><span>en chargement...</span></div>");
351 url: mw_site_url + "index.php?e=content/sources/sources&id=" + id_block,
353 success: function(content){
354 $("#source_list_" + id_block + " .pistes").html(content);
355 init_players("#source_list_" + id_block + " .pistes");
356 init_menu_source("#source_list_" + id_block + " .pistes");
362 function toggle_derivation_list(id_block){
363 var content = $("#derivation_list_" + id_block + " .derivation").html();
364 if(content.length > 0){
365 $("#derivation_list_" + id_block).slideUp(200);
366 $("#derivation_list_" + id_block + " .derivation").empty();
367 $("#toggle_derivation_list_" + id_block + ".block_list_toggle").html("[+]");
370 $("#derivation_list_" + id_block).slideDown(200);
371 $("#toggle_derivation_list_" + id_block + ".block_list_toggle").html("[-]");
372 $("#derivation_list_" + id_block + " .derivation").html("<div class=\"loading\"><span>en chargement...</span></div>");
374 url: mw_site_url + "index.php?e=content/sources/derivations&id=" + id_block,
376 success: function(content){
377 $("#derivation_list_" + id_block + " .derivation").html(content);
378 init_players("#derivation_list_" + id_block + " .derivation");
379 init_menu_source("#derivation_list_" + id_block + " .derivation");
385 // -----------------------------------------------------------------
389 function init_menu_source(prefix){
390 $(prefix + " .menu_source a.submit").click(
392 $(this).parents("form").first().submit();