OSDN Git Service

Version 0.6.25, bugfix.
[pettanr/clientJs.git] / 0.6.x / js / dom / 12_XDomEvent.js
1 /**
2  * use X.Callback
3  * 
4  * http://d.hatena.ne.jp/uupaa/20100430/1272561922
5  * 
6  */
7
8 if( window.addEventListener ){
9         X.Dom.Event = function( e, xnode ){
10                 //this._event        = e;
11                 this.type          = e.type;
12                 
13                 //http://www.quirksmode.org/js/events_properties.html
14                 this.target        = Node._getXNode( e.target.nodeType === 3 ? e.target.parentNode : e.target );// defeat Safari bug // xnode
15                 
16                 this.currentTarget = xnode; // xnode
17                 this.relatedTarget = Node._getXNode( e.relatedTarget ); // xnode
18                 this.eventPhase    = e.eventPhase;
19                 
20                 this.clientX       = e.clientX;
21                 this.clientY       = e.clientY;
22                 //this.screenX       = e.screenX;
23                 //this.screenY       = e.screenY;
24                 this.pageX         = e.pageX;
25                 this.pageY         = e.pageY;
26                 this.offsetX       = e.offsetX || e.layerX;
27                 this.offsetY       = e.offsetY || e.layerY;
28                 
29                 this.keyCode       = e.keyCode;
30                 this.altKey        = e.altKey;
31                 this.ctrlKey       = e.ctrlKey;
32                 this.shiftKey      = e.shiftKey;
33                 
34                 // http://www.programming-magic.com/20090127231544/
35                 this.which         = e.which || ( e.button + 1 ); // 左:1, 中:2, 右:3
36                 
37                 // https://developer.mozilla.org/ja/docs/DOM/DOM_event_reference/mousewheel
38                 if( e.wheelDeltaY !== undefined ){
39                         this.wheelDeltaX = e.wheelDeltaX / 12;
40                         this.wheelDeltaY = e.wheelDeltaY / 12;
41                 } else
42                 if( e.wheelDelta !== undefined ){
43                         this.wheelDeltaX = this.wheelDeltaY = e.wheelDelta / 12;
44                 } else
45                 if( e.detail !== undefined ){
46                         this.wheelDeltaX = this.wheelDeltaY = - e.detail * 3;
47                 } else {
48                         this.wheelDeltaX = this.wheelDeltaY = 0;
49                 };
50                 
51                 if( e.constructor === window.TouchEvent ){
52                         // TouchEvent
53                         this.touches        = e.touches;
54                         this.changedTouches = e.changedTouches;
55                         this.targetTouches  = e.targetTouches;
56                         this.metaKey        = e.metaKey;
57                         this.force          = e.force || e.webkitForce || 0;
58                 } else
59                 if( e.constructor === window.PointerEvent ){
60                         // PointerEvent;
61                         this.currentPoint  = e.currentPoint;
62                         this.width         = e.width;
63                         this.height        = e.height;
64                         this.timeStamp     = e.timeStamp;
65                         this.hwTimestamp   = e.hwTimestamp;
66                         this.intermediatePoints = e.intermediatePoints;
67                         this.isPrimary     = e.isPrimary;
68                         this.pointerId     = e.pointerId;
69                         this.pointerType   = e.pointerType;
70                         this.pressure      = e.pressure;
71                         this.tiltX         = e.tiltX;
72                         this.tiltY         = e.tiltY;
73                 };
74         };
75 } else {
76         X.Dom.Event = function( e, xnode, element ){
77                 var btn;
78                 
79                 //this._event        = e;
80                 this.type          = e.type;
81                 this.target        = Node._getXNode( e.srcElement ); // xnode
82                 if( this.target && this.target._xnodeType === 3 ) this.target = this.target.parent; // ie4 の fake Textnode がヒットしていないか?
83                 this.currentTarget = xnode; // xnode
84                 this.relatedTarget = Node._getXNode( e.formElement ? e.formElement : e.toElement ); // xnode
85                 this.eventPhase    = e.srcElement === element ? 2: 3;
86                 
87                 this.clientX       = e.clientX;
88                 this.clientY       = e.clientY;
89                 //this.screenX       = e.screenX;
90                 //this.screenY       = e.screenY;
91                 
92                 if( X.Dom._root ){ // uuu...
93                         
94                         this.pageX         = e.clientX + X.Dom._root.scrollLeft;
95                         this.pageY         = e.clientY + X.Dom._root.scrollTop;
96                         
97                         // DOMAssistant 2.8.1
98                         //event.pageX = DOMAssistant.def(e.pageX)? e.pageX : (event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0));
99                         //event.pageY = DOMAssistant.def(e.pageY)? e.pageY : (event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0));                                     
100                 };
101                 
102
103                 
104                 if( X.UA.IE && 5 <= X.UA.IE ){
105                         this.offsetX       = e.offsetX; // イベントターゲット左上からの座標
106                         this.offsetY       = e.offsetY;                 
107                 }// else
108                 //if( e.srcElement ){
109                 //      this.offsetX       = e.x - e.srcElement.offsetLeft; // e.x はイベント発生要素の親要素を基準にした座標。
110                 //      this.offsetY       = e.y - e.srcElement.offsetTop;      
111                 //};
112                 
113                 this.keyCode       = e.keyCode;
114                 this.altKey        = e.altKey;
115                 this.ctrlKey       = e.ctrlKey;
116                 this.shiftKey      = e.shiftKey;
117                 
118                 // http://www.programming-magic.com/20090127231544/
119                 switch( this.type ){
120                         case 'click'    :
121                         case 'dblclick' :
122                                 this.which = 1;
123                                 break;
124                         case 'contextmenu' :
125                                 this.which = 3;
126                                 break;
127                         default :
128                                 btn = e.button;
129                                 this.which =
130                                         btn & 1 ? 1 :
131                                         btn & 4 ? 2 :
132                                         btn & 2 ? 3 : 0; // 左:1(click:0), 中:4, 右:2
133                 };
134                 this.wheelDeltaX = this.wheelDeltaY = e.wheelDelta / 12;
135         };
136 };
137
138 X.Dom.Event.DOM_PRE_INIT        = 0;
139 X.Dom.Event.DOM_INIT            = 1;
140 X.Dom.Event.XDOM_READY          = 2;
141 X.Dom.Event.VIEW_ACTIVATE       = 3;
142 X.Dom.Event.VIEW_DEACTIVATE     = 4;
143 X.Dom.Event.VIEW_RESIZED        = 5;
144 X.Dom.Event.BASE_FONT_RESIZED   = 6;
145 // on_screen_keyboard_show
146 // on_screen_keyboard_hide
147 X.Dom.Event.BEFORE_UPDATE       = 7;
148 X.Dom.Event.COMMIT_UPDATE       = 8;
149 // hash_change
150 X.Dom.Event.BEFORE_UNLOAD       = 9;
151 X.Dom.Event.UNLOAD              = 10;
152 X.Dom.Event.LOAD_BEFORE_STOP    = 11;
153 X.Dom.Event.LOAD_ASSET_STOP     = 12;
154 X.Dom.Event.LOAD_ASSET_COMPLETE = 13;
155 X.Dom.Event.LOAD_ASSET_ERROR    = 14;
156
157 X.Dom.Event.ANIME_BEFORE_START  = 15;
158 X.Dom.Event.ANIME_START         = 16;
159 X.Dom.Event.ANIME               = 17;
160 X.Dom.Event.ANIME_END           = 18;
161 X.Dom.Event.ANIME_BEFORE_STOP   = 19; // xnode.stop() のみ、指定時間による停止では呼ばれない
162 X.Dom.Event.ANIME_STOP          = 20;
163 X.Dom.Event._LAST_EVENT         = 20; // ここに書いてあるイベントの最後の値 X.Dom.Event.ANIME_STOP と同じ値
164
165
166 X.Dom.Node.prototype.listen = function( type, arg1, arg2, arg3 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
167         var elm;
168         
169         if( this._xnodeType === 0 || this._xnodeType === 3 || !arg1 ) return this;
170         
171         ( !this._listeners || !this._listeners[ type ] ) && this._addEvent( type );
172         
173         return typeof arg1 === 'function' ?
174                 X.EventDispatcher.prototype.listen.call( this, type, this, arg1, arg2 ) :
175                 X.EventDispatcher.prototype.listen.apply( this, arguments );
176 };
177
178 X.Dom.Node.prototype._addEvent =
179         document.removeEventListener ?
180                 (function( type ){
181                         this._rawNode && this._rawNode.addEventListener( type, this, false );
182                 }) :
183         document.detachEvent ?
184                 (function( type ){
185                         if( !this._rawNode ) return;
186                         this._handleEvent = this._handleEvent || X.Callback.create( this );
187                         this._rawNode.attachEvent( 'on' + type, this._handleEvent );
188                 }) :
189                 (function( type ){
190                         var elm = this._ie4getRawNode();
191                         if( !elm ) return;
192                         this._handleEvent = elm[ 'on' + type ] = this._handleEvent || X.Callback.create( this );
193                 });
194
195
196 X.Dom.Node.prototype.unlisten = function( type /* , arg1, arg2, arg3 */ ){
197         var list = this._listeners,
198                 l    = !this._dispatching && list && type !== undefined && list[ type ] && list[ type ].length;
199         
200         X.EventDispatcher.prototype.unlisten.apply( this, arguments );
201         
202         l && !list[ type ] && this._removeEvent( type );
203         
204         return this;
205 };
206
207 X.Dom.Node.prototype._removeEvent =
208         document.removeEventListener ?
209                 (function( type ){
210                         var elm = this._rawNode;
211                         if( !elm ) return;
212                         elm.removeEventListener( type, this, false );
213                 }) :
214         document.detachEvent ?
215                 (function( type ){
216                         var elm = this._rawNode;
217                         if( !elm ) return;
218                         elm.detachEvent( 'on' + type, this._handleEvent );
219                         if( !this._listeners ){
220                                 X.Callback._correct( this._handleEvent );
221                                 delete this._handleEvent;
222                         };
223                 }) :
224                 (function( type ){
225                         var elm = this._rawNode || this._ie4getRawNode();
226                         if( !elm ) return;
227                         elm[ 'on' + type ] = X.emptyFunction;
228                         elm[ 'on' + type ] = '';
229                         if( !this._listeners ){
230                                 X.Callback._correct( this._handleEvent );
231                                 delete this._handleEvent;
232                         };
233                 });
234
235
236 X.Dom.Node.prototype.handleEvent =
237         document.removeEventListener ?
238                 (function( e ){
239                         var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( e, this ) );
240
241                         if( ret & X.Callback.STOP_PROPAGATION ){
242                                 e.stopPropagation();
243                         };
244                         if( ret & X.Callback.PREVENT_DEFAULT ){
245                                 e.preventDefault();
246                                 return false;
247                         };
248                 }) :
249                 (function(){
250                         var ret = X.EventDispatcher.prototype.dispatch.call( this, new X.Dom.Event( event, this, this._rawNode ) );
251
252                         if( ret & X.Callback.STOP_PROPAGATION ){
253                                 event.cancelBubble = true;
254                         };
255                         if( ret & X.Callback.PREVENT_DEFAULT ){
256                                 return event.returnValue = false;
257                         };
258                 });
259
260
261 // イベントの退避、dom が画面から抜かれる場合に実施しておく
262 X.Dom.Node.prototype._migrateEvent = function(){
263         var hash = this._listeners,
264                 type;
265         if( !hash ) return;
266         for( type in hash ){
267                 this._removeEvent( type );
268         };
269 };
270
271 // 退避したイベントの復帰
272 X.Dom.Node.prototype._restoreEvent = function(){
273         var hash = this._listeners,
274                 type;
275         if( !hash ) return;
276         for( type in hash ){
277                 this._addEvent( type );
278         };
279 };
280
281
282
283 /* -----------------------------------------------
284  * Document Ready
285  *  Dean Edwards/Matthias Miller/John Resig
286  */
287 /* for ie9+/Mozilla/Opera9 */
288 if( document.addEventListener ){
289         X.Dom.Node._document.listenOnce( 'DOMContentLoaded', X.Dom._init );
290 } else
291 if( 5 <= X.UA.IE && X.inHead ){
292         // if this script in Head
293         document.write( "<script id=__ie_onload defer src=javascript:void(0)><\/script>" );
294         X.Dom._script = document.getElementById( "__ie_onload" );
295         X.Dom._script.onreadystatechange = function(){
296                 this.readyState === 'complete' && X.Dom._init();
297         };
298 } else
299 if( X.UA.WebKit ){ // sniff
300         X.Timer.add( 10, function(){
301                 if( !X.Dom._init ) return X.Callback.UN_LISTEN;
302                 if( 'loaded|complete'.indexOf( document.readyState ) !== -1 ) return X.Dom._init();
303         });
304 };
305
306 /* for other browsers */
307 X.Dom.Node._window.listenOnce( 'load', X.Dom._init );
308
309 //
310 X.Dom.listenOnce( X.Dom.Event.XDOM_READY, function(e){ console.log( 'X.Dom XDomReady ' + X.Dom.readyState ); } );
311
312 X.Dom.listenOnce( X.Dom.Event.VIEW_RESIZED, function(e){ console.log( 'X.Dom VIEW_RESIZED ' + e.w + 'x' + e.h ); } );
313
314
315 /* --------------------------------------
316  *  load
317  */
318 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
319         
320         Node._html = document.documentElement ?
321                         new Node( document.documentElement ) :
322                 document.getElementsByTagName ?
323                         new Node( document.getElementsByTagName( 'html' )[ 0 ] ) :
324                 document.all ?
325                         new Node( document.all.tags( 'html' )[ 0 ] ) :
326                         null;
327
328         var r    = Node.root = new Node( document.body ),
329                 body = r._rawNode,
330                 createTree, xnodes, s, i, n = 0;
331         r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' );
332         
333         r._root  = Node._html._root = r;
334         r.parent = Node._html;
335         Node._html._xnodes = [ r ];
336         //r.width  = new Function( 'return X.Dom.getSize()[ 0 ]' );
337         //r.height = new Function( 'return X.Dom.getSize()[ 1 ]' );
338         
339         // todo: cleanup tree
340         
341         
342         
343         
344         body.childNodes && (function( elm, skip, head ){
345                 var me         = arguments.callee,
346                         moveToHead = 'style,bgsound,area,base,meta'.split( ',' ),
347                         remove     = 'script,noscript,noframes,comment,!,noembed,nolayer'.split( ',' ),
348                         noncleanup = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ),
349                         nodes      = X.copyArray( elm.childNodes ),
350                         i          = 0,
351                         l          = nodes.length,
352                         node, tag, textNode, content;
353                 for( ; i < l; ++i ){
354                         node = nodes[ i ];
355                         switch( node.nodeType ){
356                                 case 1 :
357                                         tag = node.tagName.toLowerCase();
358                                         if( moveToHead.indexOf( tag ) !== -1 ){
359                                                 head = head || document.getElementsByTagName( 'head' )[ 0 ];
360                                                 head.appendChild( node );
361                                                 continue;
362                                         } else
363                                         if( remove.indexOf( tag ) !== -1 ){
364                                                 elm.removeChild( node );
365                                                 continue;
366                                         } else {
367                                                 // pre タグ以下はスペースの置換は行わない
368                                                 node.childNodes && node.childNodes.length &&  me( node, skip || noncleanup.indexOf( tag ) !== -1, head );
369                                         };
370                                         textNode = false;                       
371                                         break;
372                                 case 3 :
373                                         content = skip ? node.data : X.Dom.cleanupWhiteSpace( node.data );
374                                         //console.log( 'Delete space ' + node.data.length + ' => ' + content.length );
375                                         if( !textNode && content !== ' ' && content.length ){
376                                                 node.data = content;
377                                                 textNode  = node;
378                                                 break;
379                                         } else
380                                         if( textNode ){
381                                                 textNode.data += content; // 直前が TextNode の場合 一本化して削除
382                                         };
383                                         // ブロック要素直下のスペースだけは削除??
384                                 default :
385                                         //console.log( 'Remove type: ' + node.nodeType + ' value: ' + node.nodeValue );
386                                         elm.removeChild( node );
387                                         //++count;
388                         };
389                 };
390         })( body );
391         
392         createTree =
393                 body.childNodes ?
394                         (function( xnode, childNodes, skipCleanup ){
395                                 var i = 0,
396                                         j = 0,
397                                         l = childNodes.length,
398                                         child, _xnode, f, tag, text, _xtext, doc;
399                                 childNodes = X.copyArray( childNodes );
400
401                                 for( ; i < l; ++i ){
402                                         child = childNodes[ i ];
403                                         tag   = child.tagName;
404                                         if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' ||
405                                                 ( tag && tag.charAt( 0 ) === '/' ) ){
406                                                 child.parentNode.removeChild( child );
407                                                 continue;
408                                         };
409                                         f = false;
410                                         while( xnode._xnodes && j < xnode._xnodes.length ){
411                                                 _xnode = xnode._xnodes[ j ];
412                                                 _xnode.parent   = xnode;
413                                                 
414                                                 if( _xnode._xnodeType === 1 ){
415                                                         if( child.nodeType !== 1 ){
416                                                                 if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
417                                                                         child.parentNode.removeChild( child );
418                                                                         break;
419                                                                 };
420                                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + '] !== ' + child.nodeType + '\n' + child.data );
421                                                                 ++j;
422                                                                 continue;
423                                                         };
424                                                         if( _xnode._tag.toUpperCase() !== tag ){
425                                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + '\n' + child.outerHTML );
426                                                                 ++j;
427                                                                 continue;
428                                                         } else {
429                                                                 _xnode._rawNode = child;
430                                                                 //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){
431                                                                         if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );
432                                                                         _xnode._tag     = tag; // .toUpperCase()
433                                                                 //};
434                                                                 _xnode._root    = xnode._root;
435                                                                 child.UID = _xnode._uid;
436                                                                 if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処
437                                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + '] remove ... ' );
438                                                                         _xnode.destroy();
439                                                                         ++n;
440                                                                         continue;
441                                                                 } else {
442                                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );
443                                                                         child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
444                                                                 };
445                                                                 _xtext = null;
446                                                                 f = true;
447                                                                 ++j;
448                                                                 break;
449                                                         };
450                                                 } else
451                                                 if( _xnode._xnodeType === 3 ){
452                                                         if( child.nodeType !== 3 ){
453                                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
454                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
455                                                                         _xnode.destroy();
456                                                                         ++n;
457                                                                         continue;
458                                                                 };
459                                                                 alert(  xnode._tag + '>' + '"' + _xnode._text + '" !== ' + tag + '\n' + child.outerHTML );
460                                                                 ++j;
461                                                                 continue;
462                                                         };
463                                                         
464                                                         _xnode._rawNode = child;
465                                                         _xnode._root    = xnode._root;
466                                                         if( !skipCleanup ){
467                                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
468                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
469                                                                         _xnode.destroy();
470                                                                         ++n;
471                                                                         continue;
472                                                                 };
473                                                                 if( _xtext ){
474                                                                         _xtext.text( _xtext._text + text );
475                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
476                                                                         _xnode.destroy();
477                                                                         ++n;
478                                                                         continue;
479                                                                 } else {
480                                                                         //alert( xnode._tag + '>' + '"' + text + '"\n' + child.data );
481                                                                         _xnode.text( text );
482                                                                 };
483                                                         } else
484                                                         if( _xtext ){
485                                                                 _xtext.text( _xtext._text + _xnode.text );
486                                                                 console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
487                                                                 _xnode.destroy();
488                                                                 ++n;
489                                                                 continue;
490                                                         };
491                                                         _xtext = _xtext || _xnode;
492                                                         ++j;
493                                                         break;
494                                                 } else {
495                                                         alert( 'no hit!' );
496                                                 };
497                                                 ++j;
498
499                                         };                              
500                                         //if( !f ) alert( '**** ' + child.outerHTML );
501                                 };
502                                 while( xnode._xnodes && j < xnode._xnodes.length ){
503                                         _xnode = xnode._xnodes[ j ];
504                                         _xnode.parent = xnode;
505                                         _xnode.destroy();
506                                         ++n;
507                                         continue;
508                                 };
509                         }) :
510                 body.children ? 
511                         (function( xnode, children, skipCleanup ){
512                                 var parent = xnode,
513                                         xnodes = parent._xnodes,
514                                         l      = xnodes && xnodes.length,
515                                         m      = children.length,
516                                         i = 0, j = 0, flag = 0,
517                                         elm, tag, xtext, text;
518                                 //children = X.copyArray( children );
519
520                                 for( ; i < xnodes.length; ++i ){
521                                         xnode = xnodes[ i ];
522                                         xnode.parent = parent;
523                                         
524                                         if( xnode._xnodeType === 3 ){
525                                                 //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );
526                                                 if( !skipCleanup ){
527                                                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
528                                                                 xnode.destroy();
529                                                                 --i;
530                                                         } else
531                                                         if( xtext ){
532                                                                 //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );
533                                                                 xtext.text( xtext._text + text );
534                                                                 xnode.destroy();
535                                                                 --i;
536                                                         } else {
537                                                                 //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );
538                                                                 xnode.text( text );
539                                                         };
540                                                 } else
541                                                 if( xtext ){
542                                                         //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );
543                                                         xtext.text( xtext._text + xnode._text );
544                                                         xnode.destroy();
545                                                         --i;
546                                                 };
547                                                 flag |= 4;
548                                                 xtext = xtext || xnode;
549                                                 continue;
550                                         };
551                                         
552                                         if( xnode._xnodeType !== 1 ){
553                                                 //alert( xnode._xnodeType )
554                                                 continue;
555                                         };
556                                         
557                                         for( ; j < m; ++j ){
558                                                 elm = children[ j ];
559                                                 tag = elm.tagName;
560                                                 /*
561                                                  * 未知のタグについては、閉じタグも含めてタグ名扱いになる
562                                                  */
563                                                 if( tag === '!' || tag.charAt( 0 ) === '/' ){
564                                                         continue;
565                                                 } else
566                                                 if( xnode._tag !== tag ){
567                                                         alert( xnode._tag + ' ' + xnode._xnodeType + ' !== ' + tag + '\n' + elm.outerHTML );
568                                                 } else {
569                                                         xnode._rawNode = elm;
570                                                         xnode._root    = parent._root;
571                                                         if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){
572                                                                 xnode.destroy();
573                                                                 --i;
574                                                                 break;
575                                                         } else {
576                                                                 xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
577                                                                 
578                                                                 !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );//( elm.id = 'ie4uid' + xnode._uid );
579                                                                 elm.setAttribute( 'UID', xnode._uid );
580                                                                 
581                                                                 tag === 'INPUT' && (
582                                                                         !xnode._attrs ?
583                                                                                 ( xnode._attrs = { type : 'text' } ) :
584                                                                                 ( !xnode._attrs.type ) || ( xnode._attrs.type = 'text' )
585                                                                 );
586                                                                 flag |= 3;
587                                                                 xtext = null;
588                                                                 break;
589                                                         };
590                                                 };
591                                         };
592                                         // for
593                                         if( !xnode._rawNode ){
594                                                 alert( xnode._tag + ' ' + xnode._id + ' !== none...' );
595                                                 --i;
596                                         };
597                                         ++j;
598                                         flag &= 6;
599                                 };
600                                 // textNode がある
601                                 ( flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );
602                                 //( flag & 4 ) && ( parent._state |= X.Dom.Dirty.ONLY_TEXTNODE );
603                         }) : 0;
604         
605         r._xnodes = xnodes = [];
606         // body の属性値の取得
607
608         Node.skipCreate = true;
609         /*
610          * http://support.microsoft.com/kb/812417/ja
611          * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。
612          * 
613          * body.innerHTML でなく、 body.outerHTML にはできなかった、、、
614          */
615         xnodes.push.apply( xnodes, X.Dom.parse( body.innerHTML, true ) );
616         delete Node.skipCreate;
617         
618         //alert(n +  ' ' + body.innerHTML);
619         
620         createTree( r, body.childNodes || body.children );
621         //r._dirty = X.Dom.Dirty.IE4_TEXTNODE_FIX;
622         
623         i = xnodes.length;
624         Node._systemNode = s = r.create( 'div' ).className( 'hidden-sysyem-node' );
625         //alert( i + ' -> ' + xnodes.length );
626         
627         r._startUpdate();
628         
629         //xnodes.splice( xnodes.indexOf( s ), 1 ); // hide from api user
630         
631         //alert(n +  ' ' + body.innerHTML);
632 } );
633
634