scripts/ajax.js
changeset 18 69af47034212
parent 14 7a1573676cc4
child 21 74edc873234f
equal deleted inserted replaced
17:66c3eb4cdc4c 18:69af47034212
   173         // auto-refresh on track advance
   173         // auto-refresh on track advance
   174         if ( ct_advance_timeout )
   174         if ( ct_advance_timeout )
   175         {
   175         {
   176           clearTimeout(ct_advance_timeout);
   176           clearTimeout(ct_advance_timeout);
   177         }
   177         }
       
   178         // countdown/up timer
   178         var time_remaining = response.current_track_length - response.current_track_pos;
   179         var time_remaining = response.current_track_length - response.current_track_pos;
   179         current_track_length = response.current_track_length;
   180         current_track_length = response.current_track_length;
   180         current_track_pos = response.current_track_pos;
   181         current_track_pos = response.current_track_pos;
   181         if ( ct_counter )
   182         if ( ct_counter )
   182           clearInterval(ct_counter);
   183           clearInterval(ct_counter);
   183         update_clock();
   184         update_clock();
       
   185         
       
   186         // set page title
       
   187         updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
       
   188         
       
   189         // if not playing, set the position slider to zero
       
   190         if ( !is_playing )
       
   191         {
       
   192           posslide_set_position(0);
       
   193         }
       
   194         
       
   195         // set advance timer
   184         if ( is_playing && time_remaining > 0 )
   196         if ( is_playing && time_remaining > 0 )
   185         {
   197         {
   186           ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
   198           ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
   187           ct_counter = setInterval(update_clock, 1000);
   199           ct_counter = setInterval(update_clock, 1000);
   188         }
   200         }
   257         {
   269         {
   258           ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
   270           ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
   259           update_clock();
   271           update_clock();
   260           ct_counter = setInterval(update_clock, 1000);
   272           ct_counter = setInterval(update_clock, 1000);
   261         }
   273         }
       
   274         updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
   262       }
   275       }
   263     });
   276     });
   264 }
   277 }
   265 
   278 
   266 function set_playback_position(pos)
   279 function set_playback_position(pos)
   401 }
   414 }
   402 
   415 
   403 addOnloadHook(pulsar_reset);
   416 addOnloadHook(pulsar_reset);
   404 setInterval(pulsar_advance, 50);
   417 setInterval(pulsar_advance, 50);
   405 
   418 
       
   419 function updateTitle(artist, album, track)
       
   420 {
       
   421   var sep = '';
       
   422   var str = '';
       
   423   if ( track )
       
   424   {
       
   425     str += sep + track;
       
   426     sep = ' - ';
       
   427   }
       
   428   if ( artist )
       
   429   {
       
   430     str += sep + artist;
       
   431     sep = ' - ';
       
   432   }
       
   433   if ( album )
       
   434   {
       
   435     str += sep + album;
       
   436     sep = ' - ';
       
   437   }
       
   438   str += sep + 'AmaroK Playlist';
       
   439   document.title = str;
       
   440 }
       
   441