scripts/domutils.js
changeset 58 05a69bab5f10
parent 11 0faea3a6c881
--- 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)