scripts/ajax.js
changeset 18 69af47034212
parent 14 7a1573676cc4
child 21 74edc873234f
--- a/scripts/ajax.js	Sat Apr 12 09:26:01 2008 -0400
+++ b/scripts/ajax.js	Fri Apr 25 12:42:26 2008 -0400
@@ -175,12 +175,24 @@
         {
           clearTimeout(ct_advance_timeout);
         }
+        // countdown/up timer
         var time_remaining = response.current_track_length - response.current_track_pos;
         current_track_length = response.current_track_length;
         current_track_pos = response.current_track_pos;
         if ( ct_counter )
           clearInterval(ct_counter);
         update_clock();
+        
+        // set page title
+        updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
+        
+        // if not playing, set the position slider to zero
+        if ( !is_playing )
+        {
+          posslide_set_position(0);
+        }
+        
+        // set advance timer
         if ( is_playing && time_remaining > 0 )
         {
           ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
@@ -259,6 +271,7 @@
           update_clock();
           ct_counter = setInterval(update_clock, 1000);
         }
+        updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
       }
     });
 }
@@ -403,3 +416,26 @@
 addOnloadHook(pulsar_reset);
 setInterval(pulsar_advance, 50);
 
+function updateTitle(artist, album, track)
+{
+  var sep = '';
+  var str = '';
+  if ( track )
+  {
+    str += sep + track;
+    sep = ' - ';
+  }
+  if ( artist )
+  {
+    str += sep + artist;
+    sep = ' - ';
+  }
+  if ( album )
+  {
+    str += sep + album;
+    sep = ' - ';
+  }
+  str += sep + 'AmaroK Playlist';
+  document.title = str;
+}
+