scripts/volume.js
changeset 58 05a69bab5f10
parent 6 5f35ebc4f9bb
child 59 a4ca1e7c0073
--- 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();
+      }
+    }
+  });