OSDN Git Service

Version 0.6.25, bugfix.
[pettanr/clientJs.git] / 0.6.x / js / dom / 12_XDomEvent.js
index c601263..f3851a3 100644 (file)
@@ -6,15 +6,15 @@
  */
 
 if( window.addEventListener ){
-       X.Dom.Event = function( e ){
+       X.Dom.Event = function( e, xnode ){
                //this._event        = e;
                this.type          = e.type;
                
                //http://www.quirksmode.org/js/events_properties.html
-               this.target        = e.target.nodeType === 3 ? e.target.parentNode : e.target;// defeat Safari bug // xnode
+               this.target        = Node._getXNode( e.target.nodeType === 3 ? e.target.parentNode : e.target );// defeat Safari bug // xnode
                
-               this.currentTarget = e.currentTarget; // xnode
-               this.relatedTarget = e.relatedTarget; // xnode
+               this.currentTarget = xnode; // xnode
+               this.relatedTarget = Node._getXNode( e.relatedTarget ); // xnode
                this.eventPhase    = e.eventPhase;
                
                this.clientX       = e.clientX;
@@ -53,12 +53,8 @@ if( window.addEventListener ){
                        this.touches        = e.touches;
                        this.changedTouches = e.changedTouches;
                        this.targetTouches  = e.targetTouches;
-                       //this.altKey         = e.altKey;
-                       //this.ctrlKey        = e.ctrlKey;
                        this.metaKey        = e.metaKey;
-                       //this.shiftKey       = e.shiftKey;
-                       //this.type           = e.type;
-                       //this.target         = e.target;
+                       this.force          = e.force || e.webkitForce || 0;
                } else
                if( e.constructor === window.PointerEvent ){
                        // PointerEvent;
@@ -77,14 +73,15 @@ if( window.addEventListener ){
                };
        };
 } else {
-       X.Dom.Event = function( e, element ){
+       X.Dom.Event = function( e, xnode, element ){
                var btn;
                
                //this._event        = e;
                this.type          = e.type;
-               this.target        = e.srcElement; // xnode
-               this.currentTarget = element; // xnode
-               this.relatedTarget = e.formElement ? e.formElement : e.toElement; // xnode
+               this.target        = Node._getXNode( e.srcElement ); // xnode
+               if( this.target && this.target._xnodeType === 3 ) this.target = this.target.parent; // ie4 の fake Textnode がヒットしていないか?
+               this.currentTarget = xnode; // xnode
+               this.relatedTarget = Node._getXNode( e.formElement ? e.formElement : e.toElement ); // xnode
                this.eventPhase    = e.srcElement === element ? 2: 3;
                
                this.clientX       = e.clientX;
@@ -93,17 +90,25 @@ if( window.addEventListener ){
                //this.screenY       = e.screenY;
                
                if( X.Dom._root ){ // uuu...
+                       
                        this.pageX         = e.clientX + X.Dom._root.scrollLeft;
-                       this.pageY         = e.clientY + X.Dom._root.scrollTop;                 
+                       this.pageY         = e.clientY + X.Dom._root.scrollTop;
+                       
+                       // DOMAssistant 2.8.1
+                       //event.pageX = DOMAssistant.def(e.pageX)? e.pageX : (event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0));
+                       //event.pageY = DOMAssistant.def(e.pageY)? e.pageY : (event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0));                                     
                };
                
+
+               
                if( X.UA.IE && 5 <= X.UA.IE ){
                        this.offsetX       = e.offsetX; // イベントターゲット左上からの座標
                        this.offsetY       = e.offsetY;                 
-               } else {
-                       //this.offsetX       = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。
-                       //this.offsetY       = e.y - e.srcElement.offsetTop;    
-               };
+               }// else
+               //if( e.srcElement ){
+               //      this.offsetX       = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。
+               //      this.offsetY       = e.y - e.srcElement.offsetTop;      
+               //};
                
                this.keyCode       = e.keyCode;
                this.altKey        = e.altKey;
@@ -136,34 +141,37 @@ X.Dom.Event.XDOM_READY          = 2;
 X.Dom.Event.VIEW_ACTIVATE       = 3;
 X.Dom.Event.VIEW_DEACTIVATE     = 4;
 X.Dom.Event.VIEW_RESIZED        = 5;
+X.Dom.Event.BASE_FONT_RESIZED   = 6;
 // on_screen_keyboard_show
 // on_screen_keyboard_hide
-// before_commit_update
-X.Dom.Event.COMMIT_UPDATE       = 6;
+X.Dom.Event.BEFORE_UPDATE       = 7;
+X.Dom.Event.COMMIT_UPDATE       = 8;
 // hash_change
-// before_unload
-// X.Dom.Event.LOAD_BEFORE_STOP    = 7;
-X.Dom.Event.LOAD_ASSET_COMPLETE = 7;
-X.Dom.Event.LOAD_ASSET_ERROR    = 8;
+X.Dom.Event.BEFORE_UNLOAD       = 9;
+X.Dom.Event.UNLOAD              = 10;
+X.Dom.Event.LOAD_BEFORE_STOP    = 11;
+X.Dom.Event.LOAD_ASSET_STOP     = 12;
+X.Dom.Event.LOAD_ASSET_COMPLETE = 13;
+X.Dom.Event.LOAD_ASSET_ERROR    = 14;
 
-X.Dom.Event.ANIME_BEFORE_START  = 9;
-X.Dom.Event.ANIME_START         = 10;
-X.Dom.Event.ANIME               = 11;
-X.Dom.Event.ANIME_END           = 12;
-X.Dom.Event.ANIME_BEFORE_STOP   = 13; // xnode.stop() のみ、指定時間による停止では呼ばれない
-X.Dom.Event.ANIME_STOP          = 14;
-X.Dom.Event._LAST_EVENT         = 14; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値
+X.Dom.Event.ANIME_BEFORE_START  = 15;
+X.Dom.Event.ANIME_START         = 16;
+X.Dom.Event.ANIME               = 17;
+X.Dom.Event.ANIME_END           = 18;
+X.Dom.Event.ANIME_BEFORE_STOP   = 19; // xnode.stop() のみ、指定時間による停止では呼ばれない
+X.Dom.Event.ANIME_STOP          = 20;
+X.Dom.Event._LAST_EVENT         = 20; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値
 
 
-X.Dom.Node.prototype.listen = function( type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
+X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
        var elm;
        
-       if( this._xnodeType === 0 || this._xnodeType === 3 || !arg2 ) return this;
+       if( this._xnodeType === 0 || this._xnodeType === 3 || !arg1 ) return this;
        
        ( !this._listeners || !this._listeners[ type ] ) && this._addEvent( type );
        
-       return typeof arg2 === 'function' ?
-               X.EventDispatcher.prototype.listen.call( this, type, this, arg2, arg3 ) :
+       return typeof arg1 === 'function' ?
+               X.EventDispatcher.prototype.listen.call( this, type, this, arg1, arg2 ) :
                X.EventDispatcher.prototype.listen.apply( this, arguments );
 };
 
@@ -185,7 +193,7 @@ X.Dom.Node.prototype._addEvent =
                });
 
 
-X.Dom.Node.prototype.unlisten = function( type /* , arg2, arg3, arg4 */ ){
+X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){
        var list = this._listeners,
                l    = !this._dispatching && list && type !== undefined && list[ type ] && list[ type ].length;
        
@@ -199,13 +207,13 @@ X.Dom.Node.prototype.unlisten = function( type /* , arg2, arg3, arg4 */ ){
 X.Dom.Node.prototype._removeEvent =
        document.removeEventListener ?
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode;
                        if( !elm ) return;
                        elm.removeEventListener( type, this, false );
                }) :
        document.detachEvent ?
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode;
                        if( !elm ) return;
                        elm.detachEvent( 'on' + type, this._handleEvent );
                        if( !this._listeners ){
@@ -214,7 +222,7 @@ X.Dom.Node.prototype._removeEvent =
                        };
                }) :
                (function( type ){
-                       var elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
+                       var elm = this._rawNode || this._ie4getRawNode();
                        if( !elm ) return;
                        elm[ 'on' + type ] = X.emptyFunction;
                        elm[ 'on' + type ] = '';
@@ -228,7 +236,7 @@ X.Dom.Node.prototype._removeEvent =
 X.Dom.Node.prototype.handleEvent =
        document.removeEventListener ?
                (function( e ){
-                       var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e ) );
+                       var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e, this ) );
 
                        if( ret & X.Callback.STOP_PROPAGATION ){
                                e.stopPropagation();
@@ -239,7 +247,7 @@ X.Dom.Node.prototype.handleEvent =
                        };
                }) :
                (function(){
-                       var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this._rawNode ) );
+                       var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this, this._rawNode ) );
 
                        if( ret & X.Callback.STOP_PROPAGATION ){
                                event.cancelBubble = true;
@@ -299,9 +307,9 @@ if( X.UA.WebKit ){ // sniff
 X.Dom.Node._window.listenOnce( 'load', X.Dom._init );
 
 //
-X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.readyState ) } );
+X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.readyState ); } );
 
