scripts/ajax.js
changeset 11 0faea3a6c881
parent 10 d3059e20b0fa
child 13 b5db2345c397
--- a/scripts/ajax.js	Mon Mar 24 02:53:42 2008 -0400
+++ b/scripts/ajax.js	Wed Mar 26 09:57:42 2008 -0400
@@ -148,6 +148,7 @@
           {
             $(nt_id).addClass('current');
           }
+          pulsar_reset();
         }
         // update playing status
         is_playing = response.is_playing;
@@ -237,6 +238,8 @@
         {
           $(nt_id).addClass('current');
         }
+        // update pulsar
+        pulsar_reset();
         // update playing status
         var img = $('btn_playpause').object.getElementsByTagName('img')[0];
         is_playing = true;
@@ -316,3 +319,66 @@
 
 addOnloadHook(refresh_playlist);
 
+// pulse the current track
+var pulsar_current = 0, pulsar_tdlist = [], pulsar_direction = 1;
+
+var pulsar_reset = function()
+{
+  // remove any pulsar classes from items that aren't "current"
+  var boobylist = document.getElementsByTagName('tr');
+  for ( var i = 0; i < boobylist.length; i++ )
+  {
+    var booby = boobylist[i];
+    var match = booby.className.match(/(^| )(pulsar[0-9])( |$)/);
+    if ( match && !$(booby).hasClass('current') )
+    {
+      $(booby).rmClass(match[2]);
+    }
+  }
+  var tdlist_new = document.getElementsByClassName('current', 'tr');
+  if ( pulsar_current == 0 && tdlist_new == pulsar_tdlist )
+  {
+    return true;
+  }
+  pulsar_tdlist = tdlist_new;
+  pulsar_current = 0;
+  for ( var i = 0; i < pulsar_tdlist.length; i++ )
+  {
+    var td = pulsar_reset[i];
+    for ( var i = 1; i < 10; i++ )
+    {
+      if ( $(td).hasClass('pulsar' + i) )
+      {
+        $(td).rmClass('pulsar' + i);
+      }
+    }
+    if ( ! $(td).hasClass('pulsar0') )
+    {
+      $(td).addClass('pulsar0');
+    }
+  }
+}
+
+var pulsar_advance = function()
+{
+  if ( !is_playing )
+    return true;
+  if ( pulsar_current + pulsar_direction == 10 )
+  {
+    pulsar_direction = -1;
+  }
+  else if ( pulsar_current + pulsar_direction == -1 )
+  {
+    pulsar_direction = 1;
+  }
+  var nc = pulsar_current + pulsar_direction;
+  for ( var i = 0; i < pulsar_tdlist.length; i++ )
+  {
+    $(pulsar_tdlist[i]).rmClass('pulsar' + pulsar_current).addClass('pulsar' + nc);
+  }
+  pulsar_current = nc;
+}
+
+addOnloadHook(pulsar_reset);
+setInterval(pulsar_advance, 50);
+