Added custom volume setting function (press v in the playlist window)
authorDan
Sun, 23 Nov 2008 23:43:59 -0500
changeset 58 05a69bab5f10
parent 57 31ce64a3ff6c
child 59 a4ca1e7c0073
Added custom volume setting function (press v in the playlist window)
greyhound.php
scripts/domutils.js
scripts/volume.js
trans80.png
--- a/greyhound.php	Sun Nov 23 23:43:52 2008 -0500
+++ b/greyhound.php	Sun Nov 23 23:43:59 2008 -0500
@@ -112,7 +112,27 @@
 rebuild_playlist();
 
 // startup webserver
-$ip = ( $public ) ? '0.0.0.0' : '127.0.0.1';
+$ip = array();
+if ( !$enable_ipv4 && !$enable_ipv6 )
+{
+  warning('Both IPv4 and IPv6 are disabled, enabling IPv4 access');
+  $enable_ipv4 = true;
+}
+if ( $public )
+{
+  if ( $enable_ipv6 )
+    $ip[] = '::';
+  if ( $enable_ipv4 )
+    $ip[] = '0.0.0.0';
+}
+else
+{
+  if ( $enable_ipv6 )
+    $ip[] = '::1';
+  if ( $enable_ipv4 )
+    $ip[] = '127.0.0.1';
+}
+
 $port = 7447;
 
 try
@@ -160,6 +180,7 @@
   $httpd->add_handler('favicon.ico',          'file',     GREY_ROOT . '/amarok_icon.ico');
   $httpd->add_handler('apple-touch-icon.png', 'file',     GREY_ROOT . '/apple-touch-icon.png');
   $httpd->add_handler('spacer.gif',           'file',     GREY_ROOT . '/spacer.gif');
+  $httpd->add_handler('trans80.png',          'file',     GREY_ROOT . '/trans80.png');
   $httpd->threader->ipc_register('reloadconfig', 'grey_reload_config');
   // load all themes if forking is enabled
   // Themes are loaded when the playlist is requested. This is fine for
--- a/scripts/domutils.js	Sun Nov 23 23:43:52 2008 -0500
+++ b/scripts/domutils.js	Sun Nov 23 23:43:59 2008 -0500
@@ -12,10 +12,19 @@
   if ( !this.object )
   {
     this.object = false;
-    return this;
+    return false;
   }
+  if ( this.object.Dynano )
+  {
+    return this.object.Dynano;
+  }
+  this.object.Dynano = this;
   this.height = __DNObjGetHeight(this.object);
   this.width = __DNObjGetWidth(this.object);
+  // fixme: make more accurate?
+  this.object.DN_opac = 100;
+  
+  return true;
 }
 function __DNObjGetHeight(o) {
   return o.offsetHeight;
@@ -82,10 +91,83 @@
 DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
 DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
 DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };
