};
};
+X.Dom.Event._chashe = [ {}, {}, null, {} ]; // window, document, documentElement, body
+X.Dom.Event._chashe2 = [];
+
X.Dom.Event.add = function( element, type, arg2, arg3, arg4 /* [ listener || ( context + function ) || function ][ arguments ] */ ){
- var xhe = X.Dom.Event, callback, helper, list;
+ var XEvent = X.Dom.Event,
+ hash = XEvent._getHash( element, true ),
+ helper = hash[ type ],
+ callback;
callback = typeof arg2 === 'function' ? X.Callback.create( element, arg2, arg3 ) : X.Callback.create( arg2, arg3, arg4 );
- if( helper = xhe._find( element, type ) ){
+ if( helper ){
list = helper.list;
- if( list.indexOf( callback ) === -1 ) list[ list.length ] = callback;
+ list.indexOf( callback ) === -1 && ( list[ list.length ] = callback );
+ } else {
+ helper = hash[ type ] = new XEvent._Helper( element, type );
+ helper.elm = element;
+ helper.type = type;
+ helper.list = [ callback ];
+ };
+};
+
+X.Dom.Event._getHash = function( element, create ){
+ var uid, ret;
+ if( element === window ){
+ return this._chashe[ 0 ];
+ } else
+ if( element === document ){
+ return this._chashe[ 1 ];
+ } else
+ if( element === document.body ){
+ return this._chashe[ 3 ];
+ } else
+ if( element === document.documentElement ){
+ return this._chashe[ 2 ] || ( create && ( this._chashe[ 2 ] = {} ) );
+ };
+
+ if( X.UA.IE && X.UA.IE < 5 ){
+ if( uid = 2 + parseFloat( element.getAttribute( 'UID' ) ) ){
+ if( ret = this._chashe[ uid ] ) return ret;
+ if( create ) return ( this._chashe[ uid ] = {} );
+ };
+ // wrong!
+ if( uid = parseFloat( element.getAttribute( '_UID' ) ) ){
+ return this._chashe2[ uid ];
+ };
+ element.setAttrivute( '_UID', uid = this._chashe2.length );
+ if( create ) return this._chashe2[ uid ] = {};
+ //
} else {
- xhe._LIST[ xhe._LIST.length ] = new xhe._Helper( element, type, callback );
+ if( uid = 2 + element.UID ){
+ if( ret = this._chashe[ uid ] ) return ret;
+ if( create ) return ( this._chashe[ uid ] = {} );
+ };
+ // wrong!
+ if( uid = element._UID ){
+ return this._chashe2[ uid ];
+ };
+ element._UID = uid = this._chashe2.length;
+ if( create ) return this._chashe2[ uid ] = {};
+ //
};
};
X.Dom.Event.remove = function( element, type, arg2, arg3 ){
- var t = X.Dom.Event._find( element, type ),
- c = X.Callback._find( arg2, arg3 ),
- i;
- if( t && c ){
- i = t.list.indexOf( c );
+ var XEvent = X.Dom.Event,
+ hash = XEvent._getHash( element ),
+ helper, callback, i;
+ if( !hash ) return;
+
+ // element のみ指定
+ if( type === void 0 ){
+ for( type in hash ){
+ XEvent.remove( element, type );
+ };
+ XEvent._chashe.splice( XEvent._chashe.indexOf( hash ), 1 );
+ return;
+ };
+ // element, type まで指定
+ if( arg2 === void 0 ){
+ if( !( helper = hash[ type ] ) ) return;
+ list = helper.list;
+ i = list.length;
+ for( ; i; ){
+ callback = list[ --i ];
+ X.Callback._correct( callback );
+ };
+ list.length = 0;
+ helper.removeEvent();
+ delete hash[ type ];
+ return;
+ };
+ if( !( helper = hash[ type ] ) ){
+ list = helper.list;
+ i = list.indexOf( callback );
if( i !== -1 ){
- t.list.splice( i, 1 );
- X.Callback._correct( c );
+ list.splice( i, 1 );
+ if( list.pointer && i <= list.pointer ){
+ ++list.removed;
+ };
+ X.Callback._correct( callback );
+ if( list.length === 0 ){
+ helper.removeEvent();
+ delete hash[ type ];
+ };
};
- t.list.length === 0 && t.removeEvent();
};
};
-X.Dom.Event._LIST = [];
+// イベントの退避、dom が画面から抜かれる場合に実施しておく
+X.Dom.Event.migrate = function( element ){
+ var XEvent = X.Dom.Event,
+ hash = XEvent._getHash( element ),
+ type;
+ if( !hash ) return;
+ for( type in hash ){
+ hash[ type ].removeEvent( true );
+ };
+};
-X.Dom.Event._find = function( element, type ){
- var list = X.Dom.Event._LIST,
- i = list.length,
- helper;
- for( ; i; ){
- helper = list[ --i ];
- if( helper.elm === element && helper.type === type ) return helper;
+// 退避したイベントの復帰
+X.Dom.Event.restore = function( element ){
+ var XEvent = X.Dom.Event,
+ hash = XEvent._getHash( element ),
+ helper = XEvent._Helper,
+ type;
+ if( !hash ) return;
+ for( type in hash ){
+ helper.call( hash[ type ], element, type );
};
};
X.Dom.Event._Helper =
document.addEventListener ?
- (function( elm, type, callback ){
- this.elm = elm;
- this.type = type;
- this.list = [ callback ];
+ (function( elm, type ){
elm.addEventListener( type, this, false );
}) :
document.attachEvent ?
- (function( elm, type, callback ){
- this.elm = elm;
- this.type = type;
- this.list = [ callback ];
+ (function( elm, type ){
elm.attachEvent( 'on' + type, ( this.callback = X.Callback.create( this ) ) );
}) :
- (function( elm, type, callback ){
- this.elm = elm;
- this.type = type;
- this.list = [ callback ];
+ (function( elm, type ){
this.callback = elm[ 'on' + type ] = X.Callback.create( this );
});
-X.Dom.Event._Helper.prototype.handleEvent =
- window.addEventListener ?
- (function( e ){
- var list = this.list,
- e = new X.Dom.Event( e ),
- i = 0,
- ret = 0,
- f, r;
- for( ; i < list.length; ){
- f = list[ i ];
- r = f( e );
- ret |= r;
- if( r & X.Callback.UN_LISTEN ){
- list.splice( i, 1 );
- X.Callback._correct( f );
- list.length === 0 && this.removeEvent();
- } else {
- ++i;
- };
- if( r & X.Callback.CANCEL_NOW ) break;
- };
- if( ( ret & X.Callback.STOP_PROPAGATION ) ){
- e.stopPropagation();
- };
- if( ( ret & X.Callback.PREVENT_DEFAULT ) ){
- e.preventDefault();
- return false;
- };
- }) :
- (function(){
- var list = this.list,
- e = new X.Dom.Event( event, this.elm ),
- i = 0,
- ret = 0,
- r, f;
- for( ; i < list.length; ){
- f = list[ i ];
- r = f( e );
- ret |= r;
- if( r & X.Callback.UN_LISTEN ){
- list.splice( i, 1 );
- X.Callback._correct( f );
- list.length === 0 && this.removeEvent();
- } else {
- ++i;
- };
- if( r & X.Callback.CANCEL_NOW ) break;
- };
- if( ( ret & X.Callback.STOP_PROPAGATION ) ){
- event.cancelBubble = true;
- };
- if( ( ret & X.Callback.PREVENT_DEFAULT ) ){
- return event.returnValue = false;
+/*
+ * eventDispatch 中の Event.remove への対処.
+ * 現在 dispatch 中の function より以前の function が抜かれた場合の対策
+ */
+X.Dom.Event._currentList = void 0;
+
+// eventDispatch 内で remove, add されていたら?
+X.Dom.Event._Helper.prototype.handleEvent = function( e ){
+ var list = X.Dom.Event._currentList = this.list,
+ e = window.addEventListener ?
+ new X.Dom.Event( e ) :
+ new X.Dom.Event( event, this.elm ),
+ me = X.Dom.Event,
+ i = 0,
+ ret = 0,
+ p, f, r;
+ list.removed = 0;
+ for( ; i < list.length; ){
+ me._currentList = list;
+ list.pointer = p = i - list.removed;
+ f = list[ p ];
+ r = f( e ) || 0;
+ me._currentList = null;
+ ret |= r;
+ if( r & X.Callback.UN_LISTEN ){
+ list.splice( p, 1 );
+ X.Callback._correct( f );
+ if( list.length === 0 ){
+ this.removeEvent();
+ break;
};
- });
+ } else {
+ ++i;
+ };
+ if( r & X.Callback.CANCEL_NOW ) break;
+ };
+ delete me._currentList;
+ if( window.addEventListener ){
+ if( ret & X.Callback.STOP_PROPAGATION ){
+ e.stopPropagation();
+ };
+ if( ret & X.Callback.PREVENT_DEFAULT ){
+ e.preventDefault();
+ return false;
+ };
+ } else {
+ if( ret & X.Callback.STOP_PROPAGATION ){
+ event.cancelBubble = true;
+ };
+ if( ret & X.Callback.PREVENT_DEFAULT ){
+ return event.returnValue = false;
+ };
+ };
+};
X.Dom.Event._Helper.prototype.removeEvent =
document.removeEventListener ?
- (function(){
- this.elm.removeEventListener( this.type, this );
+ (function( migrate ){
+ this.type && this.elm.removeEventListener( this.type, this, false );
+ if( migrate ) return;
delete this.elm;
delete this.type;
delete this.list;
- X.Dom.Event._LIST.splice( X.Dom.Event._LIST.indexOf( this ), 1 );
}) :
document.detachEvent ?
- (function(){
- this.elm.detachEvent( 'on' + this.type, this.callback );
+ (function( migrate ){
+ this.type && this.elm.detachEvent( 'on' + this.type, this.callback );
X.Callback._correct( this.callback );
+ if( migrate ) return;
delete this.elm;
delete this.type;
delete this.list;
delete this.callback;
- X.Dom.Event._LIST.splice( X.Dom.Event._LIST.indexOf( this ), 1 );
}) :
- (function(){
+ (function( migrate ){
this.elm[ 'on' + this.type ] = X.Dom.Event.emptyFunc;
this.elm[ 'on' + this.type ] = '';
X.Callback._correct( this.callback );
+ if( migrate ) return;
delete this.elm;
delete this.type;
delete this.list;
- X.Dom.Event._LIST.splice( X.Dom.Event._LIST.indexOf( this ), 1 );
+ delete this.callback;
});
if( !document.removeEventListener && !document.detachEvent ){
/*\r
* Node( rawElement | rawTextnode | htmlString | textString )\r
*/\r
-;(function( window, document, undeifned ){\r
+//;(function( window, document, undeifned ){\r
X.Dom.Node = function( v ){\r
- var nodeList, xnode, parent, uid;\r
+ var xnodes, xnode, parent, uid = Node._chashe.length;\r
\r
if( Node._newByTag ){\r
delete Node._newByTag;\r
if( !this || this.append !== Node.prototype.append ) return new Node( v );\r
\r
switch( Node._getType( v ) ){\r
- case Node.IS_XHNODE :\r
+ case Node.IS_XNODE :\r
+ case Node.IS_XNODE_LIST :\r
return v;\r
case Node.IS_RAW_HTML :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
this.parent = v !== document.body && ( parent = v.parentNode || v.parentElement ) && Node._getXNode( parent );\r
this._rawNode = v;\r
this._nodeType = 1;\r
+ v.setAttribute( 'UID', '' + uid );\r
break;\r
case Node.IS_RAW_TEXT :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
break;\r
case Node.IS_HTML_STRING :\r
case Node.IS_STRING :\r
- if( nodeList = X.Dom.parse( v, true ) && 1 < nodeList.length ) return new X.Dom.NodeList( nodeList );\r
- if( nodeList.length ) return nodeList[ 0 ];\r
- return Node._chashe[ 0 ];\r
+ if( xnodes = X.Dom.parse( v, true ) && 1 < xnodes.length ) return new X.Dom.NodeList( xnodes );\r
+ if( xnodes.length ) return xnodes[ 0 ];\r
+ return Node.none;\r
default :\r
- if( Node._chashe.length ) return Node._chashe[ 0 ];\r
+ if( Node.none ) return Node.none;\r
return;\r
}; \r
};\r
\r
- this._uid = Node._chashe.length;\r
- Node._chashe[ this._uid ] = this;\r
- \r
- this._rawNode && this._nodeType === 1 && v.setAttribute( 'UID', '' + this._uid );\r
+ Node._chashe[ this._uid = uid ] = this;\r
};\r
\r
var Node = X.Dom.Node;\r
\r
+Node.IS_XNODE = 1;\r
+Node.IS_RAW_HTML = 2;\r
+Node.IS_RAW_TEXT = 3;\r
+Node.IS_HTML_STRING = 4;\r
+Node.IS_STRING = 5;\r
+Node.IS_DOC_FRAG = 6;\r
+Node.IS_XNODE_LIST = 7;\r
+\r
+Node.prototype._uid = 0;\r
+Node.prototype._nodeType = 0;\r
+Node.prototype._rawNode = null;\r
+Node.prototype._tag = null;\r
+Node.prototype._text = null;\r
+Node.prototype._id = null;\r
+Node.prototype._className = null;\r
+Node.prototype._attrs = null;\r
+Node.prototype._children = null;\r
+Node.prototype._events = null;\r
+Node.prototype.parent = null;\r
+\r
Node._getType = function( v ){\r
if( v === '' ) return Node.IS_STRING;\r
if( !v ) return 0;\r
- if( v.constructor === Node ) return Node.IS_XHNODE;\r
+ if( v.constructor === Node ) return Node.IS_XNODE;\r
+ if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST;\r
if( v.tagName ) return Node.IS_RAW_HTML;\r
if( v.nodeType === 3 ) return Node.IS_RAW_TEXT;\r
if( typeof v === 'string' ){\r
};\r
\r
Node._chashe = [];\r
-Node._chashe[ 0 ] = new Node();\r
+Node.none = Node._chashe[ 0 ] = new Node();\r
Node._getXNode = function( node ){\r
- if( !node ) return;\r
var uid;\r
+ if( !node ) return;\r
if( X.UA.IE && X.UA.IE < 5 ){\r
uid = parseFloat( node.getAttribute( 'UID' ) );\r
return uid && Node._chashe[ uid ];\r
- } else {\r
- return node.uid && Node._chashe[ node.UID ];\r
};\r
+ return node.UID && Node._chashe[ node.UID ];\r
};\r
\r
-Node.hasClass = function( elm , className ){\r
+Node.hasClass = function( elm, className ){\r
var cnames = ( elm.className || '' ).split( ' ' ),\r
_cnames = className.split( ' ' ),\r
- cname,\r
+ _cname,\r
i = _cnames.length;\r
for( ; i; ){\r
- cname = _cnames[ --i ];\r
- if( cname === '' ) continue;\r
- if( cnames.indexOf( cname ) === -1 ) return false;\r
+ _cname = _cnames[ --i ];\r
+ if( _cname === '' ) continue;\r
+ if( cnames.indexOf( _cname ) === -1 ) return false;\r
};\r
return true;\r
};\r
return text;\r
};\r
\r
-Node.IS_XHNODE = 1;\r
-Node.IS_RAW_HTML = 2;\r
-Node.IS_RAW_TEXT = 3;\r
-Node.IS_HTML_STRING = 4;\r
-Node.IS_STRING = 5;\r
-Node.IS_DOC_FRAG = 6;\r
-\r
-Node.prototype._uid = 0;\r
-Node.prototype._nodeType = 0;\r
-Node.prototype._rawNode = null;\r
-Node.prototype._tag = null;\r
-Node.prototype._text = null;\r
-Node.prototype._id = null;\r
-Node.prototype._className = null;\r
-Node.prototype._attrs = null;\r
-Node.prototype._children = null;\r
-Node.prototype._events = null;\r
-Node.prototype.parent = null;\r
-\r
/* --------------------------------------\r
* Dom Level 2\r
*/\r
*/\r
Node.prototype._create =\r
// document.createElement of ie4 is only for OPTION & IMAGE.\r
- ( document.appendChild ) ? (function( isChild ){\r
+ document.appendChild ? (function( isChild ){\r
var tag = this._tag, node, frg;\r
if( tag === 'input' ){\r
// ie7 以下では createElement では name 等が働かない!\r
};\r
return node;\r
}) :\r
- document.all ? (function( skipRemove ){\r
- var elm, id, html, attrs, attr, p, v, children, i, l, child;\r
+ document.all ? (function( skipRemove, skipContainsDirty ){\r
+ var id, html, attrs, attr, children, i, l, child;\r
if( this._nodeType !== 1 ) return this._text;\r
\r
- if( elm = this._rawNode || this._ie4getRawNode() ){\r
+ if( this._rawNode || this._ie4getRawNode() ){\r
if( skipRemove ){\r
- this._ie4beforeRemove();\r
+ this._beforeRemove();\r
} else {\r
// 追加する前に要素を抜く\r
this.remove(); \r
};\r
- if( !this._ie4containsDirty() ){\r
+ if( !skipContainsDirty && !this._ie4containsDirty() ){\r
return this._htmlText;\r
};\r
};\r
- id = this._id || this._ie4uid || ( 'ie4uid' + this._uid );\r
- if( id !== this._id ) this._ie4uid = id;\r
- html = [ '<', this._tag, id ? ( ' id="' + id + '"' ) : '' ];\r
+ id = this._id || ( 'ie4uid' + this._uid );\r
+ html = [ '<', this._tag, ' id=', id ];\r
if( attrs = this._attrs ){\r
for ( i = 0, l = attrs.length; i < l; ++i ){\r
attr = attrs[ i ];\r
//if( attr.name === 'id' ) continue;\r
html[ html.length ] = ' ' + ( attr.name || attr ) + '="' + ( attr.escaped || attr ) + '"';\r
- //if( attr.name === 'href' ) alert( attr.escaped );\r
};\r
};\r
html[ html.length ] = '>';\r
\r
if( ( children = this._children ) && ( l = children.length ) ){\r
for( i = 0; i < l; ++i ){\r
- child = children[ i ];\r
- html[ html.length ] = child.constructor === Node && child._create( skipRemove );\r
+ html[ html.length ] = children[ i ]._create( true, true );\r
};\r
};\r
html[ html.length ] = '<\/' + this._tag + '>';\r
eChildren = node.childNodes,\r
_child, i, l;\r
this.parent = parent;\r
+ if( this._nodeType !== 1 ) return;\r
if( this._isNew ){\r
if( _children && !document.createDocumentFragment ){ \r
Node._dom2cleanUp( this ); // docFrg が使えない場合、doc 追加後に子を追加\r
};\r
- node.uid = this._uid;\r
+ node.UID = this._uid;\r
// attr\r
// イベントの復帰\r
+ X.Dom.Event.restore( node );\r
delete this._isNew;\r
};\r
/*\r
children[ --i ]._afterCreate( this );\r
};\r
};\r
- /*\r
- * イベントの復帰 if( this._events && ( elm = this._ie4getRawNode() ) )\r
- */\r
- elm = this._ie4getRawNode();\r
+ // イベントの復帰\r
+ ( elm = this._ie4getRawNode() ) && X.Dom.Event.restore( elm );\r
}) :\r
(function(){});\r
\r
* HtmlElement の場合は内部使用専用 そのため event の破棄等しない\r
*/\r
Node.prototype.append = function( v ){\r
- var elm, i, l, children;\r
+ var elm, i, l, children, frg;\r
if( this._nodeType !== 1 ) return;\r
\r
- if( 1 < arguments.length ){\r
- for( i = 0, l = arguments.length; i < l; ++i ){\r
- // Node.fragment.append( arguments[ i ] )\r
- this.append( arguments[ i ] );\r
+ if( 1 < ( l = arguments.length ) ){\r
+ if( document.createDocumentFragment && this._rawNode ){\r
+ frg = document.createDocumentFragment();\r
+ for( i = 0; i < l; ++i ){\r
+ v = arguments[ i ];\r
+ v = v.constructor === Node ? v : new Node( v );\r
+ frg.appendChild( v._create() );\r
+ this._children[ this._children.length ] = v;\r
+ v._afterCreate( this );\r
+ };\r
+ this._rawNode.appendChild( frg );\r
+ return this;\r
+ } else {\r
+ for( i = 0; i < l; ++i ){\r
+ this.append( arguments[ i ] );\r
+ };\r
};\r
return this;\r
};\r
case Node.IS_STRING :\r
this.append( X.Dom.parse( v, true ) );\r
break;\r
- case Node.IS_XHNODE :\r
+ case Node.IS_XNODE :\r
+ if( v === Node.none ) return this;\r
if( elm ){\r
if( document.appendChild ){\r
elm.appendChild( v._create() );\r
\r
\r
Node.prototype.appendAt = function( start, v ){\r
- var l = arguments.length,\r
- children = this._children,\r
- node, i, prev, next;\r
+ var children, l, elm, i, prev, next;\r
+ \r
if( this._nodeType !== 1 ) return this;\r
\r
- if( !children ) children = this._children = [];\r
+ if( !( children = this._children ) ) children = this._children = [];\r
\r
+ l = arguments.length;\r
if( children.length <= start ){\r
- for( i = 1; i < l; ++i ){\r
- // Node.fragment.append( arguments[ i ] )\r
- return this.append( arguments[ i ] );\r
+ if( l === 2 ) return this.append( v );\r
+ v = [];\r
+ for( ; 1 < l; ){\r
+ v[ l - 2 ] = arguments[ --l ];\r
};\r
- return this;\r
+ return this.append.apply( this, v );\r
};\r
if( start < 0 ) start = 0;\r
if( 2 < l ){\r
+ if( document.createDocumentFragment && ( elm = this._rawNode ) ){\r
+ var frg = document.createDocumentFragment();\r
+ for( i = 0; i < l; ++i ){\r
+ v = arguments[ i ];\r
+ v = v.constructor === Node ? v : new Node( v );\r
+ frg.appendChild( v._create() );\r
+ children.splice( start + i, 0, v );\r
+ v._afterCreate( this );\r
+ };\r
+ elm.insertBefore( frg, elm.childNodes[ start ] );\r
+ return this;\r
+ };\r
for( ; l; ){\r
- // Node.fragment.appendAt( 0, arguments[ i ] )\r
this.appendAt( start, arguments[ --l ] );\r
};\r
return this;\r
children.push.apply( children, v );\r
};\r
break;\r
- case Node.IS_XHNODE :\r
+ case Node.IS_XNODE :\r
+ if( v === Node.none ) return this;\r
if( elm ){\r
if( document.appendChild ){\r
elm.insertBefore( v._create(), elm.childNodes[ start ] );\r
return this;\r
};\r
\r
-Node.prototype.appendTo = function( parent, opt_start ){\r
+Node.prototype.appendTo = function( parent, opt_index ){\r
if( parent.constructor === Node ){\r
- opt_start === undefined ? parent.append( this ) : parent.appendAt( opt_start, this );\r
+ opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
} else {\r
- opt_start === undefined ? new Node( parent ).append( this ) : new Node( parent ).appendAt( opt_start, this );\r
+ opt_index === undefined ? new Node( parent ).append( this ) : new Node( parent ).appendAt( opt_index, this );\r
};\r
return this;\r
};\r
\r
-Node.prototype.appendToRoot = function( opt_start ){\r
- !opt_start ? Node.root.append( this ) : Node.root.appendAt( opt_start, this );\r
+Node.prototype.appendToRoot = function( opt_index ){\r
+ opt_index === undefined ? Node.root.append( this ) : Node.root.appendAt( opt_index, this );\r
return this;\r
};\r
\r
* Before , After\r
*/\r
Node.prototype.before = function( v ){\r
- \r
+ var l;\r
+ if( this._nodeType !== 1 || !this.parent ) return this;\r
+ l = arguments.length;\r
+ if( 1 < l ){\r
+ v = [ this.getOrder() ];\r
+ for( ; l; ){\r
+ v[ l ] = arguments[ --l ];\r
+ };\r
+ return this.parent.appendAt.apply( this.parent, v );\r
+ };\r
+ return this.parent.appendAt( this.getOrder(), v );\r
};\r
\r
Node.prototype.after = function( v ){\r
- \r
+ var l;\r
+ if( this._nodeType !== 1 || !this.parent ) return this;\r
+ l = arguments.length;\r
+ if( 1 < l ){\r
+ v = [ this.getOrder() + 1 ];\r
+ for( ; l; ){\r
+ v[ l ] = arguments[ --l ];\r
+ };\r
+ return this.parent.appendAt.apply( this.parent, v );\r
+ };\r
+ return this.parent.appendAt( this.getOrder() + 1, v );\r
};\r
\r
/* --------------------------------------\r
\r
if( !parent ) return this;\r
if( document.removeChild ){\r
- this._rawNode && parent._rawNode.removeChild( this._rawNode );\r
+ if( this._rawNode ){\r
+ this._nodeType === 1 && this._beforeRemove();\r
+ parent._rawNode.removeChild( this._rawNode );\r
+ };\r
} else\r
if( document.all ){\r
- this._ie4beforeRemove();\r
+ this._nodeType === 1 && this._beforeRemove();\r
delete this._ie4dirty;\r
delete this._ie4dirtyChildren;\r
parent._ie4reserveUpdate();\r
return this;\r
};\r
\r
+Node.prototype._beforeRemove = \r
+ document.removeChild ?\r
+ ( function(){\r
+ var elm = this._rawNode, children,\r
+ child, i, l;\r
+ if( !elm ) return;\r
+ X.Dom.Event.migrate( elm ); // イベントの退避\r
+ if( children = this._children ){\r
+ for( i = 0, l = children.length; i < l; ++i ){\r
+ child = children[ i ];\r
+ child._nodeType === 1 && child._beforeRemove();\r
+ };\r
+ };\r
+ }) :\r
+ document.all ? \r
+ ( function(){\r
+ var elm = this._ie4getRawNode(),\r
+ children, i, l;\r
+ if( children = this._children ){\r
+ for( i = 0, l = children.length; i < l; ++i ){\r
+ children[ i ]._beforeRemove();\r
+ }; \r
+ };\r
+ if( !elm ) return;\r
+ X.Dom.Event.migrate( elm );// イベントの退避 \r
+ this._htmlText = elm.outerHTML;\r
+ elm.removeAttribute( 'id' ); \r
+ }) :\r
+ (function(){});\r
+\r
Node.prototype.empty = function( v ){\r
\r
};\r
* for ie4\r
*/\r
if( !document.getElementById && document.all ){\r
- Node.prototype._ie4beforeRemove = function(){\r
- var children = this._children,\r
- child, i, l, elm, id;\r
- if( children ){\r
- for( i = 0, l = children.length; i < l; ++i ){\r
- child = children[ i ];\r
- child.constructor === Node && child._ie4beforeRemove();\r
- }; \r
- };\r
- if( elm = this._ie4getRawNode() ){\r
- // イベントの削除\r
- if( ( id = elm.getAttribute( 'id' ) ) && id !== this._ie4uid ){\r
- this._id = id;\r
- } else\r
- if( !id ){\r
- elm.setAttribute( 'id', ( this._ie4uid = 'ie4uid' + this._uid ) );\r
- };\r
- this._htmlText = elm.outerHTML;\r
- elm.removeAttribute( 'id' );\r
- };\r
- };\r
- \r
+\r
Node.prototype._ie4getRawNode = function(){\r
- var elm, uid, all, i, l;\r
+ var elm, uid;\r
if( elm = this._rawNode ) return elm;\r
if( ( uid = this._id ) && ( elm = this._rawNode = document.all[ uid ] ) ){\r
return elm;\r
};\r
- if( ( uid = this._ie4uid ) && ( elm = this._rawNode = document.all[ uid ] ) ){\r
+ if( elm = this._rawNode = document.all[ 'ie4uid' + this._uid ] ){\r
if( this._id ) elm.setAttribute( 'id', this._id );\r
return elm;\r
};\r
* contains\r
*/\r
Node.prototype.contains = function( v ){\r
- var node, _node;\r
- if( !this.parent || this._nodeType !== -1 ) return false;\r
- node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
- switch( Node._getType( v ) ){\r
- case Node.IS_RAW_HTML :\r
- case Node.IS_RAW_TEXT :\r
- return node.contains( v );\r
- case Node.IS_XHNODE :\r
- _node = v._ie4getRawNode ? v._ie4getRawNode() : v._rawNode;\r
- if( _node ) return node.contains( _node );\r
- default :\r
- return false;\r
+ var node, children;\r
+ if( !v || !this.parent || this._nodeType !== -1 ) return false;\r
+ // contains ie4+\r
+ if( document.contains ){\r
+ node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
+ switch( Node._getType( v ) ){\r
+ case Node.IS_RAW_HTML :\r
+ case Node.IS_RAW_TEXT :\r
+ return node.contains( v );\r
+ case Node.IS_XNODE :\r
+ v = v._ie4getRawNode ? v._ie4getRawNode() : v._rawNode;\r
+ if( v ) return node.contains( v );\r
+ default :\r
+ return false;\r
+ }; \r
};\r
- if( this._children.indexOf( v ) !== -1 ) return true;\r
- for( i = 0, l = this._children.length; i < l; ++i ){\r
- if( ( new Node( this._children[ i ] ) ).contains( v ) === true ) return true\r
+ children = this._children;\r
+ if( children.indexOf( v ) !== -1 ) return true;\r
+ if( ( node = this._rawNode ) && node === v.parentNode ) return;\r
+ for( i = children.length; i; ){\r
+ if( children[ --i ].contains( v ) ) return true;\r
};\r
return false;\r
};\r
};\r
};\r
createTree( r, elm, elm.childNodes );\r
- alert( n)\r
} else\r
if( elm.children ){\r
createTree = function( xnode, children ){\r
return X.Callback.UN_LISTEN;\r
} );\r
\r
-})( window, document );
\ No newline at end of file
+//})( window, document );
\ No newline at end of file