OSDN Git Service

Version 0.6.13, X.UI use X.Dom.Node.
[pettanr/clientJs.git] / 0.6.x / js / dom / 13_XDomStyle.js
index 9b97dcf..cc13866 100644 (file)
@@ -34,17 +34,17 @@ X.Dom.Style = {
        PropNo : {},
        
        UNIT : {
-               'px' : 0,
-               'em' : 1,
-               'cm' : 2,
-               'mm' : 3,
-               'in' : 4,
-               '%'  : 5,
-               'pct' : 5,
-               'ms'  : 6,
-               's'   : 7,
-               '#'   : 8,
-               'rgb' : 9,
+               'px'   : 0,
+               'em'   : 1,
+               'cm'   : 2,
+               'mm'   : 3,
+               'in'   : 4,
+               '%'    : 5,
+               'pct'  : 5,
+               'ms'   : 6,
+               's'    : 7,
+               '#'    : 8,
+               'rgb'  : 9,
                'rgba' : 10
        },
        
@@ -117,7 +117,8 @@ X.Dom.Style = {
                return css.join( ';' );
        },
        
-       _FONT_SIZE_RATIO : {},
+       _UNIT_RATIO      : null,
+       _FONT_SIZE_RATIO : null,
        
        absoluteFontSizeToPx : function( fontsize ){
                return X.Dom.Style._FONT_SIZE_RATIO[ fontsize ] || 0;
@@ -294,7 +295,7 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
                args = arguments,
                css  = this._css,
                p, valOrUnit, name, v, node, camelize;
-       if( this._nodeType !== 1 ) return this;
+       if( this._xnodeType !== 1 ) return this;
        // setter
        if( X.Type.isObject( nameOrObj ) ){
                if( !css ) css = this._css = {};
@@ -306,8 +307,11 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
                if( node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode ){
                        if( this._cssText ){
                                node.style.cssText = this._cssText;
+                               this._styleText = ' style="' + this._cssText + '"';
                        } else {
                                node.removeAttribute( 'style' );
+                               delete this._cssText;
+                               delete this._styleText;
                        };
                };
                return this;
@@ -316,8 +320,22 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
                if( !css ) css = this._css = {};
                name = XDomStyle.camelize( nameOrObj );
                v    = args[ 1 ];
+               node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
                if( css[ name ] === v ) return this;
-               if( node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode ){
+               if( !v && v !== 0 ){
+                       delete css[ name ];
+                       if( node ){
+                               node.style[ name ] = ''; // val
+                       };
+                       this._cssText = XDomStyle.objToCssText( css );
+                       if( !this._cssText ){
+                               delete this._cssText;
+                               delete this._styleText;
+                               node && node.removeAttribute( 'style' );
+                       };
+                       return this;
+               };
+               if( node ){
                        node.style[ name ] = v; // val
                };
                if( !css[ name ] ){
@@ -325,10 +343,9 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
                        css[ name ] = v;
                } else {
                        css[ name ] = v;
-                       // build _cssText
                        this._cssText = XDomStyle.objToCssText( css );
                };
-               node && !this._cssText && node.removeAttribute( 'style' );
+               this._styleText = ' style="' + this._cssText + '"';
                return this;
        };
        // getter
@@ -376,8 +393,7 @@ X.Dom.Node.prototype._getCharSize =
                        
                });
 
-X.Dom.listenOnce( X.Dom.Event.DOM_PREINIT, function(){
-       
+X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){
        var testStyle = X.Dom._view;
        
        X.Dom.Style.VENDER_PREFIX = (function(){
@@ -438,31 +454,23 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PREINIT, function(){
 } );
 
 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
-       var xnode = Node._systemNode;
-
-       var ret = X.Dom.Style._UNIT_RATIO = {},
-               unit,
-               units = 'em,cm,mm,in,pt,pc'.split( ',' ),
-               i     = units.length;
+       var xnode  = Node._systemNode,
+               output = X.Dom.Style._UNIT_RATIO = {},
+               list   = 'em,cm,mm,in,pt,pc'.split( ',' ),
+               unit,size, base, i;
        
-       for( ; i; ){
-               unit = units[ --i ];
-               xnode.css( 'width', 100 + unit );
-               ret[ unit ] = xnode.width() / 100;
-               console.log( unit + ':' + ret[ unit ] );
+       for( i = list.length; i; ){
+               unit = list[ --i ];
+               output[ unit ] = xnode.css( 'width', 100 + unit ).width() / 100;
        };
-       xnode.css( 'width', '' );
 
-       var ret = X.Dom.Style._FONT_SIZE_RATIO = {},
-               size, base,
-               list = 'xx-large,x-large,large,larger,medium,small,smaller,x-small,xx-small'.split( ',' ),
-               i = list.length;
+       output = X.Dom.Style._FONT_SIZE_RATIO = {},
+       list   = 'xx-large,x-large,large,larger,medium,small,smaller,x-small,xx-small'.split( ',' );
+       base   = xnode.css( 'lineHeight', 1 ).text( 'X' ).height();
        
-       base = xnode.css( 'lineHeight', 1 ).text( 'X' ).height();
-       for( ; i; ){
+       for( i = list.length; i; ){
                size = list[ --i ];
-               ret[ size ] = xnode.css( 'fontSize', size ).height() / base;
-               console.log( size + ':' + ( ret[ size ] * 100 | 0 ) + '%' );
+               output[ size ] = xnode.css( 'fontSize', size ).height() / base;
        };
        
        xnode.empty().cssText( '' );