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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     1
/**
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     2
 * Volume widget presentation code
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     3
 * 
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     4
 * Web control interface script for Amarok
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     5
 * Written by Dan Fuhry - 2008
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     6
 *
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     7
 * This script is in the public domain. Use it for good, not evil.
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     8
 */
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     9
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    10
var current_volume = 0;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    11
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    12
function set_volume_fill(amount)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    13
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    14
  amount = 10 * ( Math.round(amount / 10) );
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    15
  if ( amount == 0 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    16
    amount = -10;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    17
  for ( var i = 0; i <= amount; i += 10 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    18
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    19
    if ( !$('volbtn_' + i).hasClass('volume_button_active') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    20
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    21
      $('volbtn_' + i).addClass('volume_button_active');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    22
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    23
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    24
  for ( ; i <= 100; i += 10 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    25
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    26
    if ( $('volbtn_' + i).hasClass('volume_button_active') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    27
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    28
      $('volbtn_' + i).rmClass('volume_button_active');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    29
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    30
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    31
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    32
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    33
function volume_over(amount)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    34
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    35
  set_volume_fill(amount);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    36
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    37
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    38
function volume_out()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    39
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    40
  set_volume_fill(current_volume);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    41
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    42
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    43
function set_volume(level)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    44
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    45
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    46
  if ( level == current_volume )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    47
    return false;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    48
  ajaxGet('/action.json/volume/' + level, function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    49
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    50
      if ( ajax.readyState == 4 && ajax.status == 200 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    51
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    52
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    53
        var response = (' ' + ajax.responseText).substr(1);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    54
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    55
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    56
        // update volume
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    57
        if ( response.volume != current_volume )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    58
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    59
          set_volume_fill(response.volume);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    60
          current_volume = response.volume;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    61
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    62
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    63
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    64
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    65