scripts/ajax.js
author Dan
Wed, 26 Mar 2008 09:57:42 -0400
changeset 11 0faea3a6c881
parent 10 d3059e20b0fa
child 13 b5db2345c397
permissions -rw-r--r--
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
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: 0
diff changeset
     1
/**
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
     2
 * AJAX functions
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
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: 3
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: 0
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: 3
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: 3
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: 3
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: 3
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: 3
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: 0
diff changeset
    12
 */
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    13
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    14
var ajax;
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: 3
diff changeset
    15
var is_playing = false, current_track = -1, current_track_length, current_track_pos, ct_advance_timeout = false, ct_counter = false, playlist_md5 = false, first_load = true;
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    16
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    17
var onload_hooks = new Array();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    18
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    19
function addOnloadHook(func)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    20
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    21
  if ( typeof ( func ) == 'function' )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    22
  {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    23
    if ( typeof(onload_hooks.push) == 'function' )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    24
    {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    25
      onload_hooks.push(func);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    26
    }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    27
    else
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    28
    {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    29
      onload_hooks[onload_hooks.length] = func;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    30
    }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    31
  }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    32
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    33
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    34
function runOnloadHooks(e)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    35
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    36
  var _errorTrapper = 0;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    37
  for ( var _oLc = 0; _oLc < onload_hooks.length; _oLc++ )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    38
  {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    39
    _errorTrapper++;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    40
    if ( _errorTrapper >= 1000 )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    41
      break;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    42
    var _f = onload_hooks[_oLc];
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    43
    if ( typeof(_f) == 'function' )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    44
    {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    45
      _f(e);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    46
    }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    47
  }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    48
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
    49
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    50
function ajaxGet(uri, f)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    51
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    52
  if (window.XMLHttpRequest)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    53
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    54
    ajax = new XMLHttpRequest();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    55
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    56
  else
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    57
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    58
    if (window.ActiveXObject) {           
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    59
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    60
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    61
    else
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    62
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    63
      alert('AmaroK client-side runtime error: No AJAX support, unable to continue');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    64
      return;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    65
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    66
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    67
  ajax.onreadystatechange = f;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    68
  ajax.open('GET', uri, true);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    69
  ajax.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    70
  ajax.send(null);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    71
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    72
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    73
function ajaxPost(uri, parms, f)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    74
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    75
  if (window.XMLHttpRequest)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    76
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    77
    ajax = new XMLHttpRequest();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    78
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    79
  else
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    80
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    81
    if (window.ActiveXObject)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    82
    {           
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    83
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    84
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    85
    else
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    86
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    87
      alert('AmaroK client-side runtime error: No AJAX support, unable to continue');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    88
      return;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    89
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    90
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    91
  ajax.onreadystatechange = f;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    92
  ajax.open('POST', uri, true);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    93
  ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    94
  // Setting Content-length in Safari triggers a warning
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    95
  if ( !is_Safari )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    96
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    97
    ajax.setRequestHeader("Content-length", parms.length);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    98
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    99
  ajax.setRequestHeader("Connection", "close");
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   100
  ajax.send(parms);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   101
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   102
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   103
function setAjaxLoading()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   104
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   105
  $('ajax_status').object.src = img_ajax;
3
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   106
  $('ajax_status').object.style.display = 'block';
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   107
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   108
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   109
function unsetAjaxLoading()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   110
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   111
  $('ajax_status').object.src = 'about:blank';
3
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   112
  $('ajax_status').object.style.display = 'none';
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   113
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   114
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   115
var refresh_playlist = function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   116
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   117
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   118
  ajaxGet('/action.json/refresh', function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   119
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   120
      if ( ajax.readyState == 4 && ajax.status == 200 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   121
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   122
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   123
        var response = (' ' + ajax.responseText).substr(1);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   124
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   125
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   126
        // has the playlist been modified?
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   127
        if ( playlist_md5 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   128
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   129
          if ( response.playlist_hash != playlist_md5 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   130
          {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   131
            // playlist has changed, reload
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   132
            window.location.reload();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   133
            return false;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   134
          }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   135
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   136
        playlist_md5 = response.playlist_hash;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   137
        // update track number
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   138
        if ( response.current_track != current_track )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   139
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   140
          var ot_id = 'track_' + current_track;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   141
          var nt_id = 'track_' + response.current_track;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   142
          current_track = response.current_track;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   143
          if ( $(ot_id).hasClass('current') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   144
          {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   145
            $(ot_id).rmClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   146
          }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   147
          if ( ! $(nt_id).hasClass('current') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   148
          {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   149
            $(nt_id).addClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   150
          }
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   151
          pulsar_reset();
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   152
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   153
        // update playing status
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   154
        is_playing = response.is_playing;
3
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   155
        if ( allow_control )
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   156
        {
3
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   157
          var img = $('btn_playpause').object.getElementsByTagName('img')[0];
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   158
          if ( is_playing )
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   159
          {
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   160
            img.src = img_pause;
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   161
          }
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   162
          else
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   163
          {
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   164
            img.src = img_play;
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   165
          }
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   166
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   167
        // update volume
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   168
        if ( response.volume != current_volume )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   169
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   170
          set_volume_fill(response.volume);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   171
          current_volume = response.volume;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   172
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   173
        // auto-refresh on track advance
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   174
        if ( ct_advance_timeout )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   175
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   176
          clearTimeout(ct_advance_timeout);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   177
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   178
        var time_remaining = response.current_track_length - response.current_track_pos;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   179
        current_track_length = response.current_track_length;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   180
        current_track_pos = response.current_track_pos;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   181
        if ( ct_counter )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   182
          clearInterval(ct_counter);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   183
        update_clock();
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   184
        if ( is_playing && time_remaining > 0 )
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   185
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   186
          ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   187
          ct_counter = setInterval(update_clock, 1000);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   188
        }
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: 3
diff changeset
   189
        if ( first_load )
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: 3
diff changeset
   190
        {
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: 3
diff changeset
   191
          first_load = false;
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: 3
diff changeset
   192
          var top = $('track_' + current_track).Top() - 138;
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: 3
diff changeset
   193
          window.scroll(0, top);
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: 3
diff changeset
   194
        }
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   195
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   196
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   197
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   198
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   199
function player_action(action)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   200
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   201
  var act2 = action;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   202
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   203
  ajaxGet('/action.json/' + action, function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   204
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   205
      if ( ajax.readyState == 4 && ajax.status == 200 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   206
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   207
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   208
        refresh_playlist();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   209
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   210
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   211
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   212
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   213
function jump_to_song(tid)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   214
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   215
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   216
  if ( tid == current_track )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   217
    return false;
3
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   218
  if ( !allow_control )
e7447a6044ec $allowcontrol = false working and turned on now; switched default port back to 7447 instead of random; added favicon and apple-touch-icon
Dan
parents: 2
diff changeset
   219
    return false;
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   220
  ajaxGet('/action.json/jump/' + tid, function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   221
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   222
      if ( ajax.readyState == 4 && ajax.status == 200 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   223
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   224
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   225
        var response = (' ' + ajax.responseText).substr(1);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   226
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   227
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   228
        
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   229
        // update track number
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   230
        var ot_id = 'track_' + current_track;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   231
        var nt_id = 'track_' + tid;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   232
        current_track = tid;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   233
        if ( $(ot_id).hasClass('current') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   234
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   235
          $(ot_id).rmClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   236
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   237
        if ( ! $(nt_id).hasClass('current') )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   238
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   239
          $(nt_id).addClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   240
        }
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   241
        // update pulsar
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   242
        pulsar_reset();
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   243
        // update playing status
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   244
        var img = $('btn_playpause').object.getElementsByTagName('img')[0];
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   245
        is_playing = true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   246
        img.src = img_play;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   247
        // auto-refresh on track advance
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   248
        if ( ct_advance_timeout )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   249
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   250
          clearTimeout(ct_advance_timeout);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   251
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   252
        if ( ct_counter )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   253
          clearInterval(ct_counter);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   254
        var time_remaining = response.current_track_length - response.current_track_pos;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   255
        current_track_length = response.current_track_length;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   256
        current_track_pos = response.current_track_pos;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   257
        if ( is_playing )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   258
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   259
          ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   260
          update_clock();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   261
          ct_counter = setInterval(update_clock, 1000);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   262
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   263
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   264
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   265
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   266
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   267
function set_playback_position(pos)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   268
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   269
  pos = Math.round(( pos / 100 ) * current_track_length);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   270
  setAjaxLoading();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   271
  if ( !allow_control )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   272
    return false;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   273
  ajaxGet('/action.json/seek/' + pos, function()
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   274
    {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   275
      if ( ajax.readyState == 4 && ajax.status == 200 )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   276
      {
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   277
        unsetAjaxLoading();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   278
        current_track_pos = pos;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   279
        update_clock();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   280
      }
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   281
    });
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   282
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   283
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   284
function update_clock()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   285
{
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   286
  posslide_set_position((100 * (current_track_pos / current_track_length)));
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   287
  var str = secs_to_string(current_track_pos) + '/' + secs_to_string(current_track_length);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   288
  $('playmeter').object.innerHTML = str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   289
  current_track_pos++;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   290
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   291
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   292
function secs_to_string(time)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   293
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   294
  var count_seconds = time % 60;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   295
  var count_minutes = ( time - count_seconds ) / 60;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   296
  return fill_zeroes(count_minutes) + ':' + fill_zeroes(count_seconds);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   297
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   298
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   299
function fill_zeroes(str, len)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   300
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   301
  if ( !len )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   302
    len = 2;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   303
  if ( typeof(str) == 'number' && str == 0 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   304
    str = '0';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   305
  str = String(str);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   306
  while ( str.length < len )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   307
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   308
    str = '0' + str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   309
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   310
  return str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   311
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   312
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   313
setInterval(refresh_playlist, 10000);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   314
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   315
window.onload = function(e)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   316
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   317
  runOnloadHooks(e);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   318
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   319
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   320
addOnloadHook(refresh_playlist);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents: 6
diff changeset
   321
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   322
// pulse the current track
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   323
var pulsar_current = 0, pulsar_tdlist = [], pulsar_direction = 1;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   324
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   325
var pulsar_reset = function()
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   326
{
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   327
  // remove any pulsar classes from items that aren't "current"
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   328
  var boobylist = document.getElementsByTagName('tr');
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   329
  for ( var i = 0; i < boobylist.length; i++ )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   330
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   331
    var booby = boobylist[i];
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   332
    var match = booby.className.match(/(^| )(pulsar[0-9])( |$)/);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   333
    if ( match && !$(booby).hasClass('current') )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   334
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   335
      $(booby).rmClass(match[2]);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   336
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   337
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   338
  var tdlist_new = document.getElementsByClassName('current', 'tr');
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   339
  if ( pulsar_current == 0 && tdlist_new == pulsar_tdlist )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   340
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   341
    return true;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   342
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   343
  pulsar_tdlist = tdlist_new;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   344
  pulsar_current = 0;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   345
  for ( var i = 0; i < pulsar_tdlist.length; i++ )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   346
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   347
    var td = pulsar_reset[i];
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   348
    for ( var i = 1; i < 10; i++ )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   349
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   350
      if ( $(td).hasClass('pulsar' + i) )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   351
      {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   352
        $(td).rmClass('pulsar' + i);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   353
      }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   354
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   355
    if ( ! $(td).hasClass('pulsar0') )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   356
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   357
      $(td).addClass('pulsar0');
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   358
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   359
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   360
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   361
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   362
var pulsar_advance = function()
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   363
{
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   364
  if ( !is_playing )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   365
    return true;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   366
  if ( pulsar_current + pulsar_direction == 10 )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   367
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   368
    pulsar_direction = -1;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   369
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   370
  else if ( pulsar_current + pulsar_direction == -1 )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   371
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   372
    pulsar_direction = 1;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   373
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   374
  var nc = pulsar_current + pulsar_direction;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   375
  for ( var i = 0; i < pulsar_tdlist.length; i++ )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   376
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   377
    $(pulsar_tdlist[i]).rmClass('pulsar' + pulsar_current).addClass('pulsar' + nc);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   378
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   379
  pulsar_current = nc;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   380
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   381
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   382
addOnloadHook(pulsar_reset);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   383
setInterval(pulsar_advance, 50);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   384