-X.Dom.listenOnce( X.Dom.Event.VIEW_RESIZED, function(e){ console.log( 'X.Dom VIEW_RESIZED ' + e.w + 'x' + e.h ) } );
+X.Dom.listenOnce( X.Dom.Event.VIEW_RESIZED, function(e){ console.log( 'X.Dom VIEW_RESIZED ' + e.w + 'x' + e.h ); } );
 
 
 /* --------------------------------------
@@ -309,120 +317,318 @@ X.Dom.listenOnce( X.Dom.Event.VIEW_RESIZED, function(e){ console.log( 'X.Dom VIE
  */
 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        
-       Node._html = document.documentElement ? new Node( document.documentElement ) : null;
-       //alert( document.all.tags('html')[ 0 ].tagName );
+       Node._html = document.documentElement ?
+                       new Node( document.documentElement ) :
+               document.getElementsByTagName ?
+                       new Node( document.getElementsByTagName( 'html' )[ 0 ] ) :
+               document.all ?
+                       new Node( document.all.tags( 'html' )[ 0 ] ) :
+                       null;
+
        var r    = Node.root = new Node( document.body ),
                body = r._rawNode,
-               createTree, n = 0, s;
+               createTree, xnodes, s, i, n = 0;
        r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' );
        
-       if( body.childNodes ){
-               /*
-                * body.innerHTML(可能なら outerHTML を使って属性を控える)
-                */
-               createTree = function( xnode, elm, skipCleanup ){
-                       var     children = elm.childNodes,
-                               i = 0,
-                               l = children.length,
-                               child, _xnode, text;
-                       for( ; i < children.length; ){
-                               child = children[ i ];
-                               switch( child.nodeType ){
-                                       case 1 :
-                                               if( !xnode._xnodes ) xnode._xnodes = [];
-                                               xnode._xnodes[ xnode._xnodes.length ] = _xnode = new Node( child );
-                                               // attr の取得
-                                               _xnode.parent = xnode;
-                                               child.childNodes.length && createTree( _xnode, child, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( child.tagName ) );//.toLowerCase() ) );
+       r._root  = Node._html._root = r;
+       r.parent = Node._html;
+       Node._html._xnodes = [ r ];
+       //r.width  = new Function( 'return X.Dom.getSize()[ 0 ]' );
+       //r.height = new Function( 'return X.Dom.getSize()[ 1 ]' );
+       
+       // todo: cleanup tree
+       
+       
+       
+       
+       body.childNodes && (function( elm, skip, head ){
+               var me         = arguments.callee,
+                       moveToHead = 'style,bgsound,area,base,meta'.split( ',' ),
+                       remove     = 'script,noscript,noframes,comment,!,noembed,nolayer'.split( ',' ),
+                       noncleanup = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ),
+                       nodes      = X.copyArray( elm.childNodes ),
+                       i          = 0,
+                       l          = nodes.length,
+                       node, tag, textNode, content;
+               for( ; i < l; ++i ){
+                       node = nodes[ i ];
+                       switch( node.nodeType ){
+                               case 1 :
+                                       tag = node.tagName.toLowerCase();
+                                       if( moveToHead.indexOf( tag ) !== -1 ){
+                                               head = head || document.getElementsByTagName( 'head' )[ 0 ];
+                                               head.appendChild( node );
+                                               continue;
+                                       } else
+                                       if( remove.indexOf( tag ) !== -1 ){
+                                               elm.removeChild( node );
+                                               continue;
+                                       } else {
+                                               // pre タグ以下はスペースの置換は行わない
+                                               node.childNodes && node.childNodes.length &&  me( node, skip || noncleanup.indexOf( tag ) !== -1, head );
+                                       };
+                                       textNode = false;                       
+                                       break;
+                               case 3 :
+                                       content = skip ? node.data : X.Dom.cleanupWhiteSpace( node.data );
+                                       //console.log( 'Delete space ' + node.data.length + ' => ' + content.length );
+                                       if( !textNode && content !== ' ' && content.length ){
+                                               node.data = content;
+                                               textNode  = node;
                                                break;
-                                       case 3 :
-                                               if( skipCleanup || ( ( text = child.data ) && ( text = X.Dom.cleanupWhiteSpace( text ) ) !== ' ' ) ){
-                                                       if( !skipCleanup ) child.data = text;
-                                                       if( !xnode._xnodes ) xnode._xnodes = [];
-                                                       xnode._xnodes[ xnode._xnodes.length ] = _xnode = new Node( child );
-                                                       _xnode.parent = xnode;
-                                                       break;                                                  
-                                               };
-                                       default :
-                                               elm.removeChild( child );
-                                               ++n;
-                                               continue;                                                               
-                               };
-                               ++i;
+                                       } else
+                                       if( textNode ){
+                                               textNode.data += content; // 直前が TextNode の場合 一本化して削除
+                                       };
+                                       // ブロック要素直下のスペースだけは削除??
+                               default :
+                                       //console.log( 'Remove type: ' + node.nodeType + ' value: ' + node.nodeValue );
+                                       elm.removeChild( node );
+                                       //++count;
                        };
                };
-               createTree( r, body );
-       } else
-       if( body.children ){
-               createTree = function( xnode, children, skipCleanup ){
-                       var i = 0,
-                               l = children.length,
-                               j = 0,
-                               child, _xnode, f, tag, text;
-
-                       xnode._ie4dirtyChildren = true;
-                       for( ; i < l; ++i ){
-                               child = children[ i ];
-                               if( child.tagName === '!' ) continue;
-                               f = false;
-                               while( j < xnode._xnodes.length ){
-                                       _xnode = xnode._xnodes[ j ];
-                                       _xnode.parent    = xnode;
-                                       _xnode._ie4dirty = true;
-                                       if( _xnode._xnodeType === 1 ){
-                                               tag = child.tagName; //.toLowerCase();
-                                               if( _xnode._tag !== tag ){
-                                                       alert( _xnode._tag + ' !== ' + child.tagName + ' * ' + child.outerHTML );
-                                               } else {
+       })( body );
+       
+       createTree =
+               body.childNodes ?
+                       (function( xnode, childNodes, skipCleanup ){
+                               var i = 0,
+                                       j = 0,
+                                       l = childNodes.length,
+                                       child, _xnode, f, tag, text, _xtext, doc;
+                               childNodes = X.copyArray( childNodes );
+
+                               for( ; i < l; ++i ){
+                                       child = childNodes[ i ];
+                                       tag   = child.tagName;
+                                       if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' ||
+                                               ( tag && tag.charAt( 0 ) === '/' ) ){
+                                               child.parentNode.removeChild( child );
+                                               continue;
+                                       };
+                                       f = false;
+                                       while( xnode._xnodes && j < xnode._xnodes.length ){
+                                               _xnode = xnode._xnodes[ j ];
+                                               _xnode.parent   = xnode;
+                                               
+                                               if( _xnode._xnodeType === 1 ){
+                                                       if( child.nodeType !== 1 ){
+                                                               if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
+                                                                       child.parentNode.removeChild( child );
+                                                                       break;
+                                                               };
+                                                               alert( '[' +xnode._tag + '>' +_xnode._tag + '] !== ' + child.nodeType + '\n' + child.data );
+                                                               ++j;
+                                                               continue;
+                                                       };
+                                                       if( _xnode._tag.toUpperCase() !== tag ){
+                                                               alert( '[' +xnode._tag + '>' +_xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + '\n' + child.outerHTML );
+                                                               ++j;
+                                                               continue;
+                                                       } else {
+                                                               _xnode._rawNode = child;
+                                                               //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){
+                                                                       if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );
+                                                                       _xnode._tag     = tag; // .toUpperCase()
+                                                               //};
+                                                               _xnode._root    = xnode._root;
+                                                               child.UID = _xnode._uid;
+                                                               if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処
+                                                                       //alert( '[' +xnode._tag + '>' + _xnode._tag + '] remove ... ' );
+                                                                       _xnode.destroy();
+                                                                       ++n;
+                                                                       continue;
+                                                               } else {
+                                                                       //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );
+                                                                       child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
+                                                               };
+                                                               _xtext = null;
+                                                               f = true;
+                                                               ++j;
+                                                               break;
+                                                       };
+                                               } else
+                                               if( _xnode._xnodeType === 3 ){
+                                                       if( child.nodeType !== 3 ){
+                                                               if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
+                                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
+                                                                       _xnode.destroy();
+                                                                       ++n;
+                                                                       continue;
+                                                               };
+                                                               alert(  xnode._tag + '>' + '"' + _xnode._text + '" !== ' + tag + '\n' + child.outerHTML );
+                                                               ++j;
+                                                               continue;
+                                                       };
+                                                       
                                                        _xnode._rawNode = child;
-                                                       //!( _xnode._id = child.getAttribute( 'id' ) ) && child.setAttribute( 'id', ( _xnode._ie4uid = 'ie4uid' + _xnode._uid ) );
-                                                       !_xnode._id && child.setAttribute( 'id', ( _xnode._ie4uid = 'ie4uid' + _xnode._uid ) );
-                                                       child.setAttribute( 'UID', '' + _xnode._uid );
-                                                       child.children.length && createTree( _xnode, child.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag ) );
-                                                       f = true;
+                                                       _xnode._root    = xnode._root;
+                                                       if( !skipCleanup ){
+                                                               if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
+                                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
+                                                                       _xnode.destroy();
+                                                                       ++n;
+                                                                       continue;
+                                                               };
+                                                               if( _xtext ){
+                                                                       _xtext.text( _xtext._text + text );
+                                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
+                                                                       _xnode.destroy();
+                                                                       ++n;
+                                                                       continue;
+                                                               } else {
+                                                                       //alert( xnode._tag + '>' + '"' + text + '"\n' + child.data );
+                                                                       _xnode.text( text );
+                                                               };
+                                                       } else
+                                                       if( _xtext ){
+                                                               _xtext.text( _xtext._text + _xnode.text );
+                                                               console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
+                                                               _xnode.destroy();
+                                                               ++n;
+                                                               continue;
+                                                       };
+                                                       _xtext = _xtext || _xnode;
                                                        ++j;
                                                        break;
+                                               } else {
+                                                       alert( 'no hit!' );
                                                };
-                                       } else
-                                       if( _xnode._xnodeType === 3 ){
-                                               if( !skipCleanup && ( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ) ){
-                                                       _xnode.remove();
-                                                       ++n;
+                                               ++j;
+
+                                       };                              
+                                       //if( !f ) alert( '**** ' + child.outerHTML );
+                               };
+                               while( xnode._xnodes && j < xnode._xnodes.length ){
+                                       _xnode = xnode._xnodes[ j ];
+                                       _xnode.parent = xnode;
+                                       _xnode.destroy();
+                                       ++n;
+                                       continue;
+                               };
+                       }) :
+               body.children ? 
+                       (function( xnode, children, skipCleanup ){
+                               var parent = xnode,
+                                       xnodes = parent._xnodes,
+                                       l      = xnodes && xnodes.length,
+                                       m      = children.length,
+                                       i = 0, j = 0, flag = 0,
+                                       elm, tag, xtext, text;
+                               //children = X.copyArray( children );
+
+                               for( ; i < xnodes.length; ++i ){
+                                       xnode = xnodes[ i ];
+                                       xnode.parent = parent;
+                                       
+                                       if( xnode._xnodeType === 3 ){
+                                               //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );
+                                               if( !skipCleanup ){
+                                                       if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
+                                                               xnode.destroy();
+                                                               --i;
+                                                       } else
+                                                       if( xtext ){
+                                                               //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );
+                                                               xtext.text( xtext._text + text );
+                                                               xnode.destroy();
+                                                               --i;
+                                                       } else {
+                                                               //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );
+                                                               xnode.text( text );
+                                                       };
+                                               } else
+                                               if( xtext ){
+                                                       //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );
+                                                       xtext.text( xtext._text + xnode._text );
+                                                       xnode.destroy();
+                                                       --i;
+                                               };
+                                               flag |= 4;
+                                               xtext = xtext || xnode;
+                                               continue;
+                                       };
+                                       
+                                       if( xnode._xnodeType !== 1 ){
+                                               //alert( xnode._xnodeType )
+                                               continue;
+                                       };
+                                       
+                                       for( ; j < m; ++j ){
+                                               elm = children[ j ];
+                                               tag = elm.tagName;
+                                               /*
+                                                * 未知のタグについては、閉じタグも含めてタグ名扱いになる
+                                                */
+                                               if( tag === '!' || tag.charAt( 0 ) === '/' ){
                                                        continue;
+                                               } else
+                                               if( xnode._tag !== tag ){
+                                                       alert( xnode._tag + ' ' + xnode._xnodeType + ' !== ' + tag + '\n' + elm.outerHTML );
+                                               } else {
+                                                       xnode._rawNode = elm;
+                                                       xnode._root    = parent._root;
+                                                       if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){
+                                                               xnode.destroy();
+                                                               --i;
+                                                               break;
+                                                       } else {
+                                                               xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
+                                                               
+                                                               !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );//( elm.id = 'ie4uid' + xnode._uid );
+                                                               elm.setAttribute( 'UID', xnode._uid );
+                                                               
+                                                               tag === 'INPUT' && (
+                                                                       !xnode._attrs ?
+                                                                               ( xnode._attrs = { type : 'text' } ) :
+                                                                               ( !xnode._attrs.type ) || ( xnode._attrs.type = 'text' )
+                                                               );
+                                                               flag |= 3;
+                                                               xtext = null;
+                                                               break;
+                                                       };
                                                };
-                                               if( !skipCleanup ) _xnode._text = text;
+                                       };
+                                       // for
+                                       if( !xnode._rawNode ){
+                                               alert( xnode._tag + ' ' + xnode._id + ' !== none...' );
+                                               --i;
                                        };
                                        ++j;
+                                       flag &= 6;
                                };
