X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F02_dom%2F22_XTreeBuilder.js;h=8a6c74a15882a5f03e6380b00429fe66fa53db0e;hb=8e74cf066ea48ec8cf34efb2b5e84725c10c813a;hp=7daff088107c7da06ef707804f4a5199df918f85;hpb=86c591d2888cf7b24365c1950646fb1f6190efd1;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/02_dom/22_XTreeBuilder.js b/0.6.x/js/02_dom/22_XTreeBuilder.js index 7daff08..8a6c74a 100644 --- a/0.6.x/js/02_dom/22_XTreeBuilder.js +++ b/0.6.x/js/02_dom/22_XTreeBuilder.js @@ -22,26 +22,27 @@ if( X_UA[ 'MacIE' ] ){ //node.data = ''; l = X_TEMP._removalTextNodes.length; if( parent ){ - //!l && X_Timer_once( 0, X_TEMP._timerRemove ); - //X_TEMP._removalTextNodes[ l ] = node; - //var str=[],p; - //for( p in node ){ - // str[str.length] = p; - //}; - //alert( str.join( ',' ) + parent.innerHTML ); - //node.nodeValue = ''; - //parent.replaceChild( document.createElement( 'span' ), node ); - //var e; - //var f = document.createDocumentFragment(); - //f.appendChild( e = document.createElement( 'span' ) ); - //f.replaceChild( node, e ); - //e.appendChild( f ); - //parent.appendChild( e = document.createElement( 'span' ) ); - //e.appendChild( node ); - //parent.removeChild( e ); - //node.parentNode = null; - //document.body.appendChild( node ); - //parent.replaceChild( document.createComment( '' ), node ); + /* + !l && X_Timer_once( 0, X_TEMP._timerRemove ); + X_TEMP._removalTextNodes[ l ] = node; + var str=[],p; + for( p in node ){ + str[str.length] = p; + }; + alert( str.join( ',' ) + parent.innerHTML ); + node.nodeValue = ''; + parent.replaceChild( document.createElement( 'span' ), node ); + var e; + var f = document.createDocumentFragment(); + f.appendChild( e = document.createElement( 'span' ) ); + f.replaceChild( node, e ); + e.appendChild( f ); + parent.appendChild( e = document.createElement( 'span' ) ); + e.appendChild( node ); + parent.removeChild( e ); + node.parentNode = null; + document.body.appendChild( node ); + parent.replaceChild( document.createComment( '' ), node ); */ document.body.appendChild( node ); return; if( parent.parentNode !== document.body ){ @@ -105,7 +106,8 @@ if( X_UA[ 'Opera7' ] ){ * http://kojs.sukobuto.com/docs/visible-binding * IE6 には、「空の span エレメントに続く空白は無視される」という謎な癖があります。 */ -X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, + +X_TEMP._onPreInit = X_UA_DOM.W3C ? (function(){ var r = X_Node_body, @@ -121,7 +123,7 @@ X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, // textarea の内容を控えて、消す。xnode tree 構築後に復帰。でないと、html パースでこける //X_UA[ 'MacIE' ] && alert( body.innerHTML ); // cleanup tree - (function/*cleanUpTree*/( elm, skip, head ){ + function cleanUpTree( elm, skip, head ){ var nodes = X_Object_cloneArray( elm.childNodes ), i = 0, l = nodes.length, @@ -141,7 +143,7 @@ X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, continue; } else { // pre タグ以下はスペースの置換は行わない - node.childNodes && node.childNodes.length && /*cleanUpTree*/arguments.callee( node, skip || X_Dom_DTD_SKIP_CLEANUP_TAGS[ tag ], head ); + node.childNodes && node.childNodes.length && cleanUpTree( node, skip || X_Dom_DTD_SKIP_CLEANUP_TAGS[ tag ], head ); }; textNode = null; break; @@ -167,7 +169,9 @@ X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, //++count; }; }; - })( X_UA[ 'MacIE' ] ? ( copy = body.cloneNode( true ) ) : body ); + }; + + cleanUpTree( X_UA[ 'MacIE' ] ? ( copy = body.cloneNode( true ) ) : body ); if( X_UA[ 'MacIE' ] ){ document.write( html = copy.innerHTML ); @@ -189,28 +193,18 @@ X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, }; }; - body.appendChild( elmProgress = document.createElement( 'div' ) ); + body.appendChild( X_TEMP.elmProgress = elmProgress = document.createElement( 'div' ) ); elmProgress.style.cssText = 'position:absolute;top:0;left:0;z-index:9999;width:0;height:0.5em;background:#00f;overflow:hidden;'; elmProgress.setAttribute( 'style', 'position:absolute;top:0;left:0;z-index:9999;width:0;height:0.5em;background:#00f;overflow:hidden;' ); - X_HTMLParser_asyncParse( html, true ) - [ 'listen' ]( X_EVENT_PROGRESS, - function( e ){ - elmProgress.style.width = ( e[ 'percent' ] * 100 | 0 ) + '%'; - } - ) - [ 'listenOnce' ]( X_EVENT_SUCCESS, - function( e ){ - var xnodes = X_Node_body[ '_xnodes' ] = [], t; - xnodes.push.apply( xnodes, e.xnodes ); - elmProgress.style.width = '100%'; + X_TEMP._body = body; - X_TEMP.asyncCreateTree( X_Node_body, body.childNodes, elmProgress ); - } - ); + X_HTMLParser_asyncParse( html, true ) + [ 'listen' ]( X_EVENT_PROGRESS, X_TEMP._handleEvent ) + [ 'listenOnce' ]( X_EVENT_SUCCESS, X_TEMP._handleEvent ); }) : -X_UA_DOM.IE4 ? +// X_UA_DOM.IE4 ? (function(){ var r = X_Node_body, body = r[ '_rawObject' ], @@ -218,7 +212,7 @@ X_UA_DOM.IE4 ? html; if( !X_TEMP.X_Dom_useBuilder ) return; - + /* * http://support.microsoft.com/kb/812417/ja * PRB: outerHTML の HTML 要素のプロパティは、既定の属性は表示されません。 @@ -227,27 +221,39 @@ X_UA_DOM.IE4 ? */ html = body.innerHTML; body.insertAdjacentHTML( 'BeforeEnd', '
' ); - elmProgress = document.all[ elmProgress ]; + X_TEMP.elmProgress = document.all[ elmProgress ]; + + X_TEMP._body = body; X_HTMLParser_asyncParse( html, true ) - [ 'listen' ]( X_EVENT_PROGRESS, - function( e ){ - elmProgress.style.width = ( e.percent * 100 | 0 ) + '%'; - } - ) - [ 'listenOnce' ]( X_EVENT_SUCCESS, - function( e ){ - var xnodes = X_Node_body[ '_xnodes' ] = [], t; - xnodes.push.apply( xnodes, e.xnodes ); - elmProgress.style.width = '100%'; - - X_TEMP.asyncCreateTree( X_Node_body, body.childNodes || body.children, elmProgress ); - } - ); -}) : -(function(){ + [ 'listen' ]( X_EVENT_PROGRESS, X_TEMP._handleEvent ) + [ 'listenOnce' ]( X_EVENT_SUCCESS, X_TEMP._handleEvent ); +}); + +X_ViewPort[ 'listenOnce' ]( X_EVENT_PRE_INIT, X_TEMP._onPreInit ); + +X_TEMP._handleEvent = function( e ){ + var elmProgress = X_TEMP.elmProgress, xnodes; -}) ); + switch( e.type ){ + case X_EVENT_PROGRESS : + elmProgress.style.width = ( e.percent * 100 | 0 ) + '%'; + break; + + case X_EVENT_SUCCESS : + xnodes = X_Node_body[ '_xnodes' ] = []; + + xnodes.push.apply( xnodes, e.xnodes ); + elmProgress.style.width = '100%'; + + X_TEMP.asyncCreateTree( X_Node_body, X_TEMP._body.childNodes || X_TEMP._body.children, elmProgress ); + + delete X_TEMP._onPreInit; + delete X_TEMP._body; + delete X_TEMP.elmProgress; + break; + }; +}; X_TEMP.asyncCreateTree = function( parent, elems, elmProgress, async ){ var xnodes = async ? 0 : X_Object_cloneArray( parent[ '_xnodes' ] ), @@ -311,6 +317,7 @@ X_TEMP.asyncCreateTree = function( parent, elems, elmProgress, async ){ console.log( 'xtree 作成完了' ); X_ViewPort[ 'asyncDispatch' ]( X_EVENT_XTREE_READY ); elmProgress.parentNode ? elmProgress.parentNode.removeChild( elmProgress ) : ( elmProgress.outerHTML = '' ); + delete X_TEMP.asyncCreateTree; delete X_TEMP.bindElementToXnode; delete X_TEMP.X_Dom_useBuilder;