OSDN Git Service

Version 0.6.27, bugfix for X.Dom.Parser.
[pettanr/clientJs.git] / 0.6.x / js / dom / 15_XDomStyle.js
index 1edbdd3..5fac239 100644 (file)
@@ -132,19 +132,30 @@ _GRNERAL
                        VENDER_PREFIX = me.VENDER_PREFIX,
                        FIX_PROP      = me.SPECIAL_FIX_PROP,
                        SPECIAL_FIX   = me.SPECIAL_FIX,
+                       n             = -1,
                        p, name, sp;
                for( p in obj ){
                        name = uncamelize( p );
                        if( FIX_PROP[ name ] ){
                                sp = 1;
                        } else {
-                               css[ css.length ] = [ VENDER_PREFIX[ name ] || name, obj[ p ] ].join( ':' );
+                               css[ ++n ] = [ VENDER_PREFIX[ name ] || name, obj[ p ] ].join( ':' );
                        };
                };
-               sp && ( css[ css.length ] = SPECIAL_FIX( obj ) );
+               sp && ( css[ ++n ] = SPECIAL_FIX( obj ) );
                return css.join( ';' );
        },
        
+       IE_FILTER_FIX :
+               X.UA.IE && X.UA.IE < 9 ?
+                       {
+                               opacity : 1,
+                               textShadow : 1
+                       } :
+               9 <= X.UA.IE && X.UA.IE < 10 ? // == 9
+                       {} :
+                       {},
+       
        _UNIT_RATIO      : null,
        _FONT_SIZE_RATIO : null,
 
@@ -843,35 +854,40 @@ X.Dom.Style.SPECIAL_FIX =
        X.UA.IE && X.UA.IE < 9 ?
                (function( obj ){
                        var test    = X.Dom.Style.SPECIAL_FIX_PROP,
-                               filters = [], p, id, v;
+                               filters = [],
+                               n       = -1,
+                               p, id, v, dir;
                        for( p in obj ){
                                if( !( id = test[ p ] ) ) continue;
                                v = obj[ p ];
                                switch( id ){
                                        case 1 : //'filter' :
-                                               filters[ filters.length ] = v;
+                                               filters[ ++n ] = v;
                                                break;
                                        case 2 : //'opacity' :
-                                               filters[ filters.length ] = 'aplha(opacity=' + v +')';
+                                               filters[ ++n ] = 'alpha(opacity=' + v * 100 +')';
                                                break;
                                        case 3 : //'boxShadow' :
                                                // box-shadow: 10px 10px 10px 10px rgba(0,0,0,0.4) inset;
                                                // スペース区切りで、水平方向の距離 垂直方向の距離 ぼかし距離 広がり距離 影の色 insetキーワードを指定する。 ぼかし距離 広がり距離 影の色 insetキーワードは省略可
                                                // shadow(color=#cccccc, strength=10, direction=135);
-                                               parseValue( 'boxShadow', v, 'px' );
-                                               dir = Math.atan2( ary[1], ary[0] ) * 180 / Math.PI + 90;
+                                               v = X.Dom.Style._getProperty( this, css, 'px', 'boxShadow' );
+                                               dir = Math.atan2( v[ 1 ], v[ 0 ] ) * 180 / Math.PI + 90;
                                                dir += dir < 0 ? 360 : 0;
+                                               filters[ ++n ] = 'shadow(color=' + v[ 4 ] + ',strength=' + v[ 3 ] + ',direction=' + dir + ')';
                                                break;
                                        case 4 : //'textShadow' :
                                                //text-shadow: 5px 5px 2px blue; 水平方向の距離 垂直方向の距離 影のぼかし半径 影の色 none
                                                //glow(Color=yellow,Strength=10);
                                                //どうやらCSSのbackgroundプロパティと同時に使えないようです。 
+                                               
+                                               
                                                break;
                                        case 5 : //'backgroundImage' :
                                                //
                                };
                        };
-                       if( filters ) return filters.join( ' ' );
+                       return filters.join( ' ' );
                }) :
        // IE9 textShadow に filter を使用
        X.UA.IE && 9 <= X.UA.IE && X.UA.IE < 10 ?
@@ -936,26 +952,22 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
        var XDomStyle = X.Dom.Style,
                args = arguments,
                css  = this._css,
-               p, valOrUnit, name, v, node, camelize, unit;
+               p, name, v, camelize, unit, ieFix;
        if( this._xnodeType !== 1 ) return this;
 // setter:object
        if( X.Type.isObject( nameOrObj ) ){
                if( !css ) css = this._css = {};
                camelize = XDomStyle.camelize;
+               ieFix    = X.Dom.Style.IE_FILTER_FIX;
                for( p in nameOrObj ){
-                       css[ camelize( p ) ] = nameOrObj[ p ];
-               };
-               this._cssText = XDomStyle.objToCssText( this._css );
-               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;
+                       if( ieFix[ p ] ){
+                               this._dirty |= X.Dom.Dirty.IE_FILTER;
                        };
+                       css[ camelize( p ) ] = nameOrObj[ p ];
                };
+               this._dirty |= X.Dom.Dirty.CSS;
+               this.parent && this._reserveUpdate();
+               delete this._cssText;
                return this;
        } else
        if( 1 < args.length ){
@@ -964,32 +976,19 @@ 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( X.Dom.Style.IE_FILTER_FIX[ name ] ){
+                               this._dirty |= X.Dom.Dirty.IE_FILTER;
+                       };                      
                        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 ] ){
-                               this._cssText = [ this._cssText, this._cssText ? ';' : '', XDomStyle.uncamelize( nameOrObj ), ':', v ].join( '' );
-                               css[ name ] = v;
                        } else {
                                css[ name ] = v;
-                               this._cssText = XDomStyle.objToCssText( css );
                        };
