OSDN Git Service

Version 0.6.185, fix X.AudioSprite & X_Node_onKill.
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 20_XNode.js
index c303b3d..ca28821 100644 (file)
@@ -9,7 +9,6 @@
 var    Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
        'X.Node',
        X_Class.POOL_OBJECT,
-       
        {
                /**
                 * 要素に振られるユニークID
@@ -768,10 +767,11 @@ function X_Node_swap( v ){
 };
 
 /**
- * 要素を抜く。
+ * 要素を親要素から抜く。jQuery の remove と異なり、インスタンスは破壊(kill)されず、再び別の親に挿入等できる
  * @alias Node.prototype.remove
  * @return {Node} 自身。チェインメソッド
  * @example node.remove();
+ * parent.append( node ); 新しい親に追加できる
  */
 function X_Node_remove(){
        var parent = this.parent,
@@ -821,7 +821,9 @@ function X_Node_remove(){
  */
 function X_Node_empty(){
        var xnodes = this[ '_xnodes' ], i;
+       
        if( xnodes && ( i = xnodes.length ) ){
+               delete this[ '_xnodes' ];
                for( ; i; ){
                        xnodes[ --i ][ 'kill' ]();
                };
@@ -836,18 +838,20 @@ function X_Node_onKill( that ){
        
        if( ( that[ '_flags' ] & X_NodeFlags_EXIST ) === 0 ) return;
        
-       parent && parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( that ), 1 );
+       parent && parent[ '_xnodes' ] && parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( that ), 1 );
 
        elm = that[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that );
-       // elm && that[ '_listeners' ] && X_EventDispatcher_unlistenAll( that ); // イベントの退避
 
        if( xnodes && ( i = xnodes.length ) ){
+               delete that[ '_xnodes' ];
                for( ; i; ){
                        xnodes[ --i ][ 'kill' ]();
                };
+               xnodes.length = 0;
        };
 
-       delete X_Node_CHASHE[ that[ '_uid' ] ];
+       X_Node_CHASHE[ that[ '_uid' ] ] = null; // array に対して delete X_Node_CHASHE[ uid ] はまずい!
+       
 // remove _xnodes
        if( X_UA_DOM.IE4 ){
                if( elm ){
@@ -860,7 +864,7 @@ function X_Node_onKill( that ){
        } else {
                if( elm && elm.parentNode && elm.parentNode.tagName ){
                        X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = elm;
-                       X_Node_reserveUpdate();         
+                       X_Node_reserveUpdate();
                };
        };
 };
@@ -1095,7 +1099,12 @@ function X_Node_html( html ){
        // setter
        if( html !== undefined ){ // String 以外に Number や false null なども許可
                if( !this[ '_tag' ] ) return this[ 'text' ]( html );
-               return html ? this[ 'empty' ]()[ 'append' ].apply( this, X_HtmlParser_parse( html, true ) ) : this[ 'empty' ]();
+               
+               this[ 'empty' ]();
+               if( html ){
+                       X_Node_append.apply( this, X_HtmlParser_parse( html, true ) );
+               };
+               return this;
        };
        
        // getter