scripts/domutils.js
author Dan
Tue, 26 May 2009 15:25:58 -0400
changeset 70 efabb54a418d
parent 58 05a69bab5f10
permissions -rw-r--r--
Core: should properly handle IPv4/IPv6 toggle preferences now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     1
// The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs.
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     2
// License = GPLv2
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     3
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     4
var $ = function(id)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     5
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     6
  return new DNobj(id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     7
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     8
var $dynano = $;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     9
function DNobj(id)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    10
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    11
  this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    12
  if ( !this.object )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    13
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    14
    this.object = false;
58
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    15
    return false;
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    16
  }
58
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    17
  if ( this.object.Dynano )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    18
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    19
    return this.object.Dynano;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    20
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    21
  this.object.Dynano = this;
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    22
  this.height = __DNObjGetHeight(this.object);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    23
  this.width = __DNObjGetWidth(this.object);
58
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    24
  // fixme: make more accurate?
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    25
  this.object.DN_opac = 100;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    26
  
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    27
  return true;
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    28
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    29
function __DNObjGetHeight(o) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    30
  return o.offsetHeight;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    31
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    32
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    33
function __DNObjGetWidth(o) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    34
  return o.offsetWidth;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    35
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    36
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    37
function addClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    38
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    39
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    40
  var space = ( (cnt + '').length > 0 ) ? ' ' : '';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    41
  var cls = cnt + space + clsname;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    42
  obj.className = cls;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    43
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    44
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    45
function rmClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    46
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    47
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    48
  if ( cnt == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    49
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    50
    obj.className = '';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    51
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    52
  else
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    53
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    54
    cnt = cnt.replace(clsname, '');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    55
    cnt = trim(cnt);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    56
    obj.className = cnt;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    57
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    58
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    59
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    60
function hasClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    61
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    62
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    63
  if ( !cnt )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    64
    return false;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    65
  if ( cnt == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    66
    return true;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    67
  cnt = cnt.split(' ');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    68
  
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    69
  for ( var i in cnt )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    70
    if ( cnt[i] == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    71
      return true;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    72
    
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    73
  return false;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    74
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    75
function __DNObjGetLeft(obj) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    76
  var left_offset = obj.offsetLeft;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    77
  while ((obj = obj.offsetParent) != null) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    78
    left_offset += obj.offsetLeft;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    79
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    80
  return left_offset;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    81
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    82
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    83
function __DNObjGetTop(obj) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    84
  var left_offset = obj.offsetTop;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    85
  while ((obj = obj.offsetParent) != null) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    86
    left_offset += obj.offsetTop;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    87
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    88
  return left_offset;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    89
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    90
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    91
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    92
DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    93
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };
58
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    94
DNobj.prototype.Height   = function()        { return __DNObjGetHeight(this.object); };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    95
DNobj.prototype.Width    = function()        { return __DNObjGetWidth( this.object); };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    96
DNobj.prototype.Left     = function()        { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    97
DNobj.prototype.Top      = function()        { /* return this.object.offsetTop;  */ return __DNObjGetTop( this.object); };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    98
DNobj.prototype.insertText = function(text)  { this.object.appendChild(document.createTextNode(text)); return this; };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
    99
DNobj.prototype.insertBR = function()        { this.object.appendChild(document.createElement('br')); return this; };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   100
DNobj.prototype.attr     = function(attribute, value) { this.object.setAttribute(attribute, value); return this; };
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   101
DNobj.prototype.css      = function(attribute, value)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   102
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   103
  if ( attribute == 'float' )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   104
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   105
    this.object.style.cssFloat = value;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   106
    this.object.style.styleFloat = value;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   107
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   108
  else
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   109
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   110
    // convert attribute to CamelCase format (quick and easy version)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   111
    var i;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   112
    while ( (i = attribute.indexOf('-')) > -1 )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   113
    {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   114
      attribute = attribute.substr(0, i) +
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   115
                  attribute.substr(i + 1, 1).toUpperCase() +
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   116
                  attribute.substr(i + 2);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   117
    }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   118
    this.object.style[attribute] = value;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   119
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   120
  return this;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   121
}
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   122
DNobj.prototype.opacity = function(opacity)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   123
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   124
  var object = this.object.style;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   125
  object.opacity = (opacity / 100);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   126
  object.MozOpacity = (opacity / 100);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   127
  object.KhtmlOpacity = (opacity / 100);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   128
  object.filter = "alpha(opacity=" + opacity + ")";
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   129
  this.object.DN_opac = opacity;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   130
}
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   131
DNobj.prototype.fade = function(to, time, done)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   132
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   133
  var from = this.object.DN_opac;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   134
  if ( to == from )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   135
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   136
    return this;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   137
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   138
  time = time || 500;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   139
  var op = to > from ? 1 : -1;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   140
  var timestep = time / ( op * (to - from) );
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   141
  var i = from, tick = 0, o = this.object;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   142
  this.object.id = this.object.id || 'dynano_autofade_' + Math.floor(Math.random() * 1000000);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   143
  
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   144
  while ( true )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   145
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   146
    i += op;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   147
    tick += timestep;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   148
    
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   149
    if ( ( op == -1 && i < to ) || ( op == 1 && i > to ) )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   150
      break;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   151
    
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   152
    setTimeout('$("' + this.object.id + '").opacity(' + i + ');', tick);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   153
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   154
  if ( typeof(done) == 'function' )
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   155
  {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   156
    setTimeout(function()
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   157
      {
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   158
        done(o);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   159
      }, tick);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   160
  }
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   161
  return this;
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   162
}
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   163
DNobj.prototype.fadeIn = function(time, done)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   164
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   165
  return this.fade(100, time, done);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   166
}
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   167
DNobj.prototype.fadeOut = function(time, done)
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   168
{
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   169
  return this.fade(0, time, done);
05a69bab5f10 Added custom volume setting function (press v in the playlist window)
Dan
parents: 11
diff changeset
   170
}
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   171
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   172
// Equivalent to PHP trim() function
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   173
function trim(text)
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   174
{
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   175
  text = text.replace(/^([\s]+)/, '');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   176
  text = text.replace(/([\s]+)$/, '');
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   177
  return text;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   178
}
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 1
diff changeset
   179
11
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   180
// Tell which elements have the specified CSS class
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   181
// Parameters:
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   182
//   * object - HTMLElement
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   183
//   * string - class name
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   184
//   * string - tag name, if omitted will test all elements (slow)
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   185
function getElementsByClassName(oRoot, className, tagName)
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   186
{
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   187
  tagName = ( tagName ) ? tagName : '*';
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   188
  var arrEls = document.getElementsByTagName(tagName);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   189
  var arrResult = [];
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   190
  for ( var i = 0; i < arrEls.length; i++ )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   191
  {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   192
    if ( $(arrEls[i]).hasClass(className) )
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   193
    {
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   194
      arrResult.push(arrEls[i]);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   195
    }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   196
  }
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   197
  return arrResult;
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   198
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   199
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   200
// shortcut :)
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   201
document.getElementsByClassName = function(a, b)
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   202
{
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   203
  return getElementsByClassName(document, a, b);
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   204
}
0faea3a6c881 Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents: 2
diff changeset
   205