scripts/ajax.js
changeset 11 0faea3a6c881
parent 10 d3059e20b0fa
child 13 b5db2345c397
equal deleted inserted replaced
10:d3059e20b0fa 11:0faea3a6c881
   146           }
   146           }
   147           if ( ! $(nt_id).hasClass('current') )
   147           if ( ! $(nt_id).hasClass('current') )
   148           {
   148           {
   149             $(nt_id).addClass('current');
   149             $(nt_id).addClass('current');
   150           }
   150           }
       
   151           pulsar_reset();
   151         }
   152         }
   152         // update playing status
   153         // update playing status
   153         is_playing = response.is_playing;
   154         is_playing = response.is_playing;
   154         if ( allow_control )
   155         if ( allow_control )
   155         {
   156         {
   235         }
   236         }
   236         if ( ! $(nt_id).hasClass('current') )
   237         if ( ! $(nt_id).hasClass('current') )
   237         {
   238         {
   238           $(nt_id).addClass('current');
   239           $(nt_id).addClass('current');
   239         }
   240         }
       
   241         // update pulsar
       
   242         pulsar_reset();
   240         // update playing status
   243         // update playing status
   241         var img = $('btn_playpause').object.getElementsByTagName('img')[0];
   244         var img = $('btn_playpause').object.getElementsByTagName('img')[0];
   242         is_playing = true;
   245         is_playing = true;
   243         img.src = img_play;
   246         img.src = img_play;
   244         // auto-refresh on track advance
   247         // auto-refresh on track advance
   314   runOnloadHooks(e);
   317   runOnloadHooks(e);
   315 }
   318 }
   316 
   319 
   317 addOnloadHook(refresh_playlist);
   320 addOnloadHook(refresh_playlist);
   318 
   321 
       
   322 // pulse the current track
       
   323 var pulsar_current = 0, pulsar_tdlist = [], pulsar_direction = 1;
       
   324 
       
   325 var pulsar_reset = function()
       
   326 {
       
   327   // remove any pulsar classes from items that aren't "current"
       
   328   var boobylist = document.getElementsByTagName('tr');
       
   329   for ( var i = 0; i < boobylist.length; i++ )
       
   330   {
       
   331     var booby = boobylist[i];
       
   332     var match = booby.className.match(/(^| )(pulsar[0-9])( |$)/);
       
   333     if ( match && !$(booby).hasClass('current') )
       
   334     {
       
   335       $(booby).rmClass(match[2]);
       
   336     }
       
   337   }
       
   338   var tdlist_new = document.getElementsByClassName('current', 'tr');
       
   339   if ( pulsar_current == 0 && tdlist_new == pulsar_tdlist )
       
   340   {
       
   341     return true;
       
   342   }
       
   343   pulsar_tdlist = tdlist_new;
       
   344   pulsar_current = 0;
       
   345   for ( var i = 0; i < pulsar_tdlist.length; i++ )
       
   346   {
       
   347     var td = pulsar_reset[i];
       
   348     for ( var i = 1; i < 10; i++ )
       
   349     {
       
   350       if ( $(td).hasClass('pulsar' + i) )
       
   351       {
       
   352         $(td).rmClass('pulsar' + i);
       
   353       }
       
   354     }
       
   355     if ( ! $(td).hasClass('pulsar0') )
       
   356     {
       
   357       $(td).addClass('pulsar0');
       
   358     }
       
   359   }
       
   360 }
       
   361 
       
   362 var pulsar_advance = function()
       
   363 {
       
   364   if ( !is_playing )
       
   365     return true;
       
   366   if ( pulsar_current + pulsar_direction == 10 )
       
   367   {
       
   368     pulsar_direction = -1;
       
   369   }
       
   370   else if ( pulsar_current + pulsar_direction == -1 )
       
   371   {
       
   372     pulsar_direction = 1;
       
   373   }
       
   374   var nc = pulsar_current + pulsar_direction;
       
   375   for ( var i = 0; i < pulsar_tdlist.length; i++ )
       
   376   {
       
   377     $(pulsar_tdlist[i]).rmClass('pulsar' + pulsar_current).addClass('pulsar' + nc);
       
   378   }
       
   379   pulsar_current = nc;
       
   380 }
       
   381 
       
   382 addOnloadHook(pulsar_reset);
       
   383 setInterval(pulsar_advance, 50);
       
   384