OSDN Git Service

Version 0.6.33, cleanup X.Dom.Builder.
authoritozyun <itozyun@user.sourceforge.jp>
Sat, 29 Mar 2014 04:04:24 +0000 (13:04 +0900)
committeritozyun <itozyun@user.sourceforge.jp>
Sat, 29 Mar 2014 04:04:24 +0000 (13:04 +0900)
0.6.x/js/dom/22_XDomBuilder.js

index 506f182..ce34616 100644 (file)
@@ -61,135 +61,12 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT,
                };\r
        })( body );\r
        \r
-       function createTree( xnode, childNodes, skipCleanup, textarea ){\r
-               var i = 0,\r
-                       j = 0,\r
-                       l = childNodes.length,\r
-                       child, _xnode, f, tag, text, _xtext, doc;\r
-               childNodes = X.copyArray( childNodes );\r
-\r
-               if( textarea ){\r
-                       xnode.attr( 'value', xnode.html() ).empty();\r
-                       return;\r
-               };\r
-\r
-               for( ; i < l; ++i ){\r
-                       child = childNodes[ i ];\r
-                       tag   = child.tagName;\r
-                       if( ( child.nodeType !== 1 && child.nodeType !== 3 ) || tag === '!' || ( tag && tag.charAt( 0 ) === '/' ) ){\r
-                               child.parentNode.removeChild( child );\r
-                               continue;\r
-                       };\r
-                       f = false;\r
-                       while( xnode._xnodes && j < xnode._xnodes.length ){\r
-                               _xnode = xnode._xnodes[ j ];\r
-                               _xnode.parent   = xnode;\r
-                               \r
-                               if( _xnode._xnodeType === 1 ){\r
-                                       if( child.nodeType !== 1 ){\r
-                                               if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
-                                                       child.parentNode.removeChild( child );\r
-                                                       break;\r
-                                               };\r
-                                               alert( '[' +xnode._tag + '>' +_xnode._tag + '] !== ' + child.nodeType + '\n' + child.data );\r
-                                               ++j;\r
-                                               continue;\r
-                                       };\r
-                                       if( _xnode._tag.toUpperCase() !== tag ){\r
-                                               alert( '[' +xnode._tag + '>' +_xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] !== ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + '\n' + child.outerHTML );\r
-                                               ++j;\r
-                                               continue;\r
-                                       } else {\r
-                                               _xnode._rawNode = child;\r
-                                               //if( ( doc = child.ownerDocument || child.document ) && ( doc.createElement( 'p' ).tagName === doc.createElement( 'P' ).tagName ) ){\r
-                                                       if( tag.charAt( 0 ) === '/' ) tag = tag.slice( 1 );\r
-                                                       _xnode._tag     = tag; // .toUpperCase()\r
-                                               //};\r
-                                               _xnode._root    = xnode._root;\r
-                                               child.UID = _xnode._uid;\r
-                                               if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){ // ie で body 内の script が2度よばれるのに対処\r
-                                                       //alert( '[' +xnode._tag + '>' + _xnode._tag + '] remove ... ' );\r
-                                                       _xnode.destroy();\r
-                                                       ++n;\r
-                                                       continue;\r
-                                               } else {\r
-                                                       //alert( '[' +xnode._tag + '>' + _xnode._tag + ' ' + (_xnode._xnodes ? _xnode._xnodes.length : '' ) + '] === ' + tag + ' ' + (child.childNodes ? child.childNodes.length : '' ) + ' Hit\n' + child.outerHTML );\r
-                                                       child.childNodes && child.childNodes.length && createTree( _xnode, child.childNodes, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );\r
-                                               };\r
-                                               _xtext = null;\r
-                                               f = true;\r
-                                               ++j;\r
-                                               break;\r
-                                       };\r
-                               } else\r
-                               if( _xnode._xnodeType === 3 ){\r
-                                       \r
-                                       if( child.nodeType !== 3 ){\r
-                                               if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
-                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );\r
-                                                       _xnode.destroy();\r
-                                                       ++n;\r
-                                                       continue;\r
-                                               };\r
-                                               alert(  xnode._tag + '>' + '"' + _xnode._text + '" !== ' + tag + '\n' + child.outerHTML );\r
-                                               ++j;\r
-                                               continue;\r
-                                       };\r
-                                       \r
-                                       _xnode._rawNode = child;\r
-                                       _xnode._root    = xnode._root;\r
-                                       if( !skipCleanup ){\r
-                                               if( !( text = _xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
-                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] destroy ... ' );\r
-                                                       _xnode.destroy();\r
-                                                       ++n;\r
-                                                       continue;\r
-                                               };\r
-                                               if( _xtext ){\r
-                                                       _xtext.text( _xtext._text + text );\r
-                                                       console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );\r
-                                                       _xnode.destroy();\r
-                                                       ++n;\r
-                                                       continue;\r
-                                               } else {\r
-                                                       //alert( xnode._tag + '>' + '"' + text + '"\n' + child.data );\r
-                                                       _xnode.text( text );\r
-                                               };\r
-                                       } else\r
-                                       if( _xtext ){\r
-                                               _xtext.text( _xtext._text + _xnode._text );\r
-                                               console.log( '[' +xnode._tag + '>' + _xnode._uid + '] xtext,destroy ... ' );\r
-                                               _xnode.destroy();\r
-                                               ++n;\r
-                                               continue;\r
-                                       };\r
-                                       _xtext = _xtext || _xnode;\r
-                                       ++j;\r
-                                       break;\r
-                               } else {\r
-                                       alert( 'no hit!' );\r
-                               };\r
-                               ++j;\r
-\r
-                       };                              \r
-                       //if( !f ) alert( '**** ' + child.outerHTML );\r
-               };\r
-               while( xnode._xnodes && j < xnode._xnodes.length ){\r
-                       _xnode = xnode._xnodes[ j ];\r
-                       _xnode.parent = xnode;\r
-                       _xnode.destroy();\r
-                       ++n;\r
-                       continue;\r
-               };\r
-       };\r
-       \r
        // body の属性値の取得\r
 \r
        body.appendChild( elmProgress = document.createElement( 'div' ) );\r
        elmProgress.style.cssText = 'position:absolute;top:0;left:0;z-index:9999;width:0;height:0.5em;background:#00f;overflow:hidden;';\r
        \r
        X.Dom.asyncParse( body.innerHTML, true )\r
