OSDN Git Service

Version 0.6.66, fixed around X.Callback.
[pettanr/clientJs.git] / 0.6.x / js / dom / 11_XDomNode.js
index 11bb2eb..7484184 100644 (file)
@@ -47,6 +47,8 @@ X.Dom.Node = X.EventDispatcher.inherits(
                _isNew     : false,\r
                \r
                _rawNode   : null,\r
+               _rect      : null, // \r
+               \r
                _root      : null, // xnode が文書ツリーに属しているか?はこれを見る\r
                parent     : null, // remove された枝も親子構造は維持している。\r
                _xnodes    : null,\r
@@ -175,7 +177,7 @@ Node._getType = function( v ){
        if( v === window ) return Node.IS_WINDOW;\r
        if( v === document ) return Node.IS_DOCUMENT;\r
        if( v.constructor === window.Image ) return Node.IS_IMAGE;\r
-       if( X.UA.Safari && X.UA.Safari < 3 ){\r
+       if( X.UA.WebKit < 525.13 ){ // Safari3-\r
                if( v.src !== undefined && v.onload !== undefined && X.Type.isNumber( v.height ) && X.Type.isNumber( v.width ) && X.Type.isBoolean( v.complete ) ){\r
                        return Node.IS_IMAGE;\r
                };\r
@@ -239,7 +241,7 @@ Node.createText = function( text ){
 \r
 Node.getRoot = function( xnode ){\r
        return Node._document;\r
-       //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
+       //return xNode._body._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
 };\r
        // XMLかどうかを判別する\r
 Node.isXmlDocument =\r
@@ -255,7 +257,7 @@ Node.none        = Node._chashe[ 0 ] = new Node();
 Node._window     = new Node( window ); // Node._chashe[ 1 ]\r
 Node._document   = new Node( document ); // Node._chashe[ 2 ]\r
 Node._html       = null; // Node._chashe[ 3 ]\r
-Node.root        = null;// = Node._chashe[ 4 ] body\r
+Node._body       = null;// = Node._chashe[ 4 ] body\r
 Node._systemNode = null;// = Node._chashe[ ? ]\r
 \r
 Node._reserveRemoval = [];\r
@@ -285,6 +287,9 @@ Node.prototype.create = function( tag, opt_attrs, opt_css ){
        this._root && this._reserveUpdate();\r
        return xnode;\r
 };\r
+Node.prototype.createAt = function( index, tag, opt_attrs, opt_css ){\r
+       // TODO\r
+};\r
 \r
 /* --------------------------------------\r
  *  CreateText\r
@@ -302,6 +307,9 @@ Node.prototype.createText = function( text ){
        this._xnodes[ this._xnodes.length ] = xnode;\r
        return xnode;\r
 };\r
+Node.prototype.createTextAt = function( index, text ){\r
+       // TODO\r
+};\r
 \r
 /* --------------------------------------\r
  *  Clone\r
@@ -469,16 +477,25 @@ Node.prototype.appendTo = function( parent, opt_index ){
 };\r
 \r
 Node.prototype.appendToRoot = function( opt_index ){\r
-       opt_index === undefined ? Node.root.append( this ) : Node.root.appendAt( opt_index, this );\r
+       opt_index === undefined ? Node._body.append( this ) : Node._body.appendAt( opt_index, this );\r
        return this;\r
 };\r
 \r
 /* --------------------------------------\r
  *  Before , After, Replace\r
  */\r
-Node.prototype.before = function( v ){\r
-       var parent, l, start;\r
-       if( !( parent = this.parent ) ) return this;\r
+Node.prototype.before = Node.prototype.prevNode = function( v ){\r
+       var parent = this.parent, xnodes, i, l, start;\r
+       \r
+       // getter\r
+       if( v === undefined ){\r
+               if( !parent ) return;\r
+               xnodes = parent._xnodes;\r
+               i      = xnodes.indexOf( this );\r
+               return 0 < i ? xnodes[ i - 1 ] : v;\r
+       };\r
+       \r
+       if( !parent ) return this;\r
        \r
        l = arguments.length;\r
        start = this.getOrder();\r
@@ -492,9 +509,18 @@ Node.prototype.before = function( v ){
        return this;\r
 };\r
 \r
-Node.prototype.after = function( v ){\r
-       var parent, l, i, start;\r
-       if( !( parent = this.parent ) ) return this;\r
+Node.prototype.after = Node.prototype.nextNode = function( v ){\r
+       var parent = this.parent, xnodes, i, l, start;\r
+       \r
+       // getter\r
+       if( v === undefined ){\r
+               if( !parent ) return;\r
+               xnodes = parent._xnodes;\r
+               i      = xnodes.indexOf( this );\r
+               return ++i < xnodes.length ? xnodes[ i ] : v;\r
+       };\r
+       \r
+       if( !parent ) return this;\r
        \r
        l = arguments.length;\r
        start = this.getOrder() + 1;\r
@@ -555,6 +581,8 @@ Node.prototype.empty = function(){
 /* --------------------------------------\r
  *  destory\r
  */\r
+Node._destroyChildFlag = false; // TODO\r
+\r
 Node.prototype.destroy = function( isChild ){\r
        var xnodes = this._xnodes, i, elm;\r
        \r
@@ -615,23 +643,8 @@ Node.prototype.getChildAt = function( i ){
 \r
 \r
 /* --------------------------------------\r
- *  prevNode, nextNode, firstChild, lastChild\r
+ *  firstChild, lastChild\r
  */\r
-\r
-Node.prototype.prevNode = function(){\r
-       var parent = this.parent, xnodes, index;\r
-       if( !parent ) return;\r
-       xnodes = parent._xnodes;\r
-       index = xnodes.indexOf( this );\r
-       if( 0 < index ) return xnodes[ index - 1 ];\r
-};\r
-Node.prototype.nextNode = function(){\r
-       var parent = this.parent, xnodes, index;\r
-       if( !parent ) return;\r
-       xnodes = parent._xnodes;\r
-       index  = xnodes.indexOf( this );\r
-       if( index + 1 < xnodes.length ) return xnodes[ index + 1 ];\r
-};\r
 Node.prototype.firstChild = function(){\r
        return this.getChildAt( 0 );\r
 };\r
@@ -690,7 +703,7 @@ Node.prototype.addClass = function( v ){
 Node.prototype.removeClass = function( v ){\r
        var _          = ' ',\r
                className  = this._className,\r
-               names      = v.split( ' ' ),\r
+               names      = v.split( _ ),\r
                classNames, i, f, j;\r
        if( !className ) return this;\r
        for( classNames = className.split( _ ), i = classNames.length; i; ){\r
@@ -704,10 +717,19 @@ Node.prototype.removeClass = function( v ){
                        };\r
                };\r
        };\r
-       return f ? this.className( classNames.join( ' ' ) ) : this;\r
+       return f ? this.className( classNames.join( _ ) ) : this;\r
 };\r
-Node.prototype.toggleClass = function( v ){\r
-\r
+Node.prototype.toggleClass = function( v, opt_toggle ){\r
+       var names, i, name;\r
+       if( opt_toggle !== undefined ){\r
+               return !!opt_toggle ? this.addClass( v ) : this.removeClass( v );       \r
+       };\r
+       names = v.split( ' ' );\r
+       for( i = names.length; i; ){\r
+               name = names[ --i ];\r
+               this.hassClass( name ) ? this.removeClass( name ) : this.addClass( name );\r
+       };\r
+       return this;\r
 };\r
 Node.prototype.hasClass = function( v ){\r
        var _ = ' ',\r
@@ -783,6 +805,10 @@ Node.prototype.text = function( text ){
                        return this;\r
                };\r
                if( !text ) return this.empty();\r
+               if( ( xnodes = this._xnodes ) && xnodes.length === 1 && xnodes[ 0 ]._xnodeType === 3 ){\r
+                       xnodes[ 0 ].text( text );\r
+                       return this;\r
+               };\r
                this.empty().createText( text );\r
                return this;\r
        };\r
@@ -810,7 +836,8 @@ Node.prototype.each = function( func ){
  * \r
  * state:\r
  *  0 : no_rawnode\r
- *  1 : not_added\r
+ *  1 : no_parent\r
+ *  2 : no_root\r
  *  3 : dirty\r
  *  4 : clean\r
  * \r
@@ -821,7 +848,7 @@ Node.prototype.each = function( func ){
  */\r
        \r
 Node.prototype._reserveUpdate = function(){\r
-       var root = Node.root;\r
+       var root = Node._body;\r
        if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( root, root._startUpdate );\r
 };\r
 \r
@@ -844,6 +871,8 @@ Node.prototype._startUpdate = function(){
        tmp = this._rawNode.style.visibility;\r
        //this._rawNode.style.visibility = 'hidden';\r
 \r
+       //console.log( '_actualRemove().' );\r
+\r
        if( i = removal.length ){\r
                for( ; i; ){\r
                        xnode = removal[ --i ];\r
@@ -853,8 +882,12 @@ Node.prototype._startUpdate = function(){
                removal.length = 0;\r
        };\r
 \r
+       //console.log( 'start _startUpdate().' );\r
+\r
        Node._html._dirty ? Node._html._commitUpdate() : this._commitUpdate();\r
        \r
+       //console.log( 'end of _startUpdate().' );\r
+       \r
        X.Dom._listeners && X.Dom._listeners[ X.Dom.Event.AFTER_UPDATE ] && X.Dom.asyncDispatch( 0, { type : X.Dom.Event.AFTER_UPDATE } );\r
        //this._rawNode.style.visibility = tmp;\r
 };\r
@@ -1005,9 +1038,10 @@ Node.prototype._updateRawNode =
                                                        continue;\r
                                                };\r
                                        };\r
+                                       k = \r
                                        ( v = attrs[ k ] ) === undefined ?\r
                                                elm.removeAttribute( rename[ k ] || k ) :\r
-                                               ( elm[ rename[ k ] || k ] = v );                                                \r
+                                               ( elm[ rename[ k ] || k ] = X.Dom.Attr.noValue[ k ] ? k : v );                          \r
 \r
                                };\r
                                delete this._newAttrs;\r
@@ -1058,7 +1092,7 @@ Node.prototype._updateRawNode =
                                for( k in attrs ){\r
                                        ( v = attrs[ k ] ) === undefined ?\r
                                                elm.removeAttribute( rename[ k ] || k ) :\r
-                                               elm.setAttribute( rename[ k ] || k, v );\r
+                                               elm.setAttribute( rename[ k ] || k, v ); // TODO X.Dom.Attr.noValue\r
                                };\r
                                delete this._newAttrs;\r
                        };\r
@@ -1078,7 +1112,7 @@ Node.prototype._updateRawNode =
  * 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
+ * Mozilla: 1.0+, IE: 5.5+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
  * ie6 大丈夫?fragment の場合リークしないか?チェックが必要\r
  * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx\r
  * \r
@@ -1258,7 +1292,7 @@ Node.prototype._actualRemove =
        X.Dom.DOM_IE4 ?\r
                ( function( isChild ){\r
                        var xnodes = this._xnodes,\r
-                               elm    = this._rawNode || this._xnodeType === 1 && this._ie4getRawNode(),\r
+                               elm    = this._rawNode || this._ie4getRawNode(),\r
                                i, l, xnode;\r
                        if( xnodes && ( l = xnodes.length ) ){\r
                                for( i = 0; i < l; ++i ){\r
@@ -1273,9 +1307,11 @@ Node.prototype._actualRemove =
                                this._attrs.value = elm.value;\r
                        };\r
                        elm.removeAttribute( 'id' ); // ?\r
-                       document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
+                       document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // MacIE5 でエラー\r
                        if( !isChild ) elm.outerHTML = '';\r
                        delete this._rawNode;\r
                }) :\r
                (function(){});\r
 \r
+console.log( 'X.Dom.Node' );\r
+\r