OSDN Git Service

Version 0.6.133, fix for closure compiler - ADVANCED_OPTIMIZATIONS
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 04_XBoxModel.js
index 0a5c342..85b0c9c 100644 (file)
@@ -64,19 +64,13 @@ X_ViewPort.listenOnce( X_TEMP.SYSTEM_EVENT_INIT, function(){
  * getBoundingClientRect\r
  */\r
 Node.prototype.width = function(){\r
-       if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
-               console.log( 'xnode.width() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.width() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
-               // this.css( X_Node_CSS_Unit.px, 'width' );\r
-               return this._rawObject.offsetWidth;\r
+               // TODO width : length + overflow : hidden ならそれを返す? <- block or inline\r
+               return this._rawObject ? this._rawObject.offsetWidth : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetWidth;\r
@@ -86,19 +80,13 @@ Node.prototype.width = function(){
 };\r
 \r
 Node.prototype.height = function(){\r
-       if( !this.parent ){\r
-               console.log( 'xnode.height() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.height() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'height' );\r
-               return this._rawObject.offsetHeight;\r
+               return this._rawObject ? this._rawObject.offsetHeight : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetHeight;\r
@@ -108,19 +96,13 @@ Node.prototype.height = function(){
 };\r
 \r
 Node.prototype.clientWidth = function(){\r
-       if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
-               console.log( 'xnode.width() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.width() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'width' );\r
-               return this._rawObject.clientWidth;\r
+               return this._rawObject ? this._rawObject.clientWidth : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).clientWidth;\r
@@ -130,19 +112,13 @@ Node.prototype.clientWidth = function(){
 };\r
 \r
 Node.prototype.clientHeight = function(){\r
-       if( !this.parent ){\r
-               console.log( 'xnode.height() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.height() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+\r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'height' );\r
-               return this._rawObject.clientHeight;\r
+               return this._rawObject ? this._rawObject.clientHeight : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).clientHeight;\r
@@ -152,19 +128,13 @@ Node.prototype.clientHeight = function(){
 };\r
 \r
 Node.prototype.scrollWidth = function(){\r
-       if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
-               console.log( 'xnode.width() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.width() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+\r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'width' );\r
-               return this._rawObject.scrollWidth;\r
+               return this._rawObject ? this._rawObject.scrollWidth : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollWidth;\r
@@ -174,19 +144,12 @@ Node.prototype.scrollWidth = function(){
 };\r
 \r
 Node.prototype.scrollHeight = function(){\r
-       if( !this.parent ){\r
-               console.log( 'xnode.height() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.height() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+\r
        if( X_UA_DOM.W3C ){\r
-               // this.css( X_Node_CSS_Unit.px, 'height' );\r
-               return this._rawObject.scrollHeight;\r
+               return this._rawObject ? this._rawObject.scrollHeight : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollHeight;\r
@@ -196,19 +159,13 @@ Node.prototype.scrollHeight = function(){
 };\r
 \r
 Node.prototype.scrollLeft = function(){\r
-       if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
-               console.log( 'xnode.scrollLeft() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.scrollLeft() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+\r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'width' );\r
-               return this._rawObject.scrollLeft;\r
+               return this._rawObject ? this._rawObject.scrollLeft : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollLeft;\r
@@ -218,19 +175,13 @@ Node.prototype.scrollLeft = function(){
 };\r
 \r
 Node.prototype.scrollTop = function(){\r
-       if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
-               console.log( 'xnode.scrollTop() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.scrollTop() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'width' );\r
-               return this._rawObject.scrollTop;\r
+               return this._rawObject ? this._rawObject.scrollTop : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).scrollTop;\r
@@ -248,22 +199,17 @@ Node.prototype.scrollTop = function(){
  */\r
 // X_Node_CSS_transform,\r
 Node.prototype.x = function(){\r
-       if( !this.parent ){\r
-               console.log( 'xnode.x() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.x() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'left' );\r
                // this.css( X_Node_CSS_Unit.px, 'translateX' );\r
-               return this._rawObject.offsetLeft;\r
+               return this._rawObject ? this._rawObject.offsetLeft : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
+               // pixelLeft http://www.din.or.jp/~hagi3/JavaScript/JSTips/DHTML/ProbIE5.htm\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetLeft;\r
        } else {\r
                \r
@@ -271,20 +217,14 @@ Node.prototype.x = function(){
 };\r
 \r
 Node.prototype.y = function(){\r
-       if( !this.parent ){\r
-               console.log( 'xnode.y() : no parent' );\r
-               return 0;\r
-       };\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return 0;\r
+       \r
        X_Node_updateTimerID && X_Node_startUpdate();\r
-       if( !this._root ){\r
-               console.log( 'xnode.y() : not belong tree.' );\r
-               return 0;\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return 0;\r
+       \r
        if( X_UA_DOM.W3C ){\r
                // this.css( X_Node_CSS_Unit.px, 'top' );\r
                // this.css( X_Node_CSS_Unit.px, 'transisitonY' );\r
-               return this._rawObject.offsetTop;\r
+               return this._rawObject ? this._rawObject.offsetTop : 0;\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
                return ( this._rawObject || X_Node__ie4getRawNode( this ) ).offsetTop;          \r
@@ -294,18 +234,8 @@ Node.prototype.y = function(){
 };\r
 \r
 Node.prototype.offset = function( /* xnodeParent */ ){\r
-       var x = 0, y = 0, elm;\r
-       \r
-       if( !this.parent ){\r
-               console.log( 'xnode.offset() : no parent' );\r
-               return { x : 0, y : 0 };\r
-       };\r
-       \r
-       if( !this._root ){\r
-               console.log( 'xnode.offset() : not belong tree.' );\r
-               return { x : 0, y : 0 };\r
-       };\r
-       if( this._state & X_Node_State.DISPLAY_NONE ) return { x : 0, y : 0 };\r
+\r
+       if( ( this._flags & X_Node_State.IN_TREE ) === 0 || this._flags & X_Node_State.STYLE_IS_DISPLAY_NONE ) return { x : 0, y : 0 };\r
        \r
        if( X.Doc.body === this || X.Doc.html === this ){\r
                return { x : 0, y : 0 };\r
@@ -314,22 +244,13 @@ Node.prototype.offset = function( /* xnodeParent */ ){
        X_Node_updateTimerID && X_Node_startUpdate();\r
        \r
        if( X_UA_DOM.W3C ){\r
-               elm = this._rawObject;\r
+               return this._rawObject ? X_Node_getPosition( this._rawObject ) : { x : 0, y : 0 };\r
        } else\r
        if( X_UA_DOM.IE4 ){\r
-               elm = this._rawObject || X_Node__ie4getRawNode( this );         \r
+               return X_Node_getPosition( this._rawObject || X_Node__ie4getRawNode( this ) );\r
        } else {\r
                \r
        };\r
-       \r
-       return X_Node_getPosition( elm );\r
-       \r
-       while( elm && elm !== document.body ){\r
-               x += elm.offsetLeft;\r
-               y += elm.offsetTop;\r
-               elm = elm.offsetParent || elm.parentNode || elm.parentElement;\r
-       };\r
-       return { x : x, y : y };\r
 };\r
 \r
 // エレメントの座標取得 ~スクロール要素~\r
@@ -348,18 +269,18 @@ var X_Node_getPosition =
                return  {   x:(pos.left +   (body.scrollLeft||html.scrollLeft)  -   html.clientLeft)\r
                        ,   y:(pos.top  +   (body.scrollTop||html.scrollTop)    -   html.clientTop) };\r
                } :\r
-       X.UA.Opera < 10 ?\r
+       X_UA[ 'Opera' ] < 10 ?\r
                function( el ){\r
-                   var ex  =   0;\r
-                   var ey  =   0;\r
-                   do\r
-                   \r
-                       ex  +=  el.offsetLeft;\r
-                       ey  +=  el.offsetTop;\r
-                   }\r
-                   while(  el  =   el.offsetParent );\r
-                   //\r
-                   return  {x:ex,y:ey};\r
+            var ex  =   0;\r
+            var ey  =   0;\r
+            do\r
+            { \r
+                ex  +=  el.offsetLeft;\r
+                ey  +=  el.offsetTop;\r
+            }\r
+            while(  el  =   el.offsetParent );\r
+            //\r
+            return  {x:ex,y:ey};\r
                } :\r
                function(target)\r
         {\r