OSDN Git Service

Version 0.6.57, fixed NS of X.UI & X.Class for __proto__.
[pettanr/clientJs.git] / 0.6.x / js / dom / 13_XDomBoxModel.js
index 0e77c47..855a9b5 100644 (file)
@@ -13,9 +13,37 @@ X.Dom.BoxModel = {
        hScrollbarSize   : 0\r
 };\r
 \r
+\r
+\r
 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){\r
 \r
-       var node = Node._systemNode;\r
+       var node = Node._systemNode,\r
+       \r
+               // http://jsdo.it/imaya/kTYg\r
+               body = document.body,\r
+               defaultOverflow = document.body.style.overflow,\r
+               width, height;\r
+\r
+       body.style.overflow = 'hidden';\r
+       w = body.clientWidth;\r
+       h = body.clientHeight;\r
+\r
+       body.style.overflow = 'scroll';\r
+       w -= body.clientWidth;\r
+       h -= body.clientHeight;\r
+\r
+       if( !w ) w = body.offsetWidth  - body.clientWidth;\r
+       if( !h ) h = body.offsetHeight - body.clientHeight;\r
+       body.style.overflow = defaultOverflow; \r
+\r
+       X.Dom.BoxModel.vScrollbarSize = w;\r
+       X.Dom.BoxModel.hScrollbarSize = h;\r
+       if( h <= 0 ){ // ie6, ie11, firefox で 負の値が返る\r
+               console.log( 'invalid hScrollbarSize: ' + h );\r
+               X.Dom.BoxModel.hScrollbarSize = w;\r
+       };\r
+       //\r
+       \r
        node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' );\r
        \r
        X.Dom.BoxModel.defaultBoxModel = node.width() === 10 ?\r
@@ -24,7 +52,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        \r
        if( X.Dom.BoxModel.defaultBoxModel === X.Dom.BoxModel.CONTENT_BOX ){\r
                X.Dom.BoxModel.boxSizingEnabled = node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' +\r
-                       '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
+                       '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
                                                                                        .width() === 10;\r
        };\r
        // padding\r
@@ -32,15 +60,9 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        // margin\r
        // top\r
 \r
-       node.cssText( 'width:90px;height:90px;overflow:auto;' )\r
-               .html( '<div style="width:100px;height:100px;"></div>' )\r
-               ._startUpdate();\r
-       \r
-       X.Dom.BoxModel.vScrollbarSize = 90 - node._rawNode.clientWidth;\r
-       X.Dom.BoxModel.hScrollbarSize = 90 - node._rawNode.clientHeight;\r
-\r
        X.Dom.BoxModel.absoluteOffset =\r
                node.cssText( 'position:absolute;top:0;left:0;margin:1px;border:2px solid #000;padding:4px;' )\r
+                       .append( '<div></div>' )\r
                        .firstChild().cssText( 'position:absolute;top:8px;left:8px;margin:16px;border:32px solid #666;padding:64px;' )\r
                        .y();\r
 \r
@@ -51,13 +73,16 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
  * Width, Height\r
  *  display:blobk かつ overflow:hidden かつ size(px,em)が設定されていたら、再描画しないでその値を返す\r
  *  display:none なら 0\r
+ * \r
+ * getBoxObjectFor\r
+ * 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
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.width() : not belong tree.' );\r
                return 0;\r
@@ -79,7 +104,7 @@ Node.prototype.height = function(){
                console.log( 'xnode.height() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.height() : not belong tree.' );\r
                return 0;\r
@@ -101,7 +126,7 @@ Node.prototype.scrollWidth = function(){
                console.log( 'xnode.width() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.width() : not belong tree.' );\r
                return 0;\r
@@ -123,7 +148,7 @@ Node.prototype.scrollHeight = function(){
                console.log( 'xnode.height() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.height() : not belong tree.' );\r
                return 0;\r
@@ -134,7 +159,7 @@ Node.prototype.scrollHeight = function(){
                return this._rawNode.scrollHeight;\r
        } else\r
        if( X.Dom.DOM_IE4 ){\r
-               return ( this._rawNode || this._ie4getRawNode() ).scollHeight;\r
+               return ( this._rawNode || this._ie4getRawNode() ).scrollHeight;\r
        } else {\r
                \r
        };\r
@@ -145,7 +170,7 @@ Node.prototype.scrollLeft = function(){
                console.log( 'xnode.scrollLeft() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.scrollLeft() : not belong tree.' );\r
                return 0;\r
@@ -167,7 +192,7 @@ Node.prototype.scrollTop = function(){
                console.log( 'xnode.scrollTop() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.scrollTop() : not belong tree.' );\r
                return 0;\r
@@ -197,7 +222,7 @@ Node.prototype.x = function(){
                console.log( 'xnode.x() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.x() : not belong tree.' );\r
                return 0;\r
@@ -220,7 +245,7 @@ Node.prototype.y = function(){
                console.log( 'xnode.y() : no parent' );\r
                return 0;\r
        };\r
-       Node.root._updateTimerID && Node.root._startUpdate();\r
+       Node._body._updateTimerID && Node._body._startUpdate();\r
        if( !this._root ){\r
                console.log( 'xnode.y() : not belong tree.' );\r
                return 0;\r