-                       this._styleText = ' style="' + this._cssText + '"';
+                       delete this._cssText;
+                       this._dirty |= X.Dom.Dirty.CSS;
+                       // parent でなく this._root!
+                       this.parent && this._reserveUpdate();
                        return this;
                };
 // getter unit
@@ -1009,16 +1008,14 @@ X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */
 };
 
 X.Dom.Node.prototype.cssText = function( v ){
-       var camelize, obj, i, l, attr, name;
+       var obj, i, l, attr, name;
        if( X.Type.isString( v ) ){
-               camelize = X.Dom.Style.camelize;
+               delete this._css;
                obj = {};
                v   = v.split( ';' );
-               delete this._css;
                for( i = 0, l = v.length; i < l; ++i ){
                        attr = v[ i ].split( ':' );
-                       name = camelize( attr[ 0 ] );
-                       name && ( obj[ name ] = attr[ 1 ] || true );
+                       ( name = attr[ 0 ] ) && ( obj[ name ] = attr[ 1 ] || true );
                };
                return this.css( obj );
        };
@@ -1026,7 +1023,7 @@ X.Dom.Node.prototype.cssText = function( v ){
 };
 
 /*
- * ã\81\93ã\81\93ã\81§ã\81¯ HTMLElement ã\81\8bã\81®ã\83\81ã\83£ã\83\83ã\82¯ã\81¯è¡\8cã\82\8fã\81ªã\81\84ï¼\81
+ * ここでは HTMLElement のチャックは行わない!
  */
 X.Dom.Node.prototype._getCharSize =
        window.getComputedStyle ?
@@ -1037,35 +1034,46 @@ X.Dom.Node.prototype._getCharSize =
                (function(){
                        return parseInt( document.defaultView.getComputedStyle( this._rawNode, null ).fontSize );
                }) :
-       X.UA.IE && 5 <= X.UA.IE ?
+       X.UA.IE && 5.5 <= X.UA.IE ?
                (function(){
+                       if( this === Node.root && X.Dom.Event._lastFontSize ) return X.Dom.Event._lastFontSize;
                        var font = this._rawNode.currentStyle.fontSize,
                                vu   = X.Dom.Style._Util._splitValueAndUnit( font ),
                                v    = vu[ 0 ],
-                               u    = vu[ 1 ];
+                               u    = vu[ 1 ],
+                               elm;    
+                       if( v === 0 ){
+                               if( v = X.Dom.Style._FONT_SIZE_RATIO[ font ] ) return v;
+                       } else {
+                               if( u = X.Dom.Style._UNIT_RATIO[ u ] ) return v / u;
+                       };
                        switch( u ){
                                case 'px' :
                                        return v;
                                case 'em' :
                                // body まで辿ってしまった場合は?
-                                       return this.parent._getCharSize() * v;
+                                       if( this.parent ) return this.parent._getCharSize() * v;
+                                       break;
                                case '%' :
                                // body まで辿ってしまった場合は?
-                                       return this.parent._getCharSize() * v / 100;
+                                       if( this.parent ) return this.parent._getCharSize() * v / 100;
+                                       break;
                        };
-                       return v === 0 ?
-                                       ( X.Dom.Style._FONT_SIZE_RATIO[ font ] || 0 ) :
-                                       v / ( X.Dom.Style._UNIT_RATIO[ u ] || 1 );
-                       // appendChild
-                       // removeChild
+                       elm = document.createElement( 'div' );
+                       Node._systemNode._rawNode.appendChild( elm );
+                       elm.style.cssText = 'position:absolute;top:0;left:0;overflow:hidden;line-height:1;height:1em;';
+                       elm.innerText = 'X';
+                       v = elm.offsetHeight;
+                       Node._systemNode._rawNode.removeChild( elm );
+                       return v;
                }) :
-       document.removeChild ?
+       document.getElementById ?
                (function(){
                        var elm = document.createElement( 'span' ),
                                v;
-                       elm.style.cssText = 'display:block;position:absolute;top:0;left:0;visivility:hidden;line-height:1;height:1em;';
-                       elm.innerHTML = 'X';
                        this._rawNode.appendChild( elm );
+                       elm.style.cssText = 'display:block;position:absolute;top:0;left:0;visivility:hidden;line-height:1;height:1em;';
+                       elm.innerHTML = 'X';                    
                        v = elm.offsetHeight;
                        this._rawNode.removeChild( elm );
                        return v;
@@ -1077,7 +1085,7 @@ X.Dom.Node.prototype._getCharSize =
                        elm = elm.children[ elm.children.length - 1 ];
                        v   = elm.offsetHeight;
                        elm.outerHTML = '';
-                       return v;
+                       return v * 0.75;
                }) :
                (function(){
                });
@@ -1118,7 +1126,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){
                };
                return ret;
        })();
-               
+       
        X.Dom.Style.SPECIAL_FIX_PROP =
                // ~IE8
                X.UA.IE && X.UA.IE < 9 ?
@@ -1158,12 +1166,13 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
 
        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();
+       xnode.css( { lineHeight : '100%', height : '1em' } ).text( 'X' );
        
        for( i = list.length; i; ){
                size = list[ --i ];
-               output[ size ] = xnode.css( 'fontSize', size ).height() / base;
+               output[ size ] = xnode.css( 'fontSize', size ).height();// / base;
        };
        
-       xnode.empty().cssText( '' );
-} );
\ No newline at end of file
+       xnode.cssText( '' ).empty();
+} );
+