-               //.listenOnce( X.Event.SUCCESS, X.Dom._onAsyncParseComplete, [ createTree ] )\r
                .listen( X.Event.PROGRESS,\r
                        function(e){\r
                                elmProgress.style.width = ( e.progress * 100 | 0 ) + '%';\r
@@ -199,7 +76,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_PRE_INIT,
                        var xnodes = Node.root._xnodes = [], t;\r
                        xnodes.push.apply( xnodes, e.xnodes );\r
                        \r
-                       asyncCreateTree( Node.root, body.childNodes, elmProgress );\r
+                       X.Dom._asyncCreateTree( Node.root, body.childNodes, elmProgress );\r
                } );\r
 \r
 }) :\r
@@ -208,101 +85,7 @@ document.all ?
        var r    = Node.root,\r
                body = r._rawNode,\r
                i, n = 0, elmProgress = '_xdom_builder_progress';\r
-               \r
-                       function createTree( xnode, children, skipCleanup, textarea ){\r
-                               var parent = xnode,\r
-                                       xnodes = X.copyArray( parent._xnodes ),\r
-                                       l      = xnodes && xnodes.length,\r
-                                       m      = children.length,\r
-                                       i = 0, j = 0, flag = 0,\r
-                                       elm, tag, xtext, text;\r
-                               //children = X.copyArray( children );\r
-\r
-                               if( textarea ){\r
-                                       xnode.attr( 'value', xnode.html() ).empty();\r
-                                       return;\r
-                               };\r
 \r
-                               for( ; i < xnodes.length; ++i ){\r
-                                       xnode = xnodes[ i ];\r
-                                       xnode.parent = parent;\r
-                                       \r
-                                       if( xnode._xnodeType === 3 ){\r
-                                               //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );\r
-                                               if( !skipCleanup ){\r
-                                                       if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){\r
-                                                               xnode.destroy();\r
-                                                       } else\r
-                                                       if( xtext ){\r
-                                                               //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
-                                                               xtext.text( xtext._text + text );\r
-                                                               xnode.destroy();\r
-                                                       } else {\r
-                                                               //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
-                                                               xnode.text( text );\r
-                                                       };\r
-                                               } else\r
-                                               if( xtext ){\r
-                                                       //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );\r
-                                                       xtext.text( xtext._text + xnode._text );\r
-                                                       xnode.destroy();\r
-                                               };\r
-                                               flag |= 4;\r
-                                               xtext = xtext || xnode;\r
-                                               continue;\r
-                                       };\r
-                                       \r
-                                       if( xnode._xnodeType !== 1 ){\r
-                                               //alert( xnode._xnodeType )\r
-                                               continue;\r
-                                       };\r
-                                       \r
-                                       for( ; j < m; ++j ){\r
-                                               elm = children[ j ];\r
-                                               tag = elm.tagName;\r
-                                               /*\r
-                                                * 未知のタグについては、閉じタグも含めてタグ名扱いになる\r
-                                                */\r
-                                               if( tag === '!' || tag.charAt( 0 ) === '/' ){\r
-                                                       //alert( '## ' + tag );\r
-                                                       continue;\r
-                                               } else\r
-                                               if( xnode._tag !== tag ){\r
-                                                       alert( xnode._tag + ' ' + ' !== ' + tag + '\nxnode.html():' + xnode.attr('cite') + '\nelm.outerHTML:' +  elm.outerHTML );\r
-                                               } else {\r
-                                                       xnode._rawNode = elm;\r
-                                                       xnode._root    = parent._root;\r
-                                                       //xnode._tag     = X.Dom.DTD.TAG_FIX[ tag ] || tag;\r
-                                                       if( 0 <= X.Dom.cleanupTagNames.indexOf( tag.toLowerCase() ) || tag === 'SCRIPT' ){\r
-                                                               xnode.destroy();\r
-                                                               break;\r
-                                                       } else {\r
-                                                               xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ), tag === 'TEXTAREA' );\r
-                                                               \r
-                                                               !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );\r
-                                                               elm.setAttribute( 'UID', xnode._uid );\r
-                                                               \r
-                                                               tag === 'INPUT' && (\r
-                                                                       !xnode._attrs ?\r
-                                                                               ( xnode._attrs = { type : 'text' } ) :\r
-                                                                               !xnode._attrs.type || ( xnode._attrs.type = 'text' )\r
-                                                               );\r
-                                                               flag |= 3;\r
-                                                               xtext = null;\r
-                                                               break;\r
-                                                       };\r
-                                               };\r
-                                       };\r
-                                       // for\r
-                                       if( !xnode._rawNode ){\r
-                                               alert( xnode._tag + ' ' + xnode._id + ' !== none...' );\r
-                                       };\r
-                                       ++j;\r
-                                       flag &= 6;\r
-                               };\r
-                               // textNode がある\r
-                               ( flag & 6 ) && ( parent._dirty |= X.Dom.Dirty.IE4_TEXTNODE_FIX );\r
-                       };\r
        /*\r
         * http://support.microsoft.com/kb/812417/ja\r
         * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。\r
@@ -313,7 +96,6 @@ document.all ?
        elmProgress = document.all[ elmProgress ];\r
        \r
        X.Dom.asyncParse( body.innerHTML, true )\r
-               //.listenOnce( X.Event.SUCCESS, X.Dom._onAsyncParseComplete, [ createTree ] )\r
                .listen( X.Event.PROGRESS,\r
                        function(e){\r
                                elmProgress.style.width = ( e.progress * 100 | 0 ) + '%';\r
@@ -323,28 +105,14 @@ document.all ?
                        var xnodes = Node.root._xnodes = [], t;\r
                        xnodes.push.apply( xnodes, e.xnodes );\r
                        \r
-                       asyncCreateTree( Node.root, body.childNodes || body.children, elmProgress );\r
+                       X.Dom._asyncCreateTree( Node.root, body.childNodes || body.children, elmProgress );\r
                } );\r
 }) :\r
 (function(){\r
        \r
 }) );\r
 \r
-X.Dom._onAsyncParseComplete = function( e, createTree ){\r
-       var xnodes = Node.root._xnodes = [], t;\r
-       xnodes.push.apply( xnodes, e.xnodes );\r
-       \r
-       //t = X.getTime();\r
-       createTree( Node.root, document.body.childNodes || document.body.children );\r
-       //alert( X.getTime() - t );\r
-       \r
-       X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_BUILDER_COMPLETE } );\r
-       \r
-       delete X.Dom._onAsyncParseComplete;\r
-};\r
-\r
-\r
-function asyncCreateTree( parent, elems, elmProgress, async ){\r
+X.Dom._asyncCreateTree = function ( parent, elems, elmProgress, async ){\r
        var xnodes      = async ? 0             : X.copyArray( parent._xnodes ),\r
                l           = async ? 0             : xnodes.length,\r
                current     = async ? async.current : {\r
@@ -391,7 +159,7 @@ function asyncCreateTree( parent, elems, elmProgress, async ){
                                                async.current = i < l && current;\r
                                                async.done    = done;\r
                                        };\r
-                                       X.Timer.once( 0, asyncCreateTree, [ null, null, elmProgress, async || { stack : stack, current : i < l && current, done : done } ] );\r
+                                       X.Timer.once( 0, X.Dom._asyncCreateTree, [ null, null, elmProgress, async || { stack : stack, current : i < l && current, done : done } ] );\r
                                        // progress\r
                                        elmProgress.style.width = ( ( 1 - done / Node._chashe.length ) * 100 | 0 ) + '%';\r
                                        return;\r
@@ -402,6 +170,8 @@ function asyncCreateTree( parent, elems, elmProgress, async ){
        };\r
        // complete\r
        X.Dom.asyncDispatch( 0, { type : X.Dom.Event.DOM_BUILDER_COMPLETE } );\r
+       elmProgress.parentNode ? elmProgress.parentNode.removeChild( elmProgress ) : ( elmProgress.outerHTML = '' );\r
+       delete X.Dom._asyncCreateTree;\r
 };\r
 \r
 bindElementToXnode =\r