CLASSNAME : 8, // _getCharSize, width, height, x, y\r
ATTR : 16, // _getCharSize, width, height, x, y\r
CSS : 32, // _getCharSize, width, height, x, y\r
- IE_FILTER : X.UA.IE && X.UA.IE < 9 && !X.UA.MacIE ? 64 : 0,\r
+ IE_FILTER : X.UA.IE < 9 && !X.UA.MacIE ? 64 : 0,\r
UNKNOWN_TAG_FIX : 128,\r
IE4_TEXTNODE_FIX : 256\r
};\r
\r
_isNew : false,\r
\r
- _rawNode : null,\r
+ _rawObject : null,\r
_rect : null, // \r
\r
_root : null, // xnode が文書ツリーに属しているか?はこれを見る\r
\r
_anime : null,\r
\r
+ /*\r
+ * TODO Node の継承ができない!\r
+ */\r
Constructor : function( v ){\r
var css, xnodes, xnode, parent, uid = Node._chashe.length;\r
\r
this._xnodeType = 1;\r
this._state = X.Dom.State.DISPLAY_INLINE; // todo\r
arguments[ 1 ] && this.attr( arguments[ 1 ] );\r
- css = arguments[ 2 ] || arguments[ 1 ];\r
+ css = arguments[ 2 ];\r
css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );\r
} else\r
if( Node._newByText ){\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
- if( !this || this.append !== Node.prototype.append ) return new Node( v );\r
- \r
+ //if( !this || this.append !== Node.prototype.append ){\r
+ // return new Node( v );\r
+ //};\r
switch( Node._getType( v ) ){\r
case Node.IS_XNODE :\r
case Node.IS_XNODE_LIST :\r
// v.parentNode || v.parentElement : dom1 || dom0\r
this.parent = ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );\r
this._root = this.parent ? this.parent._root : null;\r
- this._rawNode = v;\r
+ this._rawObject = v;\r
this._xnodeType = 1;\r
this._state = X.Dom.State.DISPLAY_BLOCK; // todo\r
this._tag = v.tagName.toUpperCase();\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
this.parent = Node._getXNode( v.parentNode );\r
this._root = this.parent ? this.parent._root : null;\r
- this._rawNode = v;\r
+ this._rawObject = v;\r
this._xnodeType = 3;\r
this._state = X.Dom.State.DISPLAY_INLINE;\r
this._text = v.data;\r
return Node.none;\r
case Node.IS_IMAGE :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
- this._rawNode = v;\r
+ this._rawObject = v;\r
this._xnodeType = 4;\r
v.UID = uid;\r
this._state = X.Dom.State.EXIST;\r
break;\r
+ /*\r
case Node.IS_WINDOW :\r
case Node.IS_DOCUMENT :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
- this._rawNode = v;\r
+ this._rawObject = v;\r
this._xnodeType = 2;\r
this._state = X.Dom.State.DISPLAY_BLOCK;\r
- break;\r
+ break; */\r
default :\r
if( Node.none ) return Node.none;\r
return;\r
if( !v ) return 0;\r
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.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
- }; \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( X.Type.isHTMLElement( v ) ) return Node.IS_RAW_HTML;\r
if( v.nodeType === 3 ) return Node.IS_RAW_TEXT;\r
+ if( X.Type.isImage( v ) ) return Node.IS_IMAGE;\r
if( typeof v === 'string' ){\r
return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING;\r
};\r
case Node.IS_RAW_TEXT :\r
if( v.UID ) return Node._chashe[ v.UID ];\r
for( chashe = Node._chashe, i = chashe.length; i; ){\r
- if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;\r
+ if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawObject === v ) ) return xnode;\r
};\r
};\r
};\r
\r
Node.getRoot = function( xnode ){\r
return Node._document;\r
- //return xNode._body._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
+ //return xNode._body._rawObject.documentElement ? node : node.ownerDocument || node.document;\r
};\r
// XMLかどうかを判別する\r
Node.isXmlDocument =\r
X.emptyFunction :\r
(function( root ){\r
if( X.Type.isBoolean( root.isXML ) ) return root.isXML;\r
- return root.isXML = root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
+ return root.isXML = root._rawObject.createElement( 'p' ).tagName !== root._rawObject.createElement( 'P' ).tagName;\r
});\r
\r
Node._chashe = [];\r
Node.none = Node._chashe[ 0 ] = new Node();\r
-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._body = null;// = Node._chashe[ 4 ] body\r
-Node._systemNode = null;// = Node._chashe[ ? ]\r
+Node._window = new X.EventDispatcher( window );\r
+Node._document = new X.EventDispatcher( document );\r
+Node._html = null; // = Node._chashe[ 1 ] <html>\r
+Node._body = null; // = Node._chashe[ 2 ] <body>\r
+Node._systemNode = null; // = Node._chashe[ ? ]\r
\r
Node._reserveRemoval = [];\r
\r
if( X.Dom.DOM_IE4 ){\r
Node.prototype._ie4getRawNode = function(){\r
- var elm = this._rawNode;\r
+ var elm = this._rawObject;\r
return elm ||\r
- ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawNode = elm ) ) ||\r
- ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawNode = elm );\r
+ ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawObject = elm ) ) ||\r
+ ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawObject = elm );\r
};\r
};\r
\r
return xnode;\r
};\r
Node.prototype.createAt = function( index, tag, opt_attrs, opt_css ){\r
- // TODO\r
+ var xnode = Node.create( tag, opt_attrs, opt_css );\r
+ this.appendAt( index, xnode );\r
+ return xnode;\r
};\r
\r
/* --------------------------------------\r
return xnode;\r
};\r
Node.prototype.createTextAt = function( index, text ){\r
- // TODO\r
+ var xtext = Node.createText( text );\r
+ this.appendAt( index, xtext );\r
+ return xtext;\r
};\r
\r
/* --------------------------------------\r
\r
if( !this._state ) return;\r
\r
- elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
+ elm = this._rawObject || this._ie4getRawNode && this._ie4getRawNode();\r
\r
if( xnodes && ( i = xnodes.length ) ){\r
//for( ; i; ){\r
var elm, type, xnodes, i;\r
if( !v || this._xnodeType !== 1 ) return false;\r
// contains ie4+\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
+ if( ( elm = this._rawObject || 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
// \r
//};\r
xnodes = this._xnodes;\r
- if( xnodes.indexOf( v ) !== -1 ) return true;\r
+ if( !xnodes || !xnodes.length ) return false;\r
+ if( xnodes.indexOf( v ) !== -1 ) return true; // fast\r
if( elm === v.parentNode ) return false;\r
for( i = xnodes.length; i; ){\r
if( xnodes[ --i ].contains( v ) ) return true;\r
Node.prototype.html = function( html ){\r
var _ = '', q = '"', xnodes, n, i, l;\r
// setter\r
- if( X.Type.isString( html ) ){\r
+ if( html !== undefined ){ // String 以外に Number や false null なども許可\r
if( this._xnodeType === 3 ) return this.text( html );\r
return html ? this.empty().append.apply( this, X.Dom.parse( html, true ) ) : this.empty();\r
};\r
return this._text;\r
};\r
\r
-Node.prototype.each = function( func ){\r
- func.call( this, 0 );\r
+/*\r
+ * HTML要素に対して name の関数を実行しその戻り値を返す。関数に渡す引数も任意に設定できる。\r
+ */\r
+Node.prototype.call = function( name /*, opt_args... */ ){\r
+ var raw = this._rawObject || this._ie4getRawNode && this._ie4getRawNode(),\r
+ l = arguments.length - 1,\r
+ func, args, params, i;\r
+ if( !raw ) return;\r
+ func = raw[ name ];\r
+ if( X.Type.isFunction( func ) ){\r
+ if( l ){\r
+ args = X.copyArray( arguments );\r
+ args.shift();\r
+ return func.apply( raw, args );\r
+ };\r
+ return raw[ name ](); \r
+ } else\r
+ if( X.Type.isUnknown( func ) ){\r
+ // typeof func === unknown に対策\r
+ // http://la.ma.la/blog/diary_200509031529.htm \r
+ if( l ){\r
+ args = X.copyArray( arguments );\r
+ args.shift();\r
+ \r
+ params = [];\r
+ for( i = 0; i < l; ++i ){\r
+ params[ i ] = '_' + i;\r
+ };\r
+ params = params.join( ',' );\r
+ return Function(\r
+ params,\r
+ [ 'return this.', name, '(', params, ')' ].join( '' )\r
+ ).apply( raw, args );\r
+ };\r
+ return raw[ name ]();\r
+ };\r
+};\r
+\r
+/*\r
+ * xnode を this として関数を実行する。 NodeList.each と動作を合わせてあるため関数の戻り値は破棄される。\r
+ * 関数に渡す引数も任意に設定できる。\r
+ */\r
+Node.prototype.each = function( func /*, opt_args */ ){\r
+ var args;\r
+ if( 1 < arguments.length ){\r
+ args = X.copyArray( arguments );\r
+ args[ 0 ] = 0; \r
+ func.apply( this, args );\r
+ } else {\r
+ func.call( this, 0 );\r
+ };\r
return this;\r
};\r
\r
* Async commit update\r
* \r
* state:\r
- * 0 : no_rawnode\r
+ * 0 : no_rawObject\r
* 1 : no_parent\r
* 2 : no_root\r
* 3 : dirty\r
return;\r
};\r
if( this._updateTimerID ){\r
- //X.Timer.cancelFrame( this._updateTimerID ); // fire 中の cancel が動かない、、、\r
+ X.Timer.cancelFrame( this._updateTimerID );\r
this._updateTimerID = 0;\r
} else {\r
return;\r
\r
removal = Node._reserveRemoval;\r
\r
- tmp = this._rawNode.style.visibility;\r
- //this._rawNode.style.visibility = 'hidden';\r
+ tmp = this._rawObject.style.visibility;\r
+ //this._rawObject.style.visibility = 'hidden';\r
\r
//console.log( '_actualRemove().' );\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
+ //this._rawObject.style.visibility = tmp;\r
};\r
\r
Node.prototype._commitUpdate =\r
X.Dom.DOM_W3C ?\r
( function( parentElement, nextElement ){\r
- var elm = this._rawNode,\r
+ var elm = this._rawObject,\r
xnodes, l, i, frg, next, k, v;\r
\r
if( this._state & X.Dom.State.IE5_DISPLAY_NONE_FIX ){\r
//alert( this._tag + ' ' + !!elm );\r
+ // filter の効いている要素だけdisplay:none が無視される模様。filter を切ればよい?\r
+ // 親が、display:none の場合は?\r
elm && elm.parentNode && this._actualRemove();\r
return nextElement;\r
};\r
parentElement.appendChild( this._actualCreate() );\r
this._afterActualCreate();\r
\r
- return elm || this._rawNode;\r
+ return elm || this._rawObject;\r
} else\r
if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
\r
}) :\r
X.Dom.DOM_IE4 ? \r
( function( parentElement, prevElement ){\r
- var elm = this._rawNode || this._ie4getRawNode(),\r
+ var elm = this._rawObject || this._ie4getRawNode(),\r
xnodes, l, i, html, text, prev;\r
\r
if( !elm ){\r
prevElement.insertAdjacentHTML( 'AfterEnd', this._actualCreate() ) :\r
parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );\r
this._afterActualCreate();\r
- return this._rawNode || this._ie4getRawNode();\r
+ return this._rawObject || this._ie4getRawNode();\r
};\r
\r
xnodes = this._xnodes;\r
};\r
// className\r
if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
- this._className ? ( elm.className = this._className ) : ( elm.className && elm.removeAttribute( X.UA.IE ? 'className' : 'class' ) ); \r
+ this._className ? ( elm.className = this._className ) : ( elm.className && elm.removeAttribute( X.UA.IE5678 ? 'className' : 'class' ) ); // className は ie7-? \r
\r
// ie5 only\r
if( X.Dom.State.IE5_DISPLAY_NONE_FIX && elm.currentStyle.display === 'none' ){\r
};\r
};\r
// style\r
+ // TODO display:none の場合、更新をスキップ\r
if( this._dirty & X.Dom.Dirty.CSS ){\r
if( this._cssText !== null || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
X.UA.Opera78 || X.UA.NN6 ?\r
};\r
\r
// attr\r
+ // TODO display:none の場合、更新をスキップ\r
if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
rename = X.Dom.Attr.renameForDOM;\r
for( k in attrs ){\r
continue;\r
};\r
};\r
- k = \r
+ // TODO IE では input, なぜか buttonも、type の変更が出来ない、k === 'type' && alert( this._dirty + ' ' + elm.outerHTML );\r
( v = attrs[ k ] ) === undefined ?\r
elm.removeAttribute( rename[ k ] || k ) :\r
( elm[ rename[ k ] || k ] = X.Dom.Attr.noValue[ k ] ? k : v ); \r
};\r
\r
if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
- this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
+ this._rawObject.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
};\r
\r
// attr\r
*/\r
Node.prototype._actualCreate =\r
X.Dom.DOM_W3C ? (function( isChild ){\r
- var elm = this._rawNode,\r
+ var elm = this._rawObject,\r
xnodes, frg, i, l;\r
\r
if( this._xnodeType === 3 ){\r
if( elm ) return elm;\r
delete this._dirty;\r
- return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
+ return this._rawObject = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
};\r
\r
if( !elm ){\r
delete this._cssText;\r
};\r
this._isNew = true;\r
- this._rawNode = elm =\r
+ this._rawObject = elm =\r
X.Dom._strictElmCreation ?\r
document.createElement( [\r
'<', this._tag,\r
\r
if( this._xnodeType === 3 ){\r
html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode\r
- delete this._rawNode;\r
+ delete this._rawObject;\r
} else {\r
- if( this._rawNode && !isChild ) this._actualRemove( true );\r
+ if( this._rawObject && !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
Node.prototype._afterActualCreate =\r
X.Dom.DOM_W3C ? (function(){\r
- var elm = this._rawNode, xnodes, l, attrs, k, i;\r
+ var elm = this._rawObject, xnodes, l, attrs, k, i;\r
\r
this._root = this.parent._root;\r
\r
};\r
// src の onload があるので先ではないか?\r
// ie の str から要素を作る場合、srcだけ イベント設定後ではないか?\r
- this._restoreEvent();// イベントの復帰\r
+ X_EventDispatcher_toggleAllEvents( this, true );// イベントの復帰\r
}) :\r
X.Dom.DOM_IE4 ? (function(){\r
var xnodes, i;\r
this._ie4getRawNode().style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
};\r
delete this._dirty;\r
- this._restoreEvent();// イベントの復帰\r
+ X_EventDispatcher_toggleAllEvents( this, true );// イベントの復帰\r
}) :\r
(function(){});\r
\r
X.Dom.DOM_W3C ?\r
( function( isChild ){\r
var xnodes = this._xnodes,\r
- elm = this._rawNode,\r
+ elm = this._rawObject,\r
child, i, l;\r
if( xnodes && ( l = xnodes.length ) ){\r
for( i = 0; i < l; ++i ){\r
};\r
\r
if( !elm ) return;\r
- this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+ this._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( this, false );// イベントの退避\r
// elm.parentNode.tagName for ie7\r
if( !X.UA.MacIE ){\r
!isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
X.Dom.DOM_IE4 ?\r
( function( isChild ){\r
var xnodes = this._xnodes,\r
- elm = this._rawNode || this._ie4getRawNode(),\r
+ elm = this._rawObject || this._ie4getRawNode(),\r
i, l, xnode;\r
if( xnodes && ( l = xnodes.length ) ){\r
for( i = 0; i < l; ++i ){\r
};\r
\r
if( !elm ) return;\r
- this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
+ this._xnodeType === 1 && X_EventDispatcher_toggleAllEvents( this, false );// イベントの退避\r
\r
if( X.Dom.Attr.HAS_VALUE[ this._tag ] && ( !this._newAttrs || !X.inObject( 'value', this._newAttrs ) ) ){\r
this._attrs.value = elm.value;\r
};\r
elm.removeAttribute( 'id' ); // ?\r
- document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // MacIE5 でエラー\r
+ //document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // MacIE5 でエラー\r
if( !isChild ) elm.outerHTML = '';\r
- delete this._rawNode;\r
+ delete this._rawObject;\r
}) :\r
(function(){});\r
\r