4 ID : 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 IE_FILTER : X.UA.IE && X.UA.IE < 9 ? 32 : 0,
\r
10 IE4_TEXTNODE_FIX : 64
\r
28 POSITION_ABSOLUTE : 2,
\r
29 OVERFLOW_HIDDEN : 4,
\r
30 HAS_WIDTH_LENGTH : 8,
\r
31 HAS_WIDTH_PERCENT : 16,
\r
32 HAS_HEIGHT_LENGTH : 16,
\r
33 HAS_HEIGHT_PERCENT : 32,
\r
38 * Node( rawElement | rawTextnode | htmlString | textString )
\r
40 //;(function( window, document, undeifned ){
\r
41 X.Dom.Node = X.EventDispatcher.inherits(
\r
43 X.Class.POOL_OBJECT,
\r
50 _root : null, // xnode が文書ツリーに属しているか?はこれを見る
\r
51 parent : null, // remove された枝も親子構造は維持している。
\r
60 _attrs : null, // X.Dom.Attr
\r
64 _css : null, // X.Dom.Style
\r
69 Constructor : function( v ){
\r
70 var css, xnodes, xnode, parent, uid = Node._chashe.length;
\r
72 if( Node._newByTag ){
\r
73 Node._newByTag = false;
\r
75 this._xnodeType = 1;
\r
76 this._state = X.Dom.State.DISPLAY_INLINE; // todo
\r
77 arguments[ 1 ] && this.attr( arguments[ 1 ] );
\r
78 css = arguments[ 2 ];
\r
79 css && this[ X.Type.isString( css ) ? 'cssText' : 'css' ]( css );
\r
81 if( Node._newByText ){
\r
82 Node._newByText = false;
\r
84 this._xnodeType = 3;
\r
85 this._state = X.Dom.State.DISPLAY_INLINE;
\r
87 if( 1 < arguments.length ) return new X.Dom.NodeList( arguments );
\r
88 if( X.Type.isArray( v ) && v.length ) return new X.Dom.NodeList( v );
\r
89 if( !this || this.append !== Node.prototype.append ) return new Node( v );
\r
91 switch( Node._getType( v ) ){
\r
92 case Node.IS_XNODE :
\r
93 case Node.IS_XNODE_LIST :
\r
95 case Node.IS_RAW_HTML :
\r
96 if( xnode = Node._getXNode( v ) ) return xnode;
\r
97 // v.parentNode || v.parentElement : dom1 || dom0
\r
98 this.parent = ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && Node._getXNode( parent );
\r
99 this._root = this.parent ? this.parent._root : null;
\r
101 this._xnodeType = 1;
\r
102 this._state = X.Dom.State.DISPLAY_BLOCK; // todo
\r
103 this._tag = v.tagName;
\r
105 this._className = v.className;
\r
106 this.cssText( v.style.cssText );
\r
107 // X.Dom.Dirty.CSS を落とす
\r
110 if( X.UA.IE && X.UA.IE < 5 ){
\r
111 v.setAttribute( 'UID', '' + uid );
\r
117 case Node.IS_RAW_TEXT :
\r
118 if( xnode = Node._getXNode( v ) ) return xnode;
\r
119 this.parent = Node._getXNode( v.parentNode );
\r
120 this._root = this.parent ? this.parent._root : null;
\r
122 this._xnodeType = 3;
\r
123 this._state = X.Dom.State.DISPLAY_INLINE;
\r
124 this._text = v.data;
\r
127 case Node.IS_HTML_STRING :
\r
128 case Node.IS_STRING :
\r
129 if( xnodes = X.Dom.parse( v, true ) && 1 < xnodes.length ) return new X.Dom.NodeList( xnodes );
\r
130 if( xnodes.length ) return xnodes[ 0 ];
\r
132 case Node.IS_IMAGE :
\r
134 case Node.IS_WINDOW :
\r
135 case Node.IS_DOCUMENT :
\r
137 this._xnodeType = 2;
\r
138 this._state = X.Dom.State.DISPLAY_BLOCK;
\r
141 if( Node.none ) return Node.none;
\r
146 Node._chashe[ this._uid = uid ] = this;
\r
151 var Node = X.Dom.Node;
\r
154 Node.IS_RAW_HTML = 2;
\r
155 Node.IS_RAW_TEXT = 3;
\r
156 Node.IS_HTML_STRING = 4;
\r
157 Node.IS_STRING = 5;
\r
158 //Node.IS_DOC_FRAG = 6;
\r
159 Node.IS_XNODE_LIST = 7;
\r
160 Node.IS_WINDOW = 8;
\r
161 Node.IS_DOCUMENT = 9;
\r
162 Node.IS_IMAGE = 10;
\r
164 Node._useDocumentFragment = document.createDocumentFragment && ( !X.UA.IE || 6 <= X.UA.IE ) && document.createDocumentFragment();
\r
166 Node._getType = function( v ){
\r
167 if( v === '' ) return Node.IS_STRING;
\r
169 if( v === window ) return Node.IS_WINDOW;
\r
170 if( v === document ) return Node.IS_DOCUMENT;
\r
171 if( v.constructor === window.Image ) return Node.IS_IMAGE;
\r
172 if( v.constructor === Node ) return Node.IS_XNODE;
\r
173 if( v.constructor === X.Dom.NodeList ) return Node.IS_XNODE_LIST;
\r
174 if( v.tagName ) return Node.IS_RAW_HTML;
\r
175 if( v.nodeType === 3 ) return Node.IS_RAW_TEXT;
\r
176 if( typeof v === 'string' ){
\r
177 return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? Node.IS_HTML_STRING : Node.IS_STRING;
\r
179 //if( v.nodeType === 11 ) return Node.IS_DOC_FRAG;
\r
182 Node._getXNode = function( v ){
\r
183 var uid, i, chashe, xnode;
\r
184 switch( Node._getType( v ) ){
\r
185 case Node.IS_XNODE :
\r
186 case Node.IS_XNODE_LIST :
\r
188 case Node.IS_RAW_HTML :
\r
189 case Node.IS_IMAGE :
\r
190 // fake TextNode too.
\r
191 if( X.UA.IE && X.UA.IE < 5 ){
\r
192 uid = v.getAttribute( 'UID' );
\r
193 return uid && Node._chashe[ uid ];
\r
195 return v.UID && Node._chashe[ v.UID ];
\r
196 case Node.IS_WINDOW :
\r
197 return Node._window;
\r
198 case Node.IS_DOCUMENT :
\r
199 return Node._document;
\r
200 case Node.IS_RAW_TEXT :
\r
201 for( chashe = Node._chashe, i = chashe.length; i; ){
\r
202 if( ( xnode = Node._chashe[ --i ] ) && ( xnode._rawNode === v ) ) return xnode;
\r
208 Node.create = function( tag, opt_attrs, opt_css ){
\r
209 switch( Node._getType( tag ) ){
\r
210 case Node.IS_STRING :
\r
211 Node._newByTag = true;
\r
212 return new Node( tag, opt_attrs, opt_css );
\r
213 case Node.IS_HTML_STRING :
\r
214 return X.Dom.parse( tag, true )[ 0 ];
\r
217 Node.createText = function( text ){
\r
218 Node._newByText = true;
\r
219 return new Node( text );
\r
223 Node.getRoot = function( xnode ){
\r
224 return Node._document;
\r
225 //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document;
\r
228 Node.isXmlDocument =
\r
229 X.UA.IE && X.UA.IE < 5 ?
\r
232 return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;
\r
236 Node.none = Node._chashe[ 0 ] = new Node();
\r
237 Node._window = new Node( window ); // Node._chashe[ 1 ]
\r
238 Node._document = new Node( document ); // Node._chashe[ 2 ]
\r
239 Node._html = null; // Node._chashe[ 3 ]
\r
240 Node.root = null;// = Node._chashe[ 4 ] body
\r
241 Node._systemNode = null;// = Node._chashe[ ? ]
\r
243 Node._reserveRemoval = [];
\r
245 if( !document.getElementById && document.all ){
\r
246 Node.prototype._ie4getRawNode = function(){
\r
247 var elm = this._rawNode;
\r
249 ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawNode = elm ) ) ||
\r
250 ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawNode = elm );
\r
255 /* --------------------------------------
\r
258 Node.prototype.create = function( tag, opt_attrs, opt_css ){
\r
260 if( this._xnodeType !== 1 ) return;
\r
261 if( !this._xnodes ) this._xnodes = [];
\r
263 xnode = Node.create( tag, opt_attrs, opt_css );
\r
265 xnode.parent = this;
\r
266 this._xnodes[ this._xnodes.length ] = xnode;
\r
267 this._root && this._reserveUpdate();
\r
271 /* --------------------------------------
\r
274 Node.prototype.createText = function( text ){
\r
276 if( this._xnodeType !== 1 ) return;
\r
277 if( !this._xnodes ) this._xnodes = [];
\r
279 Node._newByText = true;
\r
280 xnode = new Node( text );
\r
281 xnode.parent = this;
\r
283 this._root && this._reserveUpdate();
\r
284 this._xnodes[ this._xnodes.length ] = xnode;
\r
288 /* --------------------------------------
\r
290 * http://d.hatena.ne.jp/think49/20110724/1311472811
\r
291 * http://d.hatena.ne.jp/uupaa/20100508/1273299874
\r
293 Node.prototype.clone = function( opt_clone_children ){
\r
294 var xnode, xnodes, i, l;
\r
295 switch( this._xnodeType ){
\r
297 Node._newByTag = true;
\r
298 xnode = new Node( this._tag, X.cloneObject( this._attrs ), X.cloneObject( this._css ) )
\r
299 .attr( { 'id' : this._id } )
\r
300 .className( this._className );
\r
301 if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
302 for( i = 0; i < l; ++i ){
\r
303 xnode.append( xnodes[ i ].clone( true ) );
\r
308 Node._newByText = true;
\r
309 xnode = new Node( this._text );
\r
318 /* --------------------------------------
\r
321 * HtmlElement の場合は内部使用専用 そのため event の破棄等しない
\r
323 Node.prototype.append = function( v ){
\r
324 var i, l, xnodes, frg;
\r
325 if( this._xnodeType !== 1 ) return;
\r
327 if( 1 < ( l = arguments.length ) ){
\r
328 for( i = 0; i < l; ++i ){
\r
329 this.append( arguments[ i ] );
\r
334 if( !( xnodes = this._xnodes ) ) this._xnodes = xnodes = [];
\r
336 switch( Node._getType( v ) ){
\r
337 case Node.IS_RAW_HTML :
\r
338 case Node.IS_RAW_TEXT :
\r
341 case Node.IS_HTML_STRING :
\r
342 case Node.IS_STRING :
\r
343 return this.append.apply( this, X.Dom.parse( v, true ) );
\r
344 case Node.IS_XNODE :
\r
345 if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;
\r
346 // 親の xnodes から v を消す
\r
348 //if( document.getElementById ){
\r
349 // v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );
\r
351 //if( document.all ){
\r
357 if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){
\r
358 if( !this._state ) alert( 'xnode already destroyed!' );
\r
359 Node._reserveRemoval.splice( i, 1 );
\r
367 xnodes[ xnodes.length ] = v;
\r
368 this._root && this._reserveUpdate();
\r
373 Node.prototype.appendAt = function( start, v ){
\r
376 if( this._xnodeType !== 1 ) return this;
\r
378 l = arguments.length;
\r
379 if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = [];
\r
381 if( xnodes.length <= start ){
\r
382 if( l === 2 ) return this.append( v );
\r
383 for( i = 1; i < l; ++i ){
\r
384 this.append( arguments[ i ] );
\r
388 if( start < 0 ) start = 0;
\r
391 this.appendAt( start, arguments[ --l ] );
\r
396 switch( Node._getType( v ) ){
\r
397 case Node.IS_RAW_HTML :
\r
398 case Node.IS_RAW_TEXT :
\r
401 case Node.IS_HTML_STRING :
\r
402 case Node.IS_STRING :
\r
403 v = X.Dom.parse( v, true );
\r
404 for( i = v.length; i; ){
\r
405 this.appendAt( start, v[ --i ] );
\r
408 case Node.IS_XNODE :
\r
409 if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;
\r
410 // 親の xnodes から v を消す
\r
412 //if( document.getElementById ){
\r
413 // v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );
\r
415 //if( document.all ){
\r
421 if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){
\r
422 if( !this._state ) alert( 'xnode already destroyed!' );
\r
423 Node._reserveRemoval.splice( i, 1 );
\r
431 this._xnodes.splice( start, 0, v );
\r
432 this._root && this._reserveUpdate();
\r
436 Node.prototype.appendTo = function( parent, opt_index ){
\r
437 switch( Node._getType( parent ) ){
\r
438 case Node.IS_RAW_HTML :
\r
439 parent = new Node( parent );
\r
441 case Node.IS_HTML_STRING :
\r
442 parent = X.Dom.parse( parent, true );
\r
443 parent = parent[ 0 ] || parent;
\r
444 case Node.IS_XNODE :
\r
449 opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );
\r
453 Node.prototype.appendToRoot = function( opt_index ){
\r
454 opt_index === undefined ? Node.root.append( this ) : Node.root.appendAt( opt_index, this );
\r
458 /* --------------------------------------
\r
459 * Before , After, Replace
\r
461 Node.prototype.before = function( v ){
\r
462 var parent, l, start;
\r
463 if( !( parent = this.parent ) ) return this;
\r
465 l = arguments.length;
\r
466 start = this.getOrder();
\r
469 parent.appendAt( start, arguments[ --l ] );
\r
473 parent.appendAt( start, v );
\r
477 Node.prototype.after = function( v ){
\r
478 var parent, l, i, start;
\r
479 if( !( parent = this.parent ) ) return this;
\r
481 l = arguments.length;
\r
482 start = this.getOrder() + 1;
\r
483 if( parent._xnodes.length <= start ){
\r
485 for( i = 0; i < l; ++i ){
\r
486 parent.append( arguments[ i ] );
\r
490 parent.append( v );
\r
495 parent.appendAt( start, arguments[ --l ] );
\r
499 parent.appendAt( start, v );
\r
503 Node.prototype.replace = function( v ){
\r
504 if( !this.parent ) return this;
\r
505 return arguments.length === 1 ? this.before( v ).remove() : this.before.apply( this, arguments ).remove();
\r
508 /* --------------------------------------
\r
511 Node.prototype.remove = function(){
\r
512 var parent = this.parent;
\r
514 if( !parent ) return this;
\r
516 parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );
\r
518 Node._reserveRemoval[ Node._reserveRemoval.length ] = this;
\r
519 this._reserveUpdate();
\r
521 delete this.parent;
\r
526 Node.prototype.empty = function(){
\r
527 var xnodes = this._xnodes, child, i, l;
\r
528 if( xnodes && ( l = xnodes.length ) ){
\r
529 for( i = 0; i < l; ++i ){
\r
530 xnodes[ i ].destroy();
\r
537 /* --------------------------------------
\r
540 Node.prototype.destroy = function( isChild ){
\r
541 var xnodes = this._xnodes, i, elm;
\r
543 if( !this._state ) return;
\r
545 elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();
\r
547 if( xnodes && ( i = xnodes.length ) ){
\r
549 // xnodes[ --i ].destroy( true );
\r
551 //xnodes.length = 0;
\r
553 elm && this.unlisten(); // イベントの退避
\r
555 delete Node._chashe[ this._uid ];
\r
556 delete this._state;
\r
559 this.remove( isChild );
\r
561 this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );
\r
562 elm && !isChild && this._actualRemove();
\r
569 /* --------------------------------------
\r
572 Node.prototype.contains = function( v ){
\r
573 var elm, type, xnodes, i;
\r
574 if( !v || this._xnodeType !== 1 ) return false;
\r
576 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
577 return elm.contains( v );
\r
579 //if( document.compareDocumentPosition ){
\r
582 xnodes = this._xnodes;
\r
583 if( xnodes.indexOf( v ) !== -1 ) return true;
\r
584 if( elm === v.parentNode ) return false;
\r
585 for( i = xnodes.length; i; ){
\r
586 if( xnodes[ --i ].contains( v ) ) return true;
\r
591 /* --------------------------------------
\r
594 Node.prototype.getChildAt = function( i ){
\r
595 var xnodes = this._xnodeType === 1 && this._xnodes;
\r
596 return xnodes && 0 <= i && i < xnodes.length && xnodes[ i ];
\r
600 /* --------------------------------------
\r
601 * prevNode, nextNode, firstChild, lastChild
\r
604 Node.prototype.prevNode = function(){
\r
605 var parent = this.parent, xnodes, index;
\r
606 if( !parent ) return;
\r
607 xnodes = parent._xnodes;
\r
608 index = xnodes.indexOf( this );
\r
609 if( 0 < index ) return xnodes[ index - 1 ];
\r
611 Node.prototype.nextNode = function(){
\r
612 var parent = this.parent, xnodes, index;
\r
613 if( !parent ) return;
\r
614 xnodes = parent._xnodes;
\r
615 index = xnodes.indexOf( this );
\r
616 if( index + 1 < xnodes.length ) return xnodes[ index + 1 ];
\r
618 Node.prototype.firstChild = function(){
\r
619 return this.getChildAt( 0 );
\r
621 Node.prototype.lastChild = function(){
\r
622 return this.getChildAt( this._xnodes.length - 1 );
\r
625 /* --------------------------------------
\r
628 Node.prototype.getOrder = function(){
\r
629 var parent = this.parent;
\r
630 if( !parent ) return -1;
\r
631 return parent._xnodes.indexOf( this );
\r
634 /* --------------------------------------
\r
635 * className, addClass, removeClass, hasClass
\r
637 Node.prototype.className = function( v ){
\r
640 if( v === undefined ) return this._className;
\r
642 if( this._className === v ) return this;
\r
643 if( !v || typeof v !== 'string' ){
\r
644 delete this._className;
\r
646 this._className = v;
\r
648 this._dirty |= X.Dom.Dirty.CLASSNAME;
\r
649 this._root && this._reserveUpdate();
\r
652 Node.prototype.addClass = function( v ){
\r
653 var names = v.split( ' ' ),
\r
658 name = names[ --i ];
\r
659 if( !name ) continue;
\r
660 !this.hasClass( name ) && ( v += ( v ? ' ' : '' ) + name );
\r
662 return v ? his.className( this._className + ( this._className ? ' ' : '' ) + v ) : this;
\r
664 Node.prototype.removeClass = function( v ){
\r
666 className = this._className,
\r
667 names = v.split( ' ' ),
\r
668 classNames, i, f, j;
\r
669 if( !className ) return this;
\r
670 for( classNames = className.split( _ ), i = classNames.length; i; ){
\r
671 className = classNames[ --i ];
\r
672 for( j = names.length; j; ){
\r
673 if( className === names[ --j ] ){
\r
674 classNames.splice( i, 1 );
\r
675 names.splice( j, 1 );
\r
681 return f ? this.className( classNames.join( ' ' ) ) : this;
\r
683 Node.prototype.toggleClass = function( v ){
\r
686 Node.prototype.hasClass = function( v ){
\r
688 className = this._className,
\r
690 if( className === v ) return true;
\r
691 if( !className ) return false;
\r
693 className = _ + className + _;
\r
694 if( className.indexOf( _ + v + _ ) !== -1 ) return true; // lucky hit
\r
696 for( v = v.split( _ ), i = v.length; i; ){
\r
698 if( name === '' ) continue;
\r
699 if( className.indexOf( _ + name + _ ) === -1 ) return false;
\r
704 /* --------------------------------------
\r
707 Node.prototype.html = function( html, opt_outer ){
\r
708 var _ = '', xnodes, n, i, l;
\r
711 if( this._xnodeType === 3 ){
\r
712 if( this._text !== html ){
\r
714 this._root && this._reserveUpdate();
\r
715 this._dirty |= X.Dom.Dirty.CONTENT;
\r
719 return this.empty().append.apply( this, X.Dom.parse( html, true ) );
\r
722 if( this._xnodeType === 3 ){
\r
726 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
727 delete this._cssText;
\r
729 html = !opt_outer ? [] : [
\r
731 this._id ? ' id=' + this._id : _,
\r
732 this._className ? ' class="' + this._className + '"' : _,
\r
733 this._attrText === _ ? _ : this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
734 this._cssText ? ' style="' + this._cssText + '"' : _,
\r
738 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
739 for( i = 0; i < l; ++i ){
\r
740 html[ n ] = xnodes[ i ].html( undefined, true );
\r
744 !opt_outer || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );
\r
746 return html.join( _ );
\r
749 Node.prototype.text = function( text ){
\r
753 if( this._xnodeType === 3 ){
\r
754 if( this._text !== text ){
\r
756 this._root && this._reserveUpdate();
\r
757 this._dirty |= X.Dom.Dirty.CONTENT;
\r
761 this.empty().createText( text );
\r
765 if( this._xnodeType === 1 ){
\r
766 if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){
\r
767 for( text = [], n = -1; i; ){
\r
768 text[ ++n ] = xnodes[ --i ].text();
\r
770 return text.join( '' );
\r
777 Node.prototype.each = function( func ){
\r
778 func.call( this, 0 );
\r
783 /* --------------------------------------
\r
784 * Async commit update
\r
793 * root._reserveRemoval = [] に追加。commitUpdate で remove して state は not_added
\r
795 * root._reserveRemoval にいたら消す, new_parent._xnodes に挿入 steta は not_added にして commitUpdate を待つ
\r
798 Node.prototype._reserveUpdate = function(){
\r
799 var root = Node.root;
\r
800 if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( root, root._startUpdate );
\r
803 Node.prototype._startUpdate = function(){
\r
804 var removal, i, xnode, tmp;
\r
806 if( this._updateTimerID ){
\r
807 //X.Timer.cancelFrame( this._updateTimerID ); // fire 空の cancel が動かない、、、
\r
808 this._updateTimerID = 0;
\r
813 removal = Node._reserveRemoval;
\r
815 tmp = this._rawNode.style.visibility;
\r
816 //this._rawNode.style.visibility = 'hidden';
\r
818 if( i = removal.length ){
\r
820 xnode = removal[ --i ];
\r
821 xnode._actualRemove();
\r
822 !this._state && xnode.kill();
\r
824 removal.length = 0;
\r
827 this._commitUpdate();
\r
829 //this._rawNode.style.visibility = tmp;
\r
832 Node.prototype._commitUpdate =
\r
833 document.getElementById ?
\r
834 ( function( parentElement, nextElement ){
\r
835 var elm = this._rawNode,
\r
836 xnodes, l, i, frg, next, k, v;
\r
838 if( !elm || ( parentElement && elm.parentNode !== parentElement ) || ( nextElement && elm.nextSibling !== nextElement ) ){
\r
840 parentElement.insertBefore( this._actualCreate(), nextElement ) :
\r
841 parentElement.appendChild( this._actualCreate() );
\r
842 this._afterActualCreate();
\r
845 return elm || this._rawNode;
\r
847 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {
\r
849 /*if( elm.childNodes.length !== l && ( frg = Node._useDocumentFragment ) ){
\r
850 for( i = 0; i < l; ++i ){
\r
851 frg.appendChild( xnodes[ i ]._actualCreate( true ) );
\r
853 elm.appendChild( frg );
\r
854 for( i = 0; i < l; ++i ){
\r
855 xnodes[ i ]._afterActualCreate( true );
\r
859 next = xnodes[ --l ]._commitUpdate( elm, next );
\r
864 this._dirty && this._updateRawNode( elm );
\r
868 ( function( parentElement, prevElement ){
\r
869 var elm = this._rawNode || this._ie4getRawNode(),
\r
870 xnodes, l, i, html, text, prev;
\r
874 prevElement.insertAdjacentHTML( 'AfterEnd', this._actualCreate() ) :
\r
875 parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );
\r
876 this._afterActualCreate();
\r
877 return this._rawNode || this._ie4getRawNode();
\r
880 xnodes = this._xnodes;
\r
881 l = xnodes ? xnodes.length : 0;
\r
883 if( this._dirty & X.Dom.Dirty.IE4_TEXTNODE_FIX || ( this._state & X.Dom.State.IE4_ONLY_TEXT && ( l !== 1 || xnodes[ 0 ]._xnodeType !== 3 ) ) ){ // 1 < l && elm.children.length === 0
\r
885 for( i = 0; i < l; ++i ){
\r
886 html[ i ] = xnodes[ i ]._actualCreate();
\r
888 elm.innerHTML = html.join( '' );
\r
889 for( i = 0; i < l; ++i ){
\r
890 xnodes[ i ]._afterActualCreate();
\r
892 this._state &= ~X.Dom.State.IE4_ONLY_TEXT;
\r
894 if( this._state & X.Dom.State.IE4_ONLY_TEXT ){ // textNode が swap した場合の検出は、_root で行う
\r
895 text = xnodes[ 0 ];
\r
896 if( text._dirty || !text._root ){
\r
897 elm.innerHTML = text._text;
\r
898 delete text._dirty;
\r
899 text._root = this._root;
\r
903 for( i = 0; i < l; ++i ){
\r
904 prev = xnodes[ i ]._commitUpdate( elm, prev );
\r
907 this._dirty && this._updateRawNode( elm );
\r
912 Node.prototype._updateRawNode =
\r
913 document.getElementById ?
\r
915 var attrs, rename, k, v;
\r
918 if( this._dirty & X.Dom.Dirty.CONTENT ){
\r
919 elm.data = X.Dom.chrReferanceTo( this._text );
\r
920 delete this._dirty;
\r
924 if( this._dirty & X.Dom.Dirty.ID ){
\r
925 if( X.UA.IE && X.UA.IE < 7 ){
\r
928 this._id ? ( elm.id = this._id ) : elm.removeAttribute( 'id' );
\r
932 if( this._dirty & X.Dom.Dirty.CLASSNAME ){
\r
933 if( X.UA.IE && X.UA.IE < 7 ){
\r
934 elm.className = this._className;
\r
936 this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );
\r
940 if( this._dirty & X.Dom.Dirty.CSS ){
\r
941 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
942 elm.style.cssText = this._cssText;
\r
944 elm.style.cssText = ''; // IE5.5以下 Safari3.2 で必要
\r
945 elm.removeAttribute( 'style' );
\r
946 delete this._cssText;
\r
950 if( this._dirty & X.Dom.Dirty.IE_FILTER ){
\r
951 this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );
\r
955 if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){
\r
956 rename = X.Dom.Attr.renameForDOM;
\r
958 if( 5 <= X.UA.IE && X.UA.IE < 5.5 ){
\r
959 if( this._tag === 'TEXTAREA' && k === 'value' ){
\r
961 ( elm.firstChild.data = attrs[ k ] ) :
\r
962 elm.appendChild( document.createTextNode( attrs[ k ] ) );
\r
966 ( v = attrs[ k ] ) === undefined ?
\r
967 elm.removeAttribute( rename[ k ] || k ) :
\r
968 ( elm[ rename[ k ] || k ] = v );
\r
970 delete this._newAttrs;
\r
973 delete this._dirty;
\r
977 var attrs, rename, k, v;
\r
980 if( this._dirty & X.Dom.Dirty.CONTENT ){
\r
981 elm.innerText = this._text;
\r
982 delete this._dirty;
\r
987 * http://www.tohoho-web.com/js/element.htm
\r
988 * title、className、id、lang、language には setAttribute でなく、element.id で直接読み書きできる
\r
991 if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) );
\r
994 if( this._dirty & X.Dom.Dirty.CLASSNAME ){
\r
995 this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );
\r
998 if( this._dirty & X.Dom.Dirty.CSS ){
\r
999 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
1000 elm.style.cssText = this._cssText;
\r
1002 elm.style.cssText = '';
\r
1003 elm.removeAttribute( 'style' );
\r
1004 delete this._cssText;
\r
1008 if( this._dirty & X.Dom.Dirty.IE_FILTER ){
\r
1009 this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );
\r
1013 if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){
\r
1014 rename = X.Dom.Attr.renameForDOM;
\r
1015 for( k in attrs ){
\r
1016 ( v = attrs[ k ] ) === undefined ?
\r
1017 elm.removeAttribute( rename[ k ] || k ) :
\r
1018 elm.setAttribute( rename[ k ] || k, v );
\r
1020 delete this._newAttrs;
\r
1023 delete this._dirty;
\r
1027 /* --------------------------------------
\r
1030 * http://d.hatena.ne.jp/uupaa/20080718/1216362040
\r
1031 * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。
\r
1032 * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");
\r
1033 * insertAdjacentHTML
\r
1035 * ie7 以下では iframe の frameborder や、input name は、createElement 後に setAttribute しても無視される
\r
1037 * fragument がある場合 children も足して
\r
1038 * Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+
\r
1039 * ie6 大丈夫?fragment の場合リークしないか?チェックが必要
\r
1040 * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx
\r
1042 * document.createElement of ie4 is only for OPTION & IMAGE.
\r
1044 Node.prototype._actualCreate =
\r
1045 document.getElementById ? (function( isChild ){
\r
1046 var elm = this._rawNode,
\r
1047 xnodes, frg, i, l;
\r
1049 if( this._xnodeType === 3 ){
\r
1050 if( elm ) return elm;
\r
1051 delete this._dirty;
\r
1052 return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );
\r
1056 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
1057 delete this._cssText;
\r
1059 this._isNew = true;
\r
1060 this._rawNode = elm =
\r
1061 X.UA.IE && X.UA.IE < 9 ?
\r
1062 document.createElement( [
\r
1064 ' UID="', this._uid, '"',
\r
1065 this._id ? ' id="' + this._id + '"' : '',
\r
1066 this._className ? ' class="' + this._className + '"' : '',
\r
1067 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
1068 this._cssText ? ' style="' + this._cssText + '"' : '',
\r
1069 '>' ].join( '' ) ):
\r
1070 document.createElement( this._tag );
\r
1072 if( Node._useDocumentFragment ){
\r
1073 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
1074 !isChild && ( frg = Node._useDocumentFragment ).appendChild( elm );
\r
1075 for( i = 0; i < l; ++i ){
\r
1076 elm.appendChild( xnodes[ i ]._actualCreate( true ) );
\r
1078 return frg || elm;
\r
1084 document.all ? (function( isChild ){
\r
1085 var uid = this._uid,
\r
1086 html, xnodes, n, i, l;
\r
1088 if( this._xnodeType === 3 ){
\r
1090 //for( i = 0, l = this._text.length; i < l; ++i ){
\r
1091 // html.push( this._text.charCodeAt( i ) );
\r
1093 //html = html.join( ',' );
\r
1094 html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode
\r
1095 delete this._rawNode;
\r
1097 if( this._rawNode && !isChild ) this._actualRemove( true );
\r
1099 if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){
\r
1100 delete this._cssText;
\r
1104 '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID="', uid, '"',
\r
1105 this._className ? ' class="' + this._className + '"' : '',
\r
1106 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),
\r
1107 this._cssText ? ' style="' + this._cssText + '"' : '',
\r
1111 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){
\r
1112 if( l === 1 && xnodes[ 0 ]._xnodeType === 3 ){
\r
1114 html[ n ] = xnodes[ 0 ]._text;
\r
1116 this._state |= X.Dom.State.IE4_ONLY_TEXT;
\r
1118 for( i = 0; i < l; ++i ){
\r
1119 html[ n ] = xnodes[ i ]._actualCreate( true );
\r
1124 X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );
\r
1126 delete this._newAttrs;
\r
1129 return html.join( '' );
\r
1133 Node.prototype._afterActualCreate =
\r
1134 document.getElementById ? (function(){
\r
1135 var elm = this._rawNode, xnodes, l, attrs, k, i;
\r
1137 this._root = this.parent._root;
\r
1139 if( this._xnodeType === 3 ){
\r
1140 this._dirty && this._updateRawNode( elm );
\r
1144 xnodes = this._xnodes;
\r
1145 l = xnodes && xnodes.length;
\r
1147 if( this._isNew ){
\r
1148 if( !Node._useDocumentFragment && l ){// docFrg が使えない場合、doc 追加後に子を追加
\r
1149 for( i = 0; i < l; ++i ){
\r
1150 elm.appendChild( xnodes[ i ]._actualCreate( true ) );
\r
1153 if( !X.UA.IE || 8 < X.UA.IE ){
\r
1154 elm.UID = this._uid;
\r
1155 this._newAttrs = this._attrs;
\r
1156 this._dirty = X.Dom.Dirty.ID | X.Dom.Dirty.CLASSNAME | X.Dom.Dirty.CSS | X.Dom.Dirty.ATTR | X.Dom.Dirty.IE_FILTER;
\r
1157 this._updateRawNode( elm );
\r
1159 if( this._dirty & X.Dom.Dirty.IE_FILTER ){
\r
1160 elm.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );
\r
1161 delete this._dirty;
\r
1163 this._restoreEvent();// イベントの復帰
\r
1164 delete this._isNew;
\r
1166 this._dirty && this._updateRawNode( elm );
\r
1170 for( i = 0; i < l; ++i ){
\r
1171 xnodes[ i ]._afterActualCreate();
\r
1177 document.all ? (function(){
\r
1179 this._root = this.parent._root;
\r
1181 if( this._xnodeType !== 1 ) return this;
\r
1183 if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){
\r
1185 xnodes[ --i ]._afterActualCreate();
\r
1188 if( this._dirty & X.Dom.Dirty.IE_FILTER ){
\r
1189 this._ie4getRawNode().style.filter = X.Dom.Style.SPECIAL_FIX( this._css );
\r
1191 delete this._dirty;
\r
1192 return this._restoreEvent();// イベントの復帰
\r
1196 Node.prototype._actualRemove =
\r
1197 document.getElementById ?
\r
1198 ( function( isChild ){
\r
1199 var xnodes = this._xnodes,
\r
1200 elm = this._rawNode,
\r
1202 if( xnodes && ( l = xnodes.length ) ){
\r
1203 for( i = 0; i < l; ++i ){
\r
1204 child = xnodes[ i ];
\r
1205 child._xnodeType === 1 && child._actualRemove( true );
\r
1209 if( !elm ) return;
\r
1210 this._xnodeType === 1 && this._migrateEvent();// イベントの退避
\r
1211 // elm.parentNode.tagName check tagName is for ie7
\r
1212 !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );
\r
1215 ( function( isChild ){
\r
1216 var xnodes = this._xnodes,
\r
1217 elm = this._rawNode || this._ie4getRawNode(),
\r
1219 if( xnodes && ( l = xnodes.length ) ){
\r
1220 for( i = 0; i < l; ++i ){
\r
1221 xnodes[ i ]._actualRemove( true );
\r
1225 if( !elm ) return;
\r
1226 this._xnodeType === 1 && this._migrateEvent();// イベントの退避
\r
1228 elm.removeAttribute( 'id' ); // ?
\r
1229 document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?
\r
1230 if( !isChild ) elm.outerHTML = '';
\r
1231 delete this._rawNode;
\r
1236 //})( window, document );
\r