-DNobj.prototype.Height   = function()        { return __DNObjGetHeight(this.object); }
-DNobj.prototype.Width    = function()        { return __DNObjGetWidth( this.object); }
-DNobj.prototype.Left     = function()        { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); }
-DNobj.prototype.Top      = function()        { /* return this.object.offsetTop;  */ return __DNObjGetTop( this.object); }
+DNobj.prototype.Height   = function()        { return __DNObjGetHeight(this.object); };
+DNobj.prototype.Width    = function()        { return __DNObjGetWidth( this.object); };
+DNobj.prototype.Left     = function()        { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); };
+DNobj.prototype.Top      = function()        { /* return this.object.offsetTop;  */ return __DNObjGetTop( this.object); };
+DNobj.prototype.insertText = function(text)  { this.object.appendChild(document.createTextNode(text)); return this; };
+DNobj.prototype.insertBR = function()        { this.object.appendChild(document.createElement('br')); return this; };
+DNobj.prototype.attr     = function(attribute, value) { this.object.setAttribute(attribute, value); return this; };
+DNobj.prototype.css      = function(attribute, value)
+{
+  if ( attribute == 'float' )
+  {
+    this.object.style.cssFloat = value;
+    this.object.style.styleFloat = value;
+  }
+  else
+  {
+    // convert attribute to CamelCase format (quick and easy version)
+    var i;
+    while ( (i = attribute.indexOf('-')) > -1 )
+    {
+      attribute = attribute.substr(0, i) +
+                  attribute.substr(i + 1, 1).toUpperCase() +
+                  attribute.substr(i + 2);
+    }
+    this.object.style[attribute] = value;
+  }
+  return this;
+}
+DNobj.prototype.opacity = function(opacity)
+{
+  var object = this.object.style;
+  object.opacity = (opacity / 100);
+  object.MozOpacity = (opacity / 100);
+  object.KhtmlOpacity = (opacity / 100);
+  object.filter = "alpha(opacity=" + opacity + ")";
+  this.object.DN_opac = opacity;
+}
+DNobj.prototype.fade = function(to, time, done)
+{
+  var from = this.object.DN_opac;
+  if ( to == from )
+  {
+    return this;
+  }
+  time = time || 500;
+  var op = to > from ? 1 : -1;
+  var timestep = time / ( op * (to - from) );
+  var i = from, tick = 0, o = this.object;
+  this.object.id = this.object.id || 'dynano_autofade_' + Math.floor(Math.random() * 1000000);
+  
+  while ( true )
+  {
+    i += op;
+    tick += timestep;
+    
+    if ( ( op == -1 && i < to ) || ( op == 1 && i > to ) )
+      break;
+    
+    setTimeout('$("' + this.object.id + '").opacity(' + i + ');', tick);
+  }
+  if ( typeof(done) == 'function' )
+  {
+    setTimeout(function()
+      {
+        done(o);
+      }, tick);
+  }
+  return this;
+}
+DNobj.prototype.fadeIn = function(time, done)
+{
+  return this.fade(100, time, done);
+}
+DNobj.prototype.fadeOut = function(time, done)
+{
+  return this.fade(0, time, done);
+}
 
 // Equivalent to PHP trim() function
 function trim(text)
--- a/scripts/volume.js	Sun Nov 23 23:43:52 2008 -0500
+++ b/scripts/volume.js	Sun Nov 23 23:43:59 2008 -0500
@@ -67,3 +67,73 @@
     });
 }
 
+function volume_custom_form()
+{
+  if ( $('volumebox').object )
+  {
+    return false;
+  }
+  var box = document.createElement('div');
+  $(box)
+    .css('position', 'absolute')
+    .css('padding', '50px 80px')
+    .css('background-image', 'url(/trans80.png)')
+    .css('color', 'black')
+    .css('text-align', 'center')
+    .attr('id', 'volumebox')
+    .insertText('volume:')
+    .insertBR().insertBR()
+    .opacity(0);
+  document.body.appendChild(box);
+  
+  var field = document.createElement('input');
+  $(field)
+    .attr('type', 'text')
+    .attr('value', '')
+    .attr('size', '7')
+    .css('text-align', 'center');
+  box.appendChild(field);
+  
+  $(box)
+    .css('top',  (( $(window).Height() / 2 ) - ( $(box).Height() / 2 )) + 'px')
+    .css('left', (( $(document.body).Width() / 2 ) - ( $(box).Width() / 2 )) + 'px');
+  
+  $(box).fadeIn(250);
+  field.focus();
+  field.onkeyup = function(e)
+  {
+    if ( e.keyCode == 13 )
+    {
+      if ( this.value == '' )
+      {
+        $(this.parentNode).fadeOut(250, function(o)
+          {
+            o.parentNode.removeChild(o);
+          });
+      }
+      else if ( !this.value.match(/^[0-9]+$/) )
+      {
+        $(this.parentNode).insertBR().insertText('please enter a number');
+      }
+      else
+      {
+        set_volume(parseInt(this.value));
+        $(this.parentNode).fadeOut(250, function(o)
+          {
+            o.parentNode.removeChild(o);
+          });
+      }
+    }
+  }
+}
+
+addOnloadHook(function()
+  {
+    window.onkeyup = function(e)
+    {
+      if ( e.keyCode == 86 )
+      {
+        volume_custom_form();
+      }
+    }
+  });
Binary file trans80.png has changed