4 * style 値の変更は、enterFrame 後にまとめて適用
5 * width(), height(), x(), y() 1em の取得時にも適用
6 * css3 の ie用 fix は X.UI レベルで行う
30 AUTO : Number.POSITIVE_INFINITY,
31 FULL : X.Dom // something unigue value; 100%
51 /* font-size -> fontSize */
52 _DICTIONARY_CAMELIZE : {},
54 camelize : function( cssProp ){
56 parts, l, i, camelized;
58 if( camelized = me._DICTIONARY_CAMELIZE[ cssProp ] ) return camelized;
59 parts = cssProp.split( ' ' ).join( '' ).split( '-' );
61 if( l === 1 ) return parts[ 0 ];
63 camelized = cssProp.charAt(0) === '-'
64 ? parts[ 0 ].charAt( 0 ).toUpperCase() + parts[ 0 ].substring( 1 )
67 for( i = 1; i < l; ++i ){
68 camelized += parts[ i ].charAt( 0 ).toUpperCase() + parts[ i ].substring( 1 );
70 return me._DICTIONARY_CAMELIZE[ cssProp ] = camelized;
73 /* fontSize -> font-size */
74 CHAR_CODE_A : 'A'.charCodeAt( 0 ),
76 _DICTIONARY_UNCAMELIZE : {},
78 uncamelize : function( str ){
82 uncamelized, l, chr, code;
83 str = str.split( ' ' ).join( '' );
84 if( uncamelized = me._DICTIONARY_UNCAMELIZE[ str ] ) return uncamelized;
86 for( i = 0, l = str.length; i < l; ++i ){
87 chr = str.charAt( i );
88 code = chr.charCodeAt( 0 );
89 uncamelized += ( A <= code && code <= Z ) ? '-' + chr : chr;
91 return me._DICTIONARY_UNCAMELIZE[ str ] = uncamelized.toLowerCase();
95 * CSS における display, position, float プロパティの相互関係
96 * http://d.hatena.ne.jp/elm200/20080201/1201874740
98 * CSS21:9.7 Relationships between ’display’, ’position’, and ’float’
99 * http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo
101 * display:none? -yes-> 非表示
103 * position:absolute? -yes-> float:none,display:block;
105 * float:none? -no-> display:block;
110 display position float
111 block static|relative none
112 block static|relative right|left
114 inline static|relative none
121 objToCssText : function( obj ){
124 uncamelize = me.uncamelize,
125 VENDER_PREFIX = me.VENDER_PREFIX,
126 FIX_PROP = me.SPECIAL_FIX_PROP,
127 SPECIAL_FIX = me.SPECIAL_FIX,
131 name = uncamelize( p );
132 if( FIX_PROP[ name ] ){
135 css[ ++n ] = [ VENDER_PREFIX[ name ] || name, obj[ p ] ].join( ':' );
138 sp && ( css[ ++n ] = 'filter:' + SPECIAL_FIX( obj ) );
139 return css.join( ';' );
143 X.UA.IE && X.UA.IE < 9 ?
148 9 <= X.UA.IE && X.UA.IE < 10 ? // == 9
153 _FONT_SIZE_RATIO : null,
155 // https://developer.mozilla.org/en-US/docs/Web/CSS/transform
156 // Firefox 3.5, ie9, Opera 10.5, Safari 3.1, Chrome
157 // 3D support Firefox 10, ie10, Safari 4.0, Chrome 12.0
158 // transform : void 0,
160 // https://developer.mozilla.org/ja/docs/Web/Guide/CSS/Using_CSS_transitions
161 // Chrome 1.0, Firefox 4.0, ie10, Opera 10.5, Safari 3.2
162 // Android 2.1, Firefox Android 4.0, Opera Mobile 10, Safari Mobile 3.2
163 // transition : void 0
165 // ブラウザ毎の getComputedStyle の戻り値 http://d.hatena.ne.jp/uupaa/20080928/1222543331
187 SLATEGRAY : 0x708090,
189 GAINSBORO : 0xDCDCDC,
190 MIDNIGHTBLUE : 0x191970,
191 SLATEBLUE : 0x6A5ACD,
192 MEDIUMBLUE : 0x0000CD,
193 ROYALBLUE : 0x4169E1,
194 DODGERBLUE : 0x1E90FF,
196 STEELBLUE : 0x4682B4,
197 LIGHTBLUE : 0xADD8E6,
198 PALETURQUOISE : 0xAFEEEE,
199 TURQUOISE : 0x40E0D0,
200 LIGHTCYAN : 0xE0FFFF,
201 AQUAMARINE : 0x7FFFD4,
202 DARKGREEN : 0x006400,
204 LIGHTGREEN : 0x90EE90,
205 CHARTREUSE : 0x7FFF00,
206 GREENYELLOW : 0xADFF2F,
207 LIMEGREEN : 0x32CD32,
208 YELLOWGREEN : 0x9ACD32,
209 OLIVEDRAB : 0x6B8E23,
210 DARKKHAKI : 0xBCB76B,
211 PALEGOLDENROD : 0xEEE8AA,
212 LIGHTYELLOW : 0xFFFFE0,
214 GOLDENROD : 0xDAA520,
215 DARKGOLDENROD : 0xB8860B,
216 ROSYBROWN : 0xBC8F8F,
217 INDIANRED : 0xCD5C5C,
218 SADDLEBROWN : 0x8B4513,
221 BURLYWOOD : 0xDEB887,
224 SANDYBROWN : 0xF4A460,
226 CHOCOLATE : 0xD2691E,
227 FIREBRICK : 0xB22222,
236 PALEVIOLETRED : 0xDB7093,
240 DARKVIOLET : 0x9400D3,
241 BLUEVIOLET : 0x8A2BE2,
242 MEDIUMPURPLE : 0x9370DB,
245 MISTYROSE : 0xFFE4E1,
247 LEMONCHIFFON : 0xFFFACD
250 parseColor : function( x ){
253 if( X.Type.isNumber( x ) ){
254 return ( 0x0 <= x && x <= 0xFFFFFF ) ? x : undefined;
256 if( !X.Type.isString( x ) ) return;
258 if( X.Type.isNumber( rgb = X.Dom.Style.COLOR[ x.toUpperCase() ] ) && 0x0 <= rgb && rgb <= 0xFFFFFF ){
261 if( x.charAt( 0 ) === '#' ){
264 r = parseInt( x.substr( 1, 2 ), 16 );
265 g = parseInt( x.substr( 3, 2 ), 16 );
266 b = parseInt( x.substr( 5, 2 ), 16 );
269 r = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
270 g = parseInt( x.charAt( 2 ) + x.charAt( 2 ), 16 );
271 b = parseInt( x.charAt( 3 ) + x.charAt( 3 ), 16 );
274 r = g = b = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
280 if( x.indexOf( 'rgb(' ) === 0 ){
281 rgb = x.substr( 4 ).split( ',' );
282 r = parseFloat( rgb[ 0 ] );
283 g = parseFloat( rgb[ 1 ] );
284 b = parseFloat( rgb[ 2 ] );
285 if( x.indexOf( '%' ) !== -1 ){
291 if( x.indexOf( 'rgba(' ) === 0 ){
292 rgb = x.substr( 5 ).split( ',' );
293 r = parseFloat( rgb[ 0 ] );
294 g = parseFloat( rgb[ 1 ] );
295 b = parseFloat( rgb[ 2 ] );
296 //a = parseFloat( rgb[ 3 ] );
297 if( x.indexOf( '%' ) !== -1 ){
305 return isFinite( r + b + g ) ? ( r << 16 ) + ( g << 8 ) + b : undefined;
308 PARAMS : ( function(){
310 register( ret.percent = {},
311 'marginBottom,marginLeft,marginRight,marginTop,paddingBottom,paddingLeft,paddingRight,paddingTop,fontSize,textIndent'
313 register( ret.offset = {},
314 'height,width,bottom,left,right,top'
316 register( ret.size = {},
317 'borderBottomWidth,borderLeftWidth,borderRightWidth,borderTopWidth,letterSpacing,wordSpacing'
319 register( ret.color = {},
320 'backgroundColor,borderBottomColor,borderLeftColor,borderRightColor,borderTopColor,color'
322 register( ret.region = {},
323 'margin,padding,borderWidth,borderColor'
325 register( ret.special = {},
326 'clip,backgroundPosition,backgroundPositionX,backgroundPositionY,opacity,lineHeight,zIndex'
328 register( ret.unit = {}, 'px,cm,mm,in,pt,pc,em,%' );
330 register( ret.margin = {}, 'marginBottom,marginLeft,marginRight,marginTop,paddingBottom' );
331 register( ret.padding = {}, 'paddingBottom,paddingLeft,paddingRight,paddingTop' );
332 register( ret.borderWidth = {}, 'borderBottomWidth,borderLeftWidth,borderRightWidth,borderTopWidth' );
333 register( ret.borderColor = {}, 'borderBottomColor,borderLeftColor,borderRightColor,borderTopColor' );
335 function register( obj, params ){
336 params = params.split( ',' );
337 for( var i = params.length; i; ) obj[ params[ --i ] ] = true;
342 _CLIP_SEPARATOR : X.UA.IE && X.UA.IE < 8 ? ' ' : ',',
347 Property : X.Class.create(
351 Constructor : function( name, value, unit, xnode ){
361 equal : function( prop ){
362 if( this.unit === prop.unit ){
363 return this.value === prop.value;
365 return Math.abs( this.toPx() - prop.toPx() ) < 1;
367 convert: function( prop ){
368 var u = prop.unit, v;
369 if( this.unit === u ) return;
370 this.value = v = this.toPx();
373 // bgpX, bgpY の場合 X.Dom.Image.getActualDimension( backgroundImage url を使用 )
377 v / this.xnode._getCharSize() :
378 v / ( X.Dom.Style._UNIT_RATIO[ u ] || 1 );
381 setValue: function( v ){
384 getValue: function(){
387 getOffset: function( prop ){
388 return prop.value - this.value;
393 getValueText: function(){
394 return this.value === 0 ? '0' : this.value + this.unit;
397 var v = this.value, u = this.unit;
401 ( u === 'em' || ( u === '' && this.name === 'lineHeight' ) ) ?
402 v * this.xnode._getCharSize() :
404 v / ( X.Dom.Style._UNIT_RATIO[ u ] || 1 );
407 var p = X.Dom.Style.PARAMS,
411 z = u !== '' ? true : v === 0;
412 if( p.percent[ n ] === true ) return z;
413 if( p.offset[ n ] === true ) return z;
414 if( p.size[ n ] === true ) return z && u !== '%';
415 if( p.special[ n ] === true ){
416 if( n === 'lineHeight' ) return true;
417 if( n === 'opacity' ) return 0 <= v && v <= 1 && u === '';
418 if( n === 'zIndex' ) return u === '';
426 * backgroundPosition, clip
428 PropertyGroup : X.Class.create(
432 Constructor : function( name ){
435 for( var i = 1, l = arguments.length; i<l; ++i ){
436 this.props[ this.props.length ] = arguments[ i ];
440 equal : function( prop ){
441 var ps = this.props, i = ps.length;
444 if( ps[ i ].equal( prop[ i ] ) === false ) return false;
448 convert : function( prop ){
449 var ps = this.props, i = ps.length;
452 ps[ i ].convert( prop[ i ] );
455 setValue : function( ary ){
456 var ps = this.props, i = 0, l = ps.length;
458 ps[ i ].setValue( ary[ i ] );
461 getValue : function(){
462 var ret = [], ps = this.props, i = 0, l = ps.length;
464 ret[ ret.length ] = ps[ i ].getValue();
468 getOffset : function( prop ){
475 ret[ ret.length ] = ps[ i ].getOffset( _ps[ i ] );
479 getUnit : function(){
480 var ret = [], ps = this.props, i = 0, l = ps.length;
482 ret[ ret.length ] = ps[ i ].getUnit();
486 getValueText : function(){
487 var ret = [], ps = this.props, i = 0, l = ps.length;
489 ret[ ret.length ] = ps[ i ].getValueText();
491 if( this.name === 'clip' ){
492 return 'rect(' + ret.join( X.Dom.Style._CLIP_SEPARATOR ) + ')';
494 return ret.join( ' ' );
497 var ps = this.props, i = ps.length;
502 isValid : function( t ){
504 var ps = t.props, i = ps.length;
506 if( ps[ --i ].isValid() === false ) return false;
514 * http://css-eblog.com/ie-css-problems/rgba-pe.html
515 * ie67 では rgb() は background-color で反応しない、、、
518 ColorProperty : X.Class.create(
520 X.Class.POOL_OBJECT, {
521 Constructor : function( name, x ){
528 if( X.Type.isNumber( rgb = x ) || X.Type.isNumber( rgb = X.Dom.Style.COLOR[ x.toUpperCase() ] ) ){
529 r = ( rgb & 0xff0000 ) >> 16;
530 g = ( rgb & 0xff00 ) >> 8;
533 if( x.charAt( 0 ) === '#' ){
534 if( x.length === 7 ){
535 r = parseInt( x.charAt( 1 ) + x.charAt( 2 ), 16 );
536 g = parseInt( x.charAt( 3 ) + x.charAt( 4 ), 16 );
537 b = parseInt( x.charAt( 5 ) + x.charAt( 6 ), 16 );
539 if( x.length === 4 ){
540 r = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
541 g = parseInt( x.charAt( 2 ) + x.charAt( 2 ), 16 );
542 b = parseInt( x.charAt( 3 ) + x.charAt( 3 ), 16 );
544 if( x.length === 2 ){
545 r = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
546 g = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
547 b = parseInt( x.charAt( 1 ) + x.charAt( 1 ), 16 );
550 if( x.indexOf( 'rgb(' ) === 0 ){
551 rgb = x.substr( 4 ).split( ',' );
552 r = parseFloat( rgb[ 0 ] );
553 g = parseFloat( rgb[ 1 ] );
554 b = parseFloat( rgb[ 2 ] );
555 if( x.indexOf( '%' ) !== -1 ) pct = true;
557 if( x.indexOf( 'rgba(' ) === 0 ){
558 rgb = x.substr( 5 ).split( ',' );
559 r = parseFloat( rgb[ 0 ] );
560 g = parseFloat( rgb[ 1 ] );
561 b = parseFloat( rgb[ 2 ] );
562 a = parseFloat( rgb[ 3 ] );
563 if( x.indexOf( '%' ) !== -1 ) pct = true;
583 equal : function( prop ){
584 if( this.pct === prop.pct ){
585 return this.r === prop.r && this.g === prop.g && this.b === prop.b;
587 var rgb = this._toPct(),
588 _rgb = prop._toPct(),
592 if( Math.abs( rgb[ i ] - _rgb[ i ] ) > 1 ) return false;
596 convert : function( prop ){
598 if( this.pct === u ) return;
599 x = u === true ? 100 / 255 : 2.55;
605 setValue : function( rgb ){
610 getValue : function(){
611 return [ this.r, this.g, this.b ];
613 getOffset : function( prop ){
614 return [ prop.r - this.r, prop.g - this.g, prop.b - this.b ];
616 getUnit : function(){
617 return this.pct === true ? '%' : '';
619 getValueText : function(){
620 if( this.pct === true ){
621 return [ 'rgb(', this.r, '%,', this.g, '%,', this.b, '%)' ].join( '' );
623 var round = Math.round;
625 var rgb = '00000' + ( ( round( this.r ) << 16 ) + ( round( this.g ) << 8 ) + round( this.b ) ).toString( 16 );
626 return '#' + rgb.substr( rgb.length - 6 );
629 if( this.pct === true ) return [ this.r, this.g, this.b ];
630 return [ this.r / 2.55, this.g / 2.55, this.b / 2.55 ];
632 isValid : function( t ){
633 var isFinite = window.isFinite;
634 if( !isFinite( this.r ) || !isFinite( this.g ) || !isFinite( this.b ) ) return false;
635 if( 0 > this.r || 0 > this.g || 0 > this.b ) return false;
636 if( this.pct === true ) return this.r <= 100 && this.g <= 100 && this.b <= 100;
637 return this.r <= 255 && this.g <= 255 && this.b <= 255;
642 _getProperty : function( xnode, css, unit, p ){
644 var XDomStyle = X.Dom.Style,
645 me = XDomStyle._getProperty,
646 PARAMS = XDomStyle.PARAMS,
647 PropertyGroup = XDomStyle.PropertyGroup,
648 Property = XDomStyle.Property,
649 ColorProperty = XDomStyle.ColorProperty,
652 if( PARAMS.special[ p ] === true || PARAMS.region[ p ] === true ){
655 // rect(...) クリップします。<top>, <bottom> は上端からの、 <right>, <left> は左端からのオフセットで指定します。Internet Explorer 4~7 では、カンマの代わりにスペースで区切る必要があります。
656 // position:absolute または position:fixed を適用した要素に対してのみ有効です。
657 var top = me( p + 'Top' ),
658 right = me( p + 'Right' ),
659 bottom = me( p + 'Bottom' ),
660 left = me( p + 'Left' ),
661 ret = new PropertyGroup( p, top, right, bottom, left ),
663 if( ret.isValid() === true ) return ret;
665 all = css[ p ].split( '(' )[ 1 ].split( ')' )[ 0 ].split( XDomStyle._CLIP_SEPARATOR );
669 new Property( p + 'Top', all[ 0 ], 'px', xnode ),
670 new Property( p + 'Right', all[ 1 ], 'px', xnode ),
671 new Property( p + 'Bottom', all[ 2 ], 'px', xnode ),
672 new Property( p + 'Left', all[ 3 ], 'px', xnode )
680 var props = '$1Top$2,$1Right$2,$1Bottom$2,$1Left$2'.split( '$1' ).join( name || 'border' ).split( '$2' ).join( width || 'Width' ).split( ',' ),
681 top = me( props[ 0 ] ),
682 right = me( props[ 1 ] ),
683 bottom = me( props[ 2 ] ),
684 left = me( props[ 3 ] ),
685 ret = new PropertyGroup( p, top, right, bottom, left ),
686 all, _0, _1, _2, _3, vu, v, u;
687 if( ret.isValid() === true ) return ret;
689 all = css[ p ].split( ' ' );
694 vu = XDomStyle._splitValueAndUnit( _0 );
697 switch( all.length ){
699 top = new Property( props[ 0 ], v, u, xnode );
700 right = new Property( props[ 1 ], v, u, xnode );
701 bottom = new Property( props[ 2 ], v, u, xnode );
702 left = new Property( props[ 3 ], v, u, xnode );
705 top = new Property( props[ 0 ], v, u, xnode );
706 bottom = new Property( props[ 2 ], v, u, xnode );
707 vu = XDomStyle._splitValueAndUnit( _1 );
710 right = new Property( props[ 1 ], v, u, xnode );
711 left = new Property( props[ 3 ], v, u, xnode );
714 top = new Property( props[ 0 ], v, u, xnode );
715 vu = XDomStyle._splitValueAndUnit( _1 );
718 right = new Property( props[ 1 ], v, u, xnode );
719 left = new Property( props[ 3 ], v, u, xnode );
720 vu = XDomStyle._splitValueAndUnit( _2 );
723 bottom = new Property( props[ 2 ], v, u, xnode );
726 top = new Property( props[ 0 ], v, u, xnode );
727 vu = XDomStyle._splitValueAndUnit( _1 );
730 right = new Property( props[ 1 ], v, u, xnode );
731 vu = XDomStyle._splitValueAndUnit( _2 );
734 bottom = new Property( props[ 2 ], v,u, xnode );
735 vu = XDomStyle._splitValueAndUnit( _3 );
738 left = new Property( props[ 3 ], v, u, xnode );
741 return new PropertyGroup( p, top, right, bottom, left );
744 var props = 'borderTopColor,borderRightColor,borderBottomColor,borderLeftColor'.split( ',' ),
745 top = me( props[ 0 ] ),
746 right = me( props[ 1 ] ),
747 bottom = me( props[ 2 ] ),
748 left = me( props[ 3 ] ),
749 ret = new PropertyGroup( p, top, right, bottom, left ),
751 if( ret.isValid() === true ) return ret;
753 all = css[ p ].split( ' ' );
756 switch( all.length ){
758 top = new ColorProperty( props[ 0 ], _0 );
759 right = new ColorProperty( props[ 1 ], _0 );
760 bottom = new ColorProperty( props[ 2 ], _0 );
761 left = new ColorProperty( props[ 3 ], _0 );
764 top = new ColorProperty( props[ 0 ], _0 );
765 right = new ColorProperty( props[ 1 ], _1 );
766 bottom = new ColorProperty( props[ 2 ], _0 );
767 left = new ColorProperty( props[ 3 ], _1 );
770 top = new ColorProperty( props[ 0 ], _0 );
771 right = new ColorProperty( props[ 1 ], _1 );
772 bottom = new ColorProperty( props[ 2 ], all[ 2 ] );
773 left = new ColorProperty( props[ 3 ], _1 );
776 top = new ColorProperty( props[ 0 ], _0 );
777 right = new ColorProperty( props[ 1 ], _1 );
778 bottom = new ColorProperty( props[ 2 ], all[ 2 ] );
779 left = new ColorProperty( props[ 3 ], all[ 3 ] );
782 return new PropertyGroup( p, top, right, bottom, left );
784 case 'backgroundPosition' :
785 var x = me( p + 'X' ),
787 ret = new PropertyGroup( p, x, y ),
789 if( ret.isValid() === true ) return ret;
791 xy = css[ p ].split( ' ' );
792 x = XDomStyle._splitValueAndUnit( xy[ 0 ] );
793 y = XDomStyle._splitValueAndUnit( xy[ 1 ] );
797 new Property( p + 'X', x[ 0 ], x[ 1 ], xnode ),
798 new Property( p + 'Y', y[ 0 ], y[ 1 ], xnode )
801 // opacity, zindex, lineHeight
802 vu = XDomStyle._splitValueAndUnit( css[ p ] );
803 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
805 var x = css[ p ], e, v, u;
807 if( PARAMS.offset[ p ] === true ){
808 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
811 if( p === 'width' ) v = e.offsetWidth;
812 if( p === 'height' ) v = e.offsetHeight;
813 if( p === 'top' ) v = e.offsetTop;
814 if( p === 'bottom' ) v = e.offsetBottom;
815 if( p === 'left' ) v = e.offsetLeft;
816 if( p === 'right' ) v = e.offsetRight;
817 u = _getUnit( x, p );
818 // alert( p + XDomStyle._Util.pxTo( v, u ) + u )
819 return new Property( p, XDomStyle._Util.pxTo( v, u ), u, xnode );
821 if( p === 'fontSize' && ( v = XDomStyle._FONT_SIZE_RATIO[ x ] ) ){ // xx-small 等
822 return new Property( p, v, 'px', xnode );
824 if( PARAMS.offset[ p ] || PARAMS.percent[ p ] || PARAMS.size[ p ] ){
825 vu = XDomStyle._splitValueAndUnit( x );
826 return new Property( p, vu[ 0 ], vu[ 1 ], xnode );
829 if( PARAMS.color[ p ] ) return new ColorProperty( p, x );
832 _splitValueAndUnit : function( v ){
834 if( X.Type.isNumber( v ) ) return [ v || 0, '' ];
835 if( isNaN( num = parseFloat( v ) ) ) return [ 0, '' ];
837 if( _num.indexOf( '0.' ) === 0 ) _num = _num.slice( 1 );
838 u = v.substr( v.indexOf( _num ) + _num.length );
839 return [ num, X.Dom.Style.UNIT[ u ] ? u : 'px' ];
843 X.Dom.Style._GET_VALUE_WITH_UNIT = {
844 borderWidth : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH,
845 //borderStyle : X.Dom.Style.Type.QUARTET,
846 borderRadius : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH,
847 margin : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
848 padding : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
849 clip : X.Dom.Style.Type.QUARTET | X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
851 backgroundColor : X.Dom.Style.Type.COLOR,
852 backgroundPosition : X.Dom.Style.Type.COMBI,
856 fontSize : X.Dom.Style.Type.LENGTH,
857 lineHeight : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT | X.Dom.Style.Type.NUMERICAL,
858 textIndent : X.Dom.Style.Type.LENGTH,
859 letterSpacing : X.Dom.Style.Type.LENGTH,
860 wordSpacing : X.Dom.Style.Type.LENGTH,
862 textShadowColor : X.Dom.Style.Type.COLOR,
863 textShadowOffsetX : X.Dom.Style.Type.LENGTH,
864 textShadowOffsetY : X.Dom.Style.Type.LENGTH,
865 textShadowBlur : X.Dom.Style.Type.LENGTH, */
867 width : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
868 height : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
870 left : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
871 top : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
872 bottom : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
873 right : X.Dom.Style.Type.LENGTH | X.Dom.Style.Type.PERCENT,
876 borderSpacing : X.Dom.Style.Type.LENGTH
880 X.Dom.Style.SPECIAL_FIX =
882 X.UA.IE && X.UA.IE < 9 ?
884 var test = X.Dom.Style.SPECIAL_FIX_PROP,
889 if( !( id = test[ p ] ) ) continue;
892 case 1 : //'filter' :
895 case 2 : //'opacity' :
896 filters[ ++n ] = 'alpha(opacity=' + v * 100 +')';
898 case 3 : //'boxShadow' :
899 // box-shadow: 10px 10px 10px 10px rgba(0,0,0,0.4) inset;
900 // スペース区切りで、水平方向の距離 垂直方向の距離 ぼかし距離 広がり距離 影の色 insetキーワードを指定する。 ぼかし距離 広がり距離 影の色 insetキーワードは省略可
901 // shadow(color=#cccccc, strength=10, direction=135);
902 v = X.Dom.Style._getProperty( this, css, 'px', 'boxShadow' );
903 dir = Math.atan2( v[ 1 ], v[ 0 ] ) * 180 / Math.PI + 90;
904 dir += dir < 0 ? 360 : 0;
905 filters[ ++n ] = 'shadow(color=' + v[ 4 ] + ',strength=' + v[ 3 ] + ',direction=' + dir + ')';
907 case 4 : //'textShadow' :
908 //text-shadow: 5px 5px 2px blue; 水平方向の距離 垂直方向の距離 影のぼかし半径 影の色 none
909 //glow(Color=yellow,Strength=10);
910 //どうやらCSSのbackgroundプロパティと同時に使えないようです。
914 case 5 : //'backgroundImage' :
918 return filters.join( ' ' );
920 // IE9 textShadow に filter を使用
921 X.UA.IE && 9 <= X.UA.IE && X.UA.IE < 10 ?
923 var test = X.Dom.Style.SPECIAL_FIX_PROP,
924 filters = [], p, id, v;
926 if( !( id = test[ p ] ) ) continue;
929 case 1 : //'filter' :
930 filters[ filters.length ] = v;
934 if( filters ) return filters.join( ' ' );
937 var test = X.Dom.Style.SPECIAL_FIX_PROP,
940 if( !( id = test[ p ] ) ) continue;
943 case 1 : //'backgroundPositionX' :
946 case 2 : //'backgroundPositionY' :
949 case 3 : //'backgroundPositionX' :
952 case 4 : //'backgroundPositionX' :
955 case 5 : //'backgroundPositionX' :
958 case 6 : //'backgroundPositionX' :
963 if( bgpX || bgpY ) ret[ ret.length ] = 'background-position:';
964 if( clipT || clipB || clipL || clipR ){
965 ret[ ret.length ] = 'clip:rect(';
967 return ret.join( ';' );
975 // unitID, name 単位指定のプロパティ取得 geter
977 // name, value setter
979 X.Dom.Node.prototype.css = function( nameOrObj /* orUnitID, valuOrUnitOrName */ ){
980 var XDomStyle = X.Dom.Style,
983 p, name, v, camelize, unit, ieFix;
984 if( this._xnodeType !== 1 ) return this;
986 if( X.Type.isObject( nameOrObj ) ){
987 if( !css ) css = this._css = {};
988 camelize = XDomStyle.camelize;
989 ieFix = X.Dom.Style.IE_FILTER_FIX;
990 for( p in nameOrObj ){
992 this._dirty |= X.Dom.Dirty.IE_FILTER;
995 v || v === 0 ? css[ camelize( p ) ] = v : delete css[ camelize( p ) ];
996 if( p === 'display' ){
997 v === 'none' ? ( this._state |= X.Dom.State.IE5_DISPLAY_NONE_FIX ) : ( this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX );
998 v === 'none' ? ( this._state |= X.Dom.State.DISPLAY_NONE ) : ( this._state &= ~X.Dom.State.DISPLAY_NONE );
1001 this._dirty |= X.Dom.Dirty.CSS;
1002 this.parent && this._reserveUpdate();
1003 delete this._cssText;
1006 if( 1 < args.length ){
1007 if( !XDomStyle.UNIT[ nameOrObj ] ){
1008 // setter name, value
1009 if( !css ) css = this._css = {};
1010 name = XDomStyle.camelize( nameOrObj );
1012 if( css[ name ] === v ) return this;
1013 if( X.Dom.Style.IE_FILTER_FIX[ name ] ){
1014 this._dirty |= X.Dom.Dirty.IE_FILTER;
1016 if( !v && v !== 0 ){
1021 delete this._cssText;
1022 this._dirty |= X.Dom.Dirty.CSS;
1023 if( name === 'display' ){
1024 v === 'none' ? ( this._state |= X.Dom.State.IE5_DISPLAY_NONE_FIX ) : ( this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX );
1025 v === 'none' ? ( this._state |= X.Dom.State.DISPLAY_NONE ) : ( this._state &= ~X.Dom.State.DISPLAY_NONE );
1027 // parent でなく this._root! でなくて this._state & in tree
1028 this.parent && this._reserveUpdate();
1032 // unit 付の値取得は fontSize と 画像サイズが確定していないと正確に取れない。内部のみにする?
1034 if( !XDomStyle._GET_VALUE_WITH_UNIT[ name = XDomStyle.camelize( args[ 1 ] ) ] ) return null;
1035 p = XDomStyle._getProperty( this, css, nameOrObj, name );
1036 v = p.pxTo( nameOrObj );
1042 // 集計 border, padding, margin, backgroundPosition, clip
1043 // border で正確なデータを返せない時は、null を返す
1044 return css[ XDomStyle.camelize( nameOrObj ) ];
1047 X.Dom.Node.prototype.cssText = function( v ){
1048 var obj, i, l, attr, name;
1051 this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX;
1052 this._dirty |= X.Dom.Dirty.CSS;
1053 this.parent && this._reserveUpdate();
1054 delete this._cssText;
1057 if( X.Type.isString( v ) ){
1059 this._state &= ~X.Dom.State.IE5_DISPLAY_NONE_FIX;
1062 for( i = 0, l = v.length; i < l; ++i ){
1063 attr = v[ i ].split( ':' );
1064 ( name = attr[ 0 ] ) && ( obj[ name ] = attr[ 1 ] || true );
1066 return this.css( obj );
1069 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
1070 delete this._cssText;
1072 return this._cssText;
1076 * ここでは HTMLElement のチ1ェックは行わない!
1078 * body に css attr がセットされた場合には X.Dom.baseFontSize をクリア
1081 X.Dom.Node.prototype._getCharSize =
1082 window.getComputedStyle ?
1084 Node.root._updateTimerID && Node.root._startUpdate();
1085 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1086 if( this._fontSize ) return this._fontSize;
1087 return this._fontSize = parseFloat( getComputedStyle( this._rawNode, null ).fontSize );
1089 document.defaultView && document.defaultView.getComputedStyle ?
1091 Node.root._updateTimerID && Node.root._startUpdate();
1092 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1093 if( this._fontSize ) return this._fontSize;
1094 return this._fontSize = parseFloat( document.defaultView.getComputedStyle( this._rawNode, null ).fontSize );
1096 X.UA.IE && 5.5 <= X.UA.IE ?
1098 var font, vu, v, u, _v;
1099 Node.root._updateTimerID && Node.root._startUpdate();
1100 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1101 if( this._fontSize ) return this._fontSize;
1103 font = this._rawNode.currentStyle.fontSize;
1104 //font = this._css && this._css.fontSize || '1em';
1105 vu = X.Dom.Style._splitValueAndUnit( font );
1110 if( v = X.Dom.Style._FONT_SIZE_RATIO[ font ] ) return this._fontSize = v;
1112 if( _v = X.Dom.Style._UNIT_RATIO[ u ] ) return this._fontSize = v / _v;
1116 return this._fontSize = v;
1118 // body まで辿ってしまった場合は?
1119 if( this.parent ) return this._fontSize = this.parent._getCharSize() * v;
1122 // body まで辿ってしまった場合は?
1123 if( this.parent ) return this._fontSize = this.parent._getCharSize() * v / 100;
1130 Node.root._updateTimerID && Node.root._startUpdate();
1131 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1132 if( this._fontSize ) return this._fontSize;
1134 this._rawNode.appendChild( elm = document.createElement( 'span' ) );
1135 elm.style.cssText = 'display:block;position:absolute;top:0;left:0;visivility:hidden;line-height:1;height:1em;';
1136 elm.innerHTML = 'X';
1137 v = elm.offsetHeight;
1138 this._rawNode.removeChild( elm );
1139 return this._fontSize = v;
1143 var font, vu, v, u, _v;
1144 Node.root._updateTimerID && Node.root._startUpdate();
1145 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1146 if( this._fontSize ) return this._fontSize;
1148 if( this._css && ( font = this._css.fontSize ) ){
1149 vu = X.Dom.Style._splitValueAndUnit( font );
1154 if( _v = X.Dom.Style._FONT_SIZE_RATIO[ font ] ) return this._fontSize = _v;
1156 if( _v = X.Dom.Style._UNIT_RATIO[ u ] ) return this._fontSize = v / _v;
1165 return this._fontSize = v;
1167 // body まで辿ってしまった場合は?
1168 if( this.parent ) return this._fontSize = this.parent._getCharSize() * v;
1171 // body まで辿ってしまった場合は?
1172 if( this.parent ) return this._fontSize = this.parent._getCharSize() * v / 100;
1178 if( this === Node.root && X.Dom.baseFontSize ) return X.Dom.baseFontSize;
1179 Node.root._updateTimerID && Node.root._startUpdate();
1180 if( this._fontSize ) return this._fontSize;
1182 elm = this._rawNode || this._ie4getRawNode();
1183 elm.insertAdjacentHTML( 'BeforeEnd', '<span style="visivility:hidden;line-height:1;">X</span>' );
1184 elm = elm.children[ elm.children.length - 1 ];
1185 v = elm.offsetHeight;
1187 return this._fontSize = v * 0.75;
1191 X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT, function(){
1192 var testStyle = X.Dom._root.style;
1194 X.Dom.Style.VENDER_PREFIX = (function(){
1196 vendors = 'webkit,Webkit,Moz,moz,ms,Ms,O,o,khtml,Khtml'.split( ',' ),
1198 'opacity,boxSizing,' +
1199 'transform,transformOrigin,perspective,' +
1200 'transisiton,transitionDelay,transitionProperty,transitionDuration,transitionTimingFunction,' +
1201 'userSelect,touchAction,touchCallout,contentZooming,userDrag,tapHighlightColor'.split( ',' ),
1202 vendor, i, search, prop;
1204 vendors.unshift( '' );
1206 function findVenderPrefix( prop ){
1207 var v, i = vendors.length;
1211 if( testStyle[ v + prop ] !== undefined ){
1218 for( i = searches.length; i; ){
1219 search = searches[ --i ];
1220 prop = findVenderPrefix( search );
1221 if( search === 'transform' ) ret.transVender = vendor;
1222 if( prop ) ret[ search ] = prop;
1227 X.Dom.Style.SPECIAL_FIX_PROP =
1229 X.UA.IE && X.UA.IE < 9 ?
1232 opacity : 2//, uinode ChromeNode で行う
1235 //backgroundImage : 5
1238 X.UA.IE && 9 <= X.UA.IE && X.UA.IE < 10 ?
1244 backgroundPositionX : testStyle.backgroundPositionX === undefined ? 3 : 0,
1245 backgroundPosiitonY : testStyle.backgroundPositionX === undefined ? 3 : 0,
1246 clipTop : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 3 : 0,
1247 clipBottom : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 4 : 0,
1248 clipLeft : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 5 : 0,
1249 clipRight : testStyle.clipTop === undefined && testStyle[ 'clip-top' ] === undefined ? 6 : 0
1253 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
1254 var xnode = Node._systemNode,
1255 output = X.Dom.Style._UNIT_RATIO = {},
1256 list = 'cm,mm,in,pt,pc'.split( ',' ),
1259 for( i = list.length; i; ){
1261 output[ unit ] = xnode.css( 'width', 100 + unit ).width() / 100;
1264 output = X.Dom.Style._FONT_SIZE_RATIO = {},
1265 list = 'xx-large,x-large,large,larger,medium,small,smaller,x-small,xx-small'.split( ',' );
1266 xnode.css( { lineHeight : '100%', height : '1em' } ).text( 'X' );
1268 for( i = list.length; i; ){
1270 output[ size ] = xnode.css( 'fontSize', size ).height();// / base;
1273 // 以下解決、scroll 中に timer が無視される iOS の問題が原因(dom追加で起こったスクロール?)
1274 // ipod touch 1st で必要なんですけど、、、
1275 //xnode._rawNode.style.cssText = '';
1276 xnode.cssText( '' ).empty(); //._startUpdate();