4 TREE : 1, // width, height, x, y
\r
5 CONTENT : 2, // width, height, x, y textNode の内容
\r
6 CLASSNAME : 4, // _getCharSize, width, height, x, y
\r
7 CSS : 8, // _getCharSize, width, height, x, y
\r
8 ATTR : 16, // _getCharSize, width, height, x, y
\r
9 IE4_TEXTNODE_FIX : 32
\r
13 * Node( rawElement | rawTextnode | htmlString | textString )
\r
15 //;(function( window, document, undeifned ){
\r
16 X.Dom.Node = X.EventDispatcher.inherits(
\r
18 X.Class.POOL_OBJECT,
\r
36 _attrs : null, // X.Dom.Attr
\r
40 _css : null, // X.Dom.Style
\r
45 Constructor : function( v ){
\r
46 var css, xnodes, xnode, parent, uid = Node._chashe.length;
\r
48 if( Node._newByTag ){
\r
49 Node._newByTag = false;
\r
51 this._xnodeType = 1;
\r
52 arguments[ 1 ] && this.attr( arguments[ 1 ] );
\r
53 css = arguments[ 2 ];
\r
54 css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );
\r
56 if( Node._newByText ){
\r
57 Node._newByText = false;
\r
59 this._xnodeType = 3;
\r
60 this._charCode = '';
\r
61 for( v = 0; v < this._text.length; ++v ){
\r
62 this._charCode += this._text.charCodeAt( v ) + ',';
\r
65 if( 1 < arguments.length ) return new X.Dom.NodeList( arguments );
\r
66 if( X.Type.isArray( v ) && v.length ) return new X.Dom.NodeList( v );
\r
67 if( !this || this.append !== Node.prototype.append ) return new Node( v );
\r
69 switch( Node._getType( v ) ){
\r
70 case Node.IS_XNODE :
\r
71 case Node.IS_XNODE_LIST :
\r
73 case Node.IS_RAW_HTML :
\r
74 if( xnode = Node._getXNode( v ) ) return xnode;
\r
75 // v.parentNode || v.parentElement : dom1 || dom0
\r
76 this.parent = v !== document.body && ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );
\r
77 this._state = this.parent ? Node.STATE_STAGED : Node.STATE_NO_PARENT;
\r
79 this._xnodeType = 1;
\r
80 this._tag = v.tagName;
\r
82 this._className = v.className;
\r
83 this.cssText( v.style.cssText );
\r
86 if( X.UA.IE && X.UA.IE < 5 ){
\r
87 v.setAttribute( 'UID', '' + uid );
\r
93 case Node.IS_RAW_TEXT :
\r
94 if( xnode = Node._getXNode( v ) ) return xnode;
\r
95 this.parent = Node._getXNode( v.parentNode );
\r
96 this._state = this.parent ? Node.STATE_STAGED : Node.STATE_NO_PARENT;
\r
98 this._xnodeType = 3;
\r
99 this._text = v.data;
\r
102 case Node.IS_HTML_STRING :
\r
103 case Node.IS_STRING :
\r
104 if( xnodes = X.Dom.parse( v, true ) && 1 < xnodes.length ) return new X.Dom.NodeList( xnodes );
\r
105 if( xnodes.length ) return xnodes[ 0 ];
\r
107 case Node.IS_IMAGE :
\r
109 case Node.IS_WINDOW :
\r
110 case Node.IS_DOCUMENT :
\r
112 this._xnodeType = 2;
\r
113 this._state = Node.STATE_STAGED;
\r
116 if( Node.none ) return Node.none;
\r
121 Node._chashe[ this._uid = uid ] = this;
\r
126 var Node = X._shortcut = X.Dom.Node;
\r
129 Node.IS_RAW_HTML = 2;
\r
130 Node.IS_RAW_TEXT = 3;
\r
131 Node.IS_HTML_STRING = 4;
\r
132 Node.IS_STRING = 5;
\r
133 //Node.IS_DOC_FRAG = 6;
\r
134 Node.IS_XNODE_LIST = 7;
\r
135 Node.IS_WINDOW = 8;
\r
136 Node.IS_DOCUMENT = 9;
\r
137 Node.IS_IMAGE = 10;
\r
140 Node.STATE_NO_RAW = 0; // new Node されたばかり
\r
141 Node.STATE_NO_PARENT = 1; // exist node._rawNode
\r
142 //Node.STATE_DIRTY = 2;
\r
143 Node.STATE_STAGED = 2; // exist _rawNode.parentNode
\r
144 Node.STATE_DESTROYED = 3;
\r
146 Node._useDocumentFragment = document.createDocumentFragment && ( !X.UA.IE || 6 <= X.UA.IE ) && document.createDocumentFragment();
\r
148 Node._getType = function( v ){
\r
149 if( v === '' ) return Node.IS_STRING;
\r
151 if( v === window ) return Node.IS_WINDOW;
\r
152 if( v === document ) return Node.IS_DOCUMENT;
\r
153 if( v.constructor === window.Image ) return Node.IS_IMAGE;
\r
154 if( v.constructor === Node ) return Node.IS_XNODE;
\r
155 if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST;
\r
156 if( v.tagName ) return Node.IS_RAW_HTML;
\r
157 if( v.nodeType === 3 ) return Node.IS_RAW_TEXT;
\r
158 if( typeof v === 'string' ){
\r
159 return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING;
\r
161 //if( v.nodeType === 11 ) return Node.IS_DOC_FRAG;
\r
164 Node._getXNode = function( v ){
\r
165 var uid, i, chashe, xnode;
\r
166 switch( Node._getType( v ) ){
\r
167 case Node.IS_XNODE :
\r
168 case Node.IS_XNODE_LIST :
\r
170 case Node.IS_RAW_HTML :
\r
171 case Node.IS_IMAGE :
\r
172 // fake TextNode too.
\r
173 if( X.UA.IE && X.UA.IE < 5 ){
\r
174 uid = v.getAttribute( 'UID' );
\r
175 return uid && Node._chashe[ uid ];
\r
177 return v.UID && Node._chashe[ v.UID ];
\r
178 case Node.IS_WINDOW :
\r
179 return Node._window;
\r
180 case Node.IS_DOCUMENT :
\r
181 return Node._document;
\r
182 case Node.IS_RAW_TEXT :
\r
183 for( chashe = Node._chashe, i = chashe.length; i; ){
\r
184 if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;
\r
190 Node.create = function( tag, opt_attr, opt_css ){
\r
191 Node._newByTag = true;
\r
192 return new Node( tag, opt_attr, opt_css );
\r
194 Node.createText = function( text ){
\r
195 Node._newByText = true;
\r
196 return new Node( text );
\r
200 Node.getRoot = function( xnode ){
\r
201 return Node._document;
\r
202 //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document;
\r
205 Node.isXmlDocument =
\r
206 X.UA.IE && X.UA.IE < 5 ?
\r
209 return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;
\r
213 Node.none = Node._chashe[ 0 ] = new Node();
\r
214 Node._window = new Node( window ); // Node._chashe[ 1 ]
\r
215 Node._document = new Node( document ); // Node._chashe[ 2 ]
\r
216 Node._html = null; // Node._chashe[ 3 ]
\r
217 Node.root = null;// = Node._chashe[ 4 ] body
\r
218 Node._systemNode = null;// = Node._chashe[ ? ]
\r
220 Node._reserveRemoval = [];
\r
222 if( !document.getElementById && document.all ){
\r
223 Node.prototype._ie4getRawNode = function(){
\r
225 if( elm = this._rawNode ) return elm;
\r
226 if( this._id && ( elm = this._rawNode = document.all[ this._id ] ) ){
\r
229 if( elm = this._rawNode = document.all[ 'ie4uid' + this._uid ] ){
\r
230 if( this._id ) elm.setAttribute( 'id', this._id );
\r
237 /* --------------------------------------
\r
240 Node.prototype.create = function( tag, opt_attrs, opt_css ){
\r
242 if( this._xnodeType !== 1 ) return;
\r
243 if( !this._xnodes ) this._xnodes = [];
\r
245 Node._newByTag = true;
\r
246 xnode = new Node( tag, opt_attrs, opt_css );
\r
247 xnode.parent = this;
\r
249 this._reserveUpdate();
\r
250 this._xnodes[ this._xnodes.length ] = xnode;
\r
254 /* --------------------------------------
\r
257 Node.prototype.createText = function( text ){
\r
259 if( this._xnodeType !== 1 ) return;
\r
260 if( !this._xnodes ) this._xnodes = [];
\r
262 Node._newByText = true;
\r
263 xnode = new Node( text );
\r
264 xnode.parent = this;
\r
266 this._reserveUpdate();
\r
267 this._xnodes[ this._xnodes.length ] = xnode;
\r
271 /* --------------------------------------
\r
273 * http://d.hatena.ne.jp/think49/20110724/1311472811
\r
274 * http://d.hatena.ne.jp/uupaa/20100508/1273299874
\r
276 Node.prototype.clone = function( opt_clone_children ){
\r
277 var xnode, xnodes, i, l;
\r
278 switch( this._xnodeType ){
\r
280 Node._newByTag = true;
\r
281 xnode = new Node( this._tag, X.cloneObject( this._attrs ), X.cloneObject( this._css ) );
\r
282 xnode.className( this._className );
\r
283 if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
284 for( i = 0; i < l; ++i ){
\r
285 xnode.append( xnodes[ i ].clone( true ) );
\r
290 Node._newByText = true;
\r
291 xnode = new Node( this._text );
\r
300 /* --------------------------------------
\r
303 * HtmlElement の場合は内部使用専用 そのため event の破棄等しない
\r
305 Node.prototype.append = function( v ){
\r
306 var i, l, xnodes, frg;
\r
307 if( this._xnodeType !== 1 ) return;
\r
309 if( 1 < ( l = arguments.length ) ){
\r
310 for( i = 0; i < l; ++i ){
\r
311 this.append( arguments[ i ] );
\r
316 if( !( xnodes = this._xnodes ) ) this._xnodes = xnodes = [];
\r
318 switch( Node._getType( v ) ){
\r
319 case Node.IS_RAW_HTML :
\r
320 case Node.IS_RAW_TEXT :
\r
323 case Node.IS_HTML_STRING :
\r
324 case Node.IS_STRING :
\r
325 return this.append( X.Dom.parse( v, true ) );
\r
326 case Node.IS_XNODE :
\r
327 if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;
\r
328 // 親の xnodes から v を消す
\r
330 v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );
\r
332 !document.getElementById && document.all && v.remove();
\r
334 if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){
\r
335 if( v._destroyed ) alert( 'xnode already destroyed!' );
\r
336 Node._reserveRemoval.splice( i, 1 );
\r
343 this._reserveUpdate();
\r
345 v._state = Node.STATE_NO_PARENT;
\r
346 xnodes[ xnodes.length ] = v;
\r
351 Node.prototype.appendAt = function( start, v ){
\r
354 if( this._xnodeType !== 1 ) return this;
\r
356 if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = [];
\r
358 l = arguments.length;
\r
359 if( xnodes.length <= start ){
\r
360 if( l === 2 ) return this.append( v );
\r
363 v[ l - 2 ] = arguments[ --l ];
\r
365 return this.append.apply( this, v );
\r
367 if( start < 0 ) start = 0;
\r
370 this.appendAt( start, arguments[ --l ] );
\r
375 switch( Node._getType( v ) ){
\r
376 case Node.IS_RAW_HTML :
\r
377 case Node.IS_RAW_TEXT :
\r
380 case Node.IS_HTML_STRING :
\r
381 case Node.IS_STRING :
\r
382 v = X.Dom.parse( v, true );
\r
383 for( i = v.length; i; ){
\r
384 this.appendAt( start, v[ --i ] );
\r
387 case Node.IS_XNODE :
\r
388 if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;
\r
389 // 親の xnodes から v を消す
\r
391 v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );
\r
393 !document.getElementById && document.all && v.remove();
\r
395 if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){
\r
396 if( v._destroyed ) alert( 'xnode already destroyed!' );
\r
397 Node._reserveRemoval.splice( i, 1 );
\r
404 this._reserveUpdate();
\r
406 v._state = Node.STATE_NO_PARENT;
\r
407 this._xnodes.splice( start, 0, v );
\r
411 Node.prototype.appendTo = function( parent, opt_index ){
\r
412 if( parent.constructor === Node ){
\r
413 opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );
\r
415 opt_index === undefined ? new Node( parent ).append( this ) : new Node( parent ).appendAt( opt_index, this );
\r
420 Node.prototype.appendToRoot = function( opt_index ){
\r
421 opt_index === undefined ? Node.root.append( this ) : Node.root.appendAt( opt_index, this );
\r
425 /* --------------------------------------
\r
426 * Before , After, Replace
\r
428 Node.prototype.before = function( v ){
\r
430 if( this._xnodeType !== 1 || !( parent = this.parent ) ) return this;
\r
431 l = arguments.length;
\r
433 v = [ this.getOrder() ];
\r
435 v[ l ] = arguments[ --l ];
\r
437 parent.appendAt.apply( parent, v );
\r
440 parent.appendAt( this.getOrder(), v );
\r
444 Node.prototype.after = function( v ){
\r
446 if( this._xnodeType !== 1 || !( parent = this.parent ) ) return this;
\r
447 l = arguments.length;
\r
449 v = [ this.getOrder() + 1 ];
\r
451 v[ l ] = arguments[ --l ];
\r
453 parent.appendAt.apply( parent, v );
\r
456 parent.appendAt( this.getOrder() + 1, v );
\r
460 Node.prototype.replace = function( v ){
\r
461 if( !this.parent ) return this;
\r
462 return arguments.length === 1 ? this.before( v ).remove() : this.before.apply( this, arguments ).remove();
\r
465 /* --------------------------------------
\r
468 Node.prototype.remove = function(){
\r
469 var parent = this.parent;
\r
471 if( !parent ) return this;
\r
473 this._state = Node.STATE_NO_PARENT;
\r
474 parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );
\r
475 Node._reserveRemoval[ Node._reserveRemoval.length ] = this;
\r
476 parent._reserveUpdate();
\r
477 delete this.parent;
\r
481 Node.prototype.empty = function(){
\r
482 var xnodes = this._xnodes, child, i, l;
\r
483 if( xnodes && ( l = xnodes.length ) ){
\r
484 for( i = 0; i < l; ++i ){
\r
485 xnodes[ i ].destroy();
\r
492 /* --------------------------------------
\r
495 Node.prototype.destroy = function( isChild ){
\r
496 var xnodes = this._xnodes, i;
\r
498 if( this._destroyed ) return;
\r
500 if( xnodes && ( i = xnodes.length ) ){
\r
502 xnodes[ --i ].destroy( true );
\r
506 this.unlisten(); // イベントの退避
\r
508 delete Node._chashe[ this._uid ];
\r
510 if( this._rawNode && this._rawNode.parentNode && this._rawNode.parentNode.tagName ){
\r
512 this._state = Node.STATE_DESTROYED;
\r
513 this._destroyed = true; // state
\r
515 this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );
\r
516 !isChild && this._actualRemove();
\r
523 /* --------------------------------------
\r
526 Node.prototype.contains = function( v ){
\r
527 var node, xnodes, i;
\r
528 if( !v || !this.parent || this._xnodeType !== -1 ) return false;
\r
530 if( document.contains ){
\r
531 node = this._ie4getRawNode ? this._ie4getRawNode() : this._rawNode;
\r
532 switch( Node._getType( v ) ){
\r
533 case Node.IS_RAW_HTML :
\r
534 case Node.IS_RAW_TEXT :
\r
535 return node.contains( v );
\r
536 case Node.IS_XNODE :
\r
537 if( v.parent === this ) return true;
\r
538 v = v._ie4getRawNode ? v._ie4getRawNode() : v._rawNode;
\r
539 if( node && v ) return node.contains( v );
\r
545 //if( document.compareDocumentPosition ){
\r
548 xnodes = this._xnodes;
\r
549 if( xnodes.indexOf( v ) !== -1 ) return true;
\r
550 if( ( node = this._rawNode ) && node === v.parentNode ) return false;
\r
551 for( i = xnodes.length; i; ){
\r
552 if( xnodes[ --i ].contains( v ) ) return true;
\r
557 /* --------------------------------------
\r
560 Node.prototype.getChildAt = function( index ){
\r
561 var xnodes = this._xnodes;
\r
562 if( this._xnodeType !== 1 || index < 0 || !xnodes || xnodes.length <= index ) return; //?
\r
563 return xnodes[ index ];
\r
567 /* --------------------------------------
\r
568 * prevNode, nextNode, firstChild, lastChild
\r
571 Node.prototype.prevNode = function(){
\r
572 var parent = this.parent, xnodes, index;
\r
573 if( !parent ) return;
\r
574 xnodes = parent._xnodes;
\r
575 index = xnodes.indexOf( this );
\r
576 if( 0 < index ) return xnodes[ index - 1 ];
\r
578 Node.prototype.nextNode = function(){
\r
579 var parent = this.parent, xnodes, index;
\r
580 if( !parent ) return;
\r
581 xnodes = parent._xnodes;
\r
582 index = xnodes.indexOf( this );
\r
583 if( index + 1 < xnodes.length ) return xnodes[ index + 1 ];
\r
585 Node.prototype.firstChild = function(){
\r
586 return this.getChildAt( 0 );
\r
588 Node.prototype.lastChild = function(){
\r
589 return this.getChildAt( this._xnodes.length - 1 );
\r
592 /* --------------------------------------
\r
595 Node.prototype.getOrder = function(){
\r
596 var parent = this.parent;
\r
597 if( !parent ) return -1;
\r
598 return parent._xnodes.indexOf( this );
\r
601 /* --------------------------------------
\r
602 * className, addClass, removeClass, hasClass
\r
604 Node.prototype.className = function( v ){
\r
607 if( v === undefined ) return this._className;
\r
609 if( this._className === v ) return this;
\r
610 if( !v || typeof v !== 'string' ){
\r
611 delete this._className;
\r
613 this._className = v;
\r
615 this._dirty |= X.Dom.Dirty.CLASSNAME;
\r
618 Node.prototype.addClass = function( v ){
\r
619 var names = v.split( ' ' ),
\r
624 name = names[ --i ];
\r
625 if( !name ) continue;
\r
626 !this.hasClass( name ) && ( v += ( v ? ' ' : '' ) + name );
\r
628 return v ? his.className( this._className + ( this._className ? ' ' : '' ) + v ) : this;
\r
630 Node.prototype.removeClass = function( v ){
\r
632 className = this._className,
\r
633 names = v.split( ' ' ),
\r
635 if( !className ) return this;
\r
636 for( classNames = className.split( _ ), i = classNames.length; i; ){
\r
637 className = classNames[ --i ];
\r
638 for( j = names.length; j; ){
\r
639 if( className === names[ --j ] ){
\r
640 classNames.splice( i, 1 );
\r
641 names.splice( j, 1 );
\r
647 return f ? this.className( classNames.join( ' ' ) ) : this;
\r
649 Node.prototype.toggleClass = function( v ){
\r
652 Node.prototype.hasClass = function( v ){
\r
654 className = this._className,
\r
656 if( className === v ) return true;
\r
657 if( !className ) return false;
\r
659 className = _ + className + _;
\r
660 if( className.indexOf( _ + v + _ ) !== -1 ) return true; // lucky hit
\r
662 for( v = v.split( _ ), i = v.length; i; ){
\r
664 if( name === '' ) continue;
\r
665 if( className.indexOf( _ + name + _ ) === -1 ) return false;
\r
670 /* --------------------------------------
\r
673 Node.prototype.html = function( html, opt_wrap ){
\r
674 var xnodes, n, i, l;
\r
677 if( this._xnodeType === 3 ){
\r
678 if( this._text !== html ){
\r
680 this.parent && this._reserveUpdate();
\r
681 this._dirty |= X.Dom.Dirty.CONTENT;
\r
685 return this.empty().append.apply( this, X.Dom.parse( html, true ) );
\r
688 if( this._xnodeType === 3 ){
\r
692 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
693 delete this._cssText;
\r
695 html = !opt_wrap ? [] : [
\r
697 this._id ? ' id=' + this._id : '',
\r
698 this._className ? ' class="' + this._className + '"' : '',
\r
699 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
700 this._cssText ? ' style="' + this._cssText + '"' : '',
\r
704 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
705 for( i = 0; i < l; ++i ){
\r
706 html[ n ] = xnodes[ i ].html( undefined, true );
\r
710 !opt_wrap || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );
\r
712 return html.join( '' );
\r
715 Node.prototype.text = function( text ){
\r
719 if( this._xnodeType === 3 ){
\r
720 if( this._text !== text ){
\r
722 this.parent && this._reserveUpdate();
\r
723 this._dirty |= X.Dom.Dirty.CONTENT;
\r
727 this.empty().createText( text );
\r
731 if( this._xnodeType === 1 ){
\r
732 if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){
\r
733 for( text = [], n = -1; i; ){
\r
734 text[ ++n ] = xnodes[ --i ].text();
\r
736 return text.join( '' );
\r
743 /* --------------------------------------
\r
744 * Async commit update
\r
753 * root._reserveRemoval = [] に追加。commitUpdate で remove して state は not_added
\r
755 * root._reserveRemoval にいたら消す, new_parent._xnodes に挿入 steta は not_added にして commitUpdate を待つ
\r
758 Node.prototype._reserveUpdate = function( child ){
\r
759 var root = Node.root;
\r
760 //if( !root ) return;
\r
761 //child && ( child._dirty = true );
\r
762 if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( root, root._startUpdate );
\r
765 Node.prototype._startUpdate = function(){
\r
766 var removal, i, xnode, tmp;
\r
768 if( this._updateTimerID ){
\r
769 //X.Timer.cancelFrame( this._updateTimerID );
\r
770 this._updateTimerID = 0;
\r
775 removal = Node._reserveRemoval;
\r
776 i = removal.length;
\r
778 tmp = this._rawNode.style.visibility;
\r
779 //this._rawNode.style.visibility = 'hidden';
\r
782 xnode = removal[ --i ];
\r
783 xnode._actualRemove();
\r
784 xnode._destroyed && xnode.kill();
\r
786 this._commitUpdate();
\r
788 //this._rawNode.style.visibility = tmp;
\r
791 Node.prototype._commitUpdate =
\r
792 document.getElementById ?
\r
793 ( function( parentElement, nextElement ){
\r
794 var elm = this._rawNode,
\r
795 xnodes, l, i, next, k, v;
\r
799 parentElement.insertBefore( this._actualCreate(), nextElement ) :
\r
800 parentElement.appendChild( this._actualCreate() );
\r
801 this._afterActualCreate();
\r
802 return this._rawNode;
\r
804 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
806 next = xnodes[ --l ]._commitUpdate( elm, next );
\r
811 if( this._dirty & X.Dom.Dirty.CONTENT ) elm.data = X.Dom.chrReferanceTo( this._text );
\r
813 if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;
\r
815 if( this._dirty & X.Dom.Dirty.CSS ){
\r
816 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
817 elm.style.cssText = this._cssText;
\r
819 elm.removeAttribute( 'style' );
\r
820 delete this._cssText;
\r
824 if( this._newAttrs ){
\r
825 for( k in this._newAttrs ){
\r
826 ( v = this._newAttrs[ k ] ) === undefined ?
\r
827 elm.removeAttribute( k ) :
\r
830 delete this._newAttrs;
\r
833 delete this._dirty;
\r
838 ( function( parentElement, prevElement ){
\r
839 var elm = this._rawNode || this._ie4getRawNode(),
\r
840 xnodes = this._xnodes,
\r
841 l = xnodes && xnodes.length,
\r
842 i, html, elm, child, prev, k, v;
\r
846 prevElement.insertAdjacentText( 'AfterEnd', this._actualCreate() ) :
\r
847 parentElement.insertAdjacentText( 'BeforeEnd', this._actualCreate() );
\r
848 this._afterActualCreate();
\r
849 return this._rawNode || this._ie4getRawNode();
\r
851 if( this._dirty | X.Dom.Dirty.IE4_TEXTNODE_FIX ){
\r
853 for( i = 0; i < l; ++i ){
\r
854 html[ i ] = xnodes[ i ]._actualCreate();
\r
856 elm.innerHTML = html.join( '' );
\r
857 for( i = 0; i < l; ++i ){
\r
858 xnodes[ i ]._afterActualCreate();
\r
862 for( i = 0; i < l; ++i ){
\r
863 prev = xnodes[ i ]._commitUpdate( elm, prev );
\r
868 if( this._dirty & X.Dom.Dirty.CONTENT ) elm.innerHTML = this._text;
\r
870 if( this._dirty & X.Dom.Dirty.CLASSNAME ) elm.className = this._className;
\r
872 if( this._dirty & X.Dom.Dirty.CSS ){
\r
873 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
874 elm.style.cssText = this._cssText;
\r
876 elm.removeAttribute( 'style' );
\r
877 delete this._cssText;
\r
881 if( this._newAttrs ){
\r
882 for( k in this._newAttrs ){
\r
883 ( v = this._newAttrs[ k ] ) === undefined ?
\r
884 elm.removeAttribute( k ) :
\r
885 elm.setAttribute( k, v );
\r
887 delete this._newAttrs;
\r
890 delete this._dirty;
\r
896 /* --------------------------------------
\r
899 * http://d.hatena.ne.jp/uupaa/20080718/1216362040
\r
900 * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。
\r
901 * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");
\r
902 * insertAdjacentHTML
\r
904 * ie7 以下では iframe の frameborder や、input name は、createElement 後に aetAttribute しても無視される
\r
906 * fragument がある場合 children も足して
\r
907 * Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+
\r
908 * ie6 大丈夫?fragment の場合リークしないか?チェックが必要
\r
909 * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx
\r
911 * document.createElement of ie4 is only for OPTION & IMAGE.
\r
913 Node.prototype._actualCreate =
\r
914 document.getElementById ? (function( isChild ){
\r
915 var elm = this._rawNode,
\r
918 if( this._xnodeType === 3 ){
\r
919 return elm || ( this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) ) );
\r
923 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
924 delete this._cssText;
\r
926 this._isNew = true;
\r
927 this._rawNode = elm =
\r
929 document.createElement( [
\r
931 ' UID="', this._uid, '"',
\r
932 this._id ? ' id="' + this._id + '"' : '',
\r
933 this._className ? ' class="' + this._className + '"' : '',
\r
934 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
935 this._cssText ? ' style="' + this._cssText + '"' : '',
\r
936 '>' ].join( '' ) ):
\r
937 document.createElement( this._tag );
\r
939 if( Node._useDocumentFragment ){
\r
940 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
941 !isChild && ( frg = Node._useDocumentFragment ).appendChild( elm );
\r
942 for( i = 0; i < l; ++i ){
\r
943 elm.appendChild( xnodes[ i ]._actualCreate( true ) );
\r
951 document.all ? (function(){
\r
952 var uid = this._uid,
\r
953 html, xnodes, n, i, l;
\r
955 if( this._xnodeType === 3 ){
\r
956 html = [ '<font id=ie4uid', uid, ' UID=', uid, '>', this._text, '</font>' ];// fake textNode
\r
958 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
959 delete this._cssText;
\r
962 '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID=', uid,
\r
963 this._className ? ' class="' + this._className + '"' : '',
\r
964 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
965 this._cssText ? ' style="' + this._cssText + '"' : '',
\r
969 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
970 for( i = 0; i < l; ++i ){
\r
971 html[ n ] = xnodes[ i ]._actualCreate();
\r
975 X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );
\r
977 delete this._newAttrs;
\r
979 delete this._dirty;
\r
980 delete this._rawNode;
\r
982 return html.join( '' );
\r
986 Node.prototype._afterActualCreate =
\r
987 document.getElementById ? (function(){
\r
988 var xnodes, l, elm, attrs, k, i;
\r
990 this.state = Node.STATE_STAGED;
\r
991 delete this._dirty;
\r
992 if( this._xnodeType === 3 ){
\r
993 //elm.UID = this._uid;
\r
996 delete this._newAttrs;
\r
998 xnodes = this._xnodes;
\r
999 l = xnodes && xnodes.length;
\r
1000 elm = this._rawNode;
\r
1002 if( this._isNew ){
\r
1003 if( !Node._useDocumentFragment && l ){// docFrg が使えない場合、doc 追加後に子を追加
\r
1004 for( i = 0; i < l; ++i ){
\r
1005 elm.appendChild( xnodes[ i ]._actualCreate( true ) );
\r
1009 elm.UID = this._uid;
\r
1010 if( this._id ) elm.id = this._id;
\r
1011 if( this._className ) elm.className = this._className;
\r
1012 if( attrs = this._attrs ){
\r
1013 for( k in attrs ){
\r
1014 elm[ k ] = attrs[ k ];
\r
1017 elm.style.cssText = this._cssText;
\r
1019 this._restoreEvent();// イベントの復帰
\r
1020 delete this._isNew;
\r
1023 for( i = 0; i < l; ++i ){
\r
1024 xnodes[ i ]._afterActualCreate();
\r
1029 document.all ? (function(){
\r
1031 this.state = Node.STATE_STAGED;
\r
1033 if( this._xnodeType !== 1 ) return this;
\r
1035 if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){
\r
1037 xnodes[ --i ]._afterActualCreate();
\r
1040 return this._restoreEvent();// イベントの復帰
\r
1044 Node.prototype._actualRemove =
\r
1045 document.getElementById ?
\r
1046 ( function( isChild ){
\r
1047 var xnodes = this._xnodes,
\r
1048 elm = this._rawNode,
\r
1050 if( xnodes && ( l = xnodes.length ) ){
\r
1051 for( i = 0; i < l; ++i ){
\r
1052 child = xnodes[ i ];
\r
1053 child._xnodeType === 1 && child._actualRemove( true );
\r
1056 if( !elm ) return;
\r
1057 this._xnodeType === 1 && this._migrateEvent();// イベントの退避
\r
1058 // elm.parentNode.tagName check tagName is for ie7
\r
1059 !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );
\r
1062 ( function( isChild ){
\r
1063 var xnodes = this._xnodes,
\r
1064 elm = this._rawNode || this._ie4getRawNode(),
\r
1066 if( xnodes && ( l = xnodes.length ) ){
\r
1067 for( i = 0; i < l; ++i ){
\r
1068 xnodes[ i ]._actualRemove( true );
\r
1071 if( !elm ) return;
\r
1072 this._xnodeType === 1 && this._migrateEvent();// イベントの退避
\r
1073 delete this._rawNode;
\r
1074 elm.removeAttribute( 'id', '' );
\r
1075 document.all[ 'ie4uid' + this._uid ] = null;
\r
1076 if( !isChild ) elm.outerHTML = '';
\r
1081 //})( window, document );
\r