OSDN Git Service

Version 0.6.21, fix performance.
authoritozyun <itozyun@user.sourceforge.jp>
Fri, 21 Feb 2014 12:44:42 +0000 (21:44 +0900)
committeritozyun <itozyun@user.sourceforge.jp>
Fri, 21 Feb 2014 12:44:42 +0000 (21:44 +0900)
0.6.x/js/dom/10_XDom.js
0.6.x/js/dom/11_XDomNode.js
0.6.x/js/dom/12_XDomEvent.js
0.6.x/js/dom/14_XDomAttr.js
0.6.x/js/dom/15_XDomStyle.js
0.6.x/js/dom/18_XDomQuery.js

index 4e7fc31..9ecf64f 100644 (file)
@@ -118,7 +118,9 @@ X.Dom.cleanupTagNames     = 'noscript,noframes,comment,!,noembed,nolayer'.split(
 X.Dom.skipCleanupTagNames = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' );\r
                \r
 X.Dom.cleanupWhiteSpace = function( text ){\r
-       var _ = ' ', __ = '  ', c09 = String.fromCharCode( 9 ), c10 = String.fromCharCode( 10 );\r
+       var _ = ' ', __ = '  ', c1310 = String.fromCharCode( 13 ) + String.fromCharCode( 10 );\r
+       //text.indexOf( c1310 ) !== -1 && ( text = text.split( c1310 ).join( _ ) );\r
+       //text.indexOf( c32 ) !== -1 && ( text = text.split( c32 ).join( _ ) );\r
        text.indexOf( '\r\n' ) !== -1 && ( text = text.split( '\r\n' ).join( _ ) );\r
        text.indexOf( '\n\r' ) !== -1 && ( text = text.split( '\n\r' ).join( _ ) );\r
        text.indexOf( '\t' )   !== -1 && ( text = text.split( '\t' ).join( _ ) );\r
@@ -126,8 +128,6 @@ X.Dom.cleanupWhiteSpace = function( text ){
        text.indexOf( '\n' )   !== -1 && ( text = text.split( '\n' ).join( _ ) );\r
        text.indexOf( '\f' )   !== -1 && ( text = text.split( '\f' ).join( _ ) );\r
        text.indexOf( '\b' )   !== -1 && ( text = text.split( '\b' ).join( _ ) );\r
-       text.indexOf( c09 )    !== -1 && ( text = text.split( c09 ).join( _ ) );\r
-       text.indexOf( c10 )    !== -1 && ( text = text.split( c10 ).join( _ ) );\r
        while( text.indexOf( __ ) !== -1 ){\r
                text = text.split( __ ).join( _ );\r
        };\r
index 667a1db..04d2cc7 100644 (file)
@@ -1,7 +1,7 @@
 \r
 X.Dom.Dirty = {\r
        CLEAN            :  0,\r
-       TREE             :  1, // width, height, x, y\r
+       ID               :  1, // width, height, x, y\r
        CONTENT          :  2,  // width, height, x, y textNode の内容\r
        CLASSNAME        :  4, // _getCharSize, width, height, x, y\r
        CSS              :  8, // _getCharSize, width, height, x, y\r
@@ -10,6 +10,30 @@ X.Dom.Dirty = {
 };\r
 \r
 /*\r
+ * \r
+ *\r
+ * destroyed\r
+ * display:none\r
+ * display:block\r
+ * display:inline\r
+ * \r
+ */\r
+\r
+X.Dom.State = {\r
+       DESTROYED          : 0,\r
+       DISPLAY_NONE       : 1,\r
+       DISPLAY_BLOCK      : 2,\r
+       DISPLAY_INLINE     : 4,\r
+       POSITION_ABSOLUTE  : 2,\r
+       OVERFLOW_HIDDEN    : 4,\r
+       HAS_WIDTH_LENGTH   : 8,\r
+       HAS_WIDTH_PERCENT  : 16,\r
+       HAS_HEIGHT_LENGTH  : 16,\r
+       HAS_HEIGHT_PERCENT : 32,\r
+       IE4_ONLY_TEXT      : 64\r
+};\r
+\r
+/*\r
  * Node( rawElement | rawTextnode | htmlString | textString )\r
  */\r
 //;(function( window, document, undeifned ){\r
@@ -18,8 +42,8 @@ X.Dom.Node = X.EventDispatcher.inherits(
        X.Class.POOL_OBJECT,\r
        {\r
                _uid       : 0,\r
-               _destroyed : false,\r
-               _dirty     : 0,         \r
+               _state     : 0,\r
+               _dirty     : 0,\r
                \r
                _rawNode   : null,\r
                _root      : null, // xnode が文書ツリーに属しているか?はこれを見る\r
@@ -37,7 +61,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                _attrText  : '',\r
                \r
                _css       : null, // X.Dom.Style\r
-               _cssText   : ' ',\r
+               _cssText   : null,\r
                \r
                _anime     : null,\r
                \r
@@ -48,6 +72,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                Node._newByTag  = false;\r
                                this._tag       = v;\r
                                this._xnodeType = 1;\r
+                               this._state     = X.Dom.State.DISPLAY_INLINE; // todo\r
                                arguments[ 1 ] && this.attr( arguments[ 1 ] );\r
                                css = arguments[ 2 ];\r
                                css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
@@ -56,6 +81,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                Node._newByText = false;\r
                                this._text      = v;\r
                                this._xnodeType = 3;\r
+                               this._state     = X.Dom.State.DISPLAY_INLINE;\r
                        } else {\r
                                if( 1 < arguments.length ) return new X.Dom.NodeList( arguments );\r
                                if( X.Type.isArray( v ) && v.length ) return new X.Dom.NodeList( v );\r
@@ -72,6 +98,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                this._root      = this.parent ? this.parent._root : null;\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 1;\r
+                                               this._state     = X.Dom.State.DISPLAY_BLOCK; // todo\r
                                                this._tag       = v.tagName;\r
                                                this._id        = v.id;\r
                                                this._className = v.className;\r
@@ -93,6 +120,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                                this._root      = this.parent ? this.parent._root : null;\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 3;\r
+                                               this._state     = X.Dom.State.DISPLAY_INLINE;\r
                                                this._text      = v.data;\r
                                                v.UID = uid;\r
                                                break;\r
@@ -107,6 +135,7 @@ X.Dom.Node = X.EventDispatcher.inherits(
                                        case Node.IS_DOCUMENT :\r
                                                this._rawNode   = v;\r
                                                this._xnodeType = 2;\r
+                                               this._state     = X.Dom.State.DISPLAY_BLOCK;\r
                                                break;\r
                                        default :\r
                                                if( Node.none ) return Node.none;\r
@@ -312,17 +341,17 @@ Node.prototype.append = function( v ){
                        if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
                        if( v.parent ){\r
-                               if( document.getElementById ){\r
-                                       v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
-                               } else\r
-                               if( document.all ){\r
+                               //if( document.getElementById ){\r
+                               //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
+                               //} else\r
+                               //if( document.all ){\r
                                        v.remove();\r
-                               } else {\r
+                               //} else {\r
                                        \r
-                               };\r
+                               //};\r
                        } else\r
                        if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
-                               if( v._destroyed ) alert( 'xnode already destroyed!' );\r
+                               if( !this._state ) alert( 'xnode already destroyed!' );\r
                                Node._reserveRemoval.splice( i, 1 );\r
                        };\r
                        break;\r
@@ -342,16 +371,15 @@ Node.prototype.appendAt = function( start, v ){
        \r
        if( this._xnodeType !== 1 ) return this;\r
        \r
+       l = arguments.length;\r
        if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = [];\r
        \r
-       l = arguments.length;\r
        if( xnodes.length <= start ){\r
                if( l === 2 ) return this.append( v );\r
-               v = [];\r
-               for( ; 1 < l; ){\r
-                       v[ l - 2 ] = arguments[ --l ];\r
+               for( i = 1; i < l; ++i ){\r
+                       this.append( arguments[ i ] );\r
                };\r
-               return this.append.apply( this, v );\r
+               return this;\r
        };\r
        if( start < 0 ) start = 0;\r
        if( 2 < l ){\r
@@ -377,17 +405,17 @@ Node.prototype.appendAt = function( start, v ){
                        if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
                        // 親の xnodes から v を消す\r
                        if( v.parent ){\r
-                               if( document.getElementById ){\r
-                                       v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
-                               } else\r
-                               if( document.all ){\r
+                               //if( document.getElementById ){\r
+                               //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
+                               //} else\r
+                               //if( document.all ){\r
                                        v.remove();\r
-                               } else {\r
+                               //} else {\r
                                        \r
-                               };\r
+                               //};\r
                        } else\r
                        if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
-                               if( v._destroyed ) alert( 'xnode already destroyed!' );\r
+                               if( !this._state ) alert( 'xnode already destroyed!' );\r
                                Node._reserveRemoval.splice( i, 1 );\r
                        };\r
                        break;\r
@@ -404,8 +432,6 @@ Node.prototype.appendAt = function( start, v ){
 Node.prototype.appendTo = function( parent, opt_index ){\r
        if( parent.constructor === Node ){\r
                opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
-       } else {\r
-               opt_index === undefined ? new Node( parent ).append( this ) : new Node( parent ).appendAt( opt_index, this );\r
        };\r
        return this;\r
 };\r
@@ -419,36 +445,44 @@ Node.prototype.appendToRoot = function( opt_index ){
  *  Before , After, Replace\r
  */\r
 Node.prototype.before = function( v ){\r
-       var parent, l;\r
-       if( !( parent = this.parent ) ){\r
-               return this;\r
-       };\r
+       var parent, l, start;\r
+       if( !( parent = this.parent ) ) return this;\r
+       \r
        l = arguments.length;\r
+       start = this.getOrder();\r
        if( 1 < l ){\r
-               v = [ this.getOrder() ];\r
                for( ; l; ){\r
-                       v[ l ] = arguments[ --l ];\r
+                       parent.appendAt( start, arguments[ --l ] );\r
                };\r
-               parent.appendAt.apply( parent, v );\r
                return this;\r
        };\r
-       parent.appendAt( this.getOrder(), v );\r
+       parent.appendAt( start, v );\r
        return this;\r
 };\r
 \r
 Node.prototype.after = function( v ){\r
-       var parent, l;\r
+       var parent, l, i, start;\r
        if( !( parent = this.parent ) ) return this;\r
+       \r
        l = arguments.length;\r
+       start = this.getOrder() + 1;\r
+       if( parent._xnodes.length <= start ){\r
+               if( 1 < l ){\r
+                       for( i = 0; i < l; ++i ){\r
+                               parent.append( arguments[ i ] );\r
+                       };\r
+                       return this;\r
+               };\r
+               parent.append( v );\r
+               return this;\r
+       };\r
        if( 1 < l ){\r
-               v = [ this.getOrder() + 1 ];\r
                for( ; l; ){\r
-                       v[ l ] = arguments[ --l ];\r
+                       parent.appendAt( start, arguments[ --l ] );\r
                };\r
-               parent.appendAt.apply( parent, v );\r
                return this;\r
        };\r
-       parent.appendAt( this.getOrder() + 1, v );\r
+       parent.appendAt( start, v );\r
        return this;\r
 };\r
 \r
@@ -462,7 +496,7 @@ Node.prototype.replace = function( v ){
  */\r
 Node.prototype.remove = function(){\r
        var parent = this.parent;\r
-               \r
+       \r
        if( !parent ) return this;\r
 \r
        parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );\r
@@ -471,6 +505,7 @@ Node.prototype.remove = function(){
                parent._reserveUpdate();\r
        };\r
        delete this.parent;\r
+       delete this._root;\r
        return this;\r
 };\r
 \r
@@ -489,9 +524,11 @@ Node.prototype.empty = function(){
  *  destory\r
  */\r
 Node.prototype.destroy = function( isChild ){\r
-       var xnodes = this._xnodes, i;\r
+       var xnodes = this._xnodes, i, elm;\r
+       \r
+       if( !this._state ) return;\r
        \r
-       if( this._destroyed ) return;\r
+       elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
        \r
        if( xnodes && ( i = xnodes.length ) ){\r
                for( ; i; ){\r
@@ -499,16 +536,16 @@ Node.prototype.destroy = function( isChild ){
                };\r
                xnodes.length = 0;\r
        };\r
-       this.unlisten(); // イベントの退避\r
+       elm && this.unlisten(); // イベントの退避\r
 \r
        delete Node._chashe[ this._uid ];\r
+       delete this._state;     \r
        \r
-       if( this._root ){//this._rawNode && this._rawNode.parentNode && this._rawNode.parentNode.tagName ){\r
+       if( this._root ){\r
                this.remove();\r
-               this._destroyed = true; // state                \r
        } else {\r
                this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );\r
-               !isChild && this._actualRemove();\r
+               elm && !isChild && this._actualRemove();\r
                this.kill();\r
        };\r
 };\r
@@ -522,7 +559,7 @@ Node.prototype.contains = function( v ){
        var elm, type, xnodes, i;\r
        if( !v || this._xnodeType !== 1 ) return false;\r
        // contains ie4+\r
-       if( ( elm = this._rawNode || this._ie4getRawNode() ) && document.contains && ( type = Node._getType( v ) ) && ( type === Node.IS_RAW_HTML || type === Node.IS_RAW_TEXT ) ){\r
+       if( ( elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode() ) && document.contains && ( type = Node._getType( v ) ) && ( type === Node.IS_RAW_HTML || type === Node.IS_RAW_TEXT ) ){\r
                return elm.contains( v );       \r
        };\r
        //if( document.compareDocumentPosition ){\r
@@ -680,7 +717,7 @@ Node.prototype.html = function( html, opt_outer ){
                this._id ? ' id=' + this._id : '',\r
                this._className ? ' class="' + this._className + '"' : '',\r
                this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
-               this._cssText !== ' ' ? ' style="' + this._cssText + '"' : '',\r
+               this._cssText ? ' style="' + this._cssText + '"' : '',\r
        '>' ];\r
        \r
        n = html.length;\r
@@ -747,23 +784,26 @@ Node.prototype._startUpdate = function(){
        var removal, i, xnode, tmp;\r
        \r
        if( this._updateTimerID ){\r
-               //X.Timer.cancelFrame( this._updateTimerID );\r
+               //X.Timer.cancelFrame( this._updateTimerID ); // fire 空の cancel が動かない、、、\r
                this._updateTimerID = 0;\r
        } else {\r
                return;\r
        };\r
 \r
        removal = Node._reserveRemoval;\r
-       i       = removal.length;\r
        \r
        tmp = this._rawNode.style.visibility;\r
        //this._rawNode.style.visibility = 'hidden';\r
        \r
-       for( ; i; ){\r
-               xnode = removal[ --i ];\r
-               xnode._actualRemove();\r
-               xnode._destroyed && xnode.kill();\r
+       if( i = removal.length ){\r
+               for( ; i; ){\r
+                       xnode = removal[ --i ];\r
+                       xnode._actualRemove();\r
+                       !this._state && xnode.kill();\r
+               };\r
+               removal.length = 0;             \r
        };\r
+       \r
        this._commitUpdate();\r
        \r
        //this._rawNode.style.visibility = tmp;\r
@@ -773,54 +813,39 @@ Node.prototype._commitUpdate =
        document.getElementById ?\r
                ( function( parentElement, nextElement ){\r
                        var elm = this._rawNode,\r
-                               xnodes, l, i, next, k, v;\r
+                               xnodes, l, i, frg, next, k, v;\r
 \r
-                       if( !elm || ( parentElement && elm.parentNode !== parentElement ) ){\r
+                       if( !elm || ( parentElement && elm.parentNode !== parentElement ) || ( nextElement && elm.nextSibling !== nextElement ) ){\r
                                nextElement ?\r
                                        parentElement.insertBefore( this._actualCreate(), nextElement ) :\r
                                        parentElement.appendChild( this._actualCreate() );\r
                                this._afterActualCreate();\r
                                return elm || this._rawNode;\r
-                       } else          \r
-                       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
-                               for( ; l; ){\r
-                                       next = xnodes[ --l ]._commitUpdate( elm, next );\r
-                               };\r
+                       } else\r
+                       if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
+                               \r
+                               /*if( elm.childNodes.length !== l && ( frg = Node._useDocumentFragment ) ){\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               frg.appendChild( xnodes[ i ]._actualCreate( true ) );\r
+                                       };\r
+                                       elm.appendChild( frg );\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               xnodes[ i ]._afterActualCreate( true );\r
+                                       };\r
+                               } else {*/\r
+                                       for( ; l; ){\r
+                                               next = xnodes[ --l ]._commitUpdate( elm, next );\r
+                                       };\r
+                               //};\r
                        };\r
 \r
-                       // textNode\r
-                       if( this._dirty & X.Dom.Dirty.CONTENT ) elm.data = X.Dom.chrReferanceTo( this._text );\r
-                       // className\r
-                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
-                       // style\r
-                       if( this._dirty & X.Dom.Dirty.CSS ){\r
-                               if( this._cssText !== ' ' || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
-                                       elm.style.cssText = this._cssText;\r
-                               } else {\r
-                                       elm.removeAttribute( 'style' );\r
-                                       delete this._cssText;\r
-                               };\r
-                       };\r
-                       // attr\r
-                       if( this._newAttrs ){\r
-                               for( k in this._newAttrs ){\r
-                                       ( v = this._newAttrs[ k ] ) === undefined ?\r
-                                               elm.removeAttribute( k ) :\r
-                                               ( elm[ k ] = v );\r
-                               };\r
-                               delete this._newAttrs;\r
-                       };\r
-                       \r
-                       delete this._dirty;\r
-                       \r
+                       this._dirty && this._updateRawNode( elm );\r
                        return elm;\r
                }) :\r
        document.all ? \r
                ( function( parentElement, prevElement ){\r
                        var elm    = this._rawNode || this._ie4getRawNode(),\r
-                               xnodes = this._xnodes,\r
-                               l      = xnodes && xnodes.length || 0,\r
-                               i, html, elm, child, prev, attrs, k, v;\r
+                               xnodes, l, i, html, text, prev;\r
 \r
                        if( !elm ){\r
                                prevElement ?\r
@@ -828,8 +853,12 @@ Node.prototype._commitUpdate =
                                        parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );\r
                                this._afterActualCreate();\r
                                return this._rawNode || this._ie4getRawNode();\r
-                       } else\r
-                       if( this._dirty & X.Dom.Dirty.IE4_TEXTNODE_FIX ){\r
+                       };\r
+                       \r
+                       xnodes = this._xnodes;\r
+                       l      = xnodes ? xnodes.length : 0;\r
+                       \r
+                       if( this._dirty & X.Dom.Dirty.IE4_TEXTNODE_FIX || ( this._state & X.Dom.State.IE4_ONLY_TEXT && ( l !== 1 || xnodes[ 0 ]._xnodeType !== 3 ) ) ){\r
                                html = [];\r
                                for( i = 0; i < l; ++i ){\r
                                        html[ i ] = xnodes[ i ]._actualCreate();\r
@@ -838,20 +867,81 @@ Node.prototype._commitUpdate =
                                for( i = 0; i < l; ++i ){\r
                                        xnodes[ i ]._afterActualCreate();\r
                                };\r
-                       } else          \r
+                               this._state &= ~X.Dom.State.IE4_ONLY_TEXT;\r
+                       } else\r
+                       if( this._state & X.Dom.State.IE4_ONLY_TEXT ){ // textNode が swap した場合の検出は、_root で行う\r
+                               text = xnodes[ 0 ];\r
+                               if( text._dirty || !text._root ){\r
+                                       elm.innerHTML = text._text;\r
+                                       delete text._dirty;\r
+                                       text._root = this._root;                                        \r
+                               };\r
+                       } else\r
                        if( l ){\r
                                for( i = 0; i < l; ++i ){\r
                                        prev = xnodes[ i ]._commitUpdate( elm, prev );\r
                                };\r
                        };\r
+                       this._dirty && this._updateRawNode( elm );\r
+                       return elm;\r
+               }) :\r
+               (function(){});\r
+\r
+\r
+Node.prototype._updateRawNode =\r
+       document.getElementById ?\r
+               ( function( elm ){\r
+                       var attrs, k, v;\r
+\r
+                       // textNode\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ){\r
+                               elm.data = X.Dom.chrReferanceTo( this._text );\r
+                               delete this._dirty;\r
+                               return;\r
+                       };\r
+                       // id\r
+                       if( this._dirty & X.Dom.Dirty.ID ) elm.id = this._id;\r
+                       // className\r
+                       if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
+                       // style\r
+                       if( this._dirty & X.Dom.Dirty.CSS ){\r
+                               if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
+                                       elm.style.cssText = this._cssText;\r
+                               } else {\r
+                                       elm.removeAttribute( 'style' );\r
+                                       delete this._cssText;\r
+                               };\r
+                       };\r
+                       // attr\r
+                       if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
+                               for( k in attrs ){\r
+                                       ( v = attrs[ k ] ) === undefined ?\r
+                                               elm.removeAttribute( k ) :\r
+                                               ( elm[ k ] = v );\r
+                               };\r
+                               delete this._newAttrs;\r
+                       };\r
+                       \r
+                       delete this._dirty;\r
+               }) :\r
+       document.all ? \r
+               ( function( elm ){\r
+                       var attrs, k, v;\r
 \r
                        // fake textNode\r
-                       if( this._dirty & X.Dom.Dirty.CONTENT ) elm.innerHTML = this._text;\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ){\r
+                               elm.innerHTML = this._text;\r
+                               delete this._dirty;\r
+                               return;\r
+                       };\r
+                               \r
+                       // id\r
+                       if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id );\r
                        // className\r
                        if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;\r
                        // style\r
                        if( this._dirty & X.Dom.Dirty.CSS ){\r
-                               if( this._cssText !== ' ' || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
+                               if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
                                        elm.style.cssText = this._cssText;\r
                                } else {\r
                                        elm.removeAttribute( 'style' );\r
@@ -859,7 +949,7 @@ Node.prototype._commitUpdate =
                                };\r
                        };\r
                        // attr\r
-                       if( attrs = this._newAttrs ){\r
+                       if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
                                for( k in attrs ){\r
                                        ( v = attrs[ k ] ) === undefined ?\r
                                                elm.removeAttribute( k ) :\r
@@ -870,8 +960,6 @@ Node.prototype._commitUpdate =
                        };\r
                        \r
                        delete this._dirty;\r
-                       \r
-                       return elm;\r
                }) :\r
                (function(){});\r
 \r
@@ -883,7 +971,7 @@ Node.prototype._commitUpdate =
  * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");\r
  * insertAdjacentHTML\r
  * \r
- * ie7 以下では iframe の frameborder や、input name は、createElement 後に aetAttribute しても無視される\r
+ * ie7 以下では iframe の frameborder や、input name は、createElement 後に setAttribute しても無視される\r
  * \r
  * fragument がある場合 children も足して\r
  * Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
@@ -898,7 +986,9 @@ Node.prototype._actualCreate =
                        xnodes, frg, i, l;\r
                \r
                if( this._xnodeType === 3 ){\r
-                       return elm || ( this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) ) );\r
+                       if( elm ) return elm;\r
+                       delete this._dirty;\r
+                       return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
                };\r
                \r
                if( !elm ){\r
@@ -914,7 +1004,7 @@ Node.prototype._actualCreate =
                                                        this._id ? ' id="' + this._id + '"' : '',\r
                                                        this._className ? ' class="' + this._className + '"' : '',\r
                                                        this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
-                                                       this._cssText !== ' ' ? ' style="' + this._cssText + '"' : '',\r
+                                                       this._cssText ? ' style="' + this._cssText + '"' : '',\r
                                                '>' ].join( '' ) ):\r
                                        document.createElement( this._tag );\r
                };\r
@@ -930,34 +1020,44 @@ Node.prototype._actualCreate =
                \r
                return elm;\r
        }) :\r
-       document.all ? (function(){\r
+       document.all ? (function( isChild ){\r
                var uid = this._uid,\r
                        html, xnodes, n, i, l;\r
                \r
                if( this._xnodeType === 3 ){\r
-                       html = [ '<FONT id=ie4uid', uid, ' UID=', uid, '>', this._text, '</FONT>' ];// fake textNode\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
+                       if( this._rawNode && !isChild ) this._actualRemove( true );\r
+                       \r
                        if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
                                delete this._cssText;\r
                        };\r
+                       \r
                        html = [\r
-                               '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID=', uid,\r
+                               '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID="', uid, '"',\r
                                this._className ? ' class="' + this._className + '"' : '',\r
                                this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
-                               this._cssText !== ' ' ? ' style="' + this._cssText + '"' : '',\r
+                               this._cssText ? ' style="' + this._cssText + '"' : '',\r
                        '>' ];\r
                        \r
                        n = html.length;\r
                        if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
                                if( l === 1 && xnodes[ 0 ]._xnodeType === 3 ){\r
                                        // only textnode\r
-                                       // html[ n ] = xnodes[ 0 ]._text;\r
-                                       // ++n\r
-                                       // ONLY_TEXTNODE\r
-                               };\r
-                               for( i = 0; i < l; ++i ){\r
-                                       html[ n ] = xnodes[ i ]._actualCreate();\r
+                                       html[ n ] = xnodes[ 0 ]._text;\r
                                        ++n;\r
+                                       this._state |= X.Dom.State.IE4_ONLY_TEXT;\r
+                               } else {\r
+                                       for( i = 0; i < l; ++i ){\r
+                                               html[ n ] = xnodes[ i ]._actualCreate( true );\r
+                                               ++n;\r
+                                       };                                      \r
                                };\r
                        };\r
                        X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
@@ -965,7 +1065,6 @@ Node.prototype._actualCreate =
                        delete this._newAttrs;\r
                };\r
                delete this._dirty;\r
-               delete this._rawNode;\r
                \r
                return html.join( '' );\r
        }) :\r
@@ -973,20 +1072,17 @@ Node.prototype._actualCreate =
 \r
 Node.prototype._afterActualCreate =\r
        document.getElementById ? (function(){\r
-               var xnodes, l, elm, attrs, k, i;\r
+               var elm = this._rawNode, xnodes, l, attrs, k, i;\r
                \r
                this._root  = this.parent._root;\r
                \r
-               delete this._dirty;\r
                if( this._xnodeType === 3 ){\r
-                       //elm.UID = this._uid;\r
+                       this._dirty && this._updateRawNode( elm );\r
                        return this;\r
                };\r
-               delete this._newAttrs;\r
                        \r
                xnodes = this._xnodes;\r
                l      = xnodes && xnodes.length;\r
-               elm    = this._rawNode;\r
                \r
                if( this._isNew ){\r
                        if( !Node._useDocumentFragment && l ){// docFrg が使えない場合、doc 追加後に子を追加\r
@@ -996,18 +1092,16 @@ Node.prototype._afterActualCreate =
                        };\r
                        if( !X.UA.IE || 8 < X.UA.IE ){\r
                                elm.UID = this._uid;\r
-                               if( this._id ) elm.id = this._id;\r
-                               if( this._className ) elm.className = this._className;\r
-                               if( attrs = this._attrs ){\r
-                                       for( k in attrs ){\r
-                                               elm[ k ] = attrs[ k ];\r
-                                       };\r
-                               };\r
-                               if( this._cssText !== ' ' ) elm.style.cssText = this._cssText;\r
+                               this._newAttrs = this._attrs;\r
+                               this._dirty = X.Dom.Dirty.ID | X.Dom.Dirty.CLASSNAME | X.Dom.Dirty.CSS | X.Dom.Dirty.ATTR;\r
+                               this._updateRawNode( elm );\r
                        };\r
                        this._restoreEvent();// イベントの復帰\r
                        delete this._isNew;\r
+               } else {\r
+                       this._dirty && this._updateRawNode( elm );\r
                };\r
+               \r
                if( l ){\r
                        for( i = 0; i < l; ++i ){\r
                                xnodes[ i ]._afterActualCreate();\r
@@ -1017,7 +1111,7 @@ Node.prototype._afterActualCreate =
        }) :\r
        document.all ? (function(){\r
                var xnodes, i;\r
-               this._root  = this.parent && this.parent._root;\r
+               this._root = this.parent._root;\r
                \r
                if( this._xnodeType !== 1 ) return this;\r
                \r
@@ -1042,13 +1136,13 @@ Node.prototype._actualRemove =
                                        child._xnodeType === 1 && child._actualRemove( true );\r
                                };\r
                        };\r
-                       delete this._root;\r
+                       //delete this._root;\r
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
                        // elm.parentNode.tagName check tagName is for ie7\r
                        !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
                }) :\r
-       document.all ? \r
+       document.all ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
                                elm    = this._rawNode || this._ie4getRawNode(),\r
@@ -1058,13 +1152,14 @@ Node.prototype._actualRemove =
                                        xnodes[ i ]._actualRemove( true );\r
                                };\r
                        };\r
-                       delete this._root;\r
+                       //delete this._root;\r
                        if( !elm ) return;\r
                        this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
-                       delete this._rawNode;\r
+                       \r
                        elm.removeAttribute( 'id', '' ); // ?\r
-                       document.all[ 'ie4uid' + this._uid ] = null; // ?\r
+                       document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
                        if( !isChild ) elm.outerHTML = '';\r
+                       delete this._rawNode;\r
                }) :\r
                (function(){});\r
        \r
index ba4057d..011ef81 100644 (file)
@@ -325,11 +325,62 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                createTree, xnodes, s, i, n = 0;
        r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' );
        
-       r._root  = r;
+       r._root  = Node._html._root = r;
        r.parent = Node._html;
        //r.width  = new Function( 'return X.Dom.getSize()[ 0 ]' );
        //r.height = new Function( 'return X.Dom.getSize()[ 1 ]' );
        
+       // todo: cleanup tree
+       
+       body.childNodes && (function( elm, skip, head ){
+               var me         = arguments.callee,
+                       moveToHead = 'style,bgsound,area,base,meta'.split( ',' ),
+                       remove     = 'script,noscript,noframes,comment,!,noembed,nolayer'.split( ',' ),
+                       noncleanup = 'pre,textarea,code,kbd,samp,xmp,plaintext,listing'.split( ',' ),
+                       nodes      = elm.childNodes,
+                       i          = 0,
+                       node, tag, textNode, content;
+               for( ; i < nodes.length; ){
+                       node = nodes[ i ];
+                       switch( node.nodeType ){
+                               case 1 :
+                                       tag = node.tagName.toLowerCase();
+                                       if( moveToHead.indexOf( tag ) !== -1 ){
+                                               head = head || document.getElementsByTagName( 'head' )[ 0 ];
+                                               head.appendChild( node );
+                                               continue;
+                                       } else
+                                       if( remove.indexOf( tag ) !== -1 ){
+                                               node.parentNode.removeChild( node );
+                                               continue;
+                                       } else {
+                                               // pre タグ以下はスペースの置換は行わない
+                                               me( node, skip || noncleanup.indexOf( tag ) !== -1, head );
+                                       };
+                                       textNode = false;
+                                       ++i;                                            
+                                       break;
+                               case 3 :
+                                       content = skip ? node.data : X.Dom.cleanupWhiteSpace( node.data );
+                                       //console.log( 'Delete space ' + node.data.length + ' => ' + content.length );
+                                       if( !textNode && content !== ' ' && content.length ){
+                                               node.data = content;
+                                               textNode  = node;
+                                               ++i;
+                                               break;
+                                       } else
+                                       if( textNode ){
+                                               textNode.data += content; // 直前が TextNode の場合 一本化して削除
+                                       };
+                                       // ブロック要素直下のスペースだけは削除??
+                               default :
+                                       //console.log( 'Remove type: ' + node.nodeType + ' value: ' + node.nodeValue );
+                                       elm.removeChild( node );
+                                       //++count;
+                       };
+               };
+       })( body );
+       
        createTree =
                body.childNodes ?
                        (function( xnode, childNodes, skipCleanup ){
@@ -351,7 +402,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                
                                                if( _xnode._xnodeType === 1 ){
                                                        if( child.nodeType !== 1 ){
-                                                               if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' || !text ){
+                                                               if( !( text = child.data ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
                                                                        child.parentNode.removeChild( child );
                                                                        break;
                                                                };
@@ -457,20 +508,24 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                        xnode.parent = parent;
                                        
                                        if( xnode._xnodeType === 3 ){
+                                               //alert( X.Dom.cleanupWhiteSpace( xnode._text ) );
                                                if( !skipCleanup ){
                                                        if( !( text = xnode._text ) || ( text = X.Dom.cleanupWhiteSpace( text ) ) === ' ' ){
                                                                xnode.destroy();
                                                                --i;
                                                        } else
                                                        if( xtext ){
+                                                               //alert( 'xtext ' + text.charCodeAt( 0 ) + ' : ' + text.length );
                                                                xtext.text( xtext._text + text );
                                                                xnode.destroy();
                                                                --i;
                                                        } else {
+                                                               //alert( 'xnode ' + text.charCodeAt( 0 ) + ' : ' + text.length );
                                                                xnode.text( text );
                                                        };
                                                } else
                                                if( xtext ){
+                                                       //alert( 'skip ' + text.charCodeAt( 0 ) + ' : ' + text.length );
                                                        xtext.text( xtext._text + xnode._text );
                                                        xnode.destroy();
                                                        --i;
@@ -481,6 +536,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                        };
                                        
                                        if( xnode._xnodeType !== 1 ){
+                                               //alert( xnode._xnodeType )
                                                continue;
                                        };
                                        
@@ -501,14 +557,16 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
                                                                --i;
                                                                break;
                                                        } else {
-                                                               xnode.xnodes && xnode.xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
+                                                               xnode._xnodes && xnode._xnodes.length && createTree( xnode, elm.children, skipCleanup || 0 <= X.Dom.skipCleanupTagNames.indexOf( tag.toLowerCase() ) );
                                                                
                                                                !xnode._id && elm.setAttribute( 'id', 'ie4uid' + xnode._uid );
-                                                               elm.setAttribute( 'UID', '' + xnode._uid );
+                                                               elm.setAttribute( 'UID', xnode._uid );
                                                                
-                                                               tag === 'INPUT' ?
-                                                                       ( !xnode._attrs ) && ( xnode._attrs = { type : 'text' } ) :
-                                                                       ( !xnode._attrs.type ) && ( xnode._attrs.type = 'text' );
+                                                               tag === 'INPUT' && (
+                                                                       !xnode._attrs ?
+                                                                               ( xnode._attrs = { type : 'text' } ) :
+                                                                               ( !xnode._attrs.type ) || ( xnode._attrs.type = 'text' )
+                                                               );
                                                                flag |= 3;
                                                                xtext = null;
                                                                break;
@@ -544,7 +602,7 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        //alert(n +  ' ' + body.innerHTML);
        
        createTree( r, body.childNodes || body.children );
-       r._dirty = X.Dom.Dirty.IE4_TEXTNODE_FIX;
+       //r._dirty = X.Dom.Dirty.IE4_TEXTNODE_FIX;
        
        i = xnodes.length;
        Node._systemNode = s = r.create( 'div' ).className( 'hidden-sysyem-node' );
index fadd4f9..1433e45 100644 (file)
@@ -204,44 +204,47 @@ X.Dom.Attr = {
  * \r
  */\r
 X.Dom.Node.prototype.attr = function( nameOrObj /* v */ ){\r
-       var attrs, newAttrs, v, name;\r
+       var attrs = this._attrs, newAttrs, f;\r
        \r
        if( this._xnodeType !== 1 ) return this;\r
        \r
        if( nameOrObj && X.Type.isObject( nameOrObj ) ){\r
-               if( !( attrs = this._attrs ) ) attrs = this._attrs = {};\r
-               if( !( newAttrs = this._newAttrs ) ) newAttrs = this._newAttrs = {};\r
+               attrs || ( attrs = this._attrs = {} );\r
+               newAttrs = this._newAttrs || ( this._newAttrs = {} );\r
                \r
                for( p in nameOrObj ){\r
-                       this.__attr( attrs, newAttrs, p, nameOrObj[ p ] );\r
+                       if( this._setAttr( attrs, newAttrs, p, nameOrObj[ p ] ) === true ) f = true;\r
+               };\r
+               if( f ){\r
+                       delete this._attrText;\r
+                       this._dirty |= X.Dom.Dirty.ATTR;\r
+                       this._root && this._reserveUpdate();                    \r
                };\r
-               delete this._attrText; // = X.Dom.Attr.objToAttrText( attrs );\r
-               this._dirty |= X.Dom.Dirty.ATTR;\r
-               this.parent && this._reserveUpdate();\r
                return this;\r
        } else\r
        if( 1 < arguments.length ){\r
                // setter\r
-               if( !( attrs = this._attrs ) ) attrs = this._attrs = {};\r
-               if( !( newAttrs = this._newAttrs ) ) newAttrs = this._newAttrs = {};\r
-               \r
-               this.__attr( attrs, newAttrs, nameOrObj, arguments[ 1 ] );\r
-               delete this._attrText; // = X.Dom.Attr.objToAttrText( attrs );\r
-               this._dirty |= X.Dom.Dirty.ATTR;\r
-               this.parent && this._reserveUpdate();\r
+               if( this._setAttr( attrs || ( this._attrs = {} ), this._newAttrs || ( this._newAttrs = {} ), nameOrObj, arguments[ 1 ] ) === true ){\r
+                       delete this._attrText;\r
+                       this._dirty |= X.Dom.Dirty.ATTR;\r
+                       this._root && this._reserveUpdate();\r
+               };\r
                return this;\r
        } else\r
-       if( typeof nameOrObj === 'string' ){\r
+       if( typeof nameOrObj === 'string' && attrs ){\r
                // getter\r
-               if( !attrs ) return;\r
-               \r
-               return attrs[ v ];\r
+               return attrs[ nameOrObj ];\r
        };\r
 };\r
-X.Dom.Node.prototype.__attr = function( attrs, newAttrs, name, v ){\r
+X.Dom.Node.prototype._setAttr = function( attrs, newAttrs, name, v ){\r
        if( name === 'UID' ) return;\r
        if( name === 'id' ){\r
-               this._id = v !== 'ie4uid' + this._uid ? v : undefined;\r
+               v = v !== 'ie4uid' + this._uid ? v : undefined;\r
+               if( v !== this._id ){\r
+                       this._id = v;\r
+                       this._dirty |= X.Dom.Dirty.ID;\r
+                       this._root && this._reserveUpdate();\r
+               };\r
                return;\r
        };      \r
        if( name === 'class' ) return this.className( v );      \r
@@ -261,5 +264,6 @@ X.Dom.Node.prototype.__attr = function( attrs, newAttrs, name, v ){
        } else {\r
                newAttrs[ name ] = attrs[ name ] = v;\r
        };\r
+       return true;\r
 };\r
 \r
index 5dd18f5..45c2d45 100644 (file)
@@ -1033,7 +1033,7 @@ X.Dom.Node.prototype._getCharSize =
                        // appendChild
                        // removeChild
                }) :
-       document.removeChild ?
+       document.getElementById ?
                (function(){
                        var elm = document.createElement( 'span' ),
                                v;
@@ -1140,4 +1140,5 @@ X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){
        };
        
        xnode.empty().cssText( '' );
-} );
\ No newline at end of file
+} );
+
index 4101fe1..a16d089 100644 (file)
@@ -467,7 +467,7 @@ X.Dom.Query._parse = function( query, last ){
                        \r
                        console.log( '//end :' + ( xnodes && xnodes.length ) );\r
                };\r
-               console.log( 'multi:' + ( xnodes && xnodes.length ) )\r
+               console.log( 'multi:' + ( xnodes && xnodes.length ) );\r
                \r
                if( isMulti ){\r
                        xnodes && xnodes.length && ARY_PUSH.apply( ret, xnodes );\r
@@ -539,7 +539,7 @@ X.Dom.Query._parse = function( query, last ){
                        res      = [],\r
                        checked  = {},\r
                        flag_not = flags.not,\r
-                       i = 0, n = -1, elem, uid,\r
+                       i = 0, n = -1, uid,\r
                        c, xnode, tmp, node, tagName;\r
                for( ; xnode = xnodes[ i ]; ++i ){\r
                        uid = xnode._uid;\r
@@ -553,7 +553,7 @@ X.Dom.Query._parse = function( query, last ){
                                };\r
                                tmp = checked[ uid ];\r
                        };\r
-                       if( tmp ^ flag_not ) res[ ++n ] = elem;\r
+                       if( tmp ^ flag_not ) res[ ++n ] = xnode;\r
                };\r
                return res;\r
        };\r
@@ -661,7 +661,7 @@ X.Dom.Query._filter = {
                                        tmp = tmp.parent;\r
                                };\r
                                //tmp = !!(tmp && reg.test(tmp.getAttribute('lang')));\r
-                               if( ( !!( tmp && lang && lang.toLowerCase().indexOf( arg ) === 0 ) ) ^ flag_not ) res[ ++n ] = xnode;\r
+                               if( ( !!lang && lang.toLowerCase().indexOf( arg ) === 0 ) ^ flag_not ) res[ ++n ] = xnode;\r
                        };\r
                        return res;\r
                }\r
@@ -678,11 +678,10 @@ X.Dom.Query._filter = {
        contains : {\r
                m : function( flags, xnodes, arg ){\r
                        var res = [],\r
-                               textContent = $.browser.msie || $.browser.opera ? 'innerText' : 'textContent',\r
                                flag_not = flags.not,\r
-                               i = 0, n = -1, elem;\r
-                       for( ; elem = xnodes[ i ]; ++i ){\r
-                               if ( ( -1 < ( elem[ textContent ] || '' ).indexOf( arg ) ) ^ flag_not ) res[ ++n ] = elem;                                              \r
+                               i = 0, n = -1, xnode;\r
+                       for( ; xnode = xnodes[ i ]; ++i ){\r
+                               if ( ( -1 < ( xnode.text() ).indexOf( arg ) ) ^ flag_not ) res[ ++n ] = xnode;                                          \r
                        };\r
                        return res;\r
                }\r