scripts/ajax.js
author Dan
Fri, 12 Jun 2009 13:50:13 -0400
changeset 78 08f8a72b1f7b
parent 39 38dbcda3cf20
permissions -rw-r--r--
Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
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;
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
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, offline_mode = false;
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
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    50
// preload "offline mode" large icon
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    51
var preload = ['/offlinemodelarge.png', 'trans80.png']
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    52
for ( var i = 0; i < preload.length; i++ )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    53
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    54
  var img = new Image();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    55
  img.src = preload[i];
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    56
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    57
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    58
function offline_mode_on()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    59
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    60
  unsetAjaxLoading();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    61
  document.getElementById('offlinemode').style.display = 'block';
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    62
  offline_mode = true;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    63
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    64
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    65
function offline_mode_off()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    66
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    67
  document.getElementById('offlinemode').style.display = 'none';
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    68
  offline_mode = false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    69
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    70
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    71
function verify_online()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    72
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    73
  if ( !offline_mode )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    74
    return true;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    75
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    76
  flash_offline();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    77
  return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    78
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    79
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    80
function flash_offline()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    81
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    82
  if ( document.getElementById('offlinebox') )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    83
    return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    84
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    85
  var box = document.createElement('div');
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    86
  $(box)
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    87
    .css('position', 'absolute')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    88
    .css('padding', '50px 80px')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    89
    .css('background-image', 'url(/trans80.png)')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    90
    .css('color', 'black')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    91
    .css('text-align', 'center')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    92
    .attr('id', 'offlinebox')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    93
    .opacity(0);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    94
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    95
  var image = document.createElement('img');
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    96
  image.src = '/offlinemodelarge.png';
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    97
  box.appendChild(image);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    98
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
    99
  document.body.appendChild(box);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   100
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   101
  $(box)
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   102
    .css('top',  (( getHeight() / 2 ) - ( $(box).Height() / 2 ) + getScrollOffset()) + 'px')
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   103
    .css('left', (( $(document.body).Width() / 2 ) - ( $(box).Width() / 2 )) + 'px');
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   104
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   105
  $(box).fadeIn(250);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   106
  window.setTimeout(function()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   107
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   108
      $(box).fadeOut(250);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   109
      window.setTimeout(function()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   110
        {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   111
          document.body.removeChild(box);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   112
        }, 250);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   113
    }, 1000);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   114
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   115
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   116
function ajaxGet(uri, f)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   117
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   118
  if (window.XMLHttpRequest)
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
    ajax = new XMLHttpRequest();
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
  else
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   123
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   124
    if (window.ActiveXObject) {           
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   125
      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
   126
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   127
    else
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
      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
   130
      return;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   131
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   132
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   133
  ajax.onreadystatechange = f;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   134
  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
   135
  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
   136
  ajax.send(null);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   137
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   138
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   139
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
   140
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   141
  if (window.XMLHttpRequest)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   142
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   143
    ajax = new XMLHttpRequest();
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
  else
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 (window.ActiveXObject)
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
      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
   150
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   151
    else
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
      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
   154
      return;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   155
    }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   156
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   157
  ajax.onreadystatechange = f;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   158
  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
   159
  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
   160
  // 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
   161
  if ( !is_Safari )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   162
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   163
    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
   164
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   165
  ajax.setRequestHeader("Connection", "close");
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   166
  ajax.onerror = function()
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   167
  {
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   168
    ajax_panic();
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   169
  }
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   170
  ajax.send(parms);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   171
}
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
function setAjaxLoading()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   174
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   175
  $('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
   176
  $('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
   177
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   178
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   179
function unsetAjaxLoading()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   180
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   181
  $('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
   182
  $('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
   183
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   184
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   185
var refresh_playlist = function()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   186
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   187
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   188
  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
   189
    {
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   190
      if ( ajax.readyState == 4 && ajax.status == 200 && ( (window.location.hash != '#offlinemode' && !first_load ) || first_load ) )
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   191
      {
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   192
        offline_mode_off();
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   193
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   194
        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
   195
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   196
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   197
        // 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
   198
        if ( playlist_md5 )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   199
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   200
          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
   201
          {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   202
            // playlist has changed, reload
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   203
            window.location.reload();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   204
            return false;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   205
          }
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
        playlist_md5 = response.playlist_hash;
18
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   208
        
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   209
        update_timers(response);
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   210
      }
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   211
      else if ( ajax.readyState == 4 && ( ajax.status != 200 || window.location.hash == '#offlinemode' ) )
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   212
      {
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   213
        if ( !offline_mode )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   214
          ajax_panic();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   215
        else
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   216
          unsetAjaxLoading();
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   217
      }
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   218
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   219
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   220
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   221
function update_timers(response)
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   222
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   223
  // update track number
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   224
  if ( response.current_track != current_track )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   225
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   226
    var ot_id = 'track_' + current_track;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   227
    var nt_id = 'track_' + response.current_track;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   228
    current_track = response.current_track;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   229
    if ( $(ot_id).hasClass('current') )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   230
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   231
      $(ot_id).rmClass('current');
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   232
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   233
    if ( ! $(nt_id).hasClass('current') )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   234
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   235
      $(nt_id).addClass('current');
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   236
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   237
    pulsar_reset();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   238
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   239
  // update playing status
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   240
  is_playing = response.is_playing;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   241
  if ( allow_control )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   242
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   243
    var img = $('btn_playpause').object.getElementsByTagName('img')[0];
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   244
    if ( is_playing )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   245
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   246
      img.src = img_pause;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   247
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   248
    else
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   249
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   250
      img.src = img_play;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   251
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   252
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   253
  // update volume
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   254
  if ( response.volume != current_volume )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   255
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   256
    set_volume_fill(response.volume);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   257
    current_volume = response.volume;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   258
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   259
  // auto-refresh on track advance
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   260
  if ( ct_advance_timeout )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   261
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   262
    clearTimeout(ct_advance_timeout);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   263
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   264
  // countdown/up timer
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   265
  var time_remaining = response.current_track_length - response.current_track_pos;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   266
  current_track_length = response.current_track_length;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   267
  current_track_pos = response.current_track_pos;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   268
  if ( ct_counter )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   269
    clearInterval(ct_counter);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   270
  update_clock();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   271
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   272
  // set page title
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   273
  updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   274
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   275
  // if not playing, set the position slider to zero
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   276
  if ( !is_playing && !response.is_paused )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   277
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   278
    posslide_set_position(0);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   279
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   280
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   281
  // set advance timer
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   282
  if ( is_playing && time_remaining > 0 )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   283
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   284
    ct_advance_timeout = setTimeout(refresh_playlist, ( 1000 * time_remaining ));
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   285
    ct_counter = setInterval(update_clock, 1000);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   286
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   287
  if ( first_load )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   288
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   289
    first_load = false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   290
    if ( window.iPhone )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   291
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   292
      setTimeout('jump_current_track();', 1000);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   293
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   294
    else
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   295
    {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   296
      jump_current_track();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   297
    }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   298
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   299
}
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   300
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   301
function ajax_panic()
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   302
{
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   303
  offline_mode_on();
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   304
}
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   305
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   306
function player_action(action)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   307
{
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   308
  if ( !verify_online() )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   309
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   310
    return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   311
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   312
  
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   313
  var act2 = action;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   314
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   315
  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
   316
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   317
      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
   318
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   319
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   320
        refresh_playlist();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   321
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   322
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   323
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   324
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   325
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
   326
{
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   327
  if ( !verify_online() )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   328
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   329
    return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   330
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   331
  
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   332
  setAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   333
  if ( tid == current_track )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   334
    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
   335
  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
   336
    return false;
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   337
  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
   338
    {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   339
      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
   340
      {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   341
        unsetAjaxLoading();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   342
        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
   343
        // quickie JSON parser :)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   344
        response = eval('(' + response + ')');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   345
        
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   346
        // update track number
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   347
        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
   348
        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
   349
        current_track = tid;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   350
        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
   351
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   352
          $(ot_id).rmClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   353
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   354
        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
   355
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   356
          $(nt_id).addClass('current');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   357
        }
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   358
        // update pulsar
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   359
        pulsar_reset();
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   360
        // update playing status
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   361
        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
   362
        is_playing = true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   363
        img.src = img_play;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   364
        // 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
   365
        if ( ct_advance_timeout )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   366
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   367
          clearTimeout(ct_advance_timeout);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   368
        }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   369
        if ( ct_counter )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   370
          clearInterval(ct_counter);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   371
        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
   372
        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
   373
        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
   374
        if ( is_playing )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   375
        {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   376
          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
   377
          update_clock();
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   378
          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
   379
        }
18
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   380
        updateTitle(response.current_track_artist, response.current_track_album, response.current_track_title);
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   381
      }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   382
    });
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   383
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   384
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
   385
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
   386
{
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
   387
  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
   388
  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
   389
  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
   390
    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
   391
  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
   392
    {
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
   393
      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
   394
      {
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
   395
        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
   396
        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
   397
        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
   398
      }
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
   399
    });
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
   400
}
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
   401
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   402
function offline_advance_track()
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   403
{
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   404
  var new_track = current_track + 1;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   405
  if ( !document.getElementById('track_' + new_track) )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   406
    new_track = 0;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   407
  
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   408
  update_timers({
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   409
    is_playing: is_playing,
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   410
    is_paused: false,
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   411
    volume: current_volume,
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   412
    current_track: new_track,
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   413
    current_track_length: document.getElementById('track_' + new_track).getAttribute('amarok:length_sec'),
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   414
    current_track_pos: 0,
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   415
    current_track_artist: 'FIXME artist',
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   416
    current_track_album: 'FIXME album',
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   417
    current_track_title: 'FIXME title'
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   418
  })
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   419
}
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   420
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   421
function update_clock()
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   422
{
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   423
  if ( offline_mode && current_track_pos > current_track_length )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   424
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   425
    offline_advance_track();
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   426
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 39
diff changeset
   427
  
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
   428
  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
   429
  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
   430
  $('playmeter').object.innerHTML = str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   431
  current_track_pos++;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   432
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   433
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   434
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
   435
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   436
  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
   437
  var count_minutes = ( time - count_seconds ) / 60;
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   438
  if ( isNaN(count_seconds) )
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   439
    count_seconds = 0;
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   440
  if ( isNaN(count_minutes) )
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   441
    count_minutes = 0;
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   442
  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
   443
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   444
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   445
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
   446
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   447
  if ( !len )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   448
    len = 2;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   449
  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
   450
    str = '0';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   451
  str = String(str);
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   452
  while ( str.length < len )
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   453
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   454
    str = '0' + str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   455
  }
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   456
  return str;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   457
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   458
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   459
var pl_refresh_id = setInterval(refresh_playlist, 10000);
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   460
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
   461
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
   462
{
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
   463
  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
   464
}
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
   465
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
   466
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
   467
14
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   468
// scroll to the current track
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   469
function jump_current_track()
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   470
{
39
38dbcda3cf20 Fixed scroll-to-current-track being about 30 pixels off under iPhone
Dan
parents: 22
diff changeset
   471
  var top = $('track_' + current_track).Top() - 164;
14
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   472
  window.scroll(0, top);
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   473
  if ( typeof(fix_scroll) == 'function' )
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   474
  {
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   475
    fix_scroll();
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   476
  }
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   477
}
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   478
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   479
// pulse the current track
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   480
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
   481
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   482
var pulsar_reset = function()
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   483
{
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   484
  // 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
   485
  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
   486
  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
   487
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   488
    var booby = boobylist[i];
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   489
    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
   490
    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
   491
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   492
      $(booby).rmClass(match[2]);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   493
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   494
  }
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   495
  // recalculate list of rows that should pulse
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   496
  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
   497
  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
   498
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   499
    return true;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   500
  }
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   501
  // reset everything to 0
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   502
  pulsar_tdlist = tdlist_new;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   503
  pulsar_current = 0;
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   504
  pulsar_direction = 1;
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   505
  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
   506
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   507
    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
   508
    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
   509
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   510
      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
   511
      {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   512
        $(td).rmClass('pulsar' + i);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   513
      }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   514
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   515
    if ( ! $(td).hasClass('pulsar0') )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   516
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   517
      $(td).addClass('pulsar0');
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   518
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   519
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   520
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   521
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   522
var pulsar_advance = function()
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   523
{
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   524
  // this should be as optimized as possible, it should use a precalculated
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   525
  // list of elements to pulse and whatnot... heck even right now it's not
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   526
  // really as optimized as it should be due to the logic, but a lot of it's
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 11
diff changeset
   527
  // kinda more or less necessary.
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   528
  if ( !is_playing )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   529
    return true;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   530
  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
   531
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   532
    pulsar_direction = -1;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   533
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   534
  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
   535
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   536
    pulsar_direction = 1;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   537
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   538
  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
   539
  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
   540
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   541
    $(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
   542
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   543
  pulsar_current = nc;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   544
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   545
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   546
addOnloadHook(pulsar_reset);
22
3a4f0cd0794e Added ability to gracefully fail the client if the connection to the server fails
Dan
parents: 21
diff changeset
   547
var pulsar_interval_id = setInterval(pulsar_advance, 50);
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
   548
18
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   549
function updateTitle(artist, album, track)
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   550
{
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   551
  var sep = '';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   552
  var str = '';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   553
  if ( track )
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   554
  {
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   555
    str += sep + track;
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   556
    sep = ' - ';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   557
  }
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   558
  if ( artist )
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   559
  {
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   560
    str += sep + artist;
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   561
    sep = ' - ';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   562
  }
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   563
  if ( album )
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   564
  {
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   565
    str += sep + album;
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   566
    sep = ' - ';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   567
  }
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   568
  str += sep + 'AmaroK Playlist';
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   569
  document.title = str;
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   570
}
69af47034212 Added page-titling functionality that changes document.title to match the current track; made position slider reset to zero on stop or playlist end
Dan
parents: 14
diff changeset
   571