-                               if( !f ) alert( '**** ' + child.outerHTML );
-                       };
-               };
-               
-               r._xnodes = [];
-               Node.skipCreate = true;
-               /*
-                * http://support.microsoft.com/kb/812417/ja
-                * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。
-                * 
-                * body.innerHTML でなく、 body.outerHTML
-                */
-               r._xnodes.push.apply( r._xnodes, X.Dom.parse( body.innerHTML, true ) );
-               delete Node.skipCreate;
-               createTree( r, body.children );
-               //alert(n +  ' ' + body.innerHTML);
-               r._ie4reserveUpdate();
-               //alert(n +  ' ' + body.innerHTML);
-               r._ie4startUpdate();
-               alert(n +  ' ' + body.innerHTML);
-       } else {
-               
-       };
+                               // textNode がある
+                               ( flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );
+                               //( flag & 4 ) && ( parent._state |= X.Dom.Dirty.ONLY_TEXTNODE );
+                       }) : 0;
        
-       //r.width  = new Function( 'return X.Dom.getSize()[ 0 ]' );
-       //r.height = new Function( 'return X.Dom.getSize()[ 1 ]' );
+       r._xnodes = xnodes = [];
+       // body の属性値の取得
+
+       Node.skipCreate = true;
+       /*
+        * http://support.microsoft.com/kb/812417/ja
+        * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。
+        * 
+        * body.innerHTML でなく、 body.outerHTML にはできなかった、、、
+        */
+       xnodes.push.apply( xnodes, X.Dom.parse( body.innerHTML, true ) );
+       delete Node.skipCreate;
+       
+       //alert(n +  ' ' + body.innerHTML);
+       
+       createTree( r, body.childNodes || body.children );
+       //r._dirty = X.Dom.Dirty.IE4_TEXTNODE_FIX;
+       
+       i = xnodes.length;
+       Node._systemNode = s = r.create( 'div' ).className( 'hidden-sysyem-node' );
+       //alert( i + ' -> ' + xnodes.length );
+       
+       r._startUpdate();
+       
+       //xnodes.splice( xnodes.indexOf( s ), 1 ); // hide from api user
        
-       Node._systemNode = r.create( 'div' ).className( 'hidden-sysyem-node' );
-       r._xnodes.splice( r._xnodes.indexOf( Node._systemNode ), 1 ); // hide from api user
+       //alert(n +  ' ' + body.innerHTML);
 } );