f792d24_autoplay_14.js 3.5KB

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