OSDN Git Service

Version 0.6.41, fix for Opera8 & NN7.2+.
[pettanr/clientJs.git] / 0.6.x / js / dom / 11_XDomNode.js
index 35a03d9..1763121 100644 (file)
@@ -63,6 +63,8 @@ X.Dom.Node = X.EventDispatcher.inherits(
                _css       : null, // X.Dom.Style\r
                _cssText   : null,\r
                \r
+               _fontSize  : 0,\r
+               \r
                _anime     : null,\r
                \r
                Constructor : function( v ){\r
@@ -70,11 +72,11 @@ X.Dom.Node = X.EventDispatcher.inherits(
                        \r
                        if( Node._newByTag ){\r
                                Node._newByTag  = false;\r
-                               this._tag       = v;\r
+                               this._tag       = v.toUpperCase();\r
                                this._xnodeType = 1;\r
                                this._state     = X.Dom.State.DISPLAY_INLINE; // todo\r
                                arguments[ 1 ] && this.attr( arguments[ 1 ] );\r
-                               css = arguments[ 2 ];\r
+                               css = arguments[ 2 ] || arguments[ 1 ];\r
                                css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
                        } else\r
                        if( Node._newByText ){\r
@@ -99,14 +101,14 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                this._rawNode   = v;\r
                                                this._xnodeType = 1;\r
                                                this._state     = X.Dom.State.DISPLAY_BLOCK; // todo\r
-                                               this._tag       = v.tagName;\r
+                                               this._tag       = v.tagName.toUpperCase();\r
                                                this._id        = v.id;\r
                                                this._className = v.className;\r
                                                this.cssText( v.style.cssText );\r
                                                // X.Dom.Dirty.CSS を落とす\r
                                                this._dirty = 0;\r
                                                // attr の回収は不可能、、、\r
-                                               if( X.UA.IE && X.UA.IE < 5 ){\r
+                                               if( X.Dom.DOM_IE4 ){\r
                                                        v.setAttribute( 'UID', '' + uid );\r
                                                } else {\r
                                                        v.UID = uid;\r
@@ -129,9 +131,15 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                if( xnodes.length ) return xnodes[ 0 ];\r
                                                return Node.none;\r
                                        case Node.IS_IMAGE :\r
-                                               v.UID = uid;\r
+                                               if( xnode = Node._getXNode( v ) ) return xnode;\r
+                                               this._rawNode   = v;\r
+                                               this._xnodeType = 4;\r
+                                               v.UID           = uid;\r
+                                               this._state     = X.Dom.State.EXIST;\r
+                                               break;\r
                                        case Node.IS_WINDOW :\r
                                        case Node.IS_DOCUMENT :\r
+                                               if( xnode = Node._getXNode( v ) ) return xnode;\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 2;\r
                                                this._state     = X.Dom.State.DISPLAY_BLOCK;\r
@@ -168,6 +176,11 @@ Node._getType = function( v ){
        if( v === window ) return Node.IS_WINDOW;\r
        if( v === document ) return Node.IS_DOCUMENT;\r
        if( v.constructor === window.Image ) return Node.IS_IMAGE;\r
+       if( X.UA.Safari && X.UA.Safari < 3 ){\r
+               if( v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){\r
+                       return Node.IS_IMAGE;\r
+               };\r
+       };      \r
        if( v.constructor === Node ) return Node.IS_XNODE;\r
        if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST;\r
        if( v.tagName ) return Node.IS_RAW_HTML;\r
@@ -187,7 +200,7 @@ Node._getXNode = function( v ){
                case Node.IS_RAW_HTML :\r
                case Node.IS_IMAGE :\r
                        // fake TextNode too.\r
-                       if( X.UA.IE && X.UA.IE < 5 ){\r
+                       if( X.Dom.DOM_IE4 ){\r
                                uid = v.getAttribute( 'UID' );\r
                                return uid && Node._chashe[ uid ];\r
                        };\r
@@ -197,6 +210,7 @@ Node._getXNode = function( v ){
                case Node.IS_DOCUMENT :\r
                        return Node._document;\r
                case Node.IS_RAW_TEXT :\r
+                       if( v.UID ) return Node._chashe[ v.UID ];\r
                        for( chashe = Node._chashe, i = chashe.length; i; ){\r
                                if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;\r
                        };\r
@@ -230,10 +244,11 @@ Node.getRoot = function( xnode ){
 };\r
        // XMLかどうかを判別する\r
 Node.isXmlDocument =\r
-       X.UA.IE && X.UA.IE < 5 ?\r
+       X.Dom.DOM_IE4 ?\r
                X.emptyFunction :\r
                (function( root ){\r
-                       return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
+                       if( X.Type.isBoolean( root.isXML ) ) return root.isXML;\r
+                       return root.isXML = root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
                });\r
 \r
 Node._chashe     = [];\r
@@ -246,7 +261,7 @@ Node._systemNode = null;// = Node._chashe[ ? ]
 \r
 Node._reserveRemoval = [];\r
 \r
-if( !document.getElementById && document.all ){\r
+if( X.Dom.DOM_IE4 ){\r
        Node.prototype._ie4getRawNode = function(){\r
                var elm = this._rawNode;\r
                return elm ||\r
@@ -349,10 +364,10 @@ Node.prototype.append = function( v ){
                        if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
                        if( v.parent ){\r
-                               //if( document.getElementById ){\r
+                               //if( X.Dom.DOM_W3C ){\r
                                //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
                                //} else\r
-                               //if( document.all ){\r
+                               //if( X.Dom.DOM_IE4 ){\r
                                        v.remove();\r
                                //} else {\r
                                        \r
@@ -413,10 +428,10 @@ Node.prototype.appendAt = function( start, v ){
                        if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
                        if( v.parent ){\r
-                               //if( document.getElementById ){\r
+                               //if( X.Dom.DOM_W3C ){\r
                                //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
                                //} else\r
-                               //if( document.all ){\r
+                               //if( X.Dom.DOM_IE4 ){\r
                                        v.remove();\r
                                //} else {\r
                                        \r
@@ -752,7 +767,7 @@ Node.prototype.html = function( html ){
                };\r
                if( Node._outerFlag === this )  Node._outerFlag = null;\r
        };\r
-       !Node._outerFlag || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
+       !Node._outerFlag || X.Dom.DTD.EMPTY[ this._tag ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
        return html.join( _ );\r
 };\r
 \r
@@ -813,7 +828,9 @@ Node.prototype._reserveUpdate = function(){
 \r
 Node.prototype._startUpdate = function(){\r
        var removal, i, xnode, tmp;\r
-       \r
+       if( X.Dom.readyState < X.Dom.Event.DOM_INIT ){\r
+               return;\r
+       };\r
        if( this._updateTimerID ){\r
                //X.Timer.cancelFrame( this._updateTimerID ); // fire 中の cancel が動かない、、、\r
                this._updateTimerID = 0;\r
@@ -844,7 +861,7 @@ Node.prototype._startUpdate = function(){
 };\r
 \r
 Node.prototype._commitUpdate =\r
-       document.getElementById ?\r
+       X.Dom.DOM_W3C ?\r
                ( function( parentElement, nextElement ){\r
                        var elm = this._rawNode,\r
                                xnodes, l, i, frg, next, k, v;\r
@@ -880,13 +897,14 @@ Node.prototype._commitUpdate =
                                //};\r
                        };\r
 \r
+                       delete this._fontSize;\r
                        this._dirty && this._updateRawNode( elm );\r
                        if( this._state & X.Dom.State.IE5_DISPLAY_NONE_FIX ){\r
                                return nextElement;\r
                        };\r
                        return elm;\r
                }) :\r
-       document.all ? \r
+       X.Dom.DOM_IE4 ? \r
                ( function( parentElement, prevElement ){\r
                        var elm    = this._rawNode || this._ie4getRawNode(),\r
                                xnodes, l, i, html, text, prev;\r
@@ -926,13 +944,15 @@ Node.prototype._commitUpdate =
                                        prev = xnodes[ i ]._commitUpdate( elm, prev );\r
                                };\r
                        };\r
+                       \r
+                       delete this._fontSize;\r
                        this._dirty && this._updateRawNode( elm );\r
                        return elm;\r
                }) :\r
                (function(){});\r
 \r
 Node.prototype._updateRawNode =\r
-       document.getElementById ?\r
+       X.Dom.DOM_W3C ?\r
                ( function( elm ){\r
                        var attrs, rename, k, v;\r
 \r
@@ -968,8 +988,9 @@ Node.prototype._updateRawNode =
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
-                                       elm.style.cssText = this._cssText;\r
-                                       //elm.setAttribute( 'style', this._cssText );\r
+                                       X.UA.Opera && X.UA.Opera < 9 ?\r
+                                               elm.setAttribute( 'style', this._cssText ) : // opera8用\r
+                                               ( elm.style.cssText = this._cssText );\r
                                } else {\r
                                        elm.style.cssText = ''; // IE5.5以下 Safari3.2 で必要\r
                                        elm.removeAttribute( 'style' );\r
@@ -995,14 +1016,15 @@ Node.prototype._updateRawNode =
                                        };\r
                                        ( v = attrs[ k ] ) === undefined ?\r
                                                elm.removeAttribute( rename[ k ] || k ) :\r
-                                               ( elm[ rename[ k ] || k ] = v );\r
+                                               ( elm[ rename[ k ] || k ] = v );                                                \r
+\r
                                };\r
                                delete this._newAttrs;\r
                        };\r
                        \r
                        delete this._dirty;\r
                }) :\r
-       document.all ? \r
+       X.Dom.DOM_IE4 ? \r
                ( function( elm ){\r
                        var attrs, rename, k, v;\r
 \r
@@ -1072,7 +1094,7 @@ Node.prototype._updateRawNode =
  * document.createElement of ie4 is only for OPTION & IMAGE.\r
  */\r
 Node.prototype._actualCreate =\r
-       document.getElementById ? (function( isChild ){\r
+       X.Dom.DOM_W3C ? (function( isChild ){\r
                var elm = this._rawNode,\r
                        xnodes, frg, i, l;\r
                \r
@@ -1111,7 +1133,7 @@ Node.prototype._actualCreate =
                \r
                return elm;\r
        }) :\r
-       document.all ? (function( isChild ){\r
+       X.Dom.DOM_IE4 ? (function( isChild ){\r
                var uid = this._uid,\r
                        html, xnodes, n, i, l;\r
                \r
@@ -1146,7 +1168,7 @@ Node.prototype._actualCreate =
                                        };                                      \r
                                };\r
                        };\r
-                       X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
+                       X.Dom.DTD.EMPTY[ this._tag ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
                        \r
                        delete this._newAttrs;\r
                };\r
@@ -1156,7 +1178,7 @@ Node.prototype._actualCreate =
        (function(){});\r
 \r
 Node.prototype._afterActualCreate =\r
-       document.getElementById ? (function(){\r
+       X.Dom.DOM_W3C ? (function(){\r
                var elm = this._rawNode, xnodes, l, attrs, k, i;\r
                \r
                this._root  = this.parent._root;\r
@@ -1200,10 +1222,11 @@ Node.prototype._afterActualCreate =
                                xnodes[ i ]._afterActualCreate();\r
                        };\r
                };\r
-               \r
+               // src の onload があるので先ではないか?\r
+               // ie の str から要素を作る場合、srcだけ イベント設定後ではないか?\r
                this._restoreEvent();// イベントの復帰\r
        }) :\r
-       document.all ? (function(){\r
+       X.Dom.DOM_IE4 ? (function(){\r
                var xnodes, i;\r
                this._root = this.parent._root;\r
                \r
@@ -1224,7 +1247,7 @@ Node.prototype._afterActualCreate =
        (function(){});\r
 \r
 Node.prototype._actualRemove =\r
-       document.getElementById ?\r
+       X.Dom.DOM_W3C ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
                                elm    = this._rawNode,\r
@@ -1241,7 +1264,7 @@ Node.prototype._actualRemove =
                        // elm.parentNode.tagName for ie7\r
                        !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
                }) :\r
-       document.all ?\r
+       X.Dom.DOM_IE4 ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
                                elm    = this._rawNode || this._ie4getRawNode(),\r
@@ -1255,6 +1278,9 @@ Node.prototype._actualRemove =
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
                        \r
+                       if( X.Dom.Attr.HAS_VALUE[ this._tag ] && ( !this._newAttrs || !X.inObject( 'value', this._newAttrs ) ) ){\r
+                               this._attrs.value = elm.value;\r
+                       };\r
                        elm.removeAttribute( 'id' ); // ?\r
                        document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
                        if( !isChild ) elm.outerHTML = '';\r