OSDN Git Service

Version 0.6.23, remove AbstractBox(AbstractDisplayContainer), working ie-filter-fix.
[pettanr/clientJs.git] / 0.6.x / js / dom / 11_XDomNode.js
index 65dbf4e..775796d 100644 (file)
@@ -1,4 +1,39 @@
 \r
+X.Dom.Dirty = {\r
+       CLEAN            :  0,\r
+       ID               :  1, // width, height, x, y\r
+       CONTENT          :  2,  // width, height, x, y textNode の内容\r
+       CLASSNAME        :  4, // _getCharSize, width, height, x, y\r
+       CSS              :  8, // _getCharSize, width, height, x, y\r
+       ATTR             : 16,  // _getCharSize, width, height, x, y\r
+       IE_FILTER        : X.UA.IE && X.UA.IE < 9 ? 32 : 0,\r
+       IE4_TEXTNODE_FIX : 64\r
+};\r
+\r
+/*\r
+ * \r
+ *\r
+ * destroyed\r
+ * display:none\r
+ * display:block\r
+ * display:inline\r
+ * \r
+ */\r
+\r
+X.Dom.State = {\r
+       DESTROYED          : 0,\r
+       DISPLAY_NONE       : 1,\r
+       DISPLAY_BLOCK      : 2,\r
+       DISPLAY_INLINE     : 4,\r
+       POSITION_ABSOLUTE  : 2,\r
+       OVERFLOW_HIDDEN    : 4,\r
+       HAS_WIDTH_LENGTH   : 8,\r
+       HAS_WIDTH_PERCENT  : 16,\r
+       HAS_HEIGHT_LENGTH  : 16,\r
+       HAS_HEIGHT_PERCENT : 32,\r
+       IE4_ONLY_TEXT      : 64\r
+};\r
+\r
 /*\r
  * Node( rawElement | rawTextnode | htmlString | textString )\r
  */\r
@@ -8,8 +43,12 @@ X.Dom.Node = X.EventDispatcher.inherits(
        X.Class.POOL_OBJECT,\r
        {\r
                _uid       : 0,\r
-               _rawNode   : null,              \r
-               parent     : null,              \r
+               _state     : 0,\r
+               _dirty     : 0,\r
+               \r
+               _rawNode   : null,\r
+               _root      : null, // xnode が文書ツリーに属しているか?はこれを見る\r
+               parent     : null, // remove された枝も親子構造は維持している。\r
                _xnodes    : null,\r
        \r
                _xnodeType : 0,\r
@@ -17,13 +56,15 @@ X.Dom.Node = X.EventDispatcher.inherits(
                _text      : null,\r
                _id        : null,\r
                _className : '',\r
-               _classText : ' ',\r
 \r
                _attrs     : null, // X.Dom.Attr\r
+               _newAttrs  : null,\r
                _attrText  : '',\r
+               \r
                _css       : null, // X.Dom.Style\r
-               _cssText   : '',\r
-               _styleText : '',\r
+               _cssText   : null,\r
+               \r
+               _anime     : null,\r
                \r
                Constructor : function( v ){\r
                        var css, xnodes, xnode, parent, uid = Node._chashe.length;\r
@@ -32,14 +73,16 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                Node._newByTag  = false;\r
                                this._tag       = v;\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
-                               this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
+                               css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
                        } else\r
                        if( Node._newByText ){\r
                                Node._newByText = false;\r
                                this._text      = v;\r
                                this._xnodeType = 3;\r
+                               this._state     = X.Dom.State.DISPLAY_INLINE;\r
                        } else {\r
                                if( 1 < arguments.length ) return new X.Dom.NodeList( arguments );\r
                                if( X.Type.isArray( v ) && v.length ) return new X.Dom.NodeList( v );\r
@@ -52,14 +95,18 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                        case Node.IS_RAW_HTML :\r
                                                if( xnode = Node._getXNode( v ) ) return xnode;\r
                                                // v.parentNode || v.parentElement : dom1 || dom0\r
-                                               this.parent     = v !== document.body && ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );\r
+                                               this.parent     = ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );\r
+                                               this._root      = this.parent ? this.parent._root : null;\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 1;\r
+                                               this._state     = X.Dom.State.DISPLAY_BLOCK; // todo\r
                                                this._tag       = v.tagName;\r
                                                this._id        = v.id;\r
                                                this._className = v.className;\r
-                                               this._classText = ' class="' + this._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
                                                        v.setAttribute( 'UID', '' + uid );\r
                                                } else {\r
@@ -70,20 +117,25 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                        case Node.IS_RAW_TEXT :\r
                                                if( xnode = Node._getXNode( v ) ) return xnode;\r
                                                this.parent     = Node._getXNode( v.parentNode );\r
+                                               this._root      = this.parent ? this.parent._root : null;\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 3;\r
+                                               this._state     = X.Dom.State.DISPLAY_INLINE;\r
                                                this._text      = v.data;\r
+                                               v.UID = uid;\r
                                                break;\r
                                        case Node.IS_HTML_STRING :\r
                                        case Node.IS_STRING :\r
                                                if( xnodes = X.Dom.parse( v, true ) && 1 < xnodes.length ) return new X.Dom.NodeList( xnodes );\r
                                                if( xnodes.length ) return xnodes[ 0 ];\r
                                                return Node.none;\r
+                                       case Node.IS_IMAGE :\r
+                                               v.UID = uid;\r
                                        case Node.IS_WINDOW :\r
                                        case Node.IS_DOCUMENT :\r
-                                       case Node.IS_IMAGE :\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 2;\r
+                                               this._state     = X.Dom.State.DISPLAY_BLOCK;\r
                                                break;\r
                                        default :\r
                                                if( Node.none ) return Node.none;\r
@@ -103,12 +155,14 @@ Node.IS_RAW_HTML    = 2;
 Node.IS_RAW_TEXT    = 3;\r
 Node.IS_HTML_STRING = 4;\r
 Node.IS_STRING      = 5;\r
-Node.IS_DOC_FRAG    = 6;\r
+//Node.IS_DOC_FRAG    = 6;\r
 Node.IS_XNODE_LIST  = 7;\r
 Node.IS_WINDOW      = 8;\r
 Node.IS_DOCUMENT    = 9;\r
 Node.IS_IMAGE       = 10;\r
 \r
+Node._useDocumentFragment = document.createDocumentFragment && ( !X.UA.IE || 6 <= X.UA.IE ) && document.createDocumentFragment();\r
+\r
 Node._getType = function( v ){\r
        if( v === '' ) return Node.IS_STRING;\r
        if( !v ) return 0;\r
@@ -122,17 +176,32 @@ Node._getType = function( v ){
        if( typeof v === 'string' ){\r
                return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING;\r
        };\r
-       if( v.nodeType === 11 ) return Node.IS_DOC_FRAG;\r
+       //if( v.nodeType === 11 ) return Node.IS_DOC_FRAG;\r
        return 0;\r
 };\r
-Node._getXNode = function( node ){\r
-       var uid;\r
-       if( !node ) return;\r
-       if( X.UA.IE && X.UA.IE < 5 ){\r
-               uid = node.getAttribute( 'UID' );\r
-               return uid && Node._chashe[ uid ];\r
+Node._getXNode = function( v ){\r
+       var uid, i, chashe, xnode;\r
+       switch( Node._getType( v ) ){\r
+               case Node.IS_XNODE :\r
+               case Node.IS_XNODE_LIST :\r
+                       return v;\r
+               case Node.IS_RAW_HTML :\r
+               case Node.IS_IMAGE :\r
+                       // fake TextNode too.\r
+                       if( X.UA.IE && X.UA.IE < 5 ){\r
+                               uid = v.getAttribute( 'UID' );\r
+                               return uid && Node._chashe[ uid ];\r
+                       };\r
+                       return v.UID && Node._chashe[ v.UID ];\r
+               case Node.IS_WINDOW :\r
+                       return Node._window;\r
+               case Node.IS_DOCUMENT :\r
+                       return Node._document;\r
+               case Node.IS_RAW_TEXT :\r
+                       for( chashe = Node._chashe, i = chashe.length; i; ){\r
+                               if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;\r
+                       };\r
        };\r
-       return node.UID && Node._chashe[ node.UID ];\r
 };\r
 \r
 \r
@@ -145,32 +214,18 @@ Node.createText = function( text ){
        return new Node( text );\r
 };\r
 \r
-/* --------------------------------------\r
- *  Dom Core 1\r
- */\r
-if( document.getElementById ){\r
-       Node._dom1cleanUp = function( xnode ){\r
-               var elm      = xnode._rawNode,\r
-                       children = xnode._xnodes,\r
-                       childNodes, i, l, child, _child;\r
-               if( elm && children && ( childNodes = elm.childNodes ) ){\r
-                       for( i = 0, l = children.length; i < l; ++i ){\r
-                               child = children[ i ];\r
-                               if( child.constructor === Node ) child = child._create( true );\r
-                               if( typeof child === 'string'  ) child = document.createTextNode( child );\r
-                               if( ( _child = childNodes[ i ] ) !== child ){\r
-                                       _child ?\r
-                                               elm.insertBefore( child, _child ) :\r
-                                               elm.appendChild( child );\r
-                                       _child && elm.removeChild( _child );\r
-                               };\r
-                       };\r
-                       while( ( _child = childNodes[ i ] ) ){\r
-                               elm.removeChild( _child );\r
-                       };\r
-               };\r
-       };      \r
+\r
+Node.getRoot = function( xnode ){\r
+       return Node._document;\r
+       //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
 };\r
+       // XMLかどうかを判別する\r
+Node.isXmlDocument =\r
+       X.UA.IE && X.UA.IE < 5 ?\r
+               X.emptyFunction :\r
+               (function( root ){\r
+                       return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
+               });\r
 \r
 Node._chashe     = [];\r
 Node.none        = Node._chashe[ 0 ] = new Node();\r
@@ -180,162 +235,31 @@ Node._html       = null; // Node._chashe[ 3 ]
 Node.root        = null;// = Node._chashe[ 4 ] body\r
 Node._systemNode = null;// = Node._chashe[ ? ]\r
 \r
-/* --------------------------------------\r
- *  Create\r
- */\r
-Node.prototype._create =\r
-       // document.createElement of ie4 is only for OPTION & IMAGE.\r
-       document.appendChild ? (function( isChild ){\r
-               var tag = this._tag, node, frg;\r
-               if( tag === 'input' ){\r
-                       // ie7 以下では createElement では name 等が働かない!\r
-               };\r
-               if( !( node = this._rawNode ) ){\r
-                       this._isNew = true;\r
-                       node = this._rawNode = ( tag ? document.createElement( tag ) : document.createTextNode( this._text ) );\r
-               };\r
-               // fragument がある場合 children も足して\r
-               // Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
-               if( !isChild && document.createDocumentFragment ){\r
-                       if( node.nodeType === 1 ){\r
-                               frg = document.createDocumentFragment();\r
-                               frg.appendChild( node );\r
-                               Node._dom1cleanUp( this );\r
-                               return frg;\r
-                       };\r
-               };\r
-               \r
-/*\r
- * http://d.hatena.ne.jp/uupaa/20080718/1216362040\r
- * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。\r
- * return document.createRange().createContextualFragment("<div style='background-color: blue; height: 100px; width: 100px;'><select><option></option></select></div>");\r
- */\r
-               \r
-               return node;\r
-       }) :\r
-       document.all ? (function( skipRemove, skipContainsDirty ){\r
-               var html, attrs, attr, children, i, l, child, toName, noValue, name;\r
-               if( this._xnodeType !== 1 ) return this._text;\r
-               \r
-               if( this._rawNode || this._ie4getRawNode() ){\r
-                       if( skipRemove ){\r
-                               this._beforeRemove();\r
-                       } else {\r
-                               // 追加する前に要素を抜く\r
-                               this.remove();          \r
-                       };\r
-                       if( !skipContainsDirty && !this._ie4containsDirty() ){\r
-                               return this._htmlText;\r
-                       };\r
-               };\r
-               html = [ '<', this._tag, ' id="', ( this._id || ( 'ie4uid' + this._uid ) ), '"', this._classText, this._attrText, this._styleText, '>' ];\r
-               if( ( children = this._xnodes ) && ( l = children.length ) ){\r
-                       for( i = 0; i < l; ++i ){\r
-                               html[ html.length ] = children[ i ]._create( true, true );\r
-                       };\r
-               };\r
-               html[ html.length ] = '<\/' + this._tag + '>';\r
-               return html.join( '' );\r
-       }) :\r
-       (function(){});\r
+Node._reserveRemoval = [];\r
 \r
-Node.prototype._afterCreate =\r
-       ( document.appendChild ) ? (function( parent ){\r
-               var _children = this._xnodes,\r
-                       node      = this._rawNode,\r
-                       eChildren = node.childNodes,\r
-                       attrs, p, _child, i, l;\r
-               this.parent = parent;\r
-               if( this._xnodeType !== 1 ) return;\r
-               if( this._isNew ){\r
-                       if( _children && !document.createDocumentFragment ){\r
-                               Node._dom1cleanUp( this ); // docFrg が使えない場合、doc 追加後に子を追加\r
-                       };\r
-                       node.UID       = this._uid;\r
-                       if( this._id ) node.id = this._id;\r
-                       if( this._className ) node.className = this._className;\r
-                       // ie では createElement に <div class=...> HTML 文字列を渡すことができる\r
-                       // 動的に生成した iframe に後から frameborder 等を設定しても無視される ie7\r
-                       if( attrs = this._attrs ){\r
-                               for( p in attrs ){\r
-                                       node[ p ] = attrs[ p ];\r
-                               };\r
-                       };\r
-                       node.style.cssText = this._cssText;\r
-                       this._restoreEvent();// イベントの復帰\r
-                       delete this._isNew;\r
-               };\r
-               /*\r
-                * elm.childNodes を this._xnodes にリンクさせる\r
-                */\r
-               if( _children ){\r
-                       for( i = 0, l = _children.length; i < l; ++i ){\r
-                               _child = _children[ i ];\r
-                               _child.constructor === Node ? _child._afterCreate( this ) : ( _children[ i ] = eChildren[ i ] );\r
-                       };\r
-               } else\r
-               if( eChildren && eChildren.length ){\r
-                       this._xnodes = [];\r
-                       this._xnodes.push.apply( this._xnodes, eChildren );\r
-               };\r
-               return this;\r
-       }) :\r
-       document.all ? (function( parent ){\r
-               var elm,\r
-                       children = this._xnodes,\r
-                       child, i, l;\r
-               this.parent = parent;\r
-               delete this._ie4dirty;\r
-               \r
-               if( this._xnodeType !== 1 ) return;\r
+if( !document.getElementById && document.all ){\r
+       Node.prototype._ie4getRawNode = function(){\r
+               var elm = this._rawNode;\r
+               return elm ||\r
+                       ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawNode = elm ) ) ||\r
+                       ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawNode = elm );\r
+       };\r
+};\r
 \r
-               delete this._rawNode;\r
-               delete this._ie4dirtyChildren;\r
-               \r
-               if( children ){\r
-                       for( i = children.length; i; ){\r
-                               children[ --i ]._afterCreate( this );\r
-                       };\r
-               };\r
-               if( elm = this._ie4getRawNode() ){\r
-                       this._restoreEvent();// イベントの復帰\r
-                       elm.setAttribute( 'UID', '' + this._uid );\r
-               };\r
-       }) :\r
-       (function(){});\r
 \r
 /* --------------------------------------\r
  *  Create\r
  */\r
 Node.prototype.create = function( tag, opt_attrs, opt_css ){\r
-       var elm, xnode;\r
+       var xnode;\r
        if( this._xnodeType !== 1 ) return;\r
        if( !this._xnodes ) this._xnodes = [];\r
        \r
-       elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
-       \r
-       if( elm && !Node.skipCreate ){\r
-               if( document.appendChild ){\r
-                       // ie では iframe の frameborder が無視されるので、<iframe class=> を渡す\r
-                       elm.appendChild( document.createElement( tag ) );\r
-                       xnode = new Node( elm.lastChild );\r
-                       opt_attrs && xnode.attr( opt_attrs );\r
-                       opt_css   && xnode[ X.Type.isString( opt_css ) ? 'cssText' : 'css' ]( opt_css );\r
-               } else\r
-               if( document.all ){\r
-                       Node._newByTag = true;\r
-                       xnode = new Node( tag, opt_attrs, opt_css );\r
-                       // opt_attrs && xnode.attr( opt_attrs );\r
-                       elm.insertAdjacentHTML( 'BeforeEnd', xnode._create() );\r
-                       xnode._rawNode = elm.children[ elm.children.length - 1 ];\r
-               } else {\r
-                       \r
-               };\r
-       } else {\r
-               Node._newByTag = true;\r
-               xnode = new Node( tag, opt_attrs, opt_css );\r
-       };\r
+       Node._newByTag = true;\r
+       xnode = new Node( tag, opt_attrs, opt_css );\r
        xnode.parent = this;\r
+       \r
+       this._root && this._reserveUpdate();\r
        this._xnodes[ this._xnodes.length ] = xnode;\r
        return xnode;\r
 };\r
@@ -344,29 +268,15 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){
  *  CreateText\r
  */\r
 Node.prototype.createText = function( text ){\r
-       var elm, xnode;\r
+       var xnode;\r
        if( this._xnodeType !== 1 ) return;\r
        if( !this._xnodes ) this._xnodes = [];\r
        \r
-       elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
-       \r
-       if( elm && !Node.skipCreate ){\r
-               if( document.createTextNode ){\r
-                       elm.appendChild( document.createTextNode( text ) );\r
-                       xnode = new Node( elm.lastChild );\r
-               } else\r
-               if( document.all ){\r
-                       elm.insertAdjacentText( 'BeforeEnd', text );\r
-                       Node._newByText = true;\r
-                       xnode = new Node( text );\r
-               } else {\r
-                       \r
-               };\r
-       } else {\r
-               Node._newByText = true;\r
-               xnode = new Node( text );\r
-       };\r
+       Node._newByText = true;\r
+       xnode = new Node( text );\r
        xnode.parent = this;\r
+       \r
+       this._root && this._reserveUpdate();\r
        this._xnodes[ this._xnodes.length ] = xnode;\r
        return xnode;\r
 };\r
@@ -377,24 +287,18 @@ Node.prototype.createText = function( text ){
  * http://d.hatena.ne.jp/uupaa/20100508/1273299874\r
  */\r
 Node.prototype.clone = function( opt_clone_children ){\r
-       var xnode, elm;\r
+       var xnode, xnodes, i, l;\r
        switch( this._xnodeType ){\r
                case 1 :\r
-                       if( X.UA.IE && X.UA.IE < 5 ){\r
-                               \r
-                       } else\r
-                       if( X.UA.IE && 5 <= X.UA.IE && X.UA.IE < 10 ){\r
-                               Node._newByTag = true;\r
-                               xnode = new Node( this._tag, this._attrs, this._css );\r
-                               xnode.className( this.className() );\r
-                               if( opt_clone_children ){\r
-                                       \r
+                       Node._newByTag = true;\r
+                       xnode = new Node( this._tag, X.cloneObject( this._attrs ), X.cloneObject( this._css ) )\r
+                               .attr( { 'id' : this._id } )\r
+                               .className( this._className );\r
+                       if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
+                               for( i = 0; i < l; ++i ){\r
+                                       xnode.append( xnodes[ i ].clone( true ) );\r
                                };\r
-                       } else\r
-                       if( elm = this.rawNode ){\r
-                               xnode = new Node( elm.cloneNode( !!opt_clone_children ) );\r
                        };\r
-\r
                        return xnode;\r
                case 3 :\r
                        Node._newByText = true;\r
@@ -413,184 +317,121 @@ Node.prototype.clone = function( opt_clone_children ){
  * HtmlElement の場合は内部使用専用 そのため event の破棄等しない\r
  */\r
 Node.prototype.append = function( v ){\r
-       var elm, i, l, children, frg;\r
+       var i, l, xnodes, frg;\r
        if( this._xnodeType !== 1 ) return;\r
        \r
        if( 1 < ( l = arguments.length ) ){\r
-               if( document.createDocumentFragment && this._rawNode ){\r
-                       frg = document.createDocumentFragment();\r
-                       for( i = 0; i < l; ++i ){\r
-                               v = arguments[ i ];\r
-                               v = v.constructor === Node ? v : new Node( v );\r
-                               frg.appendChild( v._create() );\r
-                               this._xnodes[ this._xnodes.length ] = v;\r
-                               v._afterCreate( this );\r
-                       };\r
-                       this._rawNode.appendChild( frg );\r
-                       return this;\r
-               } else {\r
-                       for( i = 0; i < l; ++i ){\r
-                               this.append( arguments[ i ] );\r
-                       };\r
+               for( i = 0; i < l; ++i ){\r
+                       this.append( arguments[ i ] );\r
                };\r
                return this;\r
        };\r
        \r
-       if( !this._xnodes ) this._xnodes = [];\r
+       if( !( xnodes = this._xnodes ) ) this._xnodes = xnodes = [];\r
        \r
-       elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
        switch( Node._getType( v ) ){\r
                case Node.IS_RAW_HTML :\r
                case Node.IS_RAW_TEXT :\r
-                       if( elm ){\r
-                               if( document.appendChild ){\r
-                                       elm.appendChild( v );\r
-                               } else\r
-                               if( document.all ){\r
-                                       elm.insertAdjacentHTML( 'BeforeEnd', v.outerHTML );\r
-                                       v = elm.children[ elm.children.length - 1 ];\r
-                               } else {\r
-                                       \r
-                               };\r
-                       };\r
-                       this._xnodes[ this._xnodes.length ] = new Node( v );\r
+                       v = new Node( v );\r
                        break;\r
                case Node.IS_HTML_STRING :\r
                case Node.IS_STRING :\r
-                       this.append( X.Dom.parse( v, true ) );\r
-                       break;\r
+                       return this.append( X.Dom.parse( v, true ) );\r
                case Node.IS_XNODE :\r
-                       if( v === Node.none ) return this;\r
+                       if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
-                       v.parent && ( i = v.parent._xnodes.indexOf( v ) ) !== -1 && v.parent._xnodes.splice( i, 1 );\r
-                       if( elm ){\r
-                               if( document.appendChild ){\r
-                                       elm.appendChild( v._create() );\r
-                                       v._afterCreate( this );\r
-                               } else\r
-                               if( document.all ){\r
-                                       elm.insertAdjacentHTML( 'BeforeEnd', v._create() );\r
-                                       v._afterCreate( this );\r
-                               } else {\r
+                       if( v.parent ){\r
+                               //if( document.getElementById ){\r
+                               //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
+                               //} else\r
+                               //if( document.all ){\r
+                                       v.remove();\r
+                               //} else {\r
                                        \r
-                               };\r
+                               //};\r
+                       } else\r
+                       if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
+                               if( !this._state ) alert( 'xnode already destroyed!' );\r
+                               Node._reserveRemoval.splice( i, 1 );\r
                        };\r
-                       this._xnodes[ this._xnodes.length ] = v;\r
+                       break;\r
+               default :\r
+                       return this;\r
        };\r
+\r
+       v.parent = this;\r
+       xnodes[ xnodes.length ] = v;\r
+       this._root && this._reserveUpdate();\r
        return this;\r
 };\r
 \r
 \r
 Node.prototype.appendAt = function( start, v ){\r
-       var children, l, elm, i, prev, next;\r
+       var xnodes, l, i;\r
        \r
        if( this._xnodeType !== 1 ) return this;\r
        \r
-       if( !( children = this._xnodes ) ) children = this._xnodes = [];\r
-       \r
        l = arguments.length;\r
-       if( children.length <= start ){\r
+       if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = [];\r
+       \r
+       if( xnodes.length <= start ){\r
                if( l === 2 ) return this.append( v );\r
-               v = [];\r
-               for( ; 1 < l; ){\r
-                       v[ l - 2 ] = arguments[ --l ];\r
+               for( i = 1; i < l; ++i ){\r
+                       this.append( arguments[ i ] );\r
                };\r
-               return this.append.apply( this, v );\r
+               return this;\r
        };\r
        if( start < 0 ) start = 0;\r
        if( 2 < l ){\r
-               if( document.createDocumentFragment && ( elm = this._rawNode ) ){\r
-                       var frg = document.createDocumentFragment();\r
-                       for( i = 0; i < l; ++i ){\r
-                               v = arguments[ i ];\r
-                               v = v.constructor === Node ? v : new Node( v );\r
-                               frg.appendChild( v._create() );\r
-                               children.splice( start + i, 0, v );\r
-                               v._afterCreate( this );\r
-                       };\r
-                       elm.insertBefore( frg, elm.childNodes[ start ] );\r
-                       return this;\r
-               };\r
                for( ; l; ){\r
                        this.appendAt( start, arguments[ --l ] );\r
                };\r
                return this;\r
        };\r
-       \r
-       if( !this.parent ){\r
-               children.splice( start, 0, v );\r
-               return this;\r
-       };\r
-       elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
+\r
        switch( Node._getType( v ) ){\r
                case Node.IS_RAW_HTML :\r
                case Node.IS_RAW_TEXT :\r
-                       if( elm ){\r
-                               if( document.appendChild ){\r
-                                       elm.insertBefore( v, elm.childNodes[ start ] );\r
-                               } else\r
-                               if( document.all ){\r
-                                       if( start === 0 ){\r
-                                               elm.insertAdjacentHTML( 'AfterBegin', v.outerHTML );\r
-                                               v = elm.children[ 0 ];\r
-                                       } else\r
-                                       if( ( next = children[ start ] ) && typeof next !== 'string' && next._xnodeType !== 3 &&\r
-                                               ( next = ( next._ie4getRawNode ? next._ie4getRawNode() : next ) ) ){\r
-                                               next.insertAdjacentHTML( 'BeforeBegin', v.outerHTML );\r
-                                               v = elm.children[ ( Array.prototype.indexOf.call( elm.children, next ) ) - 1 ];\r
-                                       } else\r
-                                       if( 0 < start && ( prev = children[ start - 1 ] ) && typeof prev !== 'string' && prev._xnodeType !== 3 &&\r
-                                               ( prev = ( prev._ie4getRawNode ? prev._ie4getRawNode() : prev ) ) ){\r
-                                               prev.insertAdjacentHTML( 'AfterEnd', v.outerHTML );\r
-                                               v = elm.children[ ( Array.prototype.indexOf.call( elm.children, prev ) ) + 1 ];\r
-                                       } else {\r
-                                               this._ie4reserveUpdate( v );// テキストノードの間に入れる場合!\r
-                                       };\r
-                               } else {\r
-                                       \r
-                               };\r
-                               children.splice( start, 0, v );\r
-                       } else {\r
-                               children.splice( start, 0, v );\r
-                       };\r
+                       v = new Node( v );\r
                        break;\r
                case Node.IS_HTML_STRING :\r
                case Node.IS_STRING :\r
                        v = X.Dom.parse( v, true );\r
-                       if( elm ){\r
-                               for( i = v.length; i; ){\r
-                                       this.appendAt( start, v[ --i ] );\r
-                               };\r
-                       } else\r
-                       if( v.length ){\r
-                               children.push.apply( children, v );\r
+                       for( i = v.length; i; ){\r
+                               this.appendAt( start, v[ --i ] );\r
                        };\r
-                       break;\r
+                       return this;\r
                case Node.IS_XNODE :\r
-                       if( v === Node.none ) return this;\r
+                       if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
-                       v.parent && ( i = v.parent._xnodes.indexOf( v ) ) !== -1 && v.parent._xnodes.splice( i, 1 );\r
-                       if( elm ){\r
-                               if( document.appendChild ){\r
-                                       elm.insertBefore( v._create(), elm.childNodes[ start ] );\r
-                                       v._afterCreate( this );\r
-                               } else\r
-                               if( document.all ){\r
-                                       this._ie4reserveUpdate( v );\r
-                               } else {\r
+                       if( v.parent ){\r
+                               //if( document.getElementById ){\r
+                               //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
+                               //} else\r
+                               //if( document.all ){\r
+                                       v.remove();\r
+                               //} else {\r
                                        \r
-                               };\r
+                               //};\r
+                       } else\r
+                       if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
+                               if( !this._state ) alert( 'xnode already destroyed!' );\r
+                               Node._reserveRemoval.splice( i, 1 );\r
                        };\r
-                       children.splice( start, 0, v );\r
+                       break;\r
+               default :\r
+                       return this;\r
        };\r
+\r
+       v.parent = this;\r
+       this._xnodes.splice( start, 0, v );\r
+       this._root && this._reserveUpdate();\r
        return this;\r
 };\r
 \r
 Node.prototype.appendTo = function( parent, opt_index ){\r
        if( parent.constructor === Node ){\r
                opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
-       } else {\r
-               opt_index === undefined ? new Node( parent ).append( this ) : new Node( parent ).appendAt( opt_index, this );\r
        };\r
        return this;\r
 };\r
@@ -601,34 +442,53 @@ Node.prototype.appendToRoot = function( opt_index ){
 };\r
 \r
 /* --------------------------------------\r
- *  Before , After\r
+ *  Before , After, Replace\r
  */\r
 Node.prototype.before = function( v ){\r
-       var l;\r
-       if( this._xnodeType !== 1 || !this.parent ) return this;\r
+       var parent, l, start;\r
+       if( !( parent = this.parent ) ) return this;\r
+       \r
        l = arguments.length;\r
+       start = this.getOrder();\r
        if( 1 < l ){\r
-               v = [ this.getOrder() ];\r
                for( ; l; ){\r
-                       v[ l ] = arguments[ --l ];\r
+                       parent.appendAt( start, arguments[ --l ] );\r
                };\r
-               return this.parent.appendAt.apply( this.parent, v );\r
+               return this;\r
        };\r
-       return this.parent.appendAt( this.getOrder(), v );\r
+       parent.appendAt( start, v );\r
+       return this;\r
 };\r
 \r
 Node.prototype.after = function( v ){\r
-       var l;\r
-       if( this._xnodeType !== 1 || !this.parent ) return this;\r
+       var parent, l, i, start;\r
+       if( !( parent = this.parent ) ) return this;\r
+       \r
        l = arguments.length;\r
+       start = this.getOrder() + 1;\r
+       if( parent._xnodes.length <= start ){\r
+               if( 1 < l ){\r
+                       for( i = 0; i < l; ++i ){\r
+                               parent.append( arguments[ i ] );\r
+                       };\r
+                       return this;\r
+               };\r
+               parent.append( v );\r
+               return this;\r
+       };\r
        if( 1 < l ){\r
-               v = [ this.getOrder() + 1 ];\r
                for( ; l; ){\r
-                       v[ l ] = arguments[ --l ];\r
+                       parent.appendAt( start, arguments[ --l ] );\r
                };\r
-               return this.parent.appendAt.apply( this.parent, v );\r
+               return this;\r
        };\r
-       return this.parent.appendAt( this.getOrder() + 1, v );\r
+       parent.appendAt( start, v );\r
+       return this;\r
+};\r
+\r
+Node.prototype.replace = function( v ){\r
+       if( !this.parent ) return this;\r
+       return arguments.length === 1 ? this.before( v ).remove() : this.before.apply( this, arguments ).remove();\r
 };\r
 \r
 /* --------------------------------------\r
@@ -636,226 +496,80 @@ Node.prototype.after = function( v ){
  */\r
 Node.prototype.remove = function(){\r
        var parent = this.parent;\r
-               \r
+       \r
        if( !parent ) return this;\r
-       if( document.removeChild ){\r
-               if( this._rawNode ){\r
-                       this._xnodeType === 1 && this._beforeRemove();\r
-                       parent._rawNode.removeChild( this._rawNode );\r
-               };\r
-       } else\r
-       if( document.all ){\r
-               delete this._ie4dirty;\r
-               delete this._ie4dirtyChildren;\r
-               if( this._xnodeType === 1 ){\r
-                       this._beforeRemove();\r
-                       if( elm = this._ie4getRawNode() ){\r
-                               elm.outerHTML = '';\r
-                       };\r
-               } else {\r
-                       parent._beforeRemove(); //??\r
-                       parent._ie4reserveUpdate();\r
-               };\r
-       } else {\r
-               \r
-       };\r
 \r
        parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );\r
+       if( this._root ){\r
+               Node._reserveRemoval[ Node._reserveRemoval.length ] = this;\r
+               parent._reserveUpdate();\r
+       };\r
        delete this.parent;\r
+       delete this._root;\r
        return this;\r
 };\r
 \r
-Node.prototype._beforeRemove = \r
-       document.removeChild ?\r
-               ( function(){\r
-                       var elm = this._rawNode, children,\r
-                               child, i, l;\r
-                       if( !elm ) return;\r
-                       this._migrateEvent();// イベントの退避\r
-                       if( children = this._xnodes ){\r
-                               for( i = 0, l = children.length; i < l; ++i ){\r
-                                       child = children[ i ];\r
-                                       child._xnodeType === 1 && child._beforeRemove();\r
-                               };\r
-                       };\r
-               }) :\r
-       document.all ? \r
-               ( function(){\r
-                       var elm = this._ie4getRawNode(),\r
-                               children, i, l;\r
-                       if( children = this._xnodes ){\r
-                               for( i = 0, l = children.length; i < l; ++i ){\r
-                                       children[ i ]._beforeRemove();\r
-                               };      \r
-                       };\r
-                       if( !elm ) return;\r
-                       this._migrateEvent();// イベントの退避\r
-                       this._htmlText = elm.outerHTML;\r
-                       elm.removeAttribute( 'id' );    \r
-               }) :\r
-               (function(){});\r
-\r
-Node.prototype.empty =\r
-       document.removeChild ?\r
-               ( function(){\r
-                       var elm = this._rawNode, children,\r
-                               child, i, l;\r
-                       if( children = this._xnodes ){\r
-                               for( i = 0, l = children.length; i < l; ++i ){\r
-                                       children[ i ].destroy();\r
-                               };\r
-                               children.length = 0;\r
-                       };\r
-                       if( elm ) elm.innerHTML = '';\r
-                       return this;\r
-               }) :\r
-       document.all ? \r
-               ( function(){\r
-                       var elm = this._ie4getRawNode(),\r
-                               children, i, l;\r
-                       if( children = this._xnodes ){\r
-                               for( i = 0, l = children.length; i < l; ++i ){\r
-                                       children[ i ].destroy();\r
-                               };\r
-                               children.length = 0;\r
-                       };\r
-                       if( elm ) elm.innerHTML = '';\r
-                       return this;\r
-               }) :\r
-               (function(){});\r
-\r
-/* --------------------------------------\r
- *  replace\r
- */\r
-\r
-/* --------------------------------------\r
- *  destory\r
- */\r
-Node.prototype.destroy = function(){\r
-       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode,\r
-               children = this._xnodes;\r
-       \r
-       if( children ){\r
-               for( i = 0, l = children.length; i < l; ++i ){\r
-                       children[ i ].destroy();\r
+Node.prototype.empty = function(){\r
+       var xnodes = this._xnodes, child, i, l;\r
+       if( xnodes && ( l = xnodes.length ) ){\r
+               for( i = 0; i < l; ++i ){\r
+                       xnodes[ i ].destroy();\r
                };\r
-               children.length = 0;\r
-       };\r
-       this._xnodeType === 1 && this.unlisten(); // イベントの退避\r
-       if( elm ){\r
-               this._xnodeType === 1 && ( elm.innerHTML = '' );\r
-               // stop()\r
-               // remove() empty()\r
-               \r
-               document.removeChild && this.parent._rawNode.removeChild( elm );\r
+               xnodes.length = 0;\r
        };\r
-       delete Node._chashe[ this._uid ];\r
-       this.kill();\r
+       return this;\r
 };\r
 \r
 /* --------------------------------------\r
- *  for ie4\r
+ *  destory\r
  */\r
-if( !document.getElementById && document.all ){\r
-\r
-       Node.prototype._ie4getRawNode = function(){\r
-               var elm, uid;\r
-               if( elm = this._rawNode ) return elm;\r
-               if( this._id && ( elm = this._rawNode = document.all[ this._id ] ) ){\r
-                       return elm;\r
-               };\r
-               if( elm = this._rawNode = document.all[ 'ie4uid' + this._uid ] ){\r
-                       if( this._id ) elm.setAttribute( 'id', this._id );\r
-                       return elm;\r
-               };\r
-       };\r
+Node.prototype.destroy = function( isChild ){\r
+       var xnodes = this._xnodes, i, elm;\r
        \r
-       Node.prototype._ie4reserveUpdate = function( child ){\r
-               var root = Node.root;\r
-               child && ( child._ie4dirty = true );\r
-               this._ie4dirtyChildren = true;\r
-               if( root._ie4reserved === true ) return;\r
-               root._ie4reserved = true;\r
-               X.Timer.once( 1, root, root._ie4startUpdate );\r
-       };\r
+       if( !this._state ) return;\r
        \r
-       Node.prototype._ie4startUpdate = function(){\r
-               if( this._ie4reserved !== true ) return;\r
-               delete this._ie4reserved;\r
-               if( !this._xnodes ) return;\r
-               this._ie4commitUpdate()._ie4afterUpdate();\r
-       };\r
-       \r
-       Node.prototype._ie4commitUpdate = function(){\r
-               var children = this._xnodes,\r
-                       i, l, html;\r
-               if( !this._ie4dirtyChildren ){\r
-                       for( i = 0, l = children.length; i < l; ++i ){\r
-                               children[ i ]._ie4commitUpdate();\r
-                       };\r
-                       return this;\r
-               };\r
-               html = [];\r
-               for( i = 0, l = children.length; i < l; ++i ){\r
-                       html[ html.length ] = children[ i ]._create( true );\r
-               };\r
-               this._rawNode.innerHTML = html.join( '' );\r
-               return this;\r
-       };\r
+       elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
        \r
-       Node.prototype._ie4afterUpdate = function(){\r
-               var children = this._xnodes,\r
-                       i, l;\r
-               if( !this._ie4dirtyChildren ){\r
-                       for( i = 0, l = children.length; i < l; ++i ){\r
-                               children[ i ]._ie4afterUpdate();\r
-                       };\r
-                       return this;\r
-               };\r
-               for( i = 0, l = children.length; i < l; ++i ){\r
-                       children[ i ]._afterCreate( this );\r
+       if( xnodes && ( i = xnodes.length ) ){\r
+               for( ; i; ){\r
+                       xnodes[ --i ].destroy( true );\r
                };\r
-               delete this._ie4dirtyChildren;\r
+               xnodes.length = 0;\r
        };\r
+       elm && this.unlisten(); // イベントの退避\r
+\r
+       delete Node._chashe[ this._uid ];\r
+       delete this._state;     \r
        \r
-       Node.prototype._ie4containsDirty = function(){\r
-               var children, i;\r
-               if( this._xnodeType !== 1 ) return;\r
-               if( this._ie4dirtyChildren || this._ie4dirty ) return true;\r
-               if( !( children = this._xnodes ) || !( i = children.length ) ) return;\r
-               for( ; i; ){\r
-                       if( children[ --i ]._ie4containsDirty() ) return true;\r
-               };\r
+       if( this._root ){\r
+               this.remove();\r
+       } else {\r
+               this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );\r
+               elm && !isChild && this._actualRemove();\r
+               this.kill();\r
        };\r
 };\r
 \r
+\r
+\r
 /* --------------------------------------\r
  *  contains\r
  */\r
 Node.prototype.contains = function( v ){\r
-       var node, children, i;\r
-       if( !v || !this.parent || this._xnodeType !== -1 ) return false;\r
+       var elm, type, xnodes, i;\r
+       if( !v || this._xnodeType !== 1 ) return false;\r
        // contains ie4+\r
-       if( document.contains ){\r
-               node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
-               switch( Node._getType( v ) ){\r
-                       case Node.IS_RAW_HTML :\r
-                       case Node.IS_RAW_TEXT :\r
-                               return node.contains( v );\r
-                       case Node.IS_XNODE :\r
-                               if( v.parent === this ) return true;\r
-                               v = v._ie4getRawNode ? v._ie4getRawNode() : v._rawNode;\r
-                               if( node && v ) return node.contains( v );\r
-                               break;\r
-                       default :\r
-                               return false;\r
-               };              \r
+       if( ( elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode() ) && document.contains && ( type = Node._getType( v ) ) && ( type === Node.IS_RAW_HTML || type === Node.IS_RAW_TEXT ) ){\r
+               return elm.contains( v );       \r
        };\r
-       children = this._xnodes;\r
-       if( children.indexOf( v ) !== -1 ) return true;\r
-       if( ( node = this._rawNode ) && node === v.parentNode ) return;\r
-       for( i = children.length; i; ){\r
-               if( children[ --i ].contains( v ) ) return true;\r
+       //if( document.compareDocumentPosition ){\r
+       //      \r
+       //};\r
+       xnodes = this._xnodes;\r
+       if( xnodes.indexOf( v ) !== -1 ) return true;\r
+       if( elm === v.parentNode ) return false;\r
+       for( i = xnodes.length; i; ){\r
+               if( xnodes[ --i ].contains( v ) ) return true;\r
        };\r
        return false;\r
 };\r
@@ -863,37 +577,29 @@ Node.prototype.contains = function( v ){
 /* --------------------------------------\r
  *  getChild\r
  */\r
-Node.prototype.getChildAt = function( index ){\r
-       var children = this._xnodes,\r
-               elm, childNodes, child, xnode;\r
-       if( this._xnodeType !== 1 || index < 0 ) return;\r
-       if( children.length <= index ) return;\r
-       child = children[ index ];\r
-       if( child.constructor === Node ) return child;\r
-       xnode = new Node( child );\r
-       xnode.parent = this;\r
-       return children[ index ] = xnode;\r
+Node.prototype.getChildAt = function( i ){\r
+       var xnodes = this._xnodeType === 1 && this._xnodes;\r
+       return xnodes && 0 <= i && i < xnodes.length && xnodes[ i ];\r
 };\r
 \r
-// listen, unlisten, listening\r
 \r
 /* --------------------------------------\r
  *  prevNode, nextNode, firstChild, lastChild\r
  */\r
 \r
 Node.prototype.prevNode = function(){\r
-       var parent = this.parent, children, index;\r
+       var parent = this.parent, xnodes, index;\r
        if( !parent ) return;\r
-       children = parent._xnodes;\r
-       index = children.indexOf( this );\r
-       if( 0 < index ) return children[ index - 1 ];\r
+       xnodes = parent._xnodes;\r
+       index = xnodes.indexOf( this );\r
+       if( 0 < index ) return xnodes[ index - 1 ];\r
 };\r
 Node.prototype.nextNode = function(){\r
-       var parent = this.parent, children, index;\r
+       var parent = this.parent, xnodes, index;\r
        if( !parent ) return;\r
-       children = parent._xnodes;\r
-       index    = children.indexOf( this );\r
-       if( index !== -1 && index + 1 < children.length ) return children[ index + 1 ];\r
+       xnodes = parent._xnodes;\r
+       index  = xnodes.indexOf( this );\r
+       if( index + 1 < xnodes.length ) return xnodes[ index + 1 ];\r
 };\r
 Node.prototype.firstChild = function(){\r
        return this.getChildAt( 0 );\r
@@ -917,61 +623,125 @@ Node.prototype.getOrder = function(){
 Node.prototype.className = function( v ){\r
        var node;\r
        // getter\r
-       if(  typeof v !== 'string' ) return this._className;\r
+       if( v === undefined ) return this._className;\r
        // setter\r
-       if( this._className === v ) return;\r
-       if( !v ) delete this._className;\r
-       node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
-       if( node ) node.className = v;\r
-       this._className = v;\r
-       this._classText = ' class="' + v + '" ';\r
+       if( this._className === v ) return this;\r
+       if( !v || typeof v !== 'string' ){\r
+               delete this._className;\r
+       } else {\r
+               this._className = v;    \r
+       };\r
+       this._dirty |= X.Dom.Dirty.CLASSNAME;\r
+       this._root && this._reserveUpdate();\r
        return this;\r
 };\r
-Node.prototype.addClass = function(){\r
-       \r
+Node.prototype.addClass = function( v ){\r
+       var names = v.split( ' ' ),\r
+               i     = names.length,\r
+               name;\r
+       v = '';\r
+       for( ; i; ){\r
+               name = names[ --i ];\r
+               if( !name ) continue;\r
+               !this.hasClass( name ) && ( v += ( v ? ' ' : '' ) + name );\r
+       };\r
+       return v ? his.className( this._className + ( this._className ? ' ' : '' ) + v ) : this;\r
 };\r
-Node.prototype.removeClass = function(){\r
-       \r
+Node.prototype.removeClass = function( v ){\r
+       var _          = ' ',\r
+               className  = this._className,\r
+               names      = v.split( ' ' ),\r
+               classNames, i, f, j;\r
+       if( !className ) return this;\r
+       for( classNames = className.split( _ ), i = classNames.length; i; ){\r
+               className = classNames[ --i ];\r
+               for( j = names.length; j; ){\r
+                       if( className === names[ --j ] ){\r
+                               classNames.splice( i, 1 );\r
+                               names.splice( j, 1 );\r
+                               f = true;\r
+                               break;\r
+                       };\r
+               };\r
+       };\r
+       return f ? this.className( classNames.join( ' ' ) ) : this;\r
 };\r
-Node.prototype.toggleClass = function(){\r
-       \r
+Node.prototype.toggleClass = function( v ){\r
+\r
 };\r
-Node.prototype.hasClass = function(){\r
-       /*\r
-       var cnames  = ( elm.className || '' ).split( ' ' ),\r
-               _cnames = className.split( ' ' ),\r
-               _cname,\r
-               i = _cnames.length;\r
-       for( ; i; ){\r
-               _cname = _cnames[ --i ];\r
-               if( _cname === '' ) continue;\r
-               if( cnames.indexOf( _cname ) === -1 ) return false;\r
+Node.prototype.hasClass = function( v ){\r
+       var _ = ' ',\r
+               className = this._className,\r
+               i, name;\r
+       if( className === v ) return true;\r
+       if( !className ) return false;\r
+       \r
+       className = _ + className + _;\r
+       if( className.indexOf( _ + v + _ ) !== -1 ) return true; // lucky hit\r
+       \r
+       for( v = v.split( _ ), i = v.length; i; ){\r
+               name = v[ --i ];\r
+               if( name === '' ) continue;\r
+               if( className.indexOf( _ + name + _ ) === -1 ) return false;\r
        };\r
-       return true; */\r
+       return true;\r
 };\r
 \r
 /* --------------------------------------\r
  *  html, text\r
  */\r
-Node.prototype.html = function( html ){\r
+Node.prototype.html = function( html, opt_outer ){\r
+       var xnodes, n, i, l;\r
+       // setter\r
        if( html ){\r
                if( this._xnodeType === 3 ){\r
-                       this._text = html;\r
-                       if( this._rawNode ) this._rawNode.data = html;\r
+                       if( this._text !== html ){\r
+                               this._text = html;\r
+                               this._root && this._reserveUpdate();\r
+                               this._dirty |= X.Dom.Dirty.CONTENT;\r
+                       };\r
                        return this;\r
                };\r
-               return this.empty().append.call( this, X.Dom.parse( html, true ) );\r
+               return this.empty().append.apply( this, X.Dom.parse( html, true ) );\r
+       };\r
+       // getter\r
+       if( this._xnodeType === 3 ){\r
+               return this._text;\r
        };\r
-       // if dirty\r
-       return this._rawNode ? this._rawNode.innerHTML : '';\r
+       \r
+       if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
+               delete this._cssText;\r
+       };\r
+       html = !opt_outer ? [] : [\r
+               '<', this._tag,\r
+               this._id ? ' id=' + this._id : '',\r
+               this._className ? ' class="' + this._className + '"' : '',\r
+               this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
+               this._cssText ? ' style="' + this._cssText + '"' : '',\r
+       '>' ];\r
+       \r
+       n = html.length;\r
+       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
+               for( i = 0; i < l; ++i ){\r
+                       html[ n ] = xnodes[ i ].html( undefined, true );\r
+                       ++n;\r
+               };\r
+       };\r
+       !opt_outer || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
+\r
+       return html.join( '' );\r
 };\r
 \r
 Node.prototype.text = function( text ){\r
+       var xnodes, n, i;\r
        // setter\r
        if( text ){\r
                if( this._xnodeType === 3 ){\r
-                       this._text = text;\r
-                       if( this._rawNode ) this._rawNode.data = text;\r
+                       if( this._text !== text ){\r
+                               this._text = text;\r
+                               this._root && this._reserveUpdate();\r
+                               this._dirty |= X.Dom.Dirty.CONTENT;\r
+                       };\r
                        return this;\r
                };\r
                this.empty().createText( text );\r
@@ -979,11 +749,444 @@ Node.prototype.text = function( text ){
        };\r
        // getter\r
        if( this._xnodeType === 1 ){\r
-               //\r
+               if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){\r
+                       for( text = [], n = -1; i; ){\r
+                               text[ ++n ] = xnodes[ --i ].text();\r
+                       };\r
+                       return text.join( '' );\r
+               };\r
+               return '';\r
        };\r
        return this._text;\r
 };\r
 \r
+/* --------------------------------------\r
+ *  Async commit update\r
+ * \r
+ * state:\r
+ *  0 : no_rawnode\r
+ *  1 : not_added\r
+ *  3 : dirty\r
+ *  4 : clean\r
+ * \r
+ * remove :\r
+ * root._reserveRemoval = [] に追加。commitUpdate で remove して state は not_added\r
+ * add :\r
+ * root._reserveRemoval にいたら消す, new_parent._xnodes に挿入 steta は not_added にして commitUpdate を待つ\r
+ */\r
+       \r
+Node.prototype._reserveUpdate = function(){\r
+       var root = Node.root;\r
+       if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( root, root._startUpdate );\r
+};\r
+\r
+Node.prototype._startUpdate = function(){\r
+       var removal, i, xnode, tmp;\r
+       \r
+       if( this._updateTimerID ){\r
+               //X.Timer.cancelFrame( this._updateTimerID ); // fire 空の cancel が動かない、、、\r
+               this._updateTimerID = 0;\r
+       } else {\r
+               return;\r
+       };\r
+\r
+       removal = Node._reserveRemoval;\r
+       \r
+       tmp = this._rawNode.style.visibility;\r
+       //this._rawNode.style.visibility = 'hidden';\r
+       \r
+       if( i = removal.length ){\r
+               for( ; i; ){\r
+                       xnode = removal[ --i ];\r
+                       xnode._actualRemove();\r
+                       !this._state && xnode.kill();\r
+               };\r
+               removal.length = 0;             \r
+       };\r
+       \r
+       this._commitUpdate();\r
+       \r
+       //this._rawNode.style.visibility = tmp;\r
+};\r
+\r
+Node.prototype._commitUpdate =\r
+       document.getElementById ?\r
+               ( function( parentElement, nextElement ){\r
+                       var elm = this._rawNode,\r
+                               xnodes, l, i, frg, next, k, v;\r
+\r
+                       if( !elm || ( parentElement && elm.parentNode !== parentElement ) || ( nextElement && elm.nextSibling !== nextElement ) ){\r
+                               nextElement ?\r
+                                       parentElement.insertBefore( this._actualCreate(), nextElement ) :\r
+                                       parentElement.appendChild( this._actualCreate() );\r
+                               this._afterActualCreate();\r
+                               return elm || this._rawNode;\r
+                       } else\r
+                       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
+                               \r
+                               /*if( elm.childNodes.length !== l && ( frg = Node._useDocumentFragment ) ){\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               frg.appendChild( xnodes[ i ]._actualCreate( true ) );\r
+                                       };\r
+                                       elm.appendChild( frg );\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               xnodes[ i ]._afterActualCreate( true );\r
+                                       };\r
+                               } else {*/\r
+                                       for( ; l; ){\r
+                                               next = xnodes[ --l ]._commitUpdate( elm, next );\r
+                                       };\r
+                               //};\r
+                       };\r
+\r
+                       this._dirty && this._updateRawNode( elm );\r
+                       return elm;\r
+               }) :\r
+       document.all ? \r
+               ( function( parentElement, prevElement ){\r
+                       var elm    = this._rawNode || this._ie4getRawNode(),\r
+                               xnodes, l, i, html, text, prev;\r
+\r
+                       if( !elm ){\r
+                               prevElement ?\r
+                                       prevElement.insertAdjacentHTML( 'AfterEnd', this._actualCreate() ) :\r
+                                       parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );\r
+                               this._afterActualCreate();\r
+                               return this._rawNode || this._ie4getRawNode();\r
+                       };\r
+                       \r
+                       xnodes = this._xnodes;\r
+                       l      = xnodes ? xnodes.length : 0;\r
+                       \r
+                       if( this._dirty & X.Dom.Dirty.IE4_TEXTNODE_FIX || ( this._state & X.Dom.State.IE4_ONLY_TEXT && ( l !== 1 || xnodes[ 0 ]._xnodeType !== 3 ) ) ){ // 1 < l && elm.children.length === 0\r
+                               html = [];\r
+                               for( i = 0; i < l; ++i ){\r
+                                       html[ i ] = xnodes[ i ]._actualCreate();\r
+                               };\r
+                               elm.innerHTML = html.join( '' );\r
+                               for( i = 0; i < l; ++i ){\r
+                                       xnodes[ i ]._afterActualCreate();\r
+                               };\r
+                               this._state &= ~X.Dom.State.IE4_ONLY_TEXT;\r
+                       } else\r
+                       if( this._state & X.Dom.State.IE4_ONLY_TEXT ){ // textNode が swap した場合の検出は、_root で行う\r
+                               text = xnodes[ 0 ];\r
+                               if( text._dirty || !text._root ){\r
+                                       elm.innerHTML = text._text;\r
+                                       delete text._dirty;\r
+                                       text._root = this._root;                                        \r
+                               };\r
+                       } else\r
+                       if( l ){\r
+                               for( i = 0; i < l; ++i ){\r
+                                       prev = xnodes[ i ]._commitUpdate( elm, prev );\r
+                               };\r
+                       };\r
+                       this._dirty && this._updateRawNode( elm );\r
+                       return elm;\r
+               }) :\r
+               (function(){});\r
+\r
+Node.prototype._updateRawNode =\r
+       document.getElementById ?\r
+               ( function( elm ){\r
+                       var attrs, rename, k, v;\r
+\r
+                       // textNode\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ){\r
+                               elm.data = X.Dom.chrReferanceTo( this._text );\r
+                               delete this._dirty;\r
+                               return;\r
+                       };\r
+                       // id\r
+                       if( this._dirty & X.Dom.Dirty.ID ) elm.id = this._id;\r
+                       // className\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       // 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
+                               } else {\r
+                                       elm.removeAttribute( 'style' );\r
+                                       delete this._cssText;\r
+                               };\r
+                       };\r
+                       \r
+                       if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
+                               this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+                       };\r
+                       \r
+                       // attr\r
+                       if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
+                               rename = X.Dom.Attr.renameForDOM;\r
+                               for( k in attrs ){\r
+                                       ( v = attrs[ k ] ) === undefined ?\r
+                                               elm.removeAttribute( rename[ k ] || k ) :\r
+                                               ( elm[ rename[ k ] || k ] = v );\r
+                               };\r
+                               delete this._newAttrs;\r
+                       };\r
+                       \r
+                       delete this._dirty;\r
+               }) :\r
+       document.all ? \r
+               ( function( elm ){\r
+                       var attrs, rename, k, v;\r
+\r
+                       // fake textNode\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ){\r
+                               elm.innerText = this._text;\r
+                               delete this._dirty;\r
+                               return;\r
+                       };\r
+                       \r
+               /*\r
+                * http://www.tohoho-web.com/js/element.htm\r
+                * title、className、id、lang、language には setAttribute でなく、element.id で直接読み書きできる\r
+                */     \r
+                       // id\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) );\r
+\r
+                       // className\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       // 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
+                               } else {\r
+                                       elm.removeAttribute( 'style' );\r
+                                       delete this._cssText;\r
+                               };\r
+                       };\r
+                       \r
+                       if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
+                               this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+                       };\r
+                       \r
+                       // attr\r
+                       if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
+                               rename = X.Dom.Attr.renameForDOM;\r
+                               for( k in attrs ){\r
+                                       ( v = attrs[ k ] ) === undefined ?\r
+                                               elm.removeAttribute( rename[ k ] || k ) :\r
+                                               elm.setAttribute( rename[ k ] || k, v );\r
+                               };\r
+                               delete this._newAttrs;\r
+                       };\r
+                       \r
+                       delete this._dirty;\r
+               }) :\r
+               (function(){});\r
+\r
+/* --------------------------------------\r
+ *  Create\r
+ * \r
+ * http://d.hatena.ne.jp/uupaa/20080718/1216362040\r
+ * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。\r
+ * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");\r
+ * insertAdjacentHTML\r
+ * \r
+ * ie7 以下では iframe の frameborder や、input name は、createElement 後に setAttribute しても無視される\r
+ * \r
+ * fragument がある場合 children も足して\r
+ * Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
+ * ie6 大丈夫?fragment の場合リークしないか?チェックが必要\r
+ * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx\r
+ * \r
+ * document.createElement of ie4 is only for OPTION & IMAGE.\r
+ */\r
+Node.prototype._actualCreate =\r
+       document.getElementById ? (function( isChild ){\r
+               var elm = this._rawNode,\r
+                       xnodes, frg, i, l;\r
+               \r
+               if( this._xnodeType === 3 ){\r
+                       if( elm ) return elm;\r
+                       delete this._dirty;\r
+                       return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
+               };\r
+               \r
+               if( !elm ){\r
+                       if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
+                               delete this._cssText;\r
+                       };\r
+                       this._isNew = true;\r
+                       this._rawNode = elm =\r
+                               X.UA.IE && X.UA.IE < 9 ?\r
+                                       document.createElement( [\r
+                                               '<', this._tag,\r
+                                                       ' UID="', this._uid, '"',\r
+                                                       this._id ? ' id="' + this._id + '"' : '',\r
+                                                       this._className ? ' class="' + this._className + '"' : '',\r
+                                                       this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
+                                                       this._cssText ? ' style="' + this._cssText + '"' : '',\r
+                                               '>' ].join( '' ) ):\r
+                                       document.createElement( this._tag );\r
+               };\r
+               if( Node._useDocumentFragment ){\r
+                       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
+                               !isChild && ( frg = Node._useDocumentFragment ).appendChild( elm );\r
+                               for( i = 0; i < l; ++i ){\r
+                                       elm.appendChild( xnodes[ i ]._actualCreate( true ) );\r
+                               };\r
+                               return frg || elm;\r
+                       };\r
+               };\r
+               \r
+               return elm;\r
+       }) :\r
+       document.all ? (function( isChild ){\r
+               var uid = this._uid,\r
+                       html, xnodes, n, i, l;\r
+               \r
+               if( this._xnodeType === 3 ){\r
+                       //html = [];\r
+                       //for( i = 0, l = this._text.length; i < l; ++i ){\r
+                       //      html.push( this._text.charCodeAt( i ) );\r
+                       //};\r
+                       //html = html.join( ',' );\r
+                       html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode\r
+                       delete this._rawNode;\r
+               } else {\r
+                       if( this._rawNode && !isChild ) this._actualRemove( true );\r
+                       \r
+                       if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
+                               delete this._cssText;\r
+                       };\r
+                       \r
+                       html = [\r
+                               '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID="', uid, '"',\r
+                               this._className ? ' class="' + this._className + '"' : '',\r
+                               this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
+                               this._cssText ? ' style="' + this._cssText + '"' : '',\r
+                       '>' ];\r
+                       \r
+                       n = html.length;\r
+                       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
+                               if( l === 1 && xnodes[ 0 ]._xnodeType === 3 ){\r
+                                       // only textnode\r
+                                       html[ n ] = xnodes[ 0 ]._text;\r
+                                       ++n;\r
+                                       this._state |= X.Dom.State.IE4_ONLY_TEXT;\r
+                               } else {\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               html[ n ] = xnodes[ i ]._actualCreate( true );\r
+                                               ++n;\r
+                                       };                                      \r
+                               };\r
+                       };\r
+                       X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
+                       \r
+                       delete this._newAttrs;\r
+               };\r
+               \r
+               return html.join( '' );\r
+       }) :\r
+       (function(){});\r
+\r
+Node.prototype._afterActualCreate =\r
+       document.getElementById ? (function(){\r
+               var elm = this._rawNode, xnodes, l, attrs, k, i;\r
+               \r
+               this._root  = this.parent._root;\r
+               \r
+               if( this._xnodeType === 3 ){\r
+                       this._dirty && this._updateRawNode( elm );\r
+                       return this;\r
+               };\r
+                       \r
+               xnodes = this._xnodes;\r
+               l      = xnodes && xnodes.length;\r
+               \r
+               if( this._isNew ){\r
+                       if( !Node._useDocumentFragment && l ){// docFrg が使えない場合、doc 追加後に子を追加\r
+                               for( i = 0; i < l; ++i ){\r
+                                       elm.appendChild( xnodes[ i ]._actualCreate( true ) );\r
+                               };\r
+                       };\r
+                       if( !X.UA.IE || 8 < X.UA.IE ){\r
+                               elm.UID = this._uid;\r
+                               this._newAttrs = this._attrs;\r
+                               this._dirty = X.Dom.Dirty.ID | X.Dom.Dirty.CLASSNAME | X.Dom.Dirty.CSS | X.Dom.Dirty.ATTR | X.Dom.Dirty.IE_FILTER;\r
+                               this._updateRawNode( elm );\r
+                       } else\r
+                       if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
+                               elm.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+                               delete this._dirty;\r
+                       };\r
+                       this._restoreEvent();// イベントの復帰\r
+                       delete this._isNew;\r
+               } else {\r
+                       this._dirty && this._updateRawNode( elm );\r
+               };\r
+               \r
+               if( l ){\r
+                       for( i = 0; i < l; ++i ){\r
+                               xnodes[ i ]._afterActualCreate();\r
+                       };\r
+               };\r
+               \r
+               return this;\r
+       }) :\r
+       document.all ? (function(){\r
+               var xnodes, i;\r
+               this._root = this.parent._root;\r
+               \r
+               if( this._xnodeType !== 1 ) return this;\r
+               \r
+               if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){\r
+                       for( ; i; ){\r
+                               xnodes[ --i ]._afterActualCreate();\r
+                       };\r
+               };\r
+               if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
+                       this._ie4getRawNode().style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+               };\r
+               delete this._dirty;\r
+               return this._restoreEvent();// イベントの復帰\r
+       }) :\r
+       (function(){});\r
+       \r
+Node.prototype._actualRemove =\r
+       document.getElementById ?\r
+               ( function( isChild ){\r
+                       var xnodes = this._xnodes,\r
+                               elm    = this._rawNode,\r
+                               child, i, l;\r
+                       if( xnodes && ( l = xnodes.length ) ){\r
+                               for( i = 0; i < l; ++i ){\r
+                                       child = xnodes[ i ];\r
+                                       child._xnodeType === 1 && child._actualRemove( true );\r
+                               };\r
+                       };\r
+                       //delete this._root;\r
+                       if( !elm ) return;\r
+                       this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+                       // elm.parentNode.tagName check tagName is for ie7\r
+                       !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
+               }) :\r
+       document.all ?\r
+               ( function( isChild ){\r
+                       var xnodes = this._xnodes,\r
+                               elm    = this._rawNode || this._ie4getRawNode(),\r
+                               i, l, xnode;\r
+                       if( xnodes && ( l = xnodes.length ) ){\r
+                               for( i = 0; i < l; ++i ){\r
+                                       xnodes[ i ]._actualRemove( true );\r
+                               };\r
+                       };\r
+                       //delete this._root;\r
+                       if( !elm ) return;\r
+                       this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+                       \r
+                       elm.removeAttribute( 'id', '' ); // ?\r
+                       document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
+                       if( !isChild ) elm.outerHTML = '';\r
+                       delete this._rawNode;\r
+               }) :\r
+               (function(){});\r
+       \r
+       \r
 //})( window, document );\r
 \r
 \r