\r
/*\r
* Node( rawElement | rawTextnode | htmlString | textString )\r
- * input=text ui#only.first > li.odd, li.even, li.odd\r
*/\r
-\r
-var Node = X.Dom.Node = function( v ){\r
- var nodeList, xnode, uid;\r
+;(function( window, document, undeifned ){\r
+X.Dom.Node = function( v ){\r
+ var nodeList, xnode, parent, uid;\r
\r
if( Node._newByTag ){\r
- delete Node._createByTag;\r
- this._tag = v;\r
+ delete Node._newByTag;\r
+ this._tag = v;\r
+ this._nodeType = 1;\r
} else\r
if( Node._newByText ){\r
- delete Node._createByText;\r
- this._text = v;\r
+ delete Node._newByText;\r
+ this._text = v;\r
+ this._nodeType = 3;\r
} else {\r
if( 1 < arguments.length ){\r
return new X.Dom.NodeList( arguments );\r
};\r
- if( v && 1 < v.length ){\r
+ if( v && 1 < v.length && typeof v !== 'string' && v[ v.length - 1 ] ){\r
return new X.Dom.NodeList( v );\r
};\r
- \r
- if( !this || this.constractor !== Node ) return new Node( v );\r
- \r
+\r
+ if( !this || this.append !== Node.prototype.append ) return new Node( v );\r
+\r
switch( Node._getType( v ) ){\r
case Node.IS_XHNODE :\r
return v;\r
case Node.IS_RAW_HTML :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
- ( uid = v.parentNode.uid ) && ( this.parent = Node._chashe[ uid ] );\r
- this._rawNode = v;\r
- this._type = 1;\r
+ // dom2 || dom0\r
+ this.parent = v !== document.body && ( parent = v.parentNode || v.parent ) && Node._getXNode( parent, v );\r
+ this._rawNode = v;\r
+ this._nodeType = 1;\r
break;\r
case Node.IS_RAW_TEXT :\r
if( xnode = Node._getXNode( v ) ) return xnode;\r
- ( uid = v.parentNode.uid ) && ( this.parent = Node._chashe[ uid ] );\r
- this._rawNode = v;\r
- this._type = 3;\r
+ // v.parentNode && ( this.parent = Node._getXNode( v.parentNode ) );\r
+ this._rawNode = v;\r
+ this._nodeType = 3;\r
break;\r
case Node.IS_HTML_STRING :\r
case Node.IS_STRING :\r
if( nodeList.length ) return nodeList[ 0 ];\r
return Node._chashe[ 0 ];\r
default :\r
- return Node._chashe[ 0 ];\r
+ if( Node._chashe.length ) return Node._chashe[ 0 ];\r
+ return;\r
}; \r
};\r
\r
this._uid = Node._chashe.length;\r
Node._chashe[ this._uid ] = this;\r
- this._rawNode &&\r
- ( this._type === 1 && 4 < X.UA.IE && X.UA.IE < 6 ) ?\r
- this._rawNode.setAttribute( 'uid', this._uid ) :\r
- ( this._rawNode.uid = this._uid );\r
+ \r
+ if( this._rawNode ){\r
+ //alert( this._rawNode.tagName || this._rawNode.data );\r
+ // this._nodeType === 1 && 4 < X.UA.IE && X.UA.IE < 5 ) ?\r
+ // this._rawNode.setAttribute( 'uid', '' + this._uid ) :\r
+ this._nodeType === 1 && /*this._rawNode.setAttribute( 'uid', '' + this._uid ); //*/( this._rawNode.uid = this._uid );\r
+ if( 9 < this._uid ) return;\r
+ //alert( ( this._rawNode.tagName || this._rawNode.data ) + this._rawNode.uid );\r
+ };\r
};\r
\r
+var Node = X.Dom.Node;\r
+\r
Node._getType = function( v ){\r
if( v === '' ) return Node.IS_STRING;\r
if( !v ) return 0;\r
};\r
return 0;\r
};\r
+Node.create = function( tag ){\r
+ Node._newByTag = true;\r
+ return new Node( tag );\r
+};\r
+Node.createText = function( text ){\r
+ Node._newByText = true;\r
+ return new Node( text );\r
+};\r
\r
-Node._chashe = [ new Node() ];\r
-Node._getXNode = function( node ){\r
- return node.uid && Node._chashe[ node.uid ];\r
+Node._chashe = [];\r
+Node._chashe[ 0 ] = new Node();\r
+Node._getXNode = function( node, v ){\r
+ if( !node ) return;\r
+ var uid;\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
};\r
\r
Node.hasClass = function( elm , className ){\r
Node.IS_STRING = 5;\r
\r
Node.prototype._uid = 0;\r
-Node.prototype._type = 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._attr = null;\r
+Node.prototype._children = null;\r
+Node.prototype._events = null;\r
Node.prototype.parent = null;\r
\r
/* --------------------------------------\r
* Create\r
*/\r
Node.prototype._create =\r
- document.createElement ? (function( isChild ){\r
+ // document.createElement of ie4 is only for OPTION & IMAGE.\r
+ ( document.appendChild ) ? (function( isChild ){\r
var tag = this._tag, node, frg;\r
if( tag === 'input' ){\r
// ie7 以下では createElement では name 等が働かない!\r
(function(){});\r
\r
Node.prototype._afterCreate =\r
- document.createElement ? (function( parent ){\r
+ ( document.appendChild ) ? (function( parent ){\r
var _children = this._children,\r
node = this._rawNode,\r
eChildren = node.childNodes,\r
delete this._isNew;\r
};\r
/*\r
- * elm.childNodes を __.children にリンクさせる\r
+ * elm.childNodes を this._children にリンクさせる\r
*/\r
if( _children ){\r
for( i = 0, l = _children.length; i < l; ++i ){\r
return this;\r
}) :\r
document.all ? (function( parent ){\r
- var elm = this._ie4getRawNode(),\r
+ var elm = this._nodeType === 1 && this._ie4getRawNode(),\r
_children = this._children,\r
- eChildren = elm.innerHTML && Node._ie4getChildNodes( elm ),\r
+ eChildren = elm && elm.innerHTML && Node._ie4getChildNodes( elm ),\r
_child, i, l;\r
this.parent = parent;\r
/*\r
- * elm.children を __.children にリンクさせる\r
+ * elm.children を this._children にリンクさせる\r
*/\r
if( _children ){\r
for( i = 0; i < l; ++i ){\r
};\r
};\r
} else\r
- if( elm.innerHTML ){\r
+ if( eChildren ){\r
this._children = eChildren;\r
} else {\r
\r
};\r
/*\r
- * イベントの復帰 if( __.events && ( elm = this._ie4getRawNode() ) )\r
+ * イベントの復帰 if( this._events && ( elm = this._ie4getRawNode() ) )\r
*/\r
\r
delete this._ie4dirty;\r
* Create\r
*/\r
Node.prototype.create = function( tag ){\r
- var elm, v;\r
- if( this.type !== 1 ) return;\r
+ var elm, xnode;\r
+ if( this._nodeType !== 1 ) return;\r
if( !this._children ) this._children = [];\r
\r
elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
\r
if( elm ){\r
- if( document.createElement ){\r
+ if( document.appendChild ){\r
elm.appendChild( document.createElement( tag ) );\r
- v = new Node( elm.lastChild );\r
+ xnode = new Node( elm.lastChild );\r
} else\r
if( document.all ){\r
elm.insertAdjacentHTML( 'BeforeEnd', '<' + tag + '>' );\r
- v = new Node( elm.children[ elm.children.length - 1 ] );\r
+ xnode = new Node( elm.children[ elm.children.length - 1 ] );\r
} else {\r
\r
};\r
} else {\r
Node._newByTag = true;\r
- v = new Node( v );\r
+ xnode = new Node( tag );\r
};\r
- v.parent = this;\r
- this._children[ this._children.length ] = v;\r
- return v;\r
+ xnode.parent = this;\r
+ this._children[ this._children.length ] = xnode;\r
+ return xnode;\r
};\r
\r
/* --------------------------------------\r
- * Create\r
+ * CreateText\r
*/\r
Node.prototype.createText = function( text ){\r
- var elm, v;\r
- if( this.type !== 1 ) return;\r
+ var elm, xnode;\r
+ if( this._nodeType !== 1 ) return;\r
if( !this._children ) this._children = [];\r
\r
elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
\r
if( elm ){\r
- if( document.createElement ){\r
+ if( document.createTextNode ){\r
elm.appendChild( document.createTextNode( text ) );\r
- v = new Node( elm.lastChild );\r
+ xnode = new Node( elm.lastChild );\r
} else\r
if( document.all ){\r
elm.insertAdjacentHTML( 'BeforeEnd', text );\r
Node._newByText = true;\r
- v = new Node( v );\r
+ xnode = new Node( text );\r
} else {\r
\r
};\r
} else {\r
Node._newByText = true;\r
- v = new Node( v );\r
+ xnode = new Node( text );\r
};\r
- v.parent = this;\r
- this._children[ this._children.length ] = v;\r
- return v;\r
+ xnode.parent = this;\r
+ this._children[ this._children.length ] = xnode;\r
+ return xnode;\r
};\r
\r
/* --------------------------------------\r
*/\r
Node.prototype.append = function( v ){\r
var elm, i, l, children;\r
- if( this.type !== 1 ) return;\r
+ if( this._nodeType !== 1 ) return;\r
\r
if( 1 < arguments.length ){\r
for( i = 0, l = arguments.length; i < l; ++i ){\r
this.append( v[ i ] );\r
};\r
} else\r
- if( 1 < v.length ){\r
+ if( v.length ){\r
this._children.push.apply( this._children, v );\r
- } else\r
- if( v ){\r
- this._children[ this._children.length ] = v;\r
};\r
break;\r
case Node.IS_XHNODE :\r
var l = arguments.length,\r
children = this._children,\r
node, i, prev, next;\r
- if( this.type !== 1 ) return;\r
+ if( this._nodeType !== 1 ) return;\r
\r
if( !children ) children = this._children = [];\r
\r
};\r
return this;\r
};\r
- if( this._type !== 1 ) return this;\r
+ if( this._nodeType !== 1 ) return this;\r
\r
if( !this.parent ){\r
children.splice( start, 0, v );\r
elm.insertAdjacentHTML( 'AfterBegin', v.outerHTML );\r
v = elm.children[ 0 ];\r
} else\r
- if( ( next = children[ start ] ) && typeof next !== 'string' && next._type !== 2 &&\r
+ if( ( next = children[ start ] ) && typeof next !== 'string' && next._nodeType !== 3 &&\r
( next = ( next._ie4getRawNode ? next._ie4getRawNode() : next ) ) ){\r
next.insertAdjacentHTML( 'BeforeBegin', v.outerHTML );\r
v = elm.children[ ( Array.prototype.indexOf.call( elm.children, next ) ) - 1 ];\r
} else\r
- if( 0 < start && ( prev = children[ start - 1 ] ) && typeof prev !== 'string' && prev._type !== 2 &&\r
+ if( 0 < start && ( prev = children[ start - 1 ] ) && typeof prev !== 'string' && prev._nodeType !== 3 &&\r
( prev = ( prev._ie4getRawNode ? prev._ie4getRawNode() : prev ) ) ){\r
prev.insertAdjacentHTML( 'AfterEnd', v.outerHTML );\r
v = elm.children[ ( Array.prototype.indexOf.call( elm.children, prev ) ) + 1 ];\r
this.appendAt( start, v[ --i ] );\r
};\r
} else\r
- if( 1 < v.length ){\r
+ if( v.length ){\r
children.push.apply( children, v );\r
- } else\r
- if( v ){\r
- children[ children.length ] = v;\r
};\r
break;\r
case Node.IS_XHNODE :\r
*/\r
if( !document.getElementById && document.all ){\r
Node.prototype._ie4beforeRemove = function(){\r
- var __ = this.__,\r
- children = __.children,\r
+ var children = this._children,\r
child, i, l, elm;\r
if( children ){\r
for( i = 0, l = children.length; i < l; ++i ){\r
};\r
if( elm = this._ie4getRawNode() ){\r
// イベントの削除\r
- if( elm.id && elm.id !== __.ie4uid ){\r
- __.id = elm.id;\r
+ if( elm.id && elm.id !== this._ie4uid ){\r
+ this._id = elm.id;\r
} else\r
if( !elm.id ){\r
- __.ie4uid = elm.id = 'ie4uid_' + ( ++Node.ie4uid );\r
+ this._ie4uid = elm.id = 'ie4uid_' + ( ++Node.ie4uid );\r
};\r
- __.htmlText = elm.outerHTML;\r
+ this._htmlText = elm.outerHTML;\r
delete this._rawNode;\r
};\r
};\r
\r
Node.prototype._ie4getRawNode = function(){\r
- var __ = this.__, elm, uid;\r
+ var elm, uid;\r
if( ( elm = this._rawNode ) && elm.parentElement ) return elm;\r
- if( ( uid = __.id ) && ( elm = document.all[ uid ] ) ){\r
+ if( ( uid = this._id ) && ( elm = document.all[ uid ] ) ){\r
return ( this._rawNode = elm );\r
};\r
- if( ( uid = __.ie4uid ) && ( elm = document.all[ uid ] ) ){\r
- delete __.ie4uid;\r
- delete __.htmlText;\r
- if( __.id ) elm.id = __.id;\r
+ if( ( uid = this._ie4uid ) && ( elm = document.all[ uid ] ) ){\r
+ delete this._ie4uid;\r
+ delete this._htmlText;\r
+ if( this._id ) elm.id = this._id;\r
return ( this._rawNode = elm );\r
};\r
};\r
\r
Node.prototype._ie4reserveUpdate = function( child ){\r
var root = Node.root;\r
- child && ( child.__.ie4dirty = true );\r
- this.__.ie4dirtyChildren = true;\r
- if( root.__.reserved === true ) return;\r
- root.__.reserved = true;\r
+ child && ( child._ie4dirty = true );\r
+ this._ie4dirtyChildren = true;\r
+ if( root._reserved === true ) return;\r
+ root._reserved = true;\r
X.Timer.once( 1, root, root._ie4startUpdate );\r
};\r
\r
- Node.root._ie4startUpdate = function(){\r
- var __ = this.__;\r
- if( __.reserved !== true ) return;\r
- if( this._ie4getRawNode() ) this._rawNode = document.all.tags( 'BODY' )[ 0 ];\r
+ Node.prototype._ie4startUpdate = function(){\r
+ if( this._reserved !== true ) return;\r
+ //if( this._ie4getRawNode() ) this._rawNode = document.all.tags( 'BODY' )[ 0 ];\r
// !this._rawNode && onload( )\r
- delete __.reserved;\r
- if( !__.children ) return;\r
+ delete this._reserved;\r
+ if( !this._children ) return;\r
this._ie4commitUpdate()._ie4afterUpdate();\r
};\r
\r
Node.prototype._ie4commitUpdate = function(){\r
- var __ = this.__,\r
- children = __.children,\r
+ var children = this._children,\r
i, l, child, html;\r
- if( !__.ie4dirtyChildren && !__.ie4dirty ){\r
+ if( !this._ie4dirtyChildren && !this._ie4dirty ){\r
for( i = 0, l = children.length; i < l; ++i ){\r
child = children[ i ];\r
child.constractor === Node && child._ie4commitUpdate();\r
for( i = 0, l = children.length; i < l; ++i ){\r
child = children[ i ];\r
html[ html.length ] = child.constractor === Node ?\r
- ( child.__.ie4dirty ? child._ie4commitUpdate() : child._create() ) :\r
+ ( child._ie4dirty ? child._ie4commitUpdate() : child._create() ) :\r
( child.outerHTML || child );\r
};\r
- if( !__.ie4dirty ){\r
+ if( !this._ie4dirty ){\r
this._rawNode.innerHTML = html.join( '' );\r
return this;\r
};\r
};\r
\r
Node.prototype._ie4afterUpdate = function(){\r
- var __ = this.__,\r
- children = __.children,\r
+ var children = this._children,\r
i, l, child;\r
- if( !__.ie4dirtyChildren && !__.ie4dirty ){\r
+ if( !this._ie4dirtyChildren && !this._ie4dirty ){\r
for( i = 0, l = children.length; i < l; ++i ){\r
child = children[ i ];\r
child.constractor === Node && child._ie4afterUpdate();\r
for( i = 0, l = children.length; i < l; ++i ){\r
child = children[ i ];\r
child.constractor === Node &&\r
- ( child.__.ie4dirty ? child._ie4afterUpdate() : child._afterCreate( this ) );\r
+ ( child._ie4dirty ? child._ie4afterUpdate() : child._afterCreate( this ) );\r
};\r
- delete __.ie4dirtyChildren;\r
- delete __.ie4dirty;\r
+ delete this._ie4dirtyChildren;\r
+ delete this._ie4dirty;\r
};\r
\r
/*\r
*/\r
Node.prototype.contains = function( v ){\r
var node, _node;\r
- if( !this.parent || this._type !== -1 ) return false;\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
Node.prototype.getChildAt = function( index ){\r
var children = this._children,\r
elm, childNodes, child, xnode;\r
- if( this._type !== 1 || index < 0 ) return;\r
+ if( this._nodeType !== 1 || index < 0 ) return;\r
if( !children ){\r
elm = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;\r
if( !elm ){\r
*/\r
Node.prototype.getByTag = function( tag ){\r
var parent = this.parent, elm, tags;\r
- if( !parent || this._type !== -1 ) return;\r
+ if( !parent || this._nodeType !== -1 ) return;\r
if( document.getElementsByTagName ){\r
if( !( elm = this._rawNode ) ) return;\r
new X.Dom.NodeList( elm.getElementsByTagName( tag ) );\r
} else\r
if( document.all ){\r
if( !( elm = this._ie4getRawNode() ) ) return;\r
- Node.root.__.reserved === true && Node.root._ie4startUpdate();\r
+ Node.root._reserved === true && Node.root._ie4startUpdate();\r
new X.Dom.NodeList( elm.all.tags( tag ) ); \r
} else {\r
\r
/* --------------------------------------\r
* attribute\r
*/\r
-\r
+Node.prototype.attr = function(){\r
+};\r
\r
/* --------------------------------------\r
* Width, Height\r
} else\r
if( document.all ){\r
if( !( elm = this._ie4getRawNode() ) ) return 0;\r
- Node.root.__.reserved === true && Node.root._ie4startUpdate();\r
+ Node.root._reserved === true && Node.root._ie4startUpdate();\r
return elm.offsetWidth; \r
} else {\r
\r
} else\r
if( document.all ){\r
if( !( elm = this._ie4getRawNode() ) ) return 0;\r
- Node.root.__.reserved === true && Node.root._ie4startUpdate();\r
+ Node.root._reserved === true && Node.root._ie4startUpdate();\r
return elm.offsetHeight; \r
} else {\r
\r
*/\r
\r
\r
+\r
X.Dom.Event.add( window, 'load', function(){\r
- var r = Node.root = new Node( document.body );\r
- r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function();\r
- r = null;\r
+ var r = Node.root = new Node( document.body ),\r
+ elm = r._rawNode,\r
+ createTree;\r
+ r.appendTo = r.appendToRoot = r.before = r.after = r.clone = r.remove = r.destroy = r.prevNode = r.nextNode = new Function( 'return this' );\r
+ \r
+ if( elm.childNodes ){\r
+ createTree = function( xnode, elm, children ){\r
+ var i = 0,\r
+ l = children.length,\r
+ child, _xnode;\r
+ for( ; i < l; ++i ){\r
+ child = children[ i ];\r
+ if( child.nodeType === 1 ){\r
+ if( !xnode._children ) xnode._children = [];\r
+ xnode._children[ xnode._children.length ] = _xnode = new Node( child );\r
+ _xnode.parent = xnode;\r
+ child.childNodes.length && createTree( _xnode, child, child.childNodes );\r
+ } else\r
+ if( child.nodeType === 3 ){\r
+ if( !xnode._children ) xnode._children = [];\r
+ xnode._children[ xnode._children.length ] = new Node( child );\r
+ } else {\r
+ elm.removeChild( child );\r
+ --i;\r
+ --l;\r
+ };\r
+ };\r
+ };\r
+ createTree( r, elm, elm.childNodes );\r
+ } else\r
+ if( elm.children ){\r
+ createTree = function( xnode, children ){\r
+ var i = 0,\r
+ l = children.length,\r
+ j = 0, child, _xnode;\r
+ \r
+ var nodes = [];\r
+ for( ; i < xnode._children.length; ++i ){\r
+ child = xnode._children[ i ];\r
+ nodes.push( child._tag || child._text );\r
+ };\r
+ i = 0;\r
+ for( ; i < l; ++i ){\r
+ child = children[ i ];\r
+ alert( xnode._rawNode.tagName + '[' + nodes.join( ', ' ) + '] > "' + child.tagName + '" ' + j + '/' + xnode._children.length )\r
+ while( j < xnode._children.length ){\r
+ _xnode = xnode._children[ j ];\r
+ ++j;\r
+ if( _xnode._nodeType === 1 ){\r
+ _xnode._rawNode = child;\r
+ _xnode.parent = xnode;\r
+ //alert( _xnode._tag + ' <= ' + child.tagName );\r
+ child.children.length && createTree( _xnode, child.children );\r
+ break;\r
+ };\r
+ };\r
+ };\r
+ };\r
+ r._children = [];\r
+ nodes = X.Dom.parse( elm.innerHTML, true );\r
+ for( i = nodes.length; i; ){\r
+ r._children[ --i ] = nodes[ i ];\r
+ alert( nodes[ i ]._tag || nodes[ i ]._text )\r
+ };\r
+ createTree( r, elm.children );\r
+ delete r._reserved;\r
+ } else {\r
+ \r
+ };\r
+ \r
return X.Callback.UN_LISTEN;\r
-} );
\ No newline at end of file
+} );\r
+\r
+})( window, document );
\ No newline at end of file