|
@@ -17,6 +17,11 @@ $(document).ready(function(){
|
17
|
17
|
var autoplay_player_id = "autoplay_player_id";
|
18
|
18
|
// étape de lecture, on commence naturellement a 0
|
19
|
19
|
var autoplay_step = 0;
|
|
20
|
+ // On utilise cette variable pour savoir quel est l'élélement choisis en
|
|
21
|
+ // dernier (cas du brute click)
|
|
22
|
+ var autoplay_last_element_id = null;
|
|
23
|
+ // Pour savoir si on est en bout de ligne
|
|
24
|
+ var autoplay_no_more = false;
|
20
|
25
|
|
21
|
26
|
// En cas de click sur un bouton de lecture
|
22
|
27
|
$('a#autoplay_launch').click(function(){
|
|
@@ -35,6 +40,7 @@ $(document).ready(function(){
|
35
|
40
|
{
|
36
|
41
|
// On récupère la liste d'élèments
|
37
|
42
|
autoplay_list = response.data;
|
|
43
|
+ autoplay_last_element_id = autoplay_list[0].element_id;
|
38
|
44
|
autoplay_run(0);
|
39
|
45
|
}
|
40
|
46
|
|
|
@@ -42,56 +48,76 @@ $(document).ready(function(){
|
42
|
48
|
return false;
|
43
|
49
|
});
|
44
|
50
|
|
45
|
|
- // Lancement de l'élèment suivant
|
46
|
|
- function autoplay_run(step)
|
|
51
|
+ function autoplay_load_element(element_id, timeouted)
|
47
|
52
|
{
|
48
|
|
- // En premier lieu on réinitialise le lecteur en détruisant le dom qui a
|
49
|
|
- // pu être créé par la lecture précedente.
|
50
|
|
- $('div#'+autoplay_player_div_id+'_container').html('<div id="'+autoplay_player_div_id+'"></div>');
|
51
|
|
- $('#autoplay_noelements_text').hide();
|
52
|
|
- $('li#autoplay_element_container').html('');
|
53
|
|
- $('img#autoplay_loader').show();
|
54
|
|
-
|
55
|
|
-
|
56
|
|
- ////// TMP to check
|
57
|
|
- if (autoplay_player_soundcloud)
|
|
53
|
+ // On vérifie ici que c'est le dernier élement demandé, ca evite de multiples
|
|
54
|
+ // requetes en cas de brute click sur les flèches.
|
|
55
|
+ if (!timeouted)
|
58
|
56
|
{
|
59
|
|
- autoplay_player_soundcloud.pause();
|
|
57
|
+ $('#autoplay_element_loader').show();
|
|
58
|
+ $('li#autoplay_element_container').html('');
|
|
59
|
+ setTimeout(autoplay_load_element, 1000, element_id, true);
|
60
|
60
|
}
|
61
|
|
- $('div#autoplay_player_soundcloud').hide();
|
62
|
|
-
|
63
|
|
- if (autoplay_list.length)
|
|
61
|
+ else
|
64
|
62
|
{
|
65
|
|
-
|
66
|
|
- if (array_key_exists(step, autoplay_list))
|
|
63
|
+ if (autoplay_last_element_id == element_id)
|
67
|
64
|
{
|
68
|
|
-
|
69
|
|
- // Récupération du dom d'un élement
|
70
|
|
- $.getJSON(url_element_dom_get_one_autoplay+'/'+autoplay_list[step].element_id, function(response) {
|
|
65
|
+ $.getJSON(url_element_dom_get_one_autoplay+'/'+element_id, function(response) {
|
|
66
|
+
|
|
67
|
+ $('#autoplay_element_loader').hide();
|
|
68
|
+
|
71
|
69
|
if (response.status == 'mustbeconnected')
|
72
|
70
|
{
|
73
|
71
|
$(location).attr('href', url_index);
|
74
|
72
|
}
|
75
|
|
-
|
76
|
|
- if (response.status == 'success')
|
|
73
|
+
|
|
74
|
+ if (response.status == 'success' && autoplay_last_element_id == element_id)
|
77
|
75
|
{
|
78
|
|
- // On récupère la liste d'élèments
|
79
|
|
- $('li#autoplay_element_container').html(response.data);
|
80
|
|
-
|
81
|
|
- // Youtube case
|
82
|
|
- if (autoplay_list[step].element_type == 'youtube.com' || autoplay_list[step].element_type == 'youtu.be')
|
|
76
|
+ if (!autoplay_no_more)
|
83
|
77
|
{
|
84
|
|
- youtube_create_player(autoplay_list[step].element_ref_id);
|
|
78
|
+ // On récupère la liste d'élèments
|
|
79
|
+ $('li#autoplay_element_container').html(response.data);
|
85
|
80
|
}
|
86
|
|
-
|
87
|
|
- if (autoplay_list[step].element_type == 'soundcloud.com')
|
|
81
|
+ else
|
88
|
82
|
{
|
89
|
|
- soundcloud_create_player(autoplay_list[step].element_ref_id, autoplay_list[step].element_normalized_url);
|
|
83
|
+ $('li#autoplay_element_container').html('');
|
90
|
84
|
}
|
91
|
85
|
}
|
92
|
86
|
|
93
|
87
|
});
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ }
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ // Lancement de l'élèment suivant
|
|
94
|
+ function autoplay_run(step)
|
|
95
|
+ {
|
|
96
|
+ // En premier lieu on réinitialise le lecteur en détruisant le dom qui a
|
|
97
|
+ // pu être créé par la lecture précedente.
|
|
98
|
+ autoplay_clean_for_player_creation();
|
|
99
|
+
|
|
100
|
+ // Pause des lecteurs potentiels
|
|
101
|
+ autoplay_pause_all_players();
|
|
102
|
+
|
|
103
|
+ if (autoplay_list.length)
|
|
104
|
+ {
|
|
105
|
+
|
|
106
|
+ if (array_key_exists(step, autoplay_list))
|
|
107
|
+ {
|
94
|
108
|
|
|
109
|
+ // Youtube case
|
|
110
|
+ if (autoplay_list[step].element_type == 'youtube.com' || autoplay_list[step].element_type == 'youtu.be')
|
|
111
|
+ {
|
|
112
|
+ autoplay_load_element(autoplay_list[step].element_id, false);
|
|
113
|
+ youtube_create_player(autoplay_list[step].element_ref_id);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ if (autoplay_list[step].element_type == 'soundcloud.com')
|
|
117
|
+ {
|
|
118
|
+ autoplay_load_element(autoplay_list[step].element_id, false);
|
|
119
|
+ soundcloud_create_player(autoplay_list[step].element_ref_id, autoplay_list[step].element_normalized_url);
|
|
120
|
+ }
|
95
|
121
|
|
96
|
122
|
}
|
97
|
123
|
|
|
@@ -102,8 +128,27 @@ $(document).ready(function(){
|
102
|
128
|
}
|
103
|
129
|
}
|
104
|
130
|
|
|
131
|
+ function autoplay_clean_for_player_creation(clean_element)
|
|
132
|
+ {
|
|
133
|
+ autoplay_pause_all_players();
|
|
134
|
+
|
|
135
|
+ $('div#'+autoplay_player_div_id+'_container').html('<div id="'+autoplay_player_div_id+'"></div>');
|
|
136
|
+ $('#autoplay_noelements_text').hide();
|
|
137
|
+ if (clean_element)
|
|
138
|
+ {
|
|
139
|
+ $('li#autoplay_element_container').html('');
|
|
140
|
+ }
|
|
141
|
+ $('img#autoplay_loader').show();
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ function autoplay_pause_all_players()
|
|
145
|
+ {
|
|
146
|
+ soundcloud_stop_player();
|
|
147
|
+ }
|
|
148
|
+
|
105
|
149
|
function autoplay_display_nomore()
|
106
|
150
|
{
|
|
151
|
+ autoplay_no_more = true;
|
107
|
152
|
$('div#'+autoplay_player_div_id+'_container').html('<div id="'+autoplay_player_div_id+'"></div>');
|
108
|
153
|
$('li#autoplay_element_container').html('');
|
109
|
154
|
$('#autoplay_noelements_text').show();
|
|
@@ -118,9 +163,11 @@ $(document).ready(function(){
|
118
|
163
|
// Avancer d'un élelement dans la liste
|
119
|
164
|
function autoplay_next()
|
120
|
165
|
{
|
|
166
|
+ autoplay_no_more = false;
|
121
|
167
|
autoplay_step++;
|
122
|
168
|
if (array_key_exists(autoplay_step, autoplay_list))
|
123
|
169
|
{
|
|
170
|
+ autoplay_last_element_id = autoplay_list[autoplay_step].element_id;
|
124
|
171
|
autoplay_run(autoplay_step);
|
125
|
172
|
}
|
126
|
173
|
else
|
|
@@ -133,9 +180,11 @@ $(document).ready(function(){
|
133
|
180
|
// Reculer d'un élement dans la liste
|
134
|
181
|
function autoplay_previous()
|
135
|
182
|
{
|
|
183
|
+ autoplay_no_more = false;
|
136
|
184
|
autoplay_step--;
|
137
|
185
|
if (array_key_exists(autoplay_step, autoplay_list))
|
138
|
186
|
{
|
|
187
|
+ autoplay_last_element_id = autoplay_list[autoplay_step].element_id;
|
139
|
188
|
autoplay_run(autoplay_step);
|
140
|
189
|
}
|
141
|
190
|
else
|
|
@@ -173,6 +222,9 @@ $(document).ready(function(){
|
173
|
222
|
// Création du lecteur FLASH youtube
|
174
|
223
|
function youtube_create_player(ref_id)
|
175
|
224
|
{
|
|
225
|
+ // Préparation du terrain
|
|
226
|
+ autoplay_clean_for_player_creation();
|
|
227
|
+
|
176
|
228
|
var playerapiid = "ytplayerapiid";
|
177
|
229
|
var params = {allowScriptAccess: "always"};
|
178
|
230
|
var atts = {id: autoplay_player_id};
|
|
@@ -229,6 +281,9 @@ $(document).ready(function(){
|
229
|
281
|
function soundcloud_create_player(ref_id, ref_url)
|
230
|
282
|
{
|
231
|
283
|
|
|
284
|
+ // Préparation du terrain
|
|
285
|
+ autoplay_clean_for_player_creation();
|
|
286
|
+
|
232
|
287
|
// Variable dans lequelle on met l'index dela track lu précedamment
|
233
|
288
|
var index_track_previous = 0;
|
234
|
289
|
|
|
@@ -310,4 +365,13 @@ $(document).ready(function(){
|
310
|
365
|
|
311
|
366
|
}
|
312
|
367
|
|
|
368
|
+ function soundcloud_stop_player()
|
|
369
|
+ {
|
|
370
|
+ if (autoplay_player_soundcloud)
|
|
371
|
+ {
|
|
372
|
+ autoplay_player_soundcloud.pause();
|
|
373
|
+ }
|
|
374
|
+ $('div#autoplay_player_soundcloud').hide();
|
|
375
|
+ }
|
|
376
|
+
|
313
|
377
|
});
|