OSDN Git Service

7219b085da43a4d4db2d3dbe1baf3afafa53c362
[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         
26
27         // padding
28         // border
29         // margin
30         // top
31
32
33 });
34
35 /* --------------------------------------
36  *  Width, Height
37  *  overflow:hidden かつ width か height が設定されていたら、再描画しないでその値を返す
38  */
39 Node.prototype.width = function(){
40         if( !this.parent ){
41                 console.log( 'xnode.width() : no parent' );
42                 return 0;
43         };
44         Node.root._updateTimerID && Node.root._startUpdate();
45         if( document.getElementById ){
46                 // this.css( X.Dom.Style.Unit.px, 'width' );
47                 return this._rawNode.offsetWidth;
48         } else
49         if( document.all ){
50                 return ( this._rawNode || this._ie4getRawNode() ).offsetWidth;
51         } else {
52                 
53         };
54 };
55
56 Node.prototype.height = function(){
57         if( !this.parent ){
58                 console.log( 'xnode.height() : no parent' );
59                 return 0;
60         };
61         Node.root._updateTimerID && Node.root._startUpdate();
62         if( document.getElementById ){
63                 // this.css( X.Dom.Style.Unit.px, 'height' );
64                 return this._rawNode.offsetHeight;
65         } else
66         if( document.all ){
67                 return ( this._rawNode || this._ie4getRawNode() ).offsetHeight;
68         } else {
69                 
70         };
71 };
72
73 /* --------------------------------------
74  *  x, y
75  *  position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?
76  *  position:absolute の指定で自動で top,left を補う必要あり? -> X.Dom.Style
77  *  親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。
78  * transformX, Y は加える? アニメーション中は?
79  */
80 // X.Dom.Style.transform,
81 Node.prototype.x = function(){
82         if( !this.parent ){
83                 console.log( 'xnode.x() : no parent' );
84                 return 0;
85         };
86         Node.root._updateTimerID && Node.root._startUpdate();
87         if( document.getElementById ){
88                 // this.css( X.Dom.Style.Unit.px, 'left' );
89                 // this.css( X.Dom.Style.Unit.px, 'translateX' );
90                 return this._rawNode.offsetLeft;
91         } else
92         if( document.all ){
93                 return ( this._rawNode || this._ie4getRawNode() ).offsetLeft;
94         } else {
95                 
96         };
97 };
98
99 Node.prototype.y = function(){
100         if( !this.parent ){
101                 console.log( 'xnode.y() : no parent' );
102                 return 0;
103         };
104         Node.root._updateTimerID && Node.root._startUpdate();
105         if( document.getElementById ){
106                 // this.css( X.Dom.Style.Unit.px, 'top' );
107                 // this.css( X.Dom.Style.Unit.px, 'transisitonY' );
108                 return this._rawNode.offsetTop;
109         } else
110         if( document.all ){
111                 return ( this._rawNode || this._ie4getRawNode() ).offsetTop;            
112         } else {
113                 
114         };
115 };
116