scripts/position.js
author Dan
Fri, 12 Jun 2009 13:50:13 -0400
changeset 78 08f8a72b1f7b
parent 42 774751e7faed
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:
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     1
var pos_supported = false;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     2
var pos_in_drag = false;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     3
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     4
var posslide_init = function()
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     5
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     6
  // make sure the theme supports the playhead
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     7
  var base = document.getElementById('playhead');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     8
  var inner = document.getElementById('playhead-filler');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
     9
  var slider = document.getElementById('playhead-button');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    10
  if ( !slider || !inner || !base )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    11
    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:
diff changeset
    12
  
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    13
  pos_supported = true;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    14
  
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    15
  var minX = $(base).Left() - 3;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    16
  var minY = $(base).Top() + 3;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    17
  var maxY = minY;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    18
  var maxX = minX + $(base).Width() - 6;
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
    19
  Drag.init(slider, slider, minX, maxX, minY, maxY);
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    20
  
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
    21
  slider.onDrag = posslide_handle_drag;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
    22
  slider.onDragEnd = posslide_handle_dragend;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
    23
  slider.onDragStart = function(x, y) { pos_in_drag = true; };
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    24
  base.onclick = posslide_handle_click;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    25
  
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    26
  posslide_set_position(0);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    27
  slider.style.top = minY + 'px';
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
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:
diff changeset
    29
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    30
var posslide_handle_drag = function(x, y, do_inner)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
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:
diff changeset
    32
  var inner = document.getElementById('playhead-filler');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    33
  var slider = document.getElementById('playhead-button');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    34
  var size = x - $(inner).Left() + 8;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    35
  if ( do_inner )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    36
    inner.style.width = size + 'px';
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    37
  if ( ( pos_in_drag && !do_inner ) || ( !pos_in_drag && do_inner ) )
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 10
diff changeset
    38
    slider.style.left = ( x ) + 'px';
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    39
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    40
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    41
var posslide_handle_dragend = function(x, y)
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    42
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    43
  pos_in_drag = false;
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    44
  if ( !verify_online() )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    45
  {
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    46
    posslide_set_position(current_track_pos);
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    47
    return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    48
  }
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    49
  
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    50
  var inner = document.getElementById('playhead-filler');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    51
  var base = document.getElementById('playhead');
42
774751e7faed Balanced out position slider a little more so it only moves by 240px instead of the full 250 (cosmetic only)
Dan
parents: 11
diff changeset
    52
  var multiplier = $(base).Width() - 13;
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    53
  var pos = x - $(inner).Left() + 8;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    54
  pos = 100 * ( pos / multiplier );
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    55
  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:
diff changeset
    56
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    57
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    58
var posslide_handle_click = 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:
diff changeset
    59
{
78
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    60
  if ( !verify_online() )
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    61
    return false;
08f8a72b1f7b Added Offline Mode - automatically turned on and off based on connectivity to server. Version bumped to 0.1a5.
Dan
parents: 42
diff changeset
    62
  
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    63
  e = Drag.fixE(e);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    64
  var base = document.getElementById('playhead');
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    65
  var val = e.clientX - $(base).Left();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    66
  val = 100 * ( val / $(base).Width() );
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    67
  posslide_set_position(val);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    68
  set_playback_position(val);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    69
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    70
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    71
function posslide_set_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:
diff changeset
    72
{
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    73
  if ( !pos_supported )
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    74
    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:
diff changeset
    75
  
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    76
  // pos needs to be 1-100
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    77
  var base = document.getElementById('playhead');
42
774751e7faed Balanced out position slider a little more so it only moves by 240px instead of the full 250 (cosmetic only)
Dan
parents: 11
diff changeset
    78
  var multiplier = $(base).Width() - 13;
10
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    79
  pos = ( pos / 100 ) * multiplier;
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    80
  var left = pos + $(base).Left();
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    81
  posslide_handle_drag(left, 0, true);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    82
}
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    83
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    84
addOnloadHook(posslide_init);
d3059e20b0fa SECURITY: Fix ability to crash server in ajax.php; added playback position slider and ability to seek through current song
Dan
parents:
diff changeset
    85