OSDN Git Service

Version 0.6.25, bugfix.
[pettanr/clientJs.git] / 0.6.x / js / dom / 13_XDomBoxModel.js
1 X.Dom.BoxModel = {
2         CONTENT_BOX      : 1,
3         PADDING_BOX      : 2,
4         BORDER_BOX       : 3,
5         MARGIN_BOX       : 4,
6                 
7         defaultBoxModel  : 0,
8         boxSizingEnabled : false
9 };
10
11 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
12
13         var elm = Node._systemNode._rawNode || Node._systemNode._ie4getRawNode();
14         elm.style.cssText = 'width:10px;padding:1px;border:2px solid #0;margin:4px;';
15         
16         X.Dom.BoxModel.defaultBoxModel = elm.offsetWidth === 10 ?
17                 X.Dom.BoxModel.BORDER_BOX :
18                 X.Dom.BoxModel.CONTENT_BOX;
19         
20         if( X.Dom.BoxModel.defaultBoxModel === X.Dom.BoxModel.CONTENT_BOX ){
21                 elm.style.cssText += 'box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing: border-box;-o-box-sizing:border-box;-ms-box-sizing:border-box;';
22                 
23                 X.Dom.BoxModel.boxSizingEnabled = elm.offsetWidth === 10;
24         };
25         // padding
26         // border
27         // margin
28         // top
29
30
31 });
32
33 /* --------------------------------------
34  * Width, Height
35  *  display:blobk かつ overflow:hidden かつ size(px,em)が設定されていたら、再描画しないでその値を返す
36  *  display:none なら 0
37  */
38 Node.prototype.width = function(){
39         if( !this.parent ){
40                 console.log( 'xnode.width() : no parent' );
41                 return 0;
42         };
43         Node.root._updateTimerID && Node.root._startUpdate();
44         if( document.getElementById ){
45                 // this.css( X.Dom.Style.Unit.px, 'width' );
46                 return this._rawNode.offsetWidth;
47         } else
48         if( document.all ){
49                 return ( this._rawNode || this._ie4getRawNode() ).offsetWidth;
50         } else {
51                 
52         };
53 };
54
55 Node.prototype.height = function(){
56         if( !this.parent ){
57                 console.log( 'xnode.height() : no parent' );
58                 return 0;
59         };
60         Node.root._updateTimerID && Node.root._startUpdate();
61         if( document.getElementById ){
62                 // this.css( X.Dom.Style.Unit.px, 'height' );
63                 return this._rawNode.offsetHeight;
64         } else
65         if( document.all ){
66                 return ( this._rawNode || this._ie4getRawNode() ).offsetHeight;
67         } else {
68                 
69         };
70 };
71
72 /* --------------------------------------
73  *  x, y
74  *  position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?
75  *  position:absolute の指定で自動で top,left を補う必要あり? -> X.Dom.Style
76  *  親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。
77  * transformX, Y は加える? アニメーション中は?
78  */
79 // X.Dom.Style.transform,
80 Node.prototype.x = function(){
81         if( !this.parent ){
82                 console.log( 'xnode.x() : no parent' );
83                 return 0;
84         };
85         Node.root._updateTimerID && Node.root._startUpdate();
86         if( document.getElementById ){
87                 // this.css( X.Dom.Style.Unit.px, 'left' );
88                 // this.css( X.Dom.Style.Unit.px, 'translateX' );
89                 return this._rawNode.offsetLeft;
90         } else
91         if( document.all ){
92                 return ( this._rawNode || this._ie4getRawNode() ).offsetLeft;
93         } else {
94                 
95         };
96 };
97
98 Node.prototype.y = function(){
99         if( !this.parent ){
100                 console.log( 'xnode.y() : no parent' );
101                 return 0;
102         };
103         Node.root._updateTimerID && Node.root._startUpdate();
104         if( document.getElementById ){
105                 // this.css( X.Dom.Style.Unit.px, 'top' );
106                 // this.css( X.Dom.Style.Unit.px, 'transisitonY' );
107                 return this._rawNode.offsetTop;
108         } else
109         if( document.all ){
110                 return ( this._rawNode || this._ie4getRawNode() ).offsetTop;            
111         } else {
112                 
113         };
114 };
115