1 var X_Node_BoxModel = {
\r
7 boxSizingEnabled : false,
\r
9 // TODO: offsetLeft, offsetTop の基準位置
\r
15 X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){
\r
16 var node = X_Node_systemNode;
\r
18 node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' );
\r
20 X_Node_BoxModel.defaultBoxModel = node.width() === 10 ?
\r
21 X_Node_BoxModel.BORDER_BOX :
\r
22 X_Node_BoxModel.CONTENT_BOX;
\r
24 if( X_Node_BoxModel.defaultBoxModel === X_Node_BoxModel.CONTENT_BOX ){
\r
25 X_Node_BoxModel.boxSizingEnabled = node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' +
\r
26 'box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-o-box-sizing:border-box;-ms-box-sizing:border-box;' )
\r
34 X_Node_BoxModel.absoluteOffset =
\r
35 node.cssText( 'position:absolute;top:0;left:0;margin:1px;border:2px solid #000;padding:4px;' )
\r
36 .append( '<div></div>' )
\r
37 .firstChild().cssText( 'position:absolute;top:8px;left:8px;margin:16px;border:32px solid #666;padding:64px;' )
\r
40 node.cssText( '' ).empty();
\r
43 /* --------------------------------------
\r
45 * display:blobk かつ overflow:hidden かつ size(px,em)が設定されていたら、再描画しないでその値を返す
\r
49 * getBoundingClientRect
\r
51 Node.prototype.width = function(){
\r
52 if( !this.parent ){// todo : _state で tree に所属しているか?判定
\r
53 console.log( 'xnode.width() : no parent' );
\r
56 X_Node_updateTimerID && X_Node_startUpdate();
\r
58 console.log( 'xnode.width() : not belong tree.' );
\r
61 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
63 // this.css( X_Node_CSS_Unit.px, 'width' );
\r
64 return this._rawObject.offsetWidth;
\r
67 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetWidth;
\r
73 Node.prototype.height = function(){
\r
75 console.log( 'xnode.height() : no parent' );
\r
78 X_Node_updateTimerID && X_Node_startUpdate();
\r
80 console.log( 'xnode.height() : not belong tree.' );
\r
83 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
85 // this.css( X_Node_CSS_Unit.px, 'height' );
\r
86 return this._rawObject.offsetHeight;
\r
89 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetHeight;
\r
95 Node.prototype.clientWidth = function(){
\r
96 if( !this.parent ){// todo : _state で tree に所属しているか?判定
\r
97 console.log( 'xnode.width() : no parent' );
\r
100 X_Node_updateTimerID && X_Node_startUpdate();
\r
102 console.log( 'xnode.width() : not belong tree.' );
\r
105 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
106 if( X_UA_DOM.W3C ){
\r
107 // this.css( X_Node_CSS_Unit.px, 'width' );
\r
108 return this._rawObject.clientWidth;
\r
110 if( X_UA_DOM.IE4 ){
\r
111 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).clientWidth;
\r
117 Node.prototype.clientHeight = function(){
\r
118 if( !this.parent ){
\r
119 console.log( 'xnode.height() : no parent' );
\r
122 X_Node_updateTimerID && X_Node_startUpdate();
\r
124 console.log( 'xnode.height() : not belong tree.' );
\r
127 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
128 if( X_UA_DOM.W3C ){
\r
129 // this.css( X_Node_CSS_Unit.px, 'height' );
\r
130 return this._rawObject.clientHeight;
\r
132 if( X_UA_DOM.IE4 ){
\r
133 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).clientHeight;
\r
139 Node.prototype.scrollWidth = function(){
\r
140 if( !this.parent ){// todo : _state で tree に所属しているか?判定
\r
141 console.log( 'xnode.width() : no parent' );
\r
144 X_Node_updateTimerID && X_Node_startUpdate();
\r
146 console.log( 'xnode.width() : not belong tree.' );
\r
149 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
150 if( X_UA_DOM.W3C ){
\r
151 // this.css( X_Node_CSS_Unit.px, 'width' );
\r
152 return this._rawObject.scrollWidth;
\r
154 if( X_UA_DOM.IE4 ){
\r
155 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollWidth;
\r
161 Node.prototype.scrollHeight = function(){
\r
162 if( !this.parent ){
\r
163 console.log( 'xnode.height() : no parent' );
\r
166 X_Node_updateTimerID && X_Node_startUpdate();
\r
168 console.log( 'xnode.height() : not belong tree.' );
\r
171 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
172 if( X_UA_DOM.W3C ){
\r
173 // this.css( X_Node_CSS_Unit.px, 'height' );
\r
174 return this._rawObject.scrollHeight;
\r
176 if( X_UA_DOM.IE4 ){
\r
177 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollHeight;
\r
183 Node.prototype.scrollLeft = function(){
\r
184 if( !this.parent ){// todo : _state で tree に所属しているか?判定
\r
185 console.log( 'xnode.scrollLeft() : no parent' );
\r
188 X_Node_updateTimerID && X_Node_startUpdate();
\r
190 console.log( 'xnode.scrollLeft() : not belong tree.' );
\r
193 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
194 if( X_UA_DOM.W3C ){
\r
195 // this.css( X_Node_CSS_Unit.px, 'width' );
\r
196 return this._rawObject.scrollLeft;
\r
198 if( X_UA_DOM.IE4 ){
\r
199 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollLeft;
\r
205 Node.prototype.scrollTop = function(){
\r
206 if( !this.parent ){// todo : _state で tree に所属しているか?判定
\r
207 console.log( 'xnode.scrollTop() : no parent' );
\r
210 X_Node_updateTimerID && X_Node_startUpdate();
\r
212 console.log( 'xnode.scrollTop() : not belong tree.' );
\r
215 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
216 if( X_UA_DOM.W3C ){
\r
217 // this.css( X_Node_CSS_Unit.px, 'width' );
\r
218 return this._rawObject.scrollTop;
\r
220 if( X_UA_DOM.IE4 ){
\r
221 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollTop;
\r
227 /* --------------------------------------
\r
229 * position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?
\r
230 * position:absolute の指定で自動で top,left を補う必要あり? -> X.Node.CSS
\r
231 * 親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。
\r
232 * transformX, Y は加える? アニメーション中は?
\r
234 // X_Node_CSS_transform,
\r
235 Node.prototype.x = function(){
\r
236 if( !this.parent ){
\r
237 console.log( 'xnode.x() : no parent' );
\r
240 X_Node_updateTimerID && X_Node_startUpdate();
\r
242 console.log( 'xnode.x() : not belong tree.' );
\r
245 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
246 if( X_UA_DOM.W3C ){
\r
247 // this.css( X_Node_CSS_Unit.px, 'left' );
\r
248 // this.css( X_Node_CSS_Unit.px, 'translateX' );
\r
249 return this._rawObject.offsetLeft;
\r
251 if( X_UA_DOM.IE4 ){
\r
252 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetLeft;
\r
258 Node.prototype.y = function(){
\r
259 if( !this.parent ){
\r
260 console.log( 'xnode.y() : no parent' );
\r
263 X_Node_updateTimerID && X_Node_startUpdate();
\r
265 console.log( 'xnode.y() : not belong tree.' );
\r
268 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
269 if( X_UA_DOM.W3C ){
\r
270 // this.css( X_Node_CSS_Unit.px, 'top' );
\r
271 // this.css( X_Node_CSS_Unit.px, 'transisitonY' );
\r
272 return this._rawObject.offsetTop;
\r
274 if( X_UA_DOM.IE4 ){
\r
275 return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetTop;
\r
281 Node.prototype.offset = function( /* xnodeParent */ ){
\r
282 var x = 0, y = 0, elm;
\r
284 if( !this.parent ){
\r
285 console.log( 'xnode.offset() : no parent' );
\r
286 return { x : 0, y : 0 };
\r
288 X_Node_updateTimerID && X_Node_startUpdate();
\r
290 console.log( 'xnode.offset() : not belong tree.' );
\r
291 return { x : 0, y : 0 };
\r
293 if( this._state & X_Node_State.DISPLAY_NONE ) return 0;
\r
295 if( X.Doc.body === this || X.Doc.html === this ){
\r
296 return { x : 0, y : 0 };
\r
299 if( X_UA_DOM.W3C ){
\r
300 elm = this._rawObject;
\r
302 if( X_UA_DOM.IE4 ){
\r
303 elm = this._rawObject || X_Node__ie4getRawNode( this );
\r
308 while( elm && elm !== document.body ){
\r
309 x += elm.offsetLeft;
\r
310 y += elm.offsetTop;
\r
311 elm = elm.offsetParent || elm.parentNode || elm.parentElement;
\r
313 return { x : x, y : y };
\r