OSDN Git Service

Version 0.6.32, async X.Dom.Builder.
[pettanr/clientJs.git] / 0.6.x / js / dom / 22_XDomBuilder.js
1 \r
2 X.Dom._useBuilder = true;\r
3 \r
4 /* --------------------------------------\r
5  *  通常のwebページに対して使用する場合、dom ready で dom tree を写し取るために使う.\r
6  *  完全にワンページアプリで<body/>が空な場合、このコードはビルドに含める必要はない\r
7  */\r
8 X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT,\r
9         document.getElementById ?\r
10 (function(){\r
11         var r    = Node.root,\r
12                 body = r._rawNode,\r
13                 i, n = 0;\r
14         \r
15         // cleanup tree \r
16         (function( elm, skip, head ){\r
17                 var me         = arguments.callee,\r
18                         moveToHead = 'style,bgsound,area,base,meta'.split( ',' ),\r
19                         remove     = 'script,noscript,noframes,comment,!,noembed,nolayer'.split( ',' ),\r
20                         noncleanup = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ),\r
21                         nodes      = X.copyArray( elm.childNodes ),\r
22                         i          = 0,\r
23                         l          = nodes.length,\r
24                         node, tag, textNode, content;\r
25                 for( ; i < l; ++i ){\r
26                         node = nodes[ i ];\r
27                         switch( node.nodeType ){\r
28                                 case 1 :\r
29                                         tag = node.tagName.toLowerCase();\r
30                                         if( moveToHead.indexOf( tag ) !== -1 ){\r
31                                                 head = head || document.getElementsByTagName( 'head' )[ 0 ];\r
32                                                 head.appendChild( node );\r
33                                                 continue;\r
34                                         } else\r
35                                         if( remove.indexOf( tag ) !== -1 ){\r
36                                                 elm.removeChild( node );\r
37                                                 continue;\r
38                                         } else {\r
39                                                 // pre タグ以下はスペースの置換は行わない\r
40                                                 node.childNodes && node.childNodes.length &&  me( node, skip || noncleanup.indexOf( tag ) !== -1, head );\r
41                                         };\r
42                                         textNode = false;       \r
43                                         break;\r
44                                 case 3 :\r
45                                         content = skip ? node.data : X.Dom.cleanupWhiteSpace( node.data );\r
46                                         //console.log( 'Delete space ' + node.data.length + ' => ' + content.length );\r
47                                         if( !textNode && content !== ' ' && content.length ){\r
48                                                 node.data = content;\r
49                                                 textNode  = node;\r
50                                                 break;\r
51                                         } else\r
52                                         if( textNode ){\r
53                                                 textNode.data += content; // 直前が TextNode の場合 一本化して削除\r
54                                         };\r
55                                         // ブロック要素直下のスペースだけは削除??\r
56                                 default :\r
57                                         //console.log( 'Remove type: ' + node.nodeType + ' value: ' + node.nodeValue );\r
58                                         elm.removeChild( node );\r
59                                         //++count;\r
60                         };\r
61                 };\r
62         })( body );\r
63         \r
64         function createTree( xnode, childNodes, skipCleanup, textarea ){\r
65                 var i = 0,\r
66                         j = 0,\r
67                         l = childNodes.length,\r
68                         child, _xnode, f, tag, text, _xtext, doc;\r
69                 childNodes = X.copyArray( childNodes );\r
70 \r
71                 if( textarea ){\r
72                         xnode.attr( 'value', xnode.html() ).empty();\r
73                         return;\r
74                 };\r
75 \r
76                 for( ; i < l; ++i ){\r
77                         child = childNodes[ i ];\r
78                         tag   = child.tagName;\r
79                         if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' || ( tag && tag.charAt( 0 ) === '/' ) ){\r
80                                 child.parentNode.removeChild( child );\r
81                                 continue;\r
82                         };\r
83                         f = false;\r
84                         while( xnode._xnodes && j < xnode._xnodes.length ){\r
85                                 _xnode = xnode._xnodes[ j ];\r
86                                 _xnode.parent   = xnode;\r
87                                 \r
88                                 if( _xnode._xnodeType === 1 ){\r
89                                         if( child.nodeType !== 1 ){\r
90                                                 if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
91                                                         child.parentNode.removeChild( child );\r
92                                                         break;\r
93                                                 };\r
94                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + '] !== ' + child.nodeType + '\n' + child.data );\r
95                                                 ++j;\r
96                                                 continue;\r
97                                         };\r
98                                         if( _xnode._tag.toUpperCase() !== tag ){\r
99                                                 alert( '[' +xnode._tag + '>' +_xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + '\n' + child.outerHTML );\r
100                                                 ++j;\r
101                                                 continue;\r
102                                         } else {\r
103                                                 _xnode._rawNode = child;\r
104                                                 //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){\r
105                                                         if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );\r
106                                                         _xnode._tag     = tag; // .toUpperCase()\r
107                                                 //};\r
108                                                 _xnode._root    = xnode._root;\r
109                                                 child.UID = _xnode._uid;\r
110                                                 if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処\r
111                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + '] remove ... ' );\r
112                                                         _xnode.destroy();\r
113                                                         ++n;\r
114                                                         continue;\r
115                                                 } else {\r
116                                                         //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );\r
117                                                         child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );\r
118                                                 };\r
119                                                 _xtext = null;\r
120                                                 f = true;\r
121                                                 ++j;\r
122                                                 break;\r
123                                         };\r
124                                 } else\r
125                                 if( _xnode._xnodeType === 3 ){\r
126                                         \r
127                                         if( child.nodeType !== 3 ){\r
128                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
129                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );\r
130                                                         _xnode.destroy();\r
131                                                         ++n;\r
132                                                         continue;\r
133                                                 };\r
134                                                 alert(  xnode._tag + '>' + '"' + _xnode._text + '" !== ' + tag + '\n' + child.outerHTML );\r
135                                                 ++j;\r
136                                                 continue;\r
137                                         };\r
138                                         \r
139                                         _xnode._rawNode = child;\r
140                                         _xnode._root    = xnode._root;\r
141                                         if( !skipCleanup ){\r
142                                                 if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
143                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );\r
144                                                         _xnode.destroy();\r
145                                                         ++n;\r
146                                                         continue;\r
147                                                 };\r
148                                                 if( _xtext ){\r
149                                                         _xtext.text( _xtext._text + text );\r
150                                                         console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );\r
151                                                         _xnode.destroy();\r
152                                                         ++n;\r
153                                                         continue;\r
154                                                 } else {\r
155                                                         //alert( xnode._tag + '>' + '"' + text + '"\n' + child.data );\r
156                                                         _xnode.text( text );\r
157                                                 };\r
158                                         } else\r
159                                         if( _xtext ){\r
160                                                 _xtext.text( _xtext._text + _xnode._text );\r
161                                                 console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );\r
162                                                 _xnode.destroy();\r
163                                                 ++n;\r
164                                                 continue;\r
165                                         };\r
166                                         _xtext = _xtext || _xnode;\r
167                                         ++j;\r
168                                         break;\r
169                                 } else {\r
170                                         alert( 'no hit!' );\r
171                                 };\r
172                                 ++j;\r
173 \r
174                         };                              \r
175                         //if( !f ) alert( '**** ' + child.outerHTML );\r
176                 };\r
177                 while( xnode._xnodes && j < xnode._xnodes.length ){\r
178                         _xnode = xnode._xnodes[ j ];\r
179                         _xnode.parent = xnode;\r
180                         _xnode.destroy();\r
181                         ++n;\r
182                         continue;\r
183                 };\r
184         };\r
185         \r
186         // body の属性値の取得\r
187 \r
188         body.appendChild( elmProgress = document.createElement( 'div' ) );\r
189         elmProgress.style.cssText = 'position:absolute;top:0;left:0;z-index:9999;width:0;height:0.5em;background:#00f;overflow:hidden;';\r
190         \r
191         X.Dom.asyncParse( body.innerHTML, true )\r
192                 //.listenOnce( X.Event.SUCCESS, X.Dom._onAsyncParseComplete, [ createTree ] )\r
193                 .listen( X.Event.PROGRESS,\r
194                         function(e){\r
195                                 elmProgress.style.width = ( e.progress * 100 | 0 ) + '%';\r
196                         }\r
197                 )\r
198                 .listenOnce( X.Event.SUCCESS, function( e ){\r
199                         var xnodes = Node.root._xnodes = [], t;\r
200                         xnodes.push.apply( xnodes, e.xnodes );\r
201                         \r
202                         asyncCreateTree( Node.root, body.childNodes, elmProgress );\r
203                 } );\r
204 \r
205 }) :\r
206 document.all ?\r
207 (function(){\r
208         var r    = Node.root,\r
209                 body = r._rawNode,\r
210                 i, n = 0, elmProgress = '_xdom_builder_progress';\r
211                 \r
212                         function createTree( xnode, children, skipCleanup, textarea ){\r
213                                 var parent = xnode,\r
214                                         xnodes = X.copyArray( parent._xnodes ),\r
215                                         l      = xnodes && xnodes.length,\r
216                                         m      = children.length,\r
217                                         i = 0, j = 0, flag = 0,\r
218                                         elm, tag, xtext, text;\r
219                                 //children = X.copyArray( children );\r
220 \r
221                                 if( textarea ){\r
222                                         xnode.attr( 'value', xnode.html() ).empty();\r
223                                         return;\r
224                                 };\r
225 \r
226                                 for( ; i < xnodes.length; ++i ){\r
227                                         xnode = xnodes[ i ];\r
228                                         xnode.parent = parent;\r
229                                         \r
230                                         if( xnode._xnodeType === 3 ){\r
231                                                 //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );\r
232                                                 if( !skipCleanup ){\r
233                                                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
234                                                                 xnode.destroy();\r
235                                                         } else\r
236                                                         if( xtext ){\r
237                                                                 //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
238                                                                 xtext.text( xtext._text + text );\r
239                                                                 xnode.destroy();\r
240                                                         } else {\r
241                                                                 //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
242                                                                 xnode.text( text );\r
243                                                         };\r
244                                                 } else\r
245                                                 if( xtext ){\r
246                                                         //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
247                                                         xtext.text( xtext._text + xnode._text );\r
248                                                         xnode.destroy();\r
249                                                 };\r
250                                                 flag |= 4;\r
251                                                 xtext = xtext || xnode;\r
252                                                 continue;\r
253                                         };\r
254                                         \r
255                                         if( xnode._xnodeType !== 1 ){\r
256                                                 //alert( xnode._xnodeType )\r
257                                                 continue;\r
258                                         };\r
259                                         \r
260                                         for( ; j < m; ++j ){\r
261                                                 elm = children[ j ];\r
262                                                 tag = elm.tagName;\r
263                                                 /*\r
264                                                  * 未知のタグについては、閉じタグも含めてタグ名扱いになる\r
265                                                  */\r
266                                                 if( tag === '!' || tag.charAt( 0 ) === '/' ){\r
267                                                         //alert( '## ' + tag );\r
268                                                         continue;\r
269                                                 } else\r
270                                                 if( xnode._tag !== tag ){\r
271                                                         alert( xnode._tag + ' ' + ' !== ' + tag + '\nxnode.html():' + xnode.attr('cite') + '\nelm.outerHTML:' +  elm.outerHTML );\r
272                                                 } else {\r
273                                                         xnode._rawNode = elm;\r
274                                                         xnode._root    = parent._root;\r
275                                                         //xnode._tag     = X.Dom.DTD.TAG_FIX[ tag ] || tag;\r
276                                                         if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){\r
277                                                                 xnode.destroy();\r
278                                                                 break;\r
279                                                         } else {\r
280                                                                 xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );\r
281                                                                 \r
282                                                                 !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );\r
283                                                                 elm.setAttribute( 'UID', xnode._uid );\r
284                                                                 \r
285                                                                 tag === 'INPUT' && (\r
286                                                                         !xnode._attrs ?\r
287                                                                                 ( xnode._attrs = { type : 'text' } ) :\r
288                                                                                 !xnode._attrs.type || ( xnode._attrs.type = 'text' )\r
289                                                                 );\r
290                                                                 flag |= 3;\r
291                                                                 xtext = null;\r
292                                                                 break;\r
293                                                         };\r
294                                                 };\r
295                                         };\r
296                                         // for\r
297                                         if( !xnode._rawNode ){\r
298                                                 alert( xnode._tag + ' ' + xnode._id + ' !== none...' );\r
299                                         };\r
300                                         ++j;\r
301                                         flag &= 6;\r
302                                 };\r
303                                 // textNode がある\r
304                                 ( flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );\r
305                         };\r
306         /*\r
307          * http://support.microsoft.com/kb/812417/ja\r
308          * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。\r
309          * \r
310          * body.innerHTML でなく、 body.outerHTML にはできなかった、、、\r
311          */\r
312         body.insertAdjacentHTML( 'BeforeEnd', '<div id="' + elmProgress + '" style="position:absolute;top:0;left:0;z-index:9999;width:0;height:0.5em;background:#00f;overflow:hidden;"></div>' );\r
313         elmProgress = document.all[ elmProgress ];\r
314         \r
315         X.Dom.asyncParse( body.innerHTML, true )\r
316                 //.listenOnce( X.Event.SUCCESS, X.Dom._onAsyncParseComplete, [ createTree ] )\r
317                 .listen( X.Event.PROGRESS,\r
318                         function(e){\r
319                                 elmProgress.style.width = ( e.progress * 100 | 0 ) + '%';\r
320                         }\r
321                 )\r
322                 .listenOnce( X.Event.SUCCESS, function( e ){\r
323                         var xnodes = Node.root._xnodes = [], t;\r
324                         xnodes.push.apply( xnodes, e.xnodes );\r
325                         \r
326                         asyncCreateTree( Node.root, body.childNodes || body.children, elmProgress );\r
327                 } );\r
328 }) :\r
329 (function(){\r
330         \r
331 }) );\r
332 \r
333 X.Dom._onAsyncParseComplete = function( e, createTree ){\r
334         var xnodes = Node.root._xnodes = [], t;\r
335         xnodes.push.apply( xnodes, e.xnodes );\r
336         \r
337         //t = X.getTime();\r
338         createTree( Node.root, document.body.childNodes || document.body.children );\r
339         //alert( X.getTime() - t );\r
340         \r
341         X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_BUILDER_COMPLETE } );\r
342         \r
343         delete X.Dom._onAsyncParseComplete;\r
344 };\r
345 \r
346 \r
347 function asyncCreateTree( parent, elems, elmProgress, async ){\r
348         var xnodes      = async ? 0             : X.copyArray( parent._xnodes ),\r
349                 l           = async ? 0             : xnodes.length,\r
350                 current     = async ? async.current : {\r
351                         me     : parent,\r
352                         xnodes : xnodes,\r
353                         l      : l,\r
354                         i      : 0,\r
355                         elems  : elems,\r
356                         j      : 0,\r
357                         xtext  : null,\r
358                         flag   : 0\r
359                 },\r
360                 stack       = async ? async.stack   : [],\r
361                 done        = async ? async.done    : 0,\r
362                 startTime = X.getTime(),\r
363                 xnode, i, dive;\r
364         while( current || ( current = stack.pop() ) ){\r
365                 i = current.i;\r
366                 l = current.l;\r
367                 if( i < l ){\r
368                         parent = current.me;\r
369                         xnodes = current.xnodes;\r
370                         while( xnode = xnodes[ i ] ){                   \r
371                                 //\r
372                                 dive = bindElementToXnode( parent, xnode, current );\r
373                                 \r
374                                 ++i;\r
375                                 ++done;\r
376                                 if( dive ){\r
377                                         current.i = i;\r
378                                         stack[ stack.length ] = current;\r
379                                         \r
380                                         current = dive;\r
381                                         i       = 0;\r
382                                         l       = dive.l;\r
383                                         parent  = xnode;\r
384                                         xnodes  = dive.xnodes;\r
385                                         continue;\r
386                                 };\r
387                                 \r
388                                 if( startTime + 16 <= X.getTime() ){\r
389                                         current.i = i;\r
390                                         if( async ){\r
391                                                 async.current = i < l && current;\r
392                                                 async.done    = done;\r
393                                         };\r
394                                         X.Timer.once( 0, asyncCreateTree, [ null, null, elmProgress, async || { stack : stack, current : i < l && current, done : done } ] );\r
395                                         // progress\r
396                                         elmProgress.style.width = ( ( 1 - done / Node._chashe.length ) * 100 | 0 ) + '%';\r
397                                         return;\r
398                                 };\r
399                         };                      \r
400                 };\r
401                 current = null;\r
402         };\r
403         // complete\r
404         X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_BUILDER_COMPLETE } );\r
405 };\r
406 \r
407 bindElementToXnode =\r
408 document.getElementById ?\r
409 (function( parent, xnode, current ){\r
410         var elems = current.elems,\r
411                 //j     = current.j,\r
412                 m     = elems.length,\r
413                 xtext = current.xtext,\r
414                 skipCleanup = current.skipCleanup,\r
415                 elm, tag, text;\r
416 \r
417         xnode.parent = parent;\r
418 \r
419         for( ; current.j < m; ++current.j ){\r
420                 elm = elems[ current.j ];\r
421                 tag = elm.tagName;\r
422                 if( ( elm.nodeType !== 1 && elm.nodeType !== 3 ) || tag === '!' || ( tag && tag.charAt( 0 ) === '/' ) ){\r
423                         elm.parentNode.removeChild( elm );\r
424                         continue;\r
425                 };\r
426 \r
427                 if( xnode._xnodeType === 1 ){\r
428                         if( elm.nodeType === 3 ){\r
429                                 if( !( text = elm.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
430                                         elm.parentNode.removeChild( elm );\r
431                                         continue;\r
432                                 };\r
433                                 alert( '[' +parent._tag + '>' +xnode._tag + '] !== ' + elm.nodeType + '\n' + elm.data );\r
434                         } else\r
435                         if( xnode._tag.toUpperCase() !== tag ){\r
436                                 alert( '[' +parent._tag + '>' +xnode._tag + ' ' + (xnode._xnodes ? xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (elm.childNodes ? elm.childNodes.length : '' ) + '\n' + elm.outerHTML );\r
437                         } else {\r
438                                 xnode._rawNode = elm;\r
439                                 //if( ( doc = elm.ownerDocument || elm.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){\r
440                                         if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );\r
441                                         xnode._tag = tag; // .toUpperCase()\r
442                                 //};\r
443                                 xnode._root = parent._root;\r
444                                 elm.UID     = xnode._uid;\r
445                                 \r
446                                 if( tag === 'TEXTAREA' ){\r
447                                         xnode.attr( 'value', xnode.html() ).empty();\r
448                                 } else\r
449                                 if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処\r
450                                         //alert( '[' +parent._tag + '>' + xnode._tag + '] remove ... ' );\r
451                                         xnode.destroy();\r
452                                 } else\r
453                                 if( elm.childNodes && elm.childNodes.length ){\r
454                                         //alert( '[' +parent._tag + '>' + xnode._tag + ' ' + (xnode._xnodes ? xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (elm.childNodes ? elm.childNodes.length : '' ) + ' Hit\n' + elm.outerHTML );\r
455                                         ++current.j;\r
456                                         return {\r
457                                                 me     : xnode,\r
458                                                 xnodes : X.copyArray( xnode._xnodes ),\r
459                                                 xtext  : null,\r
460                                                 flag   : 0,\r
461                                                 i      : 0,\r
462                                                 l      : xnode._xnodes.length,\r
463                                                 elems  : elm.childNodes,\r
464                                                 j      : 0,\r
465                                                 skipCleanup : skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() )\r
466                                         };\r
467                                 };\r
468                                 current.xtext = null;\r
469                         };\r
470                         ++current.j;\r
471                         break;\r
472                 };\r
473                 \r
474                 if( elm.nodeType !== 3 ){\r
475                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
476                                 console.log( '[' +parent._tag + '>' + xnode._uid + '] destroy ... ' );\r
477                                 xnode.destroy();\r
478                                 break;\r
479                         };\r
480                         alert(  parent._tag + '>' + '"' + xnode._text + '" !== ' + tag + '\n' + elm.outerHTML );\r
481                         break;\r
482                 };\r
483                 \r
484                 ++current.j;\r
485                 xnode._rawNode = elm;\r
486                 xnode._root    = parent._root;\r
487                 if( !skipCleanup ){\r
488                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
489                                 console.log( '[' +parent._tag + '>' + xnode._uid + '] destroy ... ' );\r
490                                 xnode.destroy();\r
491                         };\r
492                         if( xtext ){\r
493                                 xtext.text( xtext._text + text );\r
494                                 console.log( '[' +parent._tag + '>' + xnode._uid + '] xtext,destroy ... ' );\r
495                                 xnode.destroy();\r
496                         } else {\r
497                                 //alert( parent._tag + '>' + '"' + text + '"\n' + elm.data );\r
498                                 xnode.text( text );\r
499                         };\r
500                 } else\r
501                 if( xtext ){\r
502                         xtext.text( xtext._text + xnode._text );\r
503                         console.log( '[' +parent._tag + '>' + xnode._uid + '] xtext,destroy ... ' );\r
504                         xnode.destroy();\r
505                 };\r
506                 current.xtext = xtext || xnode;\r
507                 break;\r
508         };\r
509 }) :\r
510 (function ( parent, xnode, current ){\r
511         var elems = current.elems,\r
512                 j     = current.j,\r
513                 m     = elems.length,\r
514                 xtext = current.xtext,\r
515                 skipCleanup = current.skipCleanup,\r
516                 elm, tag, text;\r
517 \r
518         xnode.parent = parent;\r
519         \r
520         if( xnode._xnodeType === 3 ){\r
521                 //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );\r
522                 if( !skipCleanup ){\r
523                         if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
524                                 xnode.destroy();\r
525                         } else\r
526                         if( xtext ){\r
527                                 //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
528                                 xtext.text( xtext._text + text );\r
529                                 xnode.destroy();\r
530                         } else {\r
531                                 //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
532                                 xnode.text( text );\r
533                         };\r
534                 } else\r
535                 if( xtext ){\r
536                         //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
537                         xtext.text( xtext._text + xnode._text );\r
538                         xnode.destroy();\r
539                 };\r
540                 current.flag |= 4;\r
541                 current.xtext = xtext || xnode;\r
542                 return;\r
543         };\r
544         \r
545         if( xnode._xnodeType !== 1 ){\r
546                 //alert( xnode._xnodeType )\r
547                 return;\r
548         };\r
549         \r
550         for( ; j < m; ++j, ++current.j ){\r
551                 elm = elems[ j ];\r
552                 tag = elm.tagName;\r
553                 /*\r
554                  * 未知のタグについては、閉じタグも含めてタグ名扱いになる\r
555                  */\r
556                 if( tag === '!' || tag.charAt( 0 ) === '/' ){\r
557                         //alert( '## ' + tag );\r
558                         continue;\r
559                 } else\r
560                 if( xnode._tag !== tag ){\r
561                         alert( xnode._tag + ' ' + ' !== ' + tag + '\nxnode.html():' + xnode.attr('cite') + '\nelm.outerHTML:' +  elm.outerHTML );\r
562                 } else {\r
563                         ++current.j;\r
564                         \r
565                         xnode._rawNode = elm;\r
566                         xnode._root    = parent._root;\r
567                         //xnode._tag     = X.Dom.DTD.TAG_FIX[ tag ] || tag;\r
568                         if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){\r
569                                 xnode.destroy();\r
570                                 break;\r
571                         };\r
572                         \r
573                         !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );\r
574                         elm.setAttribute( 'UID', xnode._uid );\r
575                         \r
576                         tag === 'INPUT' && (\r
577                                 !xnode._attrs ?\r
578                                         ( xnode._attrs = { type : 'text' } ) :\r
579                                         !xnode._attrs.type || ( xnode._attrs.type = 'text' )\r
580                         );\r
581                         current.flag |= 3;\r
582                         current.xtext = null;\r
583                         \r
584                         if( tag === 'TEXTAREA' ){\r
585                                 xnode.attr( 'value', xnode.html() ).empty();\r
586                         } else\r
587                         if( xnode._xnodes && xnode._xnodes.length ){\r
588                                 return {\r
589                                         me     : xnode,\r
590                                         xnodes : X.copyArray( xnode._xnodes ),\r
591                                         xtext  : null,\r
592                                         flag   : 0,\r
593                                         i      : 0,\r
594                                         l      : xnode._xnodes.length,\r
595                                         elems  : elm.children,\r
596                                         j      : 0,\r
597                                         skipCleanup : skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() )\r
598                                 };\r
599                         };\r
600                         break;\r
601                 };\r
602         };\r
603         // for\r
604         if( !xnode._rawNode ){\r
605                 alert( xnode._tag + ' ' + xnode._id + ' !== none...' );\r
606         };\r
607 \r
608         // textNode がある\r
609         ( current.flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );\r
610 });\r