scripts/volume.js
author Dan
Sun, 23 Nov 2008 23:43:59 -0500
changeset 58 05a69bab5f10
parent 6 5f35ebc4f9bb
child 59 a4ca1e7c0073
permissions -rw-r--r--
Added custom volume setting function (press v in the playlist window)
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
 * 
6
5f35ebc4f9bb First release version. Renamed to Greyhound and readme/license files added.
Dan
parents: 5
diff changeset
     4
 * Greyhound - real web management for Amarok
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
     5
 * Copyright (C) 2008 Dan Fuhry
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
     6
 *
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
     9
 *
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 2
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    12
 */
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
var current_volume = 0;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    15
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    16
function set_volume_fill(amount)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    17
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    18
  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
    19
  if ( amount == 0 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    20
    amount = -10;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    21
  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
    22
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    23
    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
    24
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    25
      $('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
    26
    }
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
  for ( ; i <= 100; i += 10 )
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
    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
    31
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    32
      $('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
    33
    }
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
}
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
function volume_over(amount)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    38
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    39
  set_volume_fill(amount);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    40
}
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
function volume_out()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    43
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    44
  set_volume_fill(current_volume);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    45
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    46
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    47
function set_volume(level)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    48
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    49
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    50
  if ( level == current_volume )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    51
    return false;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    52
  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
    53
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    54
      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
    55
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    56
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    57
        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
    58
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    59
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    60
        // update volume
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    61
        if ( response.volume != current_volume )
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
          set_volume_fill(response.volume);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    64
          current_volume = response.volume;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    65
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    66
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    67
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    68
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
diff changeset
    69
58
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    70
function volume_custom_form()
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    71
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    72
  if ( $('volumebox').object )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    73
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    74
    return false;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    75
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    76
  var box = document.createElement('div');
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    77
  $(box)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    78
    .css('position', 'absolute')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    79
    .css('padding', '50px 80px')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    80
    .css('background-image', 'url(/trans80.png)')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    81
    .css('color', 'black')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    82
    .css('text-align', 'center')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    83
    .attr('id', 'volumebox')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    84
    .insertText('volume:')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    85
    .insertBR().insertBR()
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    86
    .opacity(0);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    87
  document.body.appendChild(box);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    88
  
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    89
  var field = document.createElement('input');
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    90
  $(field)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    91
    .attr('type', 'text')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    92
    .attr('value', '')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    93
    .attr('size', '7')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    94
    .css('text-align', 'center');
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    95
  box.appendChild(field);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    96
  
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    97
  $(box)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    98
    .css('top',  (( $(window).Height() / 2 ) - ( $(box).Height() / 2 )) + 'px')
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
    99
    .css('left', (( $(document.body).Width() / 2 ) - ( $(box).Width() / 2 )) + 'px');
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   100
  
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   101
  $(box).fadeIn(250);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   102
  field.focus();
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   103
  field.onkeyup = function(e)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   104
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   105
    if ( e.keyCode == 13 )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   106
    {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   107
      if ( this.value == '' )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   108
      {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   109
        $(this.parentNode).fadeOut(250, function(o)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   110
          {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   111
            o.parentNode.removeChild(o);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   112
          });
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   113
      }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   114
      else if ( !this.value.match(/^[0-9]+$/) )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   115
      {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   116
        $(this.parentNode).insertBR().insertText('please enter a number');
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   117
      }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   118
      else
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   119
      {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   120
        set_volume(parseInt(this.value));
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   121
        $(this.parentNode).fadeOut(250, function(o)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   122
          {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   123
            o.parentNode.removeChild(o);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   124
          });
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   125
      }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   126
    }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   127
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   128
}
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   129
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   130
addOnloadHook(function()
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   131
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   132
    window.onkeyup = function(e)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   133
    {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   134
      if ( e.keyCode == 86 )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   135
      {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   136
        volume_custom_form();
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   137
      }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   138
    }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 6
diff changeset
   139
  });