OSDN Git Service

Version 0.6.27, bugfix for X.Dom.Parser.
[pettanr/clientJs.git] / 0.6.x / js / dom / 11_XDomNode.js
index 86f6e07..549382a 100644 (file)
@@ -205,9 +205,19 @@ Node._getXNode = function( v ){
 };\r
 \r
 \r
-Node.create = function( tag, opt_attr, opt_css ){\r
-       Node._newByTag = true;\r
-       return new Node( tag, opt_attr, opt_css );\r
+Node.create = function( tag, opt_attrs, opt_css ){\r
+       var list, i;\r
+       switch( Node._getType( tag ) ){\r
+               case Node.IS_STRING :\r
+                       Node._newByTag = true;\r
+                       return new Node( tag, opt_attrs, opt_css );\r
+               case Node.IS_HTML_STRING :\r
+                       list = X.Dom.parse( tag, true );\r
+                       for( i = list.length; 1 < i; ){\r
+                               list[ --i ].destroy();\r
+                       };\r
+                       return list[ 0 ];\r
+       };\r
 };\r
 Node.createText = function( text ){\r
        Node._newByText = true;\r
@@ -255,12 +265,11 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){
        if( this._xnodeType !== 1 ) return;\r
        if( !this._xnodes ) this._xnodes = [];\r
        \r
-       Node._newByTag = true;\r
-       xnode = new Node( tag, opt_attrs, opt_css );\r
-       xnode.parent = this;\r
+       xnode = Node.create( tag, opt_attrs, opt_css );\r
        \r
-       this._root && this._reserveUpdate();\r
+       xnode.parent = this;\r
        this._xnodes[ this._xnodes.length ] = xnode;\r
+       this._root && this._reserveUpdate();\r
        return xnode;\r
 };\r
 \r
@@ -520,10 +529,10 @@ Node.prototype.remove = function(){
 };\r
 \r
 Node.prototype.empty = function(){\r
-       var xnodes = this._xnodes, child, i, l;\r
-       if( xnodes && ( l = xnodes.length ) ){\r
-               for( i = 0; i < l; ++i ){\r
-                       xnodes[ i ].destroy();\r
+       var xnodes = this._xnodes, i;\r
+       if( xnodes && ( i = xnodes.length ) ){\r
+               for( ; i; ){\r
+                       xnodes[ --i ].destroy();\r
                };\r
                xnodes.length = 0;\r
        };\r
@@ -544,15 +553,14 @@ Node.prototype.destroy = function( isChild ){
                //for( ; i; ){\r
                //      xnodes[ --i ].destroy( true );\r
                //};\r
-               //xnodes.length = 0;\r
        };\r
-       elm && this.unlisten(); // イベントの退避\r
+       elm && this._listeners && this.unlisten(); // イベントの退避\r
 \r
        delete Node._chashe[ this._uid ];\r
        delete this._state;\r
        \r
        if( this._root ){\r
-               this.remove( isChild );\r
+               !isChild && this.remove();\r
        } else {\r
                this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );\r
                elm && !isChild && this._actualRemove();\r
@@ -726,7 +734,7 @@ Node.prototype.html = function( html, opt_outer ){
                '<', this._tag,\r
                this._id ? ' id=' + this._id : _,\r
                this._className ? ' class="' + this._className + '"' : _,\r
-               this._attrText === _ ? _ : this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
+               this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
                this._cssText ? ' style="' + this._cssText + '"' : _,\r
        '>' ];\r
        \r
@@ -836,6 +844,8 @@ Node.prototype._commitUpdate =
                                        parentElement.insertBefore( this._actualCreate(), nextElement ) :\r
                                        parentElement.appendChild( this._actualCreate() );\r
                                this._afterActualCreate();\r
+                               \r
+                               \r
                                return elm || this._rawNode;\r
                        } else\r
                        if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
@@ -916,12 +926,20 @@ Node.prototype._updateRawNode =
                        };\r
                        // id\r
                        if( this._dirty & X.Dom.Dirty.ID ){\r
-                               //this._id ?\r
-                                       ( elm.id = this._id )// :\r
-                                       //elm.removeAttribute( 'id' );\r
+                               if( X.UA.IE && X.UA.IE < 7 ){\r
+                                       elm.id = this._id;\r
+                               } else {\r
+                                       this._id ? ( elm.id = this._id ) : elm.removeAttribute( 'id' );                                 \r
+                               };\r
                        };\r
                        // className\r
-                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
+                               if( X.UA.IE && X.UA.IE < 7 ){\r
+                                       elm.className = this._className;\r
+                               } else {\r
+                                       this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );                                 \r
+                               };\r
+                       };\r
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
@@ -977,7 +995,9 @@ Node.prototype._updateRawNode =
                        if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) );\r
 \r
                        // className\r
-                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
+                               this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );\r
+                       };\r
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
                                if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
@@ -1070,11 +1090,6 @@ Node.prototype._actualCreate =
                        html, xnodes, n, i, l;\r
                \r
                if( this._xnodeType === 3 ){\r
-                       //html = [];\r
-                       //for( i = 0, l = this._text.length; i < l; ++i ){\r
-                       //      html.push( this._text.charCodeAt( i ) );\r
-                       //};\r
-                       //html = html.join( ',' );\r
                        html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode\r
                        delete this._rawNode;\r
                } else {\r
@@ -1192,7 +1207,7 @@ Node.prototype._actualRemove =
 \r
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
-                       // elm.parentNode.tagName check tagName is for ie7\r
+                       // elm.parentNode.tagName for ie7\r
                        !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
                }) :\r
        document.all ?\r
@@ -1211,10 +1226,7 @@ Node.prototype._actualRemove =
                        \r
                        elm.removeAttribute( 'id' ); // ?\r
                        document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
-                       if( !isChild ){\r
-                               //alert( elm.tagName + this._uid + '\n' + document.all[ this._id || ( 'ie4uid' + this._uid ) ] + '\n' + elm.innerHTML );\r
-                               elm.outerHTML = '';\r
-                       };\r
+                       if( !isChild ) elm.outerHTML = '';\r
                        delete this._rawNode;\r
                }) :\r
                (function(){});\r