scripts/volume.js
author Dan
Sun, 23 Mar 2008 20:58:51 -0400
changeset 3 e7447a6044ec
parent 2 860ba7141641
child 5 9b96265b5918
permissions -rw-r--r--
$allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon

/**
 * Volume widget presentation code
 * 
 * Web control interface script for Amarok
 * Written by Dan Fuhry - 2008
 *
 * This script is in the public domain. Use it for good, not evil.
 */

var current_volume = 0;

function set_volume_fill(amount)
{
  amount = 10 * ( Math.round(amount / 10) );
  if ( amount == 0 )
    amount = -10;
  for ( var i = 0; i <= amount; i += 10 )
  {
    if ( !$('volbtn_' + i).hasClass('volume_button_active') )
    {
      $('volbtn_' + i).addClass('volume_button_active');
    }
  }
  for ( ; i <= 100; i += 10 )
  {
    if ( $('volbtn_' + i).hasClass('volume_button_active') )
    {
      $('volbtn_' + i).rmClass('volume_button_active');
    }
  }
}

function volume_over(amount)
{
  set_volume_fill(amount);
}

function volume_out()
{
  set_volume_fill(current_volume);
}

function set_volume(level)
{
  setAjaxLoading();
  if ( level == current_volume )
    return false;
  ajaxGet('/action.json/volume/' + level, function()
    {
      if ( ajax.readyState == 4 && ajax.status == 200 )
      {
        unsetAjaxLoading();
        var response = (' ' + ajax.responseText).substr(1);
        // quickie JSON parser :)
        response = eval('(' + response + ')');
        // update volume
        if ( response.volume != current_volume )
        {
          set_volume_fill(response.volume);
          current_volume = response.volume;
        }
      }
    });
}