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