f792d24_autoplay_14.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. function Autoplay()
  2. {
  3. var _playlist = new Array();
  4. var _player = null;
  5. var _current_index = 0;
  6. this.start = function()
  7. {
  8. open_popin_dialog('autoplay');
  9. initializePlaylist(this.play);
  10. }
  11. var initializePlaylist = function(callback)
  12. {
  13. JQueryJson($('a#autoplay_launch').attr('href'), {}, function(response){
  14. if (response.status == 'success')
  15. {
  16. if (response.data.length)
  17. {
  18. _playlist = response.data;
  19. }
  20. }
  21. callback(0);
  22. });
  23. }
  24. this.play = function(index_to_play, timed)
  25. {
  26. window.autoplay.stopAndClearAllPlayers();
  27. if (array_key_exists(index_to_play, _playlist))
  28. {
  29. if (!timed)
  30. {
  31. _current_index = index_to_play;
  32. $('#autoplay_element_loader').show();
  33. window.setTimeout(function(){
  34. window.autoplay.play(index_to_play, true);
  35. });
  36. }
  37. else if (_current_index == index_to_play)
  38. {
  39. loadAndDisplayInfos(_playlist[index_to_play].element_id);
  40. if (!createPlayer(_playlist[index_to_play], window.autoplay.playNext))
  41. {
  42. this.play(index_to_play+1);
  43. }
  44. else
  45. {
  46. _current_index = index_to_play;
  47. }
  48. }
  49. }
  50. else
  51. {
  52. window.autoplay.nothingToPlay();
  53. }
  54. }
  55. this.stopAndClearAllPlayers = function()
  56. {
  57. players = window.players_manager.getAll();
  58. for (var i in players)
  59. {
  60. players[i].stopAndDestroy();
  61. window.players_manager.remove(i);
  62. }
  63. }
  64. var loadAndDisplayInfos = function(element_id)
  65. {
  66. $('#autoplay_element_loader').show();
  67. JQueryJson(url_element_dom_get_one_autoplay+'/'+element_id, {}, function(response){
  68. if (response.status == 'success')
  69. {
  70. $('li#autoplay_element_container').html(response.data);
  71. $('#autoplay_element_loader').hide();
  72. }
  73. });
  74. }
  75. var createPlayer = function(play_data, finish_callback)
  76. {
  77. $('#autoplay_loader').show();
  78. if ((player = window.dynamic_player.play(
  79. $('#autoplay_player'),
  80. play_data.element_type,
  81. play_data.element_ref_id,
  82. play_data.element_id,
  83. true,
  84. finish_callback
  85. )))
  86. {
  87. $('#autoplay_loader').hide();
  88. window.players_manager.add(player, 'autoplay_'+play_data.element_id);
  89. return true;
  90. }
  91. else
  92. {
  93. return false;
  94. }
  95. }
  96. this.playNext = function()
  97. {
  98. window.autoplay.play(_current_index+1);
  99. }
  100. this.playPrevious = function()
  101. {
  102. if (array_key_exists(_current_index-1, _playlist))
  103. {
  104. window.autoplay.play(_current_index-1);
  105. }
  106. return false;
  107. }
  108. this.nothingToPlay = function()
  109. {
  110. this.stopAndClearAllPlayers();
  111. $('#autoplay_noelements_text').show();
  112. $('div#autoplay_player_container').html('<div id="autoplay_player"></div>');
  113. $('li#autoplay_element_container').html('');
  114. $('#autoplay iframe').hide();
  115. $('#autoplay img[alt="loader"]').hide();
  116. }
  117. }
  118. $(document).ready(function() {
  119. window.autoplay = new Autoplay();
  120. $('a#autoplay_launch').click(function(){
  121. window.autoplay.start();
  122. return false;
  123. });
  124. $('a#autoplay_previous').click(function(){window.autoplay.playPrevious()});
  125. $('a#autoplay_next').click(function(){window.autoplay.playNext()});
  126. $('a#autoplay_close').click(function(){
  127. // Fond gris
  128. $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  129. // On cache le lecteur
  130. $('#autoplay').hide();
  131. window.autoplay.stopAndClearAllPlayers();
  132. });
  133. });