2 * Node( rawElement | rawTextnode | htmlString | textString )
5 * @class Node HTMLElement、TextNode をラップし jQuery 風な API で操作できます。
7 * @extends {EventDispatcher}
9 var Node = X[ 'Node' ] = X_EventDispatcher[ 'inherits' ](
17 * @alias Node.prototype._uid
25 * @alias Node.prototype._flags
27 '_flags' : X_NodeFlags_DESTROYED,
29 '_rect' : null, // TODO
32 * 最後に計測したフォントサイズを保持している。ツリーが変更されると削除される。
35 * @alias Node.prototype._fontSize
40 * NodeList と動作を一致させるためのプロパティ。常に 1。
43 * @alias Node.prototype.length
50 * @alias Node.prototype.parent
52 parent : null, // remove された枝も親子構造は維持している。
58 * @alias Node.prototype._xnodes
63 * GPU レイヤーに転送されている場合、その一番親となっている Node。未実装。
66 * @alias Node.prototype._gpuParent
71 * タグ名。テキストノードの場合は空文字列。
74 * @alias Node.prototype._tag
79 * テキストコンテンツ。テキストノードで使用。
82 * @alias Node.prototype._text
90 * @alias Node.prototype._id
95 * クラス名。複数のクラスが設定されている場合、スペース区切り。
98 * @alias Node.prototype._className
100 '_className' : '', //
106 * @alias Node.prototype._attrs
108 '_attrs' : null, // see X_Node_Attr
114 * @alias Node.prototype._newAttrs
119 * 属性を文字列にしたもの。 color="red" size="8"
122 * @alias Node.prototype._attrText
130 * @alias Node.prototype._css
138 * @alias Node.prototype._cssText
146 * @alias Node.prototype._anime
151 * TODO Node の継承ができない!
153 'Constructor' : function( v ){
154 // TODO uid = X_Node_CHASHE.indexOf( null ), uid === -1 ? X_Node_CHASHE.length : uid;
155 var uid = X_Node_CHASHE.length,
156 css, xnodes, xnode, parent;
158 // TODO 継承クラスで this.Super('DIV') ができない! -> サブクラスから呼ばれた場合も
159 if( X_Node_newByTag || this.constructor !== Node ){
160 X_Node_newByTag = false;
161 this[ '_tag' ] = v.toUpperCase();
162 arguments[ 1 ] && this[ 'attr' ]( arguments[ 1 ] );
163 css = arguments[ 2 ];
164 css && this[ X_Type_isString( css ) ? 'cssText' : 'css' ]( css );
166 if( X_Node_newByText ){
167 X_Node_newByText = false;
170 if( 1 < arguments.length ) return new X_NodeList( arguments );
171 if( X_Type_isArray( v ) && v.length ) return new X_NodeList( v );
173 switch( X_Node_getType( v ) ){
174 case X_NodeType_XNODE :
175 case X_NodeType_XNODE_LIST :
178 case X_NodeType_RAW_HTML :
179 if( xnode = X_Node_getXNode( v ) ) return xnode;
180 // v.parentNode || v.parentElement : dom1 || dom0
181 this.parent = ( parent = v.parentNode || v.parentElement ) && parent.tagName /* ie7- */ && X_Node_getXNode( parent );
182 this[ '_rawObject' ] = v;
183 this[ '_tag' ] = v.tagName.toUpperCase();
184 this[ '_id' ] = v.id;
185 this[ '_className' ] = v.className;
187 this[ 'cssText' ]( v.style.cssText );
188 this[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY; // X_NodeFlags_DIRTY_CSS を落とす
190 // TODO attr の回収は不可能、、、?
192 v.setAttribute( 'UID', '' + uid );
199 case X_NodeType_RAW_TEXT :
200 if( xnode = X_Node_getXNode( v ) ) return xnode;
201 this.parent = X_Node_getXNode( v.parentNode );
202 this[ '_rawObject' ] = v;
203 this[ '_text' ] = v.data;
207 case X_NodeType_HTML_STRING :
208 case X_NodeType_STRING :
209 if( xnodes = X_HtmlParser_parse( v, true ) && 1 < xnodes.length ) return new X_NodeList( xnodes );
210 if( xnodes.length ) return xnodes[ 0 ];
214 if( X_Node_none ) return X_Node_none;
220 if( this.parent && ( this.parent[ '_flags' ] & X_NodeFlags_IN_TREE ) ){
221 this[ '_flags' ] |= X_NodeFlags_IN_TREE;
223 this[ '_flags' ] |= X_NodeFlags_EXIST;
224 X_Node_CHASHE[ this[ '_uid' ] = uid ] = this;
227 // TODO .mesure() -> X.Event.MESURED
228 'width' : X_Node_width,
229 'height' : X_Node_height,
230 'clientWidth' : X_Node_clientWidth,
231 'clientHeight' : X_Node_clientHeight,
232 'scrollWidth' : X_Node_scrollWidth,
233 'scrollHeight' : X_Node_scrollHeight,
234 'scrollLeft' : X_Node_scrollLeft,
235 'scrollTop' : X_Node_scrollTop,
238 'offset' : X_Node_offset,
240 'attr' : X_Node_attr,
242 'cssText' : X_Node_cssText,
244 'find' : X_Node_find,
246 'animate' : X_Node_animate,
247 'stop' : X_Node_stop,
250 'create' : X_Node_create,
252 'createAt' : X_Node_createAt,
254 'createText' : X_Node_createText,
256 'createTextAt' : X_Node_createTextAt,
258 'createRange' : X_Node_createRange,
260 'clone' : X_Node_clone,
262 'append' : X_Node_append,
264 'appendAt' : X_Node_appendAt,
266 'appendTo' : X_Node_appendTo,
268 'prev' : X_Node_prev,
270 'next' : X_Node_next,
272 'swap' : X_Node_swap,
274 'remove' : X_Node_remove,
276 'empty' : X_Node_empty,
278 'contains' : X_Node_contains,
280 'getChildAt' : X_Node_getChildAt,
282 'numChildren' : X_Node_numChildren,
284 'firstChild' : X_Node_firstChild,
286 'lastChild' : X_Node_lastChild,
288 'getOrder' : X_Node_getOrder,
290 'className' : X_Node_className,
291 'addClass' : X_Node_addClass,
292 'removeClass' : X_Node_removeClass,
293 'toggleClass' : X_Node_toggleClass,
294 'hasClass' : X_Node_hasClass,
296 'html' : X_Node__html,
297 'text' : X_Node_text,
298 'call' : X_Node_call,
304 var X_NodeType_XNODE = 1,
305 X_NodeType_RAW_HTML = 2,
306 X_NodeType_RAW_TEXT = 3,
307 X_NodeType_HTML_STRING = 4,
308 X_NodeType_STRING = 5,
310 X_NodeType_XNODE_LIST = 7,
311 X_NodeType_WINDOW = 8,
312 X_NodeType_DOCUMENT = 9,
313 X_NodeType_IMAGE = 10,
315 X_Node_strictElmCreation = !X_UA[ 'MacIE' ] && X_UA[ 'IE' ] <= 8,
317 X_Node_documentFragment = document.createDocumentFragment && ( !X_UA[ 'IE' ] || 5.5 <= X_UA[ 'IE' ] ) && document.createDocumentFragment(),
319 // 子の生成後に リアル文書 tree に追加する
320 X_Node_addTreeAfterChildren = !( X_UA[ 'IE' ] < 9 ),
322 X_Node_displayNoneFixForIE5 = !!X_NodeFlags_IE5_DISPLAY_NONE_FIX,
324 X_Node_newByTag = false,
326 X_Node_newByText = false,
328 X_Node_outerXNode = null,
330 X_Node_updateTimerID = 0,
333 X_Node_isXmlDocument =
337 if( X_Type_isBoolean( root.isXML ) ) return root.isXML;
338 return root.isXML = root[ '_rawObject' ].createElement( 'p' ).tagName !== root[ '_rawObject' ].createElement( 'P' ).tagName;
341 X_Node_none = X_Node_CHASHE[ 0 ] = Node(),
342 X_Node_html, // = <html>
343 X_Node_head, // = <head>
344 X_Node_body, // = <body>
345 X_Node_systemNode, // = X_Node_CHASHE[ ? ]
349 * X_Node_reserveRemoval = [] に追加。commitUpdate で remove
351 * X_Node_reserveRemoval にいたら消す, new_parent[ '_xnodes' ] に挿入
353 X_Node_reserveRemoval = [];
355 function X_Node_getType( v ){
356 if( v === '' ) return X_NodeType_STRING;
358 if( v === window ) return X_NodeType_WINDOW;
359 if( v === document ) return X_NodeType_DOCUMENT;
360 if( v.constructor === Node ) return X_NodeType_XNODE;
361 if( v.constructor === X_NodeList ) return X_NodeType_XNODE_LIST;
362 if( X_Type_isHTMLElement( v ) ) return X_NodeType_RAW_HTML;
363 if( v.nodeType === 3 ) return X_NodeType_RAW_TEXT;
364 if( X_Type_isString( v ) ){
365 return '<' === v.charAt( 0 ) && v.charAt( v.length - 1 ) === '>' ? X_NodeType_HTML_STRING : X_NodeType_STRING;
368 if( v[ 'instanceOf' ] && v[ 'instanceOf' ]( Node ) ) return X_NodeType_XNODE;
371 function X_Node_getXNode( v ){
372 var uid, i, chashe, xnode;
373 switch( X_Node_getType( v ) ){
374 case X_NodeType_XNODE :
375 case X_NodeType_XNODE_LIST :
377 case X_NodeType_RAW_HTML :
378 // fake TextNode too.
380 uid = v.getAttribute( 'UID' );
381 return uid && X_Node_CHASHE[ uid ];
383 return v[ 'UID' ] && X_Node_CHASHE[ v[ 'UID' ] ];
384 case X_NodeType_WINDOW :
386 case X_NodeType_DOCUMENT :
387 return X_ViewPort_document;
388 case X_NodeType_RAW_TEXT :
389 if( v[ 'UID' ] ) return X_Node_CHASHE[ v[ 'UID' ] ];
390 for( chashe = X_Node_CHASHE, i = chashe.length; i; ){
391 if( ( xnode = chashe[ --i ] ) && ( xnode[ '_rawObject' ] === v ) ) return xnode;
396 function X_Node_getRoot( xnode ){
397 return X_ViewPort_document;
398 //return X_Node_body[ '_rawObject' ].documentElement ? node : node.ownerDocument || node.document;
402 // TODO document.all[ uid ] -> document[ uid ]
403 var X_Node__ie4getRawNode = X_UA_DOM.IE4 && function ( that ){
404 return that[ '_rawObject' ] ||
405 ( that[ '_rawObject' ] = document.all[ 'ie4uid' + that[ '_uid' ] ] || that[ '_id' ] && document.all[ that[ '_id' ] ] );
409 function X_Node_toggleInTreeFlag( xnodes, flag ){
410 var i = xnodes.length, xnode;
412 xnode = xnodes[ --i ];
413 flag ? ( xnode[ '_flags' ] |= X_NodeFlags_IN_TREE | X_NodeFlags_DIRTY_POSITION ) : ( xnode[ '_flags' ] &= ~X_NodeFlags_IN_TREE & ~X_NodeFlags_IE5_DISPLAY_NONE_FIX );
414 xnode[ '_xnodes' ] && X_Node_toggleInTreeFlag( xnode[ '_xnodes' ], flag );
418 function X_Node_toggleInGPUFlag( gpuRoot, xnodes, flag ){
419 var i = xnodes.length, xnode;
423 xnode = xnodes[ --i ];
424 if( !xnode[ '_gpuParent' ] ){
425 xnode[ '_flags' ] |= X_NodeFlags_GPU_CHILD;
426 xnode[ '_gpuParent' ] = gpuRoot;
427 xnode[ '_xnodes' ] && X_Node_toggleInTreeFlag( gpuRoot, xnode[ '_xnodes' ], flag );
432 xnode = xnodes[ --i ];
433 if( xnode[ '_gpuParent' ] === gpuRoot ){
434 xnode[ '_flags' ] &= ~X_NodeFlags_GPU_CHILD;
435 delete xnode[ '_gpuParent' ];
436 xnode[ '_xnodes' ] && X_Node_toggleInTreeFlag( gpuRoot, xnode[ '_xnodes' ], flag );
443 * タグ名等を指定して新規に子ノードを作成し、現在のノードに追加する。
444 * @alias Node.prototype.create
445 * @param {string} [tag] タグ名
446 * @param {object} [opt_attrs=] 属性
447 * @param {object|string} [opt_css=] css
448 * @return {Node} 新規作成されたノード
449 * @example var child = parent.create( 'div' );
451 function X_Node_create( tag, opt_attrs, opt_css ){
454 if( !this[ '_tag' ] ) return;
455 this[ 'append' ]( xnode = X_Doc_create( tag, opt_attrs, opt_css ) );
459 * 挿入位置とタグ名等を指定して新規に子ノードを作成し、現在のノードに挿入する。
460 * @alias Node.prototype.createAt
461 * @param {number} [index] 挿入位置
462 * @param {string} [tag] タグ名
463 * @param {object} [opt_attrs=] 属性
464 * @param {object|string} [opt_css=] css
465 * @return {Node} 新規作成されたノード
466 * @example var child = parent.create( 2, 'div' );
468 function X_Node_createAt( index, tag, opt_attrs, opt_css ){
470 if( !this[ '_tag' ] ) return;
471 this[ 'appendAt' ]( index, xnode = X_Doc_create( tag, opt_attrs, opt_css ) );
476 * テキストを指定して新規にテキストノードを作成し、現在のノードに挿入する。
477 * @alias Node.prototype.createText
478 * @param {string} [tag] テキスト
479 * @return {Node} 新規作成されたノード
481 function X_Node_createText( text ){
483 if( !this[ '_tag' ] ) return;
484 this[ 'append' ]( xnode = X_Doc_createText( text ) );
488 * 挿入位置とテキストを指定して新規に子ノードを作成し、現在のノードに挿入する。
489 * @alias Node.prototype.createTextAt
490 * @param {number} [index] 挿入位置
491 * @param {string} [tag] テキスト
492 * @return {Node} 新規作成されたノード
494 function X_Node_createTextAt( index, text ){
496 if( !this[ '_tag' ] ) return;
497 this[ 'appendAt' ]( index, xnode = X_Doc_createText( text ) );
502 * 選択されたテキストへの参照やテキスト座標情報
503 * @alias Node.prototype.createRange
504 * @return {TextRange} 新規作成されたテキストレンジ
506 function X_Node_createRange( a, b, c ){
507 return X_TextRange( this, a, b, c );
511 * Node のクローンを作成し返す。id もクローンされる点に注意。イベントリスナはクローンされない。
512 * http://d.hatena.ne.jp/think49/20110724/1311472811
513 * http://d.hatena.ne.jp/uupaa/20100508/1273299874
514 * @alias Node.prototype.clone
515 * @param {boolean} [opt_clone_children] 子要素のクローンを行うか?
518 function X_Node_clone( opt_clone_children ){
519 var xnode, xnodes, i, l;
521 if( this[ '_tag' ] ){
522 X_Node_newByTag = true;
523 xnode = Node( this[ '_tag' ], X_Object_copy( this[ '_attrs' ] ), X_Object_copy( this[ '_css' ] ) )
524 [ 'attr' ]( { 'id' : this[ '_id' ] } )
525 [ 'className' ]( this[ '_className' ] );
527 if( this[ '_flags' ] & X_NodeFlags_IS_SVG ){
528 xnode[ '_flags' ] |= X_NodeFlags_IS_SVG;
530 if( this[ '_flags' ] & X_NodeFlags_IS_VML ){
531 xnode[ '_flags' ] |= X_NodeFlags_IS_VML;
534 if( opt_clone_children && ( xnodes = this[ '_xnodes' ] ) && ( l = xnodes.length ) ){
535 for( i = 0; i < l; ++i ){
536 xnode[ 'append' ]( xnodes[ i ][ 'clone' ]( true ) );
541 X_Node_newByText = true;
542 return Node( this[ '_text' ] );
546 * ノードを子配列の最後に追加する。文字列が渡された場合、HTMLパーサーによって Node ツリーを作成して追加する。HtmlElement, TextNode の場合は内部使用専用。
547 * @alias Node.prototype.append
548 * @param {Node|string|HTMLElement|TextNode} [v] HTMLElement と TextNode は内部のみ。
549 * @return {Node} 自身。チェインメソッド
551 * myNode.append( node );
552 * myNode.append( node, '<span>Hello,</span>', 'world.' );
554 function X_Node_append( v ){
555 var i, l, xnodes, frg;
556 if( !this[ '_tag' ] ) return;
558 if( 1 < ( l = arguments.length ) ){
559 for( i = 0; i < l; ++i ){
560 this[ 'append' ]( arguments[ i ] );
565 if( !( xnodes = this[ '_xnodes' ] ) ) this[ '_xnodes' ] = xnodes = [];
567 switch( X_Node_getType( v ) ){
568 case X_NodeType_RAW_HTML :
569 case X_NodeType_RAW_TEXT :
572 case X_NodeType_HTML_STRING :
573 case X_NodeType_STRING :
574 return X_Node_append.apply( this, X_HtmlParser_parse( v, true ) );
575 case X_NodeType_XNODE :
576 // 親の xnodes から v を消す
577 if( v.parent === this && xnodes[ xnodes.length - 1 ] === v ) return this;
579 // IE4 でテキストノードの追加、FIXED 済でない場合、親に要素の追加を通知
580 if( X_UA[ 'IE4' ] && !v[ '_tag' ] && ( ( this[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ) this[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
587 xnodes[ xnodes.length ] = v;
588 if( this[ '_flags' ] & X_NodeFlags_IN_TREE ){
589 v[ '_flags' ] |= X_NodeFlags_IN_TREE;
590 v[ '_xnodes' ] && X_Node_toggleInTreeFlag( v[ '_xnodes' ], true );
591 X_Node_reserveUpdate();
593 if( this[ '_flags' ] & X_NodeFlags_IS_SVG ){
594 v[ '_flags' ] |= X_NodeFlags_IS_SVG;
596 if( this[ '_flags' ] & X_NodeFlags_IS_VML ){
597 v[ '_flags' ] |= X_NodeFlags_IS_VML;
604 * @alias Node.prototype.appendAt
605 * @param {number} index 挿入位置 0以上
606 * @param {Node|string|HTMLElement|TextNode} [v] HTMLElement と TextNode は内部のみ。
607 * @return {Node} 自身。チェインメソッド
608 * @example myNode.appendAt( 1, node );
610 function X_Node_appendAt( start, v ){
613 if( !this[ '_tag' ] ) return this;
615 l = arguments.length;
616 if( !( xnodes = this[ '_xnodes' ] ) ) xnodes = this[ '_xnodes' ] = [];
618 if( xnodes.length <= start ){
619 if( l === 2 ) return this[ 'append' ]( v );
620 for( i = 1; i < l; ++i ){
621 this[ 'append' ]( arguments[ i ] );
625 if( start < 0 ) start = 0;
628 this[ 'appendAt' ]( start, arguments[ --l ] );
633 switch( X_Node_getType( v ) ){
634 case X_NodeType_RAW_HTML :
635 case X_NodeType_RAW_TEXT :
638 case X_NodeType_HTML_STRING :
639 case X_NodeType_STRING :
640 v = X_HtmlParser_parse( v, true );
641 for( i = v.length; i; ){
642 this[ 'appendAt' ]( start, v[ --i ] );
645 case X_NodeType_XNODE :
646 // 親の xnodes から v を消す
648 if( v.parent === this ){
649 i = v[ 'getOrder' ]();
650 if( i === start ) return this;
651 if( i < start ) --start;
655 // IE4 でテキストノードの追加、FIXED 済でない場合、親に要素の追加を通知
656 if( X_UA[ 'IE4' ] && !v[ '_tag' ] && ( ( this[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ) this[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
663 this[ '_xnodes' ].splice( start, 0, v );
664 if( this[ '_flags' ] & X_NodeFlags_IN_TREE ){
665 v[ '_flags' ] |= X_NodeFlags_IN_TREE;
666 v[ '_xnodes' ] && X_Node_toggleInTreeFlag( v[ '_xnodes' ], true );
667 X_Node_reserveUpdate();
669 if( this[ '_flags' ] & X_NodeFlags_IS_SVG ){
670 v[ '_flags' ] |= X_NodeFlags_IS_SVG;
672 if( this[ '_flags' ] & X_NodeFlags_IS_VML ){
673 v[ '_flags' ] |= X_NodeFlags_IS_VML;
679 * ノードを親に追加する。戻り値は子ノードなので、続けて操作が出来る。
680 * @alias Node.prototype.appendTo
681 * @param {Node|string|HTMLElement} [parent] HTMLElement は内部のみ。
682 * @param {number} [opt_index=-1] 挿入位置。省略した場合は最後に追加する。
683 * @return {Node} 自身。チェインメソッド
684 * @example childNode.appendTo( parentNode, 1 );
686 function X_Node_appendTo( parent, opt_index ){
687 switch( X_Node_getType( parent ) ){
688 case X_NodeType_RAW_HTML :
689 parent = Node( parent );
691 case X_NodeType_HTML_STRING :
692 parent = X_HtmlParser_parse( parent, true );
693 parent = parent[ 0 ] || parent;
694 case X_NodeType_XNODE :
699 X_Type_isFinite( opt_index ) ? parent[ 'appendAt' ]( opt_index, this ) : parent[ 'append' ]( this );
705 * ノードの直前の要素を取得。または直前に挿入。挿入する要素が先にいる兄弟でも正しく動作する。
706 * @alias Node.prototype.prev
707 * @param {Node|string|HTMLElement|TextNode} [...v] HTMLElement と TextNode は内部のみ。
708 * @return {Node} 自身。チェインメソッド
709 * @example childNode.prev( prevNode );
711 function X_Node_prev( v ){
712 var parent = this.parent, xnodes, i, l;
715 if( v === undefined ){
716 if( !parent ) return;
717 xnodes = parent[ '_xnodes' ];
718 i = xnodes.indexOf( this );
719 return 0 < i ? xnodes[ i - 1 ] : v;
722 if( !parent ) return this;
724 l = arguments.length;
726 for( i = 0; l; ++i ){
727 parent[ 'appendAt' ]( this[ 'getOrder' ]() - i, arguments[ --l ] );
731 parent[ 'appendAt' ]( this[ 'getOrder' ](), v );
736 * ノードの直後の要素を取得。または直後に挿入。挿入する要素が先にいる兄弟でも正しく動作する。
737 * @alias Node.prototype.next
738 * @param {Node|string|HTMLElement|TextNode} [v] HTMLElement と TextNode は内部のみ。
739 * @return {Node} 自身。チェインメソッド
740 * @example childNode.next( prevNode );
742 function X_Node_next( v ){
743 var parent = this.parent, xnodes, i, l, start;
746 if( v === undefined ){
747 if( !parent ) return;
748 xnodes = parent[ '_xnodes' ];
749 i = xnodes.indexOf( this );
750 return ++i < xnodes.length ? xnodes[ i ] : v;
753 if( !parent ) return this;
755 l = arguments.length;
756 start = this[ 'getOrder' ]() + 1;
758 if( parent[ '_xnodes' ].length <= start ){
759 for( i = 0; i < l; ++i ){
760 parent[ 'append' ]( arguments[ i ] );
765 parent[ 'appendAt' ]( this[ 'getOrder' ]() + 1, arguments[ --l ] );
768 parent[ 'appendAt' ]( start, v );
774 * 要素の入れ替え。自身は remove() される。
775 * @alias Node.prototype.swap
776 * @param {Node|string|HTMLElement|TextNode} [v] HTMLElement と TextNode は内部のみ。
777 * @return {Node} 自身。チェインメソッド
778 * @example node.swap( newNode );
780 function X_Node_swap( v ){
781 if( !this.parent ) return this;
782 return arguments.length === 1 ? this[ 'prev' ]( v )[ 'remove' ]() : X_Node_prev.apply( this, arguments )[ 'remove' ]();
786 * 要素を親要素から抜く。jQuery の remove と異なり、インスタンスは破壊(kill)されず、再び別の親に挿入等できる
787 * @alias Node.prototype.remove
788 * @return {Node} 自身。チェインメソッド
789 * @example node.remove();
790 * parent.append( node ); 新しい親に追加できる
792 function X_Node_remove(){
793 var parent = this.parent,
796 if( !parent ) return this;
799 if( this[ '_anime' ] && this[ '_anime' ].phase ){
800 console.log( 'Animation 中の REMOVE' );
801 X_NodeAnime_stopNow( this );
807 parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( this ), 1 );
809 if( this[ '_flags' ] & X_NodeFlags_IN_TREE ){
810 this[ '_flags' ] &= ~X_NodeFlags_IN_TREE & ~X_NodeFlags_IE5_DISPLAY_NONE_FIX;
811 this[ '_xnodes' ] && X_Node_toggleInTreeFlag( this[ '_xnodes' ], false );
814 if( elm = this[ '_rawObject' ] || X_Node__ie4getRawNode( this ) ){
815 X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this;
816 X_Node_reserveUpdate();
818 if( !this[ '_tag' ] && ( ( parent[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ){
819 parent[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
822 elm = this[ '_rawObject' ];
823 if( elm && elm.parentNode && elm.parentNode.tagName ){
824 X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this;
825 X_Node_reserveUpdate();
830 elm = this[ '_rawObject' ];
831 if( elm && elm.parentNode && elm.parentNode.tagName ){
832 X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = this;
833 X_Node_reserveUpdate();
841 * 子要素を破棄する。子要素は kill() されます。
842 * @alias Node.prototype.empty
843 * @return {Node} 自身。チェインメソッド
844 * @example node.empty();
846 function X_Node_empty(){
847 var xnodes = this[ '_xnodes' ], i;
849 if( xnodes && ( i = xnodes.length ) ){
850 delete this[ '_xnodes' ];
852 xnodes[ --i ][ 'kill' ]();
859 function X_Node_onKill( that ){
860 var parent = that.parent,
861 xnodes = that[ '_xnodes' ], i, elm;
863 if( ( that[ '_flags' ] & X_NodeFlags_EXIST ) === 0 ) return;
865 parent && parent[ '_xnodes' ] && parent[ '_xnodes' ].splice( parent[ '_xnodes' ].indexOf( that ), 1 );
867 if( xnodes && ( i = xnodes.length ) ){
868 delete that[ '_xnodes' ];
870 xnodes[ --i ][ 'kill' ]();
875 X_Node_CHASHE[ that[ '_uid' ] ] = null; // array に対して delete X_Node_CHASHE[ uid ] はまずい!
877 if( that[ '_anime' ] && that[ '_anime' ].phase ){
878 console.log( 'Animation 中の KILL' );
879 X_NodeAnime_stopNow( that );
882 elm = that[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( that );
887 X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = elm;
888 X_Node_reserveUpdate();
890 if( !that[ '_tag' ] && ( ( parent[ '_flags' ] & X_NodeFlags_IE4_FIXED ) === 0 ) ){
891 parent[ '_flags' ] |= X_NodeFlags_IE4_DIRTY_CHILDREN;
894 if( elm && elm.parentNode && elm.parentNode.tagName ){
895 X_Node_reserveRemoval[ X_Node_reserveRemoval.length ] = elm;
896 X_Node_reserveUpdate();
906 * @alias Node.prototype.contains
907 * @param {Node|string|HTMLElement|TextNode} [v] HTMLElement と TextNode は内部のみ。
909 * @example node.contains( testNode );
911 function X_Node_contains( v ){
914 if( !v || !this[ '_tag' ] || this === v ) return false;
916 xnodes = this[ '_xnodes' ];
917 if( !xnodes || !xnodes.length ) return false;
919 while( v = v[ 'parent' ] ){
920 if( this === v ) return true;
927 * @alias Node.prototype.getChildAt
928 * @param {number} index 取得する子ノードの位置。0~
930 * @example child1 = parent.getChildAt(1);
932 function X_Node_getChildAt( i ){
933 var xnodes = this[ '_xnodes' ];
934 return xnodes && 0 <= i && i < xnodes.length && xnodes[ i ];
939 * @alias Node.prototype.numChildren
940 * @return {number} 子要素の数。
941 * @example n = parent.numChildren();
943 function X_Node_numChildren(){
944 var xnodes = this[ '_xnodes' ];
945 return xnodes ? xnodes.length : 0;
950 * @alias Node.prototype.firstChild
951 * @return {Node} 最初の子要素
952 * @example child0 = parent.firstChild();
954 function X_Node_firstChild(){
955 return this[ '_xnodes' ] && this[ '_xnodes' ][ 0 ];
960 * @alias Node.prototype.lastChild
961 * @return {Node} 最後の子要素
962 * @example lastChild = parent.lastChild();
964 function X_Node_lastChild(){
965 var xnodes = this[ '_xnodes' ];
966 return xnodes && xnodes[ xnodes.length - 1 ];
971 * @alias Node.prototype.getOrder
972 * @return {number} index -1 の場合、親を持たない。
973 * @example index = node.getOrder();
975 function X_Node_getOrder(){
976 var parent = this.parent;
977 return this === X_Node_html ?
980 parent[ '_xnodes' ].indexOf( this ) :
986 * @alias Node.prototype.className
987 * @return {string|Node} getter の場合 class 文字列、setter の場合自身。
989 * className = node.className();
991 * node.className( 'myClass myClass_new' );
993 function X_Node_className( v ){
996 if( v === undefined ) return this[ '_className' ];
999 if( this[ '_className' ] === v ) return this;
1000 if( !v || !X_Type_isString( v ) ){
1001 delete this[ '_className' ];
1006 while( v.indexOf( __ ) !== -1 ){ v = v.split( __ ).join( _ ); };
1007 v.charAt( 0 ) === _ && ( v = v.substr( 1 ) );
1008 v.lastIndexOf( _ ) === 0 && ( v = v.substr( 0, v.length - 1 ) );
1010 if( this[ '_className' ] === v ) return this;
1011 v ? ( this[ '_className' ] = v ) : delete this[ '_className' ];
1013 this[ '_flags' ] |= X_NodeFlags_DIRTY_CLASSNAME;
1014 this[ '_flags' ] & X_NodeFlags_IN_TREE && X_Node_reserveUpdate();
1020 * @alias Node.prototype.addClass
1021 * @param {string} className スペース区切りで複数のクラスを追加できる。
1022 * @return {Node} 自身。
1023 * @example node.addClass( 'myClass myClass_new' );
1025 function X_Node_addClass( v ){
1026 var names = v.split( ' ' ),
1028 _class = this[ '_className' ],
1032 name = names[ --i ];
1033 if( !name ) continue;
1034 !this[ 'hasClass' ]( name ) && ( v += ( v ? ' ' : '' ) + name );
1036 return v ? this[ 'className' ]( ( _class ? _class + ' ' : '' ) + v ) : this;
1041 * @alias Node.prototype.removeClass
1042 * @param {string} className スペース区切りで複数のクラスを削除できる。
1043 * @return {Node} 自身。
1044 * @example node.removeClass( 'myClass myClass_new' );
1046 function X_Node_removeClass( v ){
1048 _class = this[ '_className' ],
1049 names = v.split( _ ),
1050 classNames, i, f, j;
1052 if( !_class ) return this;
1053 for( classNames = _class.split( _ ), i = classNames.length; i; ){
1054 _class = classNames[ --i ];
1055 for( j = names.length; j; ){
1056 if( _class === names[ --j ] ){
1057 classNames.splice( i, 1 );
1058 names.splice( j, 1 );
1064 return f ? this[ 'className' ]( classNames.join( _ ) ) : this;
1069 * @alias Node.prototype.toggleClass
1070 * @param {string} className スペース区切りで複数のクラスを削除できる。
1071 * @param {boolean} [opt_toggle=] true はクラスの追加。false はクラスの削除。undefined はクラスのトグル。
1072 * @return {Node} 自身。
1073 * @example node.toggleClass( 'myClass myClass_new', !!n );
1075 function X_Node_toggleClass( v, opt_toggle ){
1077 if( opt_toggle !== undefined ){
1078 return !opt_toggle ? this[ 'removeClass' ]( v ) : this[ 'addClass' ]( v );
1080 names = v.split( ' ' );
1081 for( i = names.length; i; ){
1082 name = names[ --i ];
1083 this[ 'hasClass' ]( name ) ? this[ 'removeClass' ]( name ) : this[ 'addClass' ]( name );
1090 * @alias Node.prototype.hasClass
1091 * @param {string} className スペース区切りで複数のクラスを削除できる。
1093 * @example node.hasClass( 'myClass myClass_new' );
1095 function X_Node_hasClass( v ){
1097 _class = this[ '_className' ],
1099 if( _class === v ) return true;
1100 if( !_class ) return false;
1102 _class = _ + _class + _;
1103 if( _class.indexOf( _ + v + _ ) !== -1 ) return true; // lucky hit
1105 for( v = v.split( _ ), i = v.length; i; ){
1107 if( name === '' ) continue;
1108 if( _class.indexOf( _ + name + _ ) === -1 ) return false;
1114 * innerHTML 取得・設定。outerHTML が欲しい場合は、xnode.call('outerHTML') とできる。
1115 * @alias Node.prototype.html
1116 * @param {string} [html=] html文字列
1117 * @return {string|Node}
1118 * @example node.html( '<img>' );
1120 function X_Node__html( html ){
1121 var _ = '', q = '"', xnodes, n, i, l;
1123 if( html !== undefined ){ // String 以外に Number や false null なども許可
1124 if( !this[ '_tag' ] ) return this[ 'text' ]( html );
1128 X_Node_append.apply( this, X_HtmlParser_parse( html, true ) );
1134 if( !this[ '_tag' ] ){
1135 return this[ '_text' ];
1138 this[ '_flags' ] & X_NodeFlags_OLD_CSSTEXT && X_Node_CSS_objToCssText( this );
1140 html = !X_Node_outerXNode ? [] : [
1141 '<', this[ '_tag' ],
1142 this[ '_id' ] ? ' id="' + this[ '_id' ] + q : _,
1143 this[ '_className' ] ? ' class="' + this[ '_className' ] + q : _,
1144 this[ '_flags' ] & X_NodeFlags_OLD_ATTRTEXT ? X_Node_Attr_objToAttrText( this ) : this[ '_attrText' ],
1145 this[ '_cssText' ] ? ' style="' + this[ '_cssText' ] + q : _,
1149 if( ( xnodes = this[ '_xnodes' ] ) && ( l = xnodes.length ) ){
1150 if( !X_Node_outerXNode ) X_Node_outerXNode = this;
1151 for( i = 0; i < l; ++i ){
1152 html[ n ] = xnodes[ i ][ 'html' ]();
1155 if( X_Node_outerXNode === this ) X_Node_outerXNode = null;
1157 !X_Node_outerXNode || X_Dom_DTD_EMPTY[ this[ '_tag' ] ] || ( html[ n ] = '<\/' + this[ '_tag' ] + '>' );
1158 return html.join( _ );
1162 * null が来たら '', 数値等が来たら文字列化
1165 * textContent 取得・設定。null が来たら '', 数値等が来たら文字列化
1166 * @alias Node.prototype.text
1167 * @param {string} [text=]
1168 * @return {string|Node}
1169 * @example node.text( 'Hello, world!' );
1171 function X_Node_text( text ){
1172 var xnodes, texts, i, l;
1174 if( text !== undefined ){
1175 if( text === null ) text = '';
1178 if( !this[ '_tag' ] ){
1179 if( this[ '_text' ] !== text ){
1180 text ? ( this[ '_text' ] = text ) : delete this[ '_text' ];
1181 this[ '_flags' ] |= X_NodeFlags_DIRTY_CONTENT;
1182 this[ '_flags' ] & X_NodeFlags_IN_TREE && X_Node_reserveUpdate();
1186 if( ( xnodes = this[ '_xnodes' ] ) && xnodes.length === 1 && !xnodes[ 0 ][ '_tag' ] ){
1187 xnodes[ 0 ][ 'text' ]( text );
1190 // TODO 一つのtextnode を残すケース 完全に削除したい場合は empty()を使う
1191 if( !text ) return this[ 'empty' ]();
1192 this[ 'empty' ]()[ 'createText' ]( text );
1196 if( this[ '_tag' ] ){
1197 if( ( xnodes = this[ '_xnodes' ] ) && ( l = xnodes.length ) ){
1198 for( texts = [], i = 0; i < l; ++i ){
1199 texts[ i ] = xnodes[ i ][ 'text' ]();
1201 return texts.join( '' );
1205 return this[ '_text' ];
1209 * HTML要素に対して name の関数を実行しその戻り値を返す。関数に渡す引数も任意に設定できる。
1210 * @alias Node.prototype.call
1211 * @param {string} [name] 要素の関数名
1213 * @example node.call( 'focus' );
1215 function X_Node_call( name /*, opt_args... */ ){
1216 var args = arguments,
1217 l = args.length - 1,
1218 v, raw, parent, body,
1219 child, childX, childY, childW, childH,
1221 parentSX, parentSY, parentSW, parentSH,
1222 visibleX, visibleY, visibleW, visibleH,
1223 visiblePartX, visiblePartY, func, args, params, i;
1227 return !!( this[ '_flags' ] & X_NodeFlags_IS_SVG );
1229 return !!( this[ '_flags' ] & X_NodeFlags_IS_VML );
1231 return this[ '_tag' ] ? 1 : 3;
1233 X_Node_outerXNode = X_Node_body; // == true ならなんでもよい。型を合わすために xbody にしている
1234 v = this[ 'html' ]();
1235 X_Node_outerXNode = null;
1237 case 'treeIsDirty' :
1238 return !!X_Node_updateTimerID;
1240 return ( this[ '_flags' ] & X_NodeFlags_IN_TREE ) ? X_Node_CSS_getCharSize( this ) : 0;
1242 return !!( this[ '_flags' ] & ( X_NodeFlags_GPU_NOW | X_NodeFlags_GPU_RELEASE_RESERVED ) );
1244 if( this[ '_flags' ] & X_NodeFlags_IN_TREE ){
1246 while( parent = parent.parent ){
1247 if( parent[ '_flags' ] & ( X_NodeFlags_GPU_NOW | X_NodeFlags_GPU_RELEASE_RESERVED ) ) return true;
1254 case 'canAnimateNow' :
1255 return ( this[ '_flags' ] & X_NodeFlags_IN_TREE ) && X_NodeAnime_detectWaitAnimation( this, true, true ) === 6;
1257 return this[ '_anime' ] ? this[ '_anime' ].phase : 0;
1258 case 'animeProgress' :
1259 return this[ '_anime' ] && this[ '_anime' ].phase === 7 ? this[ '_anime' ].progress : 0;
1262 X_Node_updateTimerID && X_Node_startUpdate();
1264 raw = this[ '_rawObject' ] || X_UA_DOM.IE4 && X_Node__ie4getRawNode( this );
1268 if( name === 'scrollTo' ){
1269 raw.scrollLeft = args[ 1 ] || 0;
1270 raw.scrollTop = args[ 2 ] || 0;
1274 if( name === 'inView' ){
1275 if( !( this[ '_flags' ] & X_NodeFlags_IN_TREE ) ) return { 'isInView' : false };
1278 visibleX = visibleY = visibleW = visibleH = 0;
1279 while( child !== body ){
1280 parent = child.parentNode || child.parentElement;
1281 parentH = parent.clientHeight;
1282 parentW = parent.clientWidth;
1283 parentSW = parent.scrollHeight;
1284 parentSH = parent.scrollWidth;
1286 if( parentH < parentSH || parentW < parentSW ){
1287 childX = child.offsetLeft + visibleX;
1288 childY = child.offsetTop + visibleY;
1289 childW = visibleW || child.offsetWidth;
1290 childH = visibleH || child.offsetHeight;
1291 parentSX = parent.scrollLeft;
1292 parentSY = parent.scrollTop;
1294 if( parentSY < childY + childH &&
1295 childY < parentSY + parentH &&
1296 parentSX < childX + childW &&
1297 childX < parentSX + parentW ){
1299 // right:子の左側が見えている left:子の左側が見えている both:完全に見えている
1301 childX < parentSX ? 'right' :
1302 ( parentSX + parentW ) < ( childX + childW ) ? 'left' : 'both';
1304 childY < parentSY ? 'bottom' :
1305 ( parentSY + parentH ) < ( childY + childH ) ? 'top' : 'both';
1308 visibleX = visiblePartX === 'right' ? 0 : childX - parentSX;
1309 visibleY = visiblePartX === 'bottom' ? 0 : childY - parentSY;
1311 visiblePartX === 'both' ? childW :
1312 visiblePartX === 'right' ? ( parentSX + parentW - childX ) : ( childX + childW - parentSX );
1314 visiblePartY === 'both' ? childH :
1315 visiblePartY === 'bottom' ? ( parentSY + parentH - childY ) : ( childY + childH - parentSY );
1317 return { 'isInView' : false };
1322 return { 'isInView' : true };
1326 if( X_Type_isFunction( func ) ){
1328 args = X_Array_copy( args );
1330 return func.apply( raw, args );
1332 return raw[ name ]();
1334 if( X_UA[ 'IE' ] < 9 && ( X_Type_isUnknown( func ) || X_Type_isObject( func ) ) ){
1335 // typeof func === unknown に対策
1336 // http://la.ma.la/blog/diary_200509031529.htm
1338 args = X_Array_copy( args );
1342 for( i = 0; i < l; ++i ){
1343 params[ i ] = '_' + i;
1345 params = params.join( ',' );
1348 [ 'return this.', name, '(', params, ')' ].join( '' )
1349 ).apply( raw, args );
1351 return raw[ name ]();
1356 * xnode を this として関数を実行する。 NodeList.each と動作を合わせてあるため関数の戻り値は破棄される。
1359 function X_Node_each( func /*, opt_args */ ){
1361 if( 1 < arguments.length ){
1362 args = X_Array_copy( arguments );
1364 func.apply( this, args );
1366 func.call( this, 0 );
1372 /* --------------------------------------
1373 * Async commit update
1375 * TODO Timer や DOM イベントの呼び出しの最後に、まだ一度も commitUpdate していないなら commitUpdate してしまう。
1378 function X_Node_reserveUpdate(){
1379 if( !X_Node_updateTimerID ) X_Node_updateTimerID = X_Timer_requestFrame( X_Node_startUpdate );
1382 var X_Node_updateReservedByReleaseGPU = false;
1384 function X_Node_startUpdate( time ){
1385 var removal, i, xnodeOrElm, xnodesIEFilterFixAfter, xnode, active;
1387 if( !X_Node_updateTimerID || X_ViewPort_readyState < X_EVENT_INIT ){
1391 X_Timer_cancelFrame( X_Node_updateTimerID );
1392 X_Node_updateTimerID = 0;
1395 // X.Timer 経由でないと発火しない このイベントでサイズを取ると無限ループに
1396 X_System[ '_listeners' ] && X_System[ '_listeners' ][ X_EVENT_BEFORE_UPDATE ] && X_System[ 'dispatch' ]( X_EVENT_BEFORE_UPDATE );
1399 removal = X_Node_reserveRemoval;
1401 if( i = removal.length ){
1403 xnodeOrElm = removal[ --i ];
1404 // TODO GPU レイヤーの子の場合、remove をスキップする。 非GPU レイヤーへ apppend される場合、clone する?
1405 // GPU レイヤーを削除する場合、cssText = '' して GPU レイヤーを解除する
1406 if( !xnodeOrElm[ 'instanceOf' ] ){
1408 xnodeOrElm.removeAttribute( 'id' ); // ?
1409 xnodeOrElm.outerHTML = ''; // xnodeOrElm.remove() ?
1411 if( !X_UA[ 'MacIE' ] ){
1412 // elm.parentNode.tagName for ie7
1413 xnodeOrElm.parentNode && xnodeOrElm.parentNode.tagName && xnodeOrElm.parentNode.removeChild( xnodeOrElm );
1415 xnodeOrElm.parentNode && xnodeOrElm.parentNode.tagName && X_TEMP._fixed_remove( xnodeOrElm, that );
1419 X_Node__actualRemove( xnodeOrElm );
1425 // 強制的に再描画を起こす, 但し activeElement からフォーカスが外れるため復帰する
1426 // IE5mode win10 で 確認
1427 if( X_UA[ 'IE5' ] ){
1428 active = FocusUtility_getFocusedElement();
1429 X_elmBody.style.visibility = 'hidden';
1432 if( X_Node_html[ '_flags' ] & X_Node_BitMask_IS_DIRTY ){
1433 X_Node__commitUpdate( X_Node_html, X_Node_html[ '_rawObject' ].parentNode, null, X_Node_html[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
1435 X_Node__commitUpdate( X_Node_head, X_Node_head[ '_rawObject' ].parentNode, null, X_Node_head[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
1436 X_Node__commitUpdate( X_Node_body, X_Node_body[ '_rawObject' ].parentNode, null, X_Node_body[ '_flags' ], 1, xnodesIEFilterFixAfter = [] );
1439 if( X_UA[ 'IE5' ] ){
1440 X_elmBody.style.visibility = '';
1441 active && active.parentNode && FocusUtility_setTemporarilyFocus( active );
1444 if( X_Node_updateReservedByReleaseGPU ){
1445 X_Node_reserveUpdate();
1446 X_Node_updateReservedByReleaseGPU = false;
1449 if( X_NodeFlags_IE_FILTER_FIX_AFTER && xnodesIEFilterFixAfter.length ){
1450 for( i = 0; xnode = xnodesIEFilterFixAfter[ i ]; ++i ){
1451 xnode[ '_flags' ] &= ~X_NodeFlags_IE_FILTER_FIX_AFTER;
1452 X_Node_CSS_onAfterUpdateIEFilterFix( xnode );
1456 // time を視て X.Timer 経由の場合、即座に発火する。
1457 // width() 等で強制的にツリーを構築している場合、UPDATE イベントのコールバックで要素を変更しサイズを取ると無限ループになる,これを防ぐため asyncDispatch とする
1458 X_System[ '_listeners' ] && X_System[ '_listeners' ][ X_EVENT_UPDATED ] && X_System[ time ? 'dispatch' : 'asyncDispatch' ]( X_EVENT_UPDATED );
1460 X_ViewPort[ '_listeners' ] && X_ViewPort[ '_listeners' ][ X_EVENT_AFTER_UPDATE ] && X_ViewPort[ 'asyncDispatch' ]( X_EVENT_AFTER_UPDATE );
1464 * 1. GPU_NOW の場合、子の変更は行わない
1465 * 2. GPU解放予約 の場合//、この要素のみ変更を行う。rAF 後にさらに更新するためフラグを立てる。
1467 * 4. style="display:none" の場合、これ以下の変更を行わない。
1468 * 5. ie5 非表示フラグが立っていて、親と自身の class・id によって非表示になっていて、親と自身に変更がない。accumulatedFlags を使用。
1469 * -> TODO これ TREE の変更を検出できない。 remove したときに 子まで X_NodeFlags_IE5_DISPLAY_NONE_FIXを落とす。
1473 * 9. ie5 親及び自身へのクラス・id指定で display:none になるケースがありそれを検出。
1474 * このままでは、生成と破棄が繰り返されてしまうので親と自身のクラス・idが変わった場合、ツリー位置の変化があった場合に再生する。
1476 var X_Node__commitUpdate =
1478 ( function( that, parentElement, nextElement, accumulatedFlags, ie8AccumulatedOpcity, xnodesIEFilterFixAfter ){
1479 var elm = that[ '_rawObject' ],
1480 created, xnodes, l, next, anime, v, currentOpcity;
1482 // 1. GPU 一切の更新をスキップ
1483 if( that[ '_flags' ] & X_NodeFlags_GPU_NOW ){
1484 console.log( '更新のskip ' + that[ '_className' ] + !!( that[ '_flags' ] & X_Node_BitMask_IS_DIRTY ) );
1485 that[ '_flags' ] & X_Node_BitMask_IS_DIRTY && X_Node__updateRawNode( that, elm );
1490 if( that[ '_flags' ] & X_NodeFlags_GPU_RELEASE_RESERVED ){
1491 console.log( 'GPU 解放 ' );
1492 //X_Node_updateReservedByReleaseGPU = true;
1493 that[ '_flags' ] &= X_Node_BitMask_RESET_GPU;
1494 //return elm;// このタイミングで更新できるっぽい。
1498 if( that[ '_flags' ] & X_NodeFlags_GPU_RESERVED ){
1499 // TODO size 取得のための update の場合、GPU化をスキップ
1500 that[ '_flags' ] &= X_Node_BitMask_RESET_GPU;
1501 that[ '_flags' ] |= X_NodeFlags_GPU_NOW;
1504 // 4. style="display:none" の場合
1505 if( that[ '_flags' ] & X_NodeFlags_STYLE_IS_DISPLAY_NONE ){
1506 if( X_Node_displayNoneFixForIE5 ){
1507 // filter の効いている要素を含む要素は display:none が無視される。
1508 // filter = '' で削除はできるが、再表示時に filter が消える。 -> filter な要素を削除してしまう。
1509 // TODO filters[0].enabled = false なんてどう?
1510 if( elm && elm.parentNode ){
1511 X_Node__actualRemove( that );
1515 elm && ( elm.style.display = 'none' );
1516 return ( elm && elm.nextSibling === nextElement ) ? elm : nextElement;
1520 accumulatedFlags |= that[ '_flags' ];
1522 if( that[ '_flags' ] & X_NodeFlags_IE5_DISPLAY_NONE_FIX ){
1523 if( ( accumulatedFlags & ( X_NodeFlags_DIRTY_POSITION | X_NodeFlags_DIRTY_ID | X_NodeFlags_DIRTY_CLASSNAME ) ) === 0 ){
1530 if( !that[ '_tag' ] ){
1531 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1532 if( X_UA[ 'IE' ] < 8 ){
1533 // \n -> \r\n に変換しないと pre タグで改行されない win10ie7(ie11 emu) で確認
1534 elm = document.createTextNode( X_String_chrReferanceTo( that[ '_text' ] ).split( '\n' ).join( X_String_CRLF ) );
1536 elm = document.createTextNode( X_String_chrReferanceTo( that[ '_text' ] ) );
1538 if( !X_UA[ 'IE' ] ){
1539 elm[ 'UID' ] = that[ '_uid' ];
1542 if( X_Node_strictElmCreation ){
1543 that[ '_flags' ] & X_NodeFlags_OLD_CSSTEXT && X_Node_CSS_objToCssText( that, true ); // OLD_CSSTEXT ??
1546 document.createElement( [
1547 '<', that[ '_tag' ],
1548 ' UID="', that[ '_uid' ], '"',
1549 that[ '_id' ] ? ' id="' + that[ '_id' ] + '"' : '',
1550 that[ '_className' ] ? ' class="' + that[ '_className' ] + '"' : '',
1551 X_Node_Attr_objToAttrText( that, true ),
1552 that[ '_cssText' ] ? ' style="' + that[ '_cssText' ] + '"' : '',
1555 if( that[ '_flags' ] & X_NodeFlags_IS_SVG ){
1556 elm = document.createElementNS( 'http://www.w3.org/2000/svg', that[ '_tag' ].toLowerCase() );
1558 // TODO math http://www.w3.org/1998/Math/MathML
1560 elm = document.createElement( that[ '_tag' ] );
1563 that[ '_rawObject' ] = elm;
1565 // IE には要素追加のタイミングで起こるメモリリークがありここで追加
1566 if( !X_Node_addTreeAfterChildren ){
1568 parentElement.insertBefore( elm, nextElement ) :
1569 parentElement.appendChild( elm );
1572 if( that[ '_tag' ] ){
1573 X_EventDispatcher_toggleAllEvents( that, true );// イベントの復帰
1574 that[ '_flags' ] |= X_NodeFlags_ACTUAL_LISTENING;
1576 //if( X_Node_documentFragment ){
1577 //( frg = X_Node_documentFragment ).appendChild( elm );
1578 // 連続する要素の差し替えの場合に有効
1581 if( X_Node_strictElmCreation ){
1582 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1583 // ie の string から要素を作る場合、ネットワーク系属性は onload イベントなどを拾うために、要素生成->イベント復帰後に適用する
1584 that[ '_newAttrs' ] && ( that[ '_flags' ] |= X_NodeFlags_DIRTY_ATTR ); // _newAttrs には ネットワーク系属性が入っている。Network 系の属性は遅らせて設定
1585 that[ '_flags' ] |= X_NodeFlags_DIRTY_IE_FILTER;// doc 追加後に filter を指定しないと有効にならない。
1587 elm[ 'UID' ] = that[ '_uid' ];
1588 that[ '_newAttrs' ] = that[ '_attrs' ];
1589 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1590 that[ '_flags' ] |= X_NodeFlags_DIRTY_ID | X_NodeFlags_DIRTY_CLASSNAME | X_NodeFlags_DIRTY_ATTR | X_NodeFlags_DIRTY_CSS | X_NodeFlags_DIRTY_IE_FILTER;
1592 // http://outcloud.blogspot.jp/2010/09/iframe.html
1593 // この問題は firefox3.6 で確認
1594 if( X_UA[ 'Gecko' ] ){
1595 if( that[ '_tag' ] === 'IFRAME' && ( !that[ '_attrs' ] || !that[ '_attrs' ][ 'src' ] ) ){
1596 //elm.contentWindow.location.replace = elm.src = 'about:blank';
1597 that[ 'attr' ]( 'src', 'about:blank' );
1606 if( elm.parentNode !== parentElement || ( nextElement && elm.nextSibling !== nextElement ) ){
1608 parentElement.insertBefore( elm, nextElement ) :
1609 parentElement.appendChild( elm );
1612 if( that[ '_listeners' ] && ( ( that[ '_flags' ] & X_NodeFlags_ACTUAL_LISTENING ) === 0 ) ){
1613 X_EventDispatcher_toggleAllEvents( that, true );// イベントの退避
1614 that[ '_flags' ] |= X_NodeFlags_ACTUAL_LISTENING;
1617 // ie8 では子要素に opacity が反映されないため、親要素の opacity を積算する
1618 currentOpcity = that[ '_css' ] && 0 <= that[ '_css' ].opacity && that[ '_css' ].opacity;
1619 ie8AccumulatedOpcity = ie8AccumulatedOpcity * ( currentOpcity || 1 );
1622 if( accumulatedFlags & X_Node_BitMask_IS_DIRTY ){
1623 delete that[ '_fontSize' ];
1624 X_Node__updateRawNode( that, elm, currentOpcity, ie8AccumulatedOpcity, accumulatedFlags );
1628 // 親及び自身へのクラス・id指定で display : none になるケースがありそれを検出
1629 // 生成と破棄が繰り返されてしまう、親と自身の id, class が変わった場合だけ再生成。 accumulatedFlags & ( ID | CLASSNAME )
1630 // currentStyle を観ていたときはエラーで停止する、alert と挟むと正常に動いて支離滅裂
1631 if( X_Node_displayNoneFixForIE5 && that[ '_tag' ] ){
1632 if( elm.runtimeStyle.display === 'none' ){
1633 X_Node__actualRemove( that );
1634 that[ '_flags' ] |= X_NodeFlags_IE5_DISPLAY_NONE_FIX;
1637 that[ '_flags' ] &= ~X_NodeFlags_IE5_DISPLAY_NONE_FIX;
1641 if( that[ '_flags' ] & X_NodeFlags_IE_FILTER_FIX_AFTER ){
1642 xnodesIEFilterFixAfter[ xnodesIEFilterFixAfter.length ] = that;
1646 if( ( xnodes = that[ '_xnodes' ] ) && ( l = xnodes.length ) ) {
1648 next = X_Node__commitUpdate( xnodes[ --l ], elm, next, accumulatedFlags, ie8AccumulatedOpcity, xnodesIEFilterFixAfter );
1652 if( created && X_Node_addTreeAfterChildren ){
1654 parentElement.insertBefore( elm, nextElement ) :
1655 parentElement.appendChild( elm );
1657 if( X_UA[ 'Gecko' ] && that[ '_tag' ] === 'IFRAME' && elm.contentWindow ){
1658 // tree に追加されるまで contentWindow は存在しない。
1659 elm.contentWindow.location.replace = elm.src;
1664 * if( ( anime = that[ '_anime' ] ) && 6 <= anime.phase && anime.doScroll ){
1665 if( anime.phase === 6 ){
1666 v = anime.fromScrollX;
1670 anime.fromScrollX = elm.scrollLeft;
1672 v = anime.fromScrollY;
1676 anime.fromScrollY = elm.scrollTop;
1679 elm.scrollLeft = anime.scrollX;
1680 elm.scrollTop = anime.scrollY;
1688 ( function( that, parentElement, prevElement, accumulatedFlags ){
1689 var elm = that[ '_rawObject' ] || X_Node__ie4getRawNode( that ),
1690 xnodes, l, i, dirty, mix, html, text, prev, anime, v;
1692 if( !that[ '_tag' ] ){
1693 that[ '_flags' ] & X_NodeFlags_DIRTY_CONTENT && X_Node__updateRawNode( that, elm );
1697 // 4. style="display:none" の場合
1698 if( that[ '_flags' ] & X_NodeFlags_STYLE_IS_DISPLAY_NONE ){
1700 elm.style.display = 'none';
1701 if( elm.style.display !== 'none' ){ // ie4 の style は currentStyle 相当らしい、、、? div 以外への display:none が効かないので remove する。
1702 X_Node__actualRemove( that );
1706 return elm || prevElement;
1711 prevElement.insertAdjacentHTML( 'AfterEnd', X_Node__actualCreate( that, false ) ) :
1712 parentElement.insertAdjacentHTML( 'AfterBegin', X_Node__actualCreate( that, false ) );
1713 X_Node__afterActualCreate( that );
1715 elm = that[ '_rawObject' ] || X_Node__ie4getRawNode( that );
1717 accumulatedFlags |= that[ '_flags' ];
1719 xnodes = that[ '_xnodes' ];
1720 l = xnodes ? xnodes.length : 0;
1721 dirty = !!( that[ '_flags' ] & X_NodeFlags_IE4_DIRTY_CHILDREN );
1724 * HTML の下に TextNode だけ 。MIX_FIXED でない場合、削除、追加 を親に通知
1726 * HTML の下は MIX -> TextNode, html の削除、変更、追加
1727 * HTML の下は MIX_FIXED -> TextNode を <font> に置き換えてあるのでW3C DON 的に触ることができる
1730 that[ '_flags' ] &= ~X_NodeFlags_IE4_DIRTY_CHILDREN;
1731 for( i = 0; i < l; ++i ){
1732 if( xnodes[ i ][ '_tag' ] ){
1733 that[ '_flags' ] |= X_NodeFlags_IE4_HAS_ELEMENT;
1735 that[ '_flags' ] |= X_NodeFlags_IE4_HAS_TEXTNODE;
1737 if( that[ '_flags' ] & X_Node_BitMask_IE4_IS_MIX === X_Node_BitMask_IE4_IS_MIX ){
1744 if( that[ '_flags' ] & X_NodeFlags_IE4_FIXED || that[ '_flags' ] & X_Node_BitMask_IE4_IS_MIX === X_NodeFlags_IE4_HAS_ELEMENT ){
1745 for( i = 0; i < l; ++i ){
1746 prev = X_Node__commitUpdate( xnodes[ i ], elm, prev, accumulatedFlags );
1751 for( i = 0; i < l; ++i ){
1752 html[ i ] = X_Node__actualCreate( xnodes[ i ], false );
1754 elm.innerHTML = html.join( '' );
1755 for( i = 0; i < l; ++i ){
1756 X_Node__afterActualCreate( xnodes[ i ] );
1758 that[ '_flags' ] |= X_NodeFlags_IE4_FIXED;
1760 if( that[ '_flags' ] & X_NodeFlags_IE4_HAS_TEXTNODE ){
1761 dirty = dirty || false;
1762 for( i = 0; i < l; ++i ){
1764 if( text[ '_flags' ] & X_Node_BitMask_IS_DIRTY ){
1765 text[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1769 if( dirty ) elm.innerHTML = that[ 'text' ]();
1772 if( accumulatedFlags & X_Node_BitMask_IS_DIRTY ) delete that[ '_fontSize' ];
1774 that[ '_flags' ] &= ~X_NodeFlags_DIRTY_POSITION;
1775 that[ '_flags' ] & X_Node_BitMask_IS_DIRTY && X_Node__updateRawNode( that, elm );
1778 if( ( anime = that[ '_anime' ] ) && 6 <= anime.phase && anime.doScroll ){
1779 if( anime.phase === 6 ){
1780 v = anime.fromScrollX;
1784 anime.fromScrollX = elm.scrollLeft;
1786 v = anime.fromScrollY;
1790 anime.fromScrollY = elm.scrollTop;
1793 elm.scrollLeft = anime.scrollX;
1794 elm.scrollTop = anime.scrollY;
1803 * GPU レイヤーするブラウザは、子要素から変更を当てていく? <- とりあえず、親要素から。
1805 var X_Node__updateRawNode =
1807 ( function( that, elm, currentOpcity, ie8AccumulatedOpcity, accumulatedFlags ){
1808 var // flags = that[ '_flags' ],
1809 attrs, rename, k, v, f;
1812 if( !that[ '_tag' ] ){
1813 if( X_UA[ 'IE' ] < 8 ){
1814 // \n -> \r\n に変換しないと pre タグで改行されない win10ie7(ie11 emu) で確認
1815 elm.data = X_String_chrReferanceTo( that[ '_text' ] ).split( '\n' ).join( X_String_CRLF );
1817 elm.data = X_String_chrReferanceTo( that[ '_text' ] );
1819 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1824 if( that[ '_flags' ] & X_NodeFlags_DIRTY_ID ){
1826 ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
1827 elm.setAttribute( 'id', that[ '_id' ] ) :
1828 ( elm.id = that[ '_id' ] )
1830 ( elm.id && elm.removeAttribute( 'id' ) );
1833 if( that[ '_flags' ] & X_NodeFlags_DIRTY_CLASSNAME ){
1834 that[ '_className' ] ?
1835 ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
1836 elm.setAttribute( 'class', that[ '_className' ] ) :
1837 ( elm.className = that[ '_className' ] )
1839 ( elm.className && elm.removeAttribute( X_UA[ 'IE' ] < 8 ? 'className' : 'class' ) ); // className は ie7-
1843 if( that[ '_flags' ] & X_NodeFlags_DIRTY_ATTR && ( attrs = that[ '_newAttrs' ] || that[ '_attrs' ] ) ){
1844 rename = X_Node_Attr_renameForDOM;
1849 switch( that[ '_tag' ] + k ){
1850 case 'TEXTAREAvalue' :
1851 // IETester 5.5 ではエラーが出なかった.MultipulIE5.5 ではエラーが出たので
1852 // MultipleIE6 でもここを通す。X_UA[ 'ieExeComError' ] の場合 MultipleIE6
1853 if( ( !X_UA[ 'MacIE' ] && X_UA[ 'IE5x' ] ) || ( X_UA[ 'ieExeComError' ] && X_UA[ 'IE6' ] ) ){
1855 ( elm.firstChild.data = v || '' ) :
1856 elm.appendChild( document.createTextNode( v || '' ) );
1862 // http://outcloud.blogspot.jp/2010/09/iframe.html
1863 // この問題は firefox3.6 で確認
1864 if( X_UA[ 'Gecko' ] && elm.contentWindow ){
1865 elm.contentWindow.location.replace = elm.src = v || '';
1871 // http://d.hatena.ne.jp/NeoCat/20080921/1221940658
1872 // こちらに名前をsetしないとtargetが動作しない
1873 // これってあとから name を変更できないバグでは? itozyun
1874 // if( X_UA[ 'IE' ] ) elm.name = elm.contentWindow.name = v || '';
1877 //if( X_EMPTY_OBJECT[ k ] ) continue;
1878 // TODO IE では input, なぜか button, object も type, name の変更が出来ない、同値で置き換えようとしても不可
1880 elm.removeAttribute( rename[ k ] || k ) :
1881 ( ( that[ '_flags' ] & X_NodeFlags_IS_SVG ) ?
1882 elm.setAttribute( k, v ) :
1883 ( elm[ rename[ k ] || k ] = X_Node_Attr_noValue[ k ] ? k : v )
1886 delete that[ '_newAttrs' ];
1889 if( accumulatedFlags & X_NodeFlags_IE8_OPACITY_FIX ){
1890 if( 0 <= currentOpcity ){
1892 that[ '_css' ].opacity = ie8AccumulatedOpcity;
1893 if( that[ '_flags' ] & X_NodeFlags_DIRTY_CSS ){
1894 that[ '_flags' ] |= X_NodeFlags_OLD_CSSTEXT;
1896 if( !( that[ '_flags' ] & X_NodeFlags_DIRTY_IE_FILTER ) ){
1897 that[ '_flags' ] |= X_NodeFlags_DIRTY_IE_FILTER;
1903 if( that[ '_flags' ] & X_NodeFlags_DIRTY_CSS ){
1904 if( that[ '_flags' ] & X_NodeFlags_OLD_CSSTEXT ? X_Node_CSS_objToCssText( that ) : that[ '_cssText' ] ){
1905 X_UA[ 'Opera78' ] || X_UA[ 'NN6' ] ?
1906 elm.setAttribute( 'style', that[ '_cssText' ] ) : // opera8用
1907 ( elm.style.cssText = that[ '_cssText' ] );
1909 elm.style.cssText = ''; // IE5.5以下 Safari3.2 で必要
1910 elm.removeAttribute( 'style' );
1913 if( that[ '_flags' ] & X_NodeFlags_DIRTY_IE_FILTER ){
1914 v = X_Node_CSS_objToIEFilterText( that );
1916 elm.style.filter = v;
1917 that[ '_flags' ] |= X_NodeFlags_IE_FILTER_NOW;
1919 elm.style.removeAttribute( 'filter' );
1920 that[ '_flags' ] &= ~X_NodeFlags_IE_FILTER_NOW;
1925 * http://jsdo.it/esukei/imOL
1926 * IE8でのfilter:alpha継承
1927 * IE8でfilter:alphaの指定がposition:relative,position:absoluteの子要素に継承されない問題
1930 that[ '_css' ].opacity = currentOpcity;
1933 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1936 ( function( that, elm ){
1937 var attrs, rename, k, v;
1940 if( !that[ '_tag' ] ){
1941 elm.innerText = that[ '_text' ];
1942 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1947 * http://www.tohoho-web.com/js/element.htm
1948 * title、className、id、lang、language には setAttribute でなく、element.id で直接読み書きできる
1951 if( that[ '_flags' ] & X_NodeFlags_DIRTY_ID ) elm.setAttribute( 'id', that[ '_id' ] || ( 'ie4uid' + that[ '_uid' ] ) );
1954 if( that[ '_flags' ] & X_NodeFlags_DIRTY_CLASSNAME ){
1955 that[ '_className' ] ? ( elm.className = that[ '_className' ] ) : elm.removeAttribute( 'class' );
1958 if( that[ '_flags' ] & X_NodeFlags_DIRTY_CSS ){
1959 if( that[ '_flags' ] & X_NodeFlags_OLD_CSSTEXT ? X_Node_CSS_objToCssText( that ) : that[ '_cssText' ] ){
1960 elm.style.cssText = that[ '_cssText' ];
1962 elm.style.cssText = '';
1963 elm.removeAttribute( 'style' );
1966 if( that[ '_flags' ] & X_NodeFlags_DIRTY_IE_FILTER ){
1967 v = X_Node_CSS_objToIEFilterText( that );
1969 elm.style.filter = v;
1970 that[ '_flags' ] |= X_NodeFlags_IE_FILTER_NOW;
1972 elm.style.removeAttribute( 'filter' );
1973 that[ '_flags' ] &= ~X_NodeFlags_IE_FILTER_NOW;
1978 if( that[ '_flags' ] & X_NodeFlags_DIRTY_ATTR && ( attrs = that[ '_newAttrs' ] || that[ '_attrs' ] ) ){
1979 rename = X_Node_Attr_renameForDOM;
1981 //if( X_EMPTY_OBJECT[ k ] ) continue;
1982 ( v = attrs[ k ] ) === undefined ?
1983 elm.removeAttribute( rename[ k ] || k ) :
1984 elm.setAttribute( rename[ k ] || k, X_Node_Attr_noValue[ k ] ? k : v );
1986 delete that[ '_newAttrs' ];
1989 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
1993 /* --------------------------------------
1996 * http://d.hatena.ne.jp/uupaa/20080718/1216362040
1997 * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。
1998 * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");
1999 * insertAdjacentHTML
2001 * ie7 以下では iframe の frameborder や、input name は、createElement 後に setAttribute しても無視される
2003 * fragument がある場合 children も足して
2004 * Mozilla: 1.0+, IE: 5.5+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+
2005 * ie6 大丈夫?fragment の場合リークしないか?チェックが必要
2006 * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx
2008 * document.createElement of ie4 is only for OPTION & IMAGE.
2010 var X_Node__actualCreate =
2011 X_UA_DOM.IE4 && (function( that, isChild ){
2012 var uid = that[ '_uid' ],
2013 html, xnodes, n, i, l;
2015 if( !that[ '_tag' ] ){
2016 html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', that[ '_text' ], '</FONT>' ];// fake textNode
2017 delete that[ '_rawObject' ];
2019 if( !isChild ) X_Node__actualRemove( that, /* true */ false );
2021 that[ '_flags' ] & X_NodeFlags_OLD_CSSTEXT && X_Node_CSS_objToCssText( that, true );
2024 '<', that[ '_tag' ], ' id=', ( that[ '_id' ] || ( 'ie4uid' + uid ) ), ' UID="', uid, '"',
2025 that[ '_className' ] ? ' class="' + that[ '_className' ] + '"' : '',
2026 X_Node_Attr_objToAttrText( that, true ),
2027 that[ '_cssText' ] ? ' style="' + that[ '_cssText' ] + '"' : '',
2031 if( ( xnodes = that[ '_xnodes' ] ) && ( l = xnodes.length ) ){
2033 that[ '_flags' ] &= ~X_NodeFlags_IE4_DIRTY_CHILDREN;
2034 for( i = 0; i < l; ++i ){
2035 if( xnodes[ i ][ '_tag' ] ){
2036 that[ '_flags' ] |= X_NodeFlags_IE4_HAS_ELEMENT;
2038 that[ '_flags' ] |= X_NodeFlags_IE4_HAS_TEXTNODE;
2040 if( that[ '_flags' ] & X_Node_BitMask_IE4_IS_MIX === X_Node_BitMask_IE4_IS_MIX ){
2045 if( that[ '_flags' ] & X_Node_BitMask_IE4_IS_MIX === X_NodeFlags_IE4_HAS_TEXTNODE ){
2047 html[ n ] = that[ 'text' ]();
2050 for( i = 0; i < l; ++i ){
2051 html[ n ] = X_Node__actualCreate( xnodes[ i ], true );
2054 that[ '_flags' ] |= X_NodeFlags_IE4_FIXED;
2057 X_Dom_DTD_EMPTY[ that[ '_tag' ] ] || ( html[ n ] = '<\/' + that[ '_tag' ] + '>' );
2059 that[ '_newAttrs' ] && ( that[ '_flags' ] |= X_NodeFlags_DIRTY_ATTR );
2062 return html.join( '' );
2065 var X_Node__afterActualCreate =
2066 X_UA_DOM.IE4 && (function( that ){
2069 if( !that[ '_tag' ] ) return that;
2071 if( ( xnodes = that[ '_xnodes' ] ) && ( i = xnodes.length ) ){
2073 X_Node__afterActualCreate( xnodes[ --i ] );
2076 // ネットワーク系属性と filter は要素生成後に適用
2077 if( that[ '_flags' ] & ( X_NodeFlags_DIRTY_ATTR | X_NodeFlags_DIRTY_IE_FILTER ) ){
2078 X_Node__updateRawNode( that, that[ '_rawObject' ] || X_Node__ie4getRawNode( that ) );
2080 that[ '_flags' ] &= X_Node_BitMask_RESET_DIRTY;
2082 X_EventDispatcher_toggleAllEvents( that, true );// イベントの復帰
2085 var X_Node__actualRemove =
2087 // GPUレイヤーにいるうちは remove しない。-> GPU解除してから remove する
2088 // Firefox34 では遭遇せず、Safari で何度かアニメーションしているうちに発生
2089 ( function( that, isChild ){
2090 var xnodes = that[ '_xnodes' ],
2091 elm = that[ '_rawObject' ],
2094 if( xnodes && ( l = xnodes.length ) ){
2095 for( i = 0; i < l; ++i ){
2096 child = xnodes[ i ];
2097 child[ '_tag' ] && X_Node__actualRemove( child, true );
2103 if( that[ '_flags' ] & X_NodeFlags_ACTUAL_LISTENING ){
2104 that[ '_listeners' ] && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避
2105 that[ '_flags' ] &= ~X_NodeFlags_ACTUAL_LISTENING;
2108 // ie5では filter の効いている要素をremove時に破棄して、再度append 時に新規生成する
2109 // ちなみに elm.filters に触ると ie8 でなぜかカラム落ちが発生、、、
2110 if( X_Node_displayNoneFixForIE5 ){
2111 if( elm.filters && elm.filters.length ){
2113 delete that[ '_rawObject' ];
2114 // 破棄前にインタラクティブな属性値を控える
2115 if( X_Node_Attr_HAS_VALUE[ that[ '_tag' ] ] && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'value', that[ '_newAttrs' ] ) ) ){
2116 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2117 that[ '_attrs' ].value = elm.value;
2119 if( that[ '_tag' ] === 'OPTION' && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'selected', that[ '_newAttrs' ] ) ) ){
2120 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2121 that[ '_attrs' ].selected = elm.selected;
2123 if( that[ '_tag' ] === 'SELECT' && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'selectedIndex', that[ '_newAttrs' ] ) ) ){
2124 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2125 that[ '_attrs' ].selectedIndex = elm.selectedIndex;
2127 if( that[ '_tag' ] === 'INPUT' && that[ '_attrs' ] && ( that[ '_attrs' ].type === 'checkbox' || that[ '_attrs' ].type === 'radio' ) && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'checked', that[ '_newAttrs' ] ) ) ){
2128 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2129 that[ '_attrs' ].checked = elm.checked;
2136 if( !X_UA[ 'MacIE' ] ){
2137 // elm.parentNode.tagName for ie7
2138 !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );
2140 !isChild && elm.parentNode && elm.parentNode.tagName && X_TEMP._fixed_remove( elm, that );
2144 ( function( that, isChild ){
2145 var xnodes = that[ '_xnodes' ],
2146 elm = that[ '_rawObject' ] || X_Node__ie4getRawNode( that ),
2148 if( xnodes && ( l = xnodes.length ) ){
2149 for( i = 0; i < l; ++i ){
2150 X_Node__actualRemove( xnodes[ i ], true );
2155 that[ '_listeners' ] && X_EventDispatcher_toggleAllEvents( that, false );// イベントの退避
2157 // 破棄前にインタラクティブな属性値を控える
2158 if( X_Node_Attr_HAS_VALUE[ that[ '_tag' ] ] && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'value', that[ '_newAttrs' ] ) ) ){
2159 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2160 that[ '_attrs' ].value = elm.value;
2162 if( that[ '_tag' ] === 'OPTION' && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'selected', that[ '_newAttrs' ] ) ) ){
2163 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2164 that[ '_attrs' ].selected = elm.selected;
2166 if( that[ '_tag' ] === 'SELECT' && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'selectedIndex', that[ '_newAttrs' ] ) ) ){
2167 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2168 that[ '_attrs' ].selectedIndex = elm.selectedIndex;
2170 if( that[ '_tag' ] === 'INPUT' && that[ '_attrs' ] && ( that[ '_attrs' ].type === 'checkbox' || that[ '_attrs' ].type === 'radio' ) && ( !that[ '_newAttrs' ] || !X_Object_inObject( 'checked', that[ '_newAttrs' ] ) ) ){
2171 if( !that[ '_attrs' ] ) that[ '_attrs' ] = {};
2172 that[ '_attrs' ].checked = elm.checked;
2175 elm.removeAttribute( 'id' ); // ?
2176 //document.all[ that[ '_id' ] || ( 'ie4uid' + that[ '_uid' ] ) ] = null; // MacIE5 でエラー
2177 if( !isChild ) elm.outerHTML = ''; // elm.remove() ?
2178 delete that[ '_rawObject' ];
2182 X_ViewPort[ 'listenOnce' ]( X_EVENT_UNLOAD, X_Node__actualRemove, [ X_Node_html, true ] );