OSDN Git Service

71ee2c1abb3e17e07464b8215877de936b30bd9a
[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, textarea ){
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                                 if( textarea ){
402                                         xnode.attr( 'value', xnode.text() );
403                                         for( l = xnode._xnodes.length; i < l; ++i ){
404                                                 xnode._xnodes[ i ].destroy();
405                                         };
406                                         xnode._xnodes.length = 0;
407                                         delete xnode._xnodes;
408                                         return;
409                                 };
410
411                                 for( ; i < l; ++i ){
412                                         child = childNodes[ i ];
413                                         tag   = child.tagName;
414                                         if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' || ( tag && tag.charAt( 0 ) === '/' ) ){
415                                                 child.parentNode.removeChild( child );
416                                                 continue;
417                                         };
418                                         f = false;
419                                         while( xnode._xnodes && j < xnode._xnodes.length ){
420                                                 _xnode = xnode._xnodes[ j ];
421                                                 _xnode.parent   = xnode;
422                                                 
423                                                 if( _xnode._xnodeType === 1 ){
424                                                         if( child.nodeType !== 1 ){
425                                                                 if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
426                                                                         child.parentNode.removeChild( child );
427                                                                         break;
428                                                                 };
429                                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + '] !== ' + child.nodeType + '\n' + child.data );
430                                                                 ++j;
431                                                                 continue;
432                                                         };
433                                                         if( _xnode._tag.toUpperCase() !== tag ){
434                                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + '\n' + child.outerHTML );
435                                                                 ++j;
436                                                                 continue;
437                                                         } else {
438                                                                 _xnode._rawNode = child;
439                                                                 //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){
440                                                                         if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );
441                                                                         _xnode._tag     = tag; // .toUpperCase()
442                                                                 //};
443                                                                 _xnode._root    = xnode._root;
444                                                                 child.UID = _xnode._uid;
445                                                                 if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処
446                                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + '] remove ... ' );
447                                                                         _xnode.destroy();
448                                                                         ++n;
449                                                                         continue;
450                                                                 } else {
451                                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );
452                                                                         child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );
453                                                                 };
454                                                                 _xtext = null;
455                                                                 f = true;
456                                                                 ++j;
457                                                                 break;
458                                                         };
459                                                 } else
460                                                 if( _xnode._xnodeType === 3 ){
461                                                         
462                                                         if( child.nodeType !== 3 ){
463                                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
464                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
465                                                                         _xnode.destroy();
466                                                                         ++n;
467                                                                         continue;
468                                                                 };
469                                                                 alert(  xnode._tag + '>' + '"' + _xnode._text + '" !== ' + tag + '\n' + child.outerHTML );
470                                                                 ++j;
471                                                                 continue;
472                                                         };
473                                                         
474                                                         _xnode._rawNode = child;
475                                                         _xnode._root    = xnode._root;
476                                                         if( !skipCleanup ){
477                                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
478                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );
479                                                                         _xnode.destroy();
480                                                                         ++n;
481                                                                         continue;
482                                                                 };
483                                                                 if( _xtext ){
484                                                                         _xtext.text( _xtext._text + text );
485                                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
486                                                                         _xnode.destroy();
487                                                                         ++n;
488                                                                         continue;
489                                                                 } else {
490                                                                         //alert( xnode._tag + '>' + '"' + text + '"\n' + child.data );
491                                                                         _xnode.text( text );
492                                                                 };
493                                                         } else
494                                                         if( _xtext ){
495                                                                 _xtext.text( _xtext._text + _xnode.text );
496                                                                 console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );
497                                                                 _xnode.destroy();
498                                                                 ++n;
499                                                                 continue;
500                                                         };
501                                                         _xtext = _xtext || _xnode;
502                                                         ++j;
503                                                         break;
504                                                 } else {
505                                                         alert( 'no hit!' );
506                                                 };
507                                                 ++j;
508
509                                         };                              
510                                         //if( !f ) alert( '**** ' + child.outerHTML );
511                                 };
512                                 while( xnode._xnodes && j < xnode._xnodes.length ){
513                                         _xnode = xnode._xnodes[ j ];
514                                         _xnode.parent = xnode;
515                                         _xnode.destroy();
516                                         ++n;
517                                         continue;
518                                 };
519                         }) :
520                 body.children ? 
521                         (function( xnode, children, skipCleanup, textarea ){
522                                 var parent = xnode,
523                                         xnodes = parent._xnodes,
524                                         l      = xnodes && xnodes.length,
525                                         m      = children.length,
526                                         i = 0, j = 0, flag = 0,
527                                         elm, tag, xtext, text;
528                                 //children = X.copyArray( children );
529
530                                 if( textarea ){
531                                         xnode.attr( 'value', xnode.text() );
532                                         for( l = xnode._xnodes.length; i < l; ++i ){
533                                                 xnode._xnodes[ i ].destroy();
534                                         };
535                                         xnode._xnodes.length = 0;
536                                         delete xnode._xnodes;
537                                         return;
538                                 };
539
540                                 for( ; i < xnodes.length; ++i ){
541                                         xnode = xnodes[ i ];
542                                         xnode.parent = parent;
543                                         
544                                         if( xnode._xnodeType === 3 ){
545                                                 //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );
546                                                 if( !skipCleanup ){
547                                                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
548                                                                 xnode.destroy();
549                                                                 --i;
550                                                         } else
551                                                         if( xtext ){
552                                                                 //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );
553                                                                 xtext.text( xtext._text + text );
554                                                                 xnode.destroy();
555                                                                 --i;
556                                                         } else {
557                                                                 //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );
558                                                                 xnode.text( text );
559                                                         };
560                                                 } else
561                                                 if( xtext ){
562                                                         //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );
563                                                         xtext.text( xtext._text + xnode._text );
564                                                         xnode.destroy();
565                                                         --i;
566                                                 };
567                                                 flag |= 4;
568                                                 xtext = xtext || xnode;
569                                                 continue;
570                                         };
571                                         
572                                         if( xnode._xnodeType !== 1 ){
573                                                 //alert( xnode._xnodeType )
574                                                 continue;
575                                         };
576                                         
577                                         for( ; j < m; ++j ){
578                                                 elm = children[ j ];
579                                                 tag = elm.tagName;
580                                                 /*
581                                                  * 未知のタグについては、閉じタグも含めてタグ名扱いになる
582                                                  */
583                                                 if( tag === '!' || tag.charAt( 0 ) === '/' ){
584                                                         continue;
585                                                 } else
586                                                 if( xnode._tag !== tag ){
587                                                         alert( xnode._tag + ' ' + xnode._xnodeType + ' !== ' + tag + '\n' + elm.outerHTML );
588                                                 } else {
589                                                         xnode._rawNode = elm;
590                                                         xnode._root    = parent._root;
591                                                         if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){
592                                                                 xnode.destroy();
593                                                                 --i;
594                                                                 break;
595                                                         } else {
596                                                                 xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );
597                                                                 
598                                                                 !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );//( elm.id = 'ie4uid' + xnode._uid );
599                                                                 elm.setAttribute( 'UID', xnode._uid );
600                                                                 
601                                                                 tag === 'INPUT' && (
602                                                                         !xnode._attrs ?
603                                                                                 ( xnode._attrs = { type : 'text' } ) :
604                                                                                 ( !xnode._attrs.type ) || ( xnode._attrs.type = 'text' )
605                                                                 );
606                                                                 flag |= 3;
607                                                                 xtext = null;
608                                                                 break;
609                                                         };
610                                                 };
611                                         };
612                                         // for
613                                         if( !xnode._rawNode ){
614                                                 alert( xnode._tag + ' ' + xnode._id + ' !== none...' );
615                                                 --i;
616                                         };
617                                         ++j;
618                                         flag &= 6;
619                                 };
620                                 // textNode がある
621                                 ( flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );
622                                 //( flag & 4 ) && ( parent._state |= X.Dom.Dirty.ONLY_TEXTNODE );
623                         }) : 0;
624         
625         r._xnodes = xnodes = [];
626         // body の属性値の取得
627
628         Node.skipCreate = true;
629         /*
630          * http://support.microsoft.com/kb/812417/ja
631          * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。
632          * 
633          * body.innerHTML でなく、 body.outerHTML にはできなかった、、、
634          */
635         xnodes.push.apply( xnodes, X.Dom.parse( body.innerHTML, true ) );
636         delete Node.skipCreate;
637         
638         createTree( r, body.childNodes || body.children );
639         
640         i = xnodes.length;
641         Node._systemNode = s = r.create( 'div' ).className( 'hidden-sysyem-node' );
642         //alert( i + ' -> ' + xnodes.length );
643         
644         Node._fontSizeNode = r.create( 'div' ).className( 'hidden-sysyem-node' ).cssText( 'line-height:1;height:1em;' ).text( 'X' );
645         
646         r.appendAt( 0, Node._systemNode, Node._fontSizeNode );
647         
648         r._startUpdate();
649         
650         //xnodes.splice( xnodes.indexOf( s ), 1 ); // hide from api user
651         
652         //alert(n +  ' ' + body.innerHTML);
653         
654         X.Timer.add( 200, X.Dom.Event._detectFontSize );
655 } );
656
657 Node._fontSizeNode = null;
658
659 X.Dom.Event._lastFontSize = 0;
660 X.Dom.Event._detectFontSize = function(){
661         var size = Node._fontSizeNode._rawNode.offsetHeight;
662         if( X.Dom.Event._lastFontSize !== size ){
663                 X.Dom.Event._lastFontSize && X.Dom.asyncDispatch( 0, { type : X.Dom.Event.BASE_FONT_RESIZED, size : size } );
664                 X.Dom.Event._lastFontSize = size;
665         };
666 };