# Anims.js

    YAHOO.ext.StyleAnim = function(css){
        var o = css;
        if(typeof css == 'string'){
             o = {};
            var re = YAHOO.ext.StyleAnim.styleRE;
            var m;
            while ((m = re.exec(css)) != null){
                o[m[1]] = m[2];
            }
        }
        this.styles = o;
        if(!YAHOO.ext.StyleAnim.measureEl){
            var el = document.createElement('div');
            el.style.position = 'absolute';
            el.style.top = '-500px';
            el.style.left = '-500px';
            el.style.width = '0px';
            el.style.visibility = 'hidden';
            document.body.appendChild(el);
            YAHOO.ext.StyleAnim.measureEl = getEl(el);
        }
    };
    YAHOO.ext.StyleAnim.styleRE = /\s?([a-z\-]*)\:([^;]*);?/gi;

    YAHOO.ext.StyleAnim.measurables = [
           'border',
           'border-width',
           'border-left',
           'border-right',
           'border-top',
           'border-bottom',
           'border-left-width',
           'border-right-width',
           'border-top-width',
           'border-bottom-width',
           'padding-left',
           'padding-right',
           'padding-top',
           'padding-bottom'
    ];
    YAHOO.ext.StyleAnim.copyStyles = [
           'border-left-width',
           'border-right-width',
           'border-top-width',
           'border-bottom-width',
           'padding-left',
           'padding-right',
           'padding-top',
           'padding-bottom'
    ];
    YAHOO.ext.StyleAnim.prototype = {
        apply : function(el, callback){
            var o = this.styles;
            var el = getEl(el);
            var adjAttr = ['width','height'];
            if(el.autoBoxAdjust && !el.isBorderBox()){
                var up = YAHOO.ext.Element.unitPattern;
                var adj;
                for(var i = 0, len = adjAttr.length; i < len; i++) {
                	var attr = adjAttr[i];
                	if(o[attr] != undefined){
                         var m = String(o[attr]).match(up);
                         if(!m || m[1] == 'px'){
                             if(!adj){
                                 adj = this.getAdjustments(el, o);
                             }
                             var v = Math.max(0, (parseInt(o[attr], 10) || 0) - adj[0]);
                             o[attr] = v;
                         }
                    }
                }
            }else{
                for(var i = 0, len = adjAttr.length; i < len; i++) {
                	var attr = adjAttr[i];
                	if(o[attr] != undefined){
                        o[attr] = Math.max(0, parseInt(o[attr], 10) || 0);
                    }
                }
            }
            var attr = {};
            for(var k in o){
                if(typeof o[k] != 'function'){
                    attr[k] = {to: o[k]};
                }
            }
            alert(YAHOO.ext.util.JSON.encode(attr))
            new YAHOO.util.Anim(el.dom, attr, .5).animate();
            return this;
        },

        getAdjustments : function(el, o){
            var mel = YAHOO.ext.StyleAnim.measureEl;
            var ms = YAHOO.ext.StyleAnim.measurables;
            mel.copyStyles(el, YAHOO.ext.StyleAnim.copyStyles);
            // apply measurable styles
            for(var i = 0, len = ms.length; i < len; i++) {
            	var s = ms[i];
            	if(o[s]){
            	    mel.setStyle(s, o[s]);
            	}
            }
            return [mel.getBorderWidth('lr')+mel.getPadding('lr'),
                    mel.getBorderWidth('tb')+mel.getPadding('tb')];
        }
    }

    YAHOO.ext.ClassAnim = function(selector){
         var rule = YAHOO.ext.util.CSS.getRule(selector);
         var s = rule.style;
         var attrs = {};
    	 for(var key in s){
    	    if(s[key] && typeof s[key] != 'function' && String(s[key]).indexOf(':') < 0 && s[key] != 'false'){
    			attrs[key] = s[key];
    	    }
    	 }
    	 YAHOO.ext.ClassAnim.superclass.constructor.call(this, attrs);
    };

    YAHOO.extendX(YAHOO.ext.ClassAnim, YAHOO.ext.StyleAnim);

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.