OSDN Git Service

Version 0.6.28, bugfix.
[pettanr/clientJs.git] / 0.6.x / js / dom / 11_XDomNode.js
1 \r
2 X.Dom.Dirty = {\r
3         CLEAN            :  0,\r
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
11 };\r
12 \r
13 /*\r
14  * \r
15  *\r
16  * destroyed\r
17  * display:none\r
18  * display:block\r
19  * display:inline\r
20  * \r
21  */\r
22 \r
23 X.Dom.State = {\r
24         DESTROYED          : 0,\r
25         DISPLAY_NONE       : 1,\r
26         DISPLAY_BLOCK      : 2,\r
27         DISPLAY_INLINE     : 4,\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
34         IE4_ONLY_TEXT      : 64\r
35 };\r
36 \r
37 /*\r
38  * Node( rawElement | rawTextnode | htmlString | textString )\r
39  */\r
40 //;(function( window, document, undeifned ){\r
41 X.Dom.Node = X.EventDispatcher.inherits(\r
42         'XDomNode',\r
43         X.Class.POOL_OBJECT,\r
44         {\r
45                 _uid       : 0,\r
46                 _state     : 0,\r
47                 _dirty     : 0,\r
48                 \r
49                 _rawNode   : null,\r
50                 _root      : null, // xnode が文書ツリーに属しているか?はこれを見る\r
51                 parent     : null, // remove された枝も親子構造は維持している。\r
52                 _xnodes    : null,\r
53         \r
54                 _xnodeType : 0,\r
55                 _tag       : null,\r
56                 _text      : null,\r
57                 _id        : null,\r
58                 _className : '',\r
59 \r
60                 _attrs     : null, // X.Dom.Attr\r
61                 _newAttrs  : null,\r
62                 _attrText  : '',\r
63                 \r
64                 _css       : null, // X.Dom.Style\r
65                 _cssText   : null,\r
66                 \r
67                 _anime     : null,\r
68                 \r
69                 Constructor : function( v ){\r
70                         var css, xnodes, xnode, parent, uid = Node._chashe.length;\r
71                         \r
72                         if( Node._newByTag ){\r
73                                 Node._newByTag  = false;\r
74                                 this._tag       = v;\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
80                         } else\r
81                         if( Node._newByText ){\r
82                                 Node._newByText = false;\r
83                                 this._text      = v;\r
84                                 this._xnodeType = 3;\r
85                                 this._state     = X.Dom.State.DISPLAY_INLINE;\r
86                         } else {\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
90                 \r
91                                 switch( Node._getType( v ) ){\r
92                                         case Node.IS_XNODE :\r
93                                         case Node.IS_XNODE_LIST :\r
94                                                 return v;\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
100                                                 this._rawNode   = v;\r
101                                                 this._xnodeType = 1;\r
102                                                 this._state     = X.Dom.State.DISPLAY_BLOCK; // todo\r
103                                                 this._tag       = v.tagName;\r
104                                                 this._id        = v.id;\r
105                                                 this._className = v.className;\r
106                                                 this.cssText( v.style.cssText );\r
107                                                 // X.Dom.Dirty.CSS を落とす\r
108                                                 this._dirty = 0;\r
109                                                 // attr の回収は不可能、、、\r
110                                                 if( X.UA.IE && X.UA.IE < 5 ){\r
111                                                         v.setAttribute( 'UID', '' + uid );\r
112                                                 } else {\r
113                                                         v.UID = uid;\r
114                                                 };\r
115                                                 // childNodes...\r
116                                                 break;\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
121                                                 this._rawNode   = v;\r
122                                                 this._xnodeType = 3;\r
123                                                 this._state     = X.Dom.State.DISPLAY_INLINE;\r
124                                                 this._text      = v.data;\r
125                                                 v.UID = uid;\r
126                                                 break;\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
131                                                 return Node.none;\r
132                                         case Node.IS_IMAGE :\r
133                                                 v.UID = uid;\r
134                                         case Node.IS_WINDOW :\r
135                                         case Node.IS_DOCUMENT :\r
136                                                 this._rawNode   = v;\r
137                                                 this._xnodeType = 2;\r
138                                                 this._state     = X.Dom.State.DISPLAY_BLOCK;\r
139                                                 break;\r
140                                         default :\r
141                                                 if( Node.none ) return Node.none;\r
142                                                 return;\r
143                                 };\r
144                         };\r
145                         \r
146                         Node._chashe[ this._uid = uid ] = this;\r
147                 }\r
148         }\r
149 );\r
150 \r
151 var Node = X.Dom.Node;\r
152 \r
153 Node.IS_XNODE       = 1;\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
163 \r
164 Node._useDocumentFragment = document.createDocumentFragment && ( !X.UA.IE || 6 <= X.UA.IE ) && document.createDocumentFragment();\r
165 \r
166 Node._getType = function( v ){\r
167         if( v === '' ) return Node.IS_STRING;\r
168         if( !v ) return 0;\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
178         };\r
179         //if( v.nodeType === 11 ) return Node.IS_DOC_FRAG;\r
180         return 0;\r
181 };\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
187                         return v;\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
194                         };\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
203                         };\r
204         };\r
205 };\r
206 \r
207 \r
208 Node.create = function( tag, opt_attrs, opt_css ){\r
209         var list, i;\r
210         switch( Node._getType( tag ) ){\r
211                 case Node.IS_STRING :\r
212                         Node._newByTag = true;\r
213                         return new Node( tag, opt_attrs, opt_css );\r
214                 case Node.IS_HTML_STRING :\r
215                         list = X.Dom.parse( tag, true );\r
216                         for( i = list.length; 1 < i; ){\r
217                                 list[ --i ].destroy();\r
218                         };\r
219                         return list[ 0 ];\r
220         };\r
221 };\r
222 Node.createText = function( text ){\r
223         Node._newByText = true;\r
224         return new Node( text );\r
225 };\r
226 \r
227 \r
228 Node.getRoot = function( xnode ){\r
229         return Node._document;\r
230         //return xnode.root._rawNode.documentElement ? node : node.ownerDocument || node.document;\r
231 };\r
232         // XMLかどうかを判別する\r
233 Node.isXmlDocument =\r
234         X.UA.IE && X.UA.IE < 5 ?\r
235                 X.emptyFunction :\r
236                 (function( root ){\r
237                         return root._rawNode.createElement( 'p' ).tagName !== root._rawNode.createElement( 'P' ).tagName;\r
238                 });\r
239 \r
240 Node._chashe     = [];\r
241 Node.none        = Node._chashe[ 0 ] = new Node();\r
242 Node._window     = new Node( window ); // Node._chashe[ 1 ]\r
243 Node._document   = new Node( document ); // Node._chashe[ 2 ]\r
244 Node._html       = null; // Node._chashe[ 3 ]\r
245 Node.root        = null;// = Node._chashe[ 4 ] body\r
246 Node._systemNode = null;// = Node._chashe[ ? ]\r
247 \r
248 Node._reserveRemoval = [];\r
249 \r
250 if( !document.getElementById && document.all ){\r
251         Node.prototype._ie4getRawNode = function(){\r
252                 var elm = this._rawNode;\r
253                 return elm ||\r
254                         ( ( elm = document.all[ 'ie4uid' + this._uid ] ) && ( this._rawNode = elm ) ) ||\r
255                         ( this._id && ( elm = document.all[ this._id ] ) ) && ( this._rawNode = elm );\r
256         };\r
257 };\r
258 \r
259 \r
260 /* --------------------------------------\r
261  *  Create\r
262  */\r
263 Node.prototype.create = function( tag, opt_attrs, opt_css ){\r
264         var xnode;\r
265         if( this._xnodeType !== 1 ) return;\r
266         if( !this._xnodes ) this._xnodes = [];\r
267         \r
268         xnode = Node.create( tag, opt_attrs, opt_css );\r
269         \r
270         xnode.parent = this;\r
271         this._xnodes[ this._xnodes.length ] = xnode;\r
272         this._root && this._reserveUpdate();\r
273         return xnode;\r
274 };\r
275 \r
276 /* --------------------------------------\r
277  *  CreateText\r
278  */\r
279 Node.prototype.createText = function( text ){\r
280         var xnode;\r
281         if( this._xnodeType !== 1 ) return;\r
282         if( !this._xnodes ) this._xnodes = [];\r
283         \r
284         Node._newByText = true;\r
285         xnode = new Node( text );\r
286         xnode.parent = this;\r
287         \r
288         this._root && this._reserveUpdate();\r
289         this._xnodes[ this._xnodes.length ] = xnode;\r
290         return xnode;\r
291 };\r
292 \r
293 /* --------------------------------------\r
294  *  Clone\r
295  * http://d.hatena.ne.jp/think49/20110724/1311472811\r
296  * http://d.hatena.ne.jp/uupaa/20100508/1273299874\r
297  */\r
298 Node.prototype.clone = function( opt_clone_children ){\r
299         var xnode, xnodes, i, l;\r
300         switch( this._xnodeType ){\r
301                 case 1 :\r
302                         Node._newByTag = true;\r
303                         xnode = new Node( this._tag, X.cloneObject( this._attrs ), X.cloneObject( this._css ) )\r
304                                 .attr( { 'id' : this._id } )\r
305                                 .className( this._className );\r
306                         if( opt_clone_children && ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
307                                 for( i = 0; i < l; ++i ){\r
308                                         xnode.append( xnodes[ i ].clone( true ) );\r
309                                 };\r
310                         };\r
311                         return xnode;\r
312                 case 3 :\r
313                         Node._newByText = true;\r
314                         xnode = new Node( this._text );\r
315                         return xnode;\r
316                 \r
317                 //case 0 :\r
318                 //case 2 :\r
319         };\r
320         return this;\r
321 };\r
322 \r
323 /* --------------------------------------\r
324  *  Add\r
325  * Node\r
326  * HtmlElement の場合は内部使用専用 そのため event の破棄等しない\r
327  */\r
328 Node.prototype.append = function( v ){\r
329         var i, l, xnodes, frg;\r
330         if( this._xnodeType !== 1 ) return;\r
331         \r
332         if( 1 < ( l = arguments.length ) ){\r
333                 for( i = 0; i < l; ++i ){\r
334                         this.append( arguments[ i ] );\r
335                 };\r
336                 return this;\r
337         };\r
338         \r
339         if( !( xnodes = this._xnodes ) ) this._xnodes = xnodes = [];\r
340         \r
341         switch( Node._getType( v ) ){\r
342                 case Node.IS_RAW_HTML :\r
343                 case Node.IS_RAW_TEXT :\r
344                         v = new Node( v );\r
345                         break;\r
346                 case Node.IS_HTML_STRING :\r
347                 case Node.IS_STRING :\r
348                         return this.append.apply( this, X.Dom.parse( v, true ) );\r
349                 case Node.IS_XNODE :\r
350                         if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
351                         // 親の xnodes から v を消す\r
352                         if( v.parent ){\r
353                                 //if( document.getElementById ){\r
354                                 //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
355                                 //} else\r
356                                 //if( document.all ){\r
357                                         v.remove();\r
358                                 //} else {\r
359                                         \r
360                                 //};\r
361                         } else\r
362                         if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
363                                 if( !this._state ) alert( 'xnode already destroyed!' );\r
364                                 Node._reserveRemoval.splice( i, 1 );\r
365                         };\r
366                         break;\r
367                 default :\r
368                         return this;\r
369         };\r
370 \r
371         v.parent = this;\r
372         xnodes[ xnodes.length ] = v;\r
373         this._root && this._reserveUpdate();\r
374         return this;\r
375 };\r
376 \r
377 \r
378 Node.prototype.appendAt = function( start, v ){\r
379         var xnodes, l, i;\r
380         \r
381         if( this._xnodeType !== 1 ) return this;\r
382         \r
383         l = arguments.length;\r
384         if( !( xnodes = this._xnodes ) ) xnodes = this._xnodes = [];\r
385         \r
386         if( xnodes.length <= start ){\r
387                 if( l === 2 ) return this.append( v );\r
388                 for( i = 1; i < l; ++i ){\r
389                         this.append( arguments[ i ] );\r
390                 };\r
391                 return this;\r
392         };\r
393         if( start < 0 ) start = 0;\r
394         if( 2 < l ){\r
395                 for( ; l; ){\r
396                         this.appendAt( start, arguments[ --l ] );\r
397                 };\r
398                 return this;\r
399         };\r
400 \r
401         switch( Node._getType( v ) ){\r
402                 case Node.IS_RAW_HTML :\r
403                 case Node.IS_RAW_TEXT :\r
404                         v = new Node( v );\r
405                         break;\r
406                 case Node.IS_HTML_STRING :\r
407                 case Node.IS_STRING :\r
408                         v = X.Dom.parse( v, true );\r
409                         for( i = v.length; i; ){\r
410                                 this.appendAt( start, v[ --i ] );\r
411                         };\r
412                         return this;\r
413                 case Node.IS_XNODE :\r
414                         if( v._xnodeType !== 1 && v._xnodeType !== 3 ) return this;\r
415                         // 親の xnodes から v を消す\r
416                         if( v.parent ){\r
417                                 //if( document.getElementById ){\r
418                                 //      v.parent._xnodes.splice( v.parent._xnodes.indexOf( v ), 1 );\r
419                                 //} else\r
420                                 //if( document.all ){\r
421                                         v.remove();\r
422                                 //} else {\r
423                                         \r
424                                 //};\r
425                         } else\r
426                         if( ( i = Node._reserveRemoval.indexOf( v ) ) !== -1 ){\r
427                                 if( !this._state ) alert( 'xnode already destroyed!' );\r
428                                 Node._reserveRemoval.splice( i, 1 );\r
429                         };\r
430                         break;\r
431                 default :\r
432                         return this;\r
433         };\r
434 \r
435         v.parent = this;\r
436         this._xnodes.splice( start, 0, v );\r
437         this._root && this._reserveUpdate();\r
438         return this;\r
439 };\r
440 \r
441 Node.prototype.appendTo = function( parent, opt_index ){\r
442         switch( Node._getType( parent ) ){\r
443                 case Node.IS_RAW_HTML :\r
444                         parent = new Node( parent );\r
445                         break;\r
446                 case Node.IS_HTML_STRING :\r
447                         parent = X.Dom.parse( parent, true );\r
448                         parent = parent[ 0 ] || parent;\r
449                 case Node.IS_XNODE :\r
450                         break;\r
451                 default :\r
452                         return this;\r
453         };\r
454         opt_index === undefined ? parent.append( this ) : parent.appendAt( opt_index, this );\r
455         return this;\r
456 };\r
457 \r
458 Node.prototype.appendToRoot = function( opt_index ){\r
459         opt_index === undefined ? Node.root.append( this ) : Node.root.appendAt( opt_index, this );\r
460         return this;\r
461 };\r
462 \r
463 /* --------------------------------------\r
464  *  Before , After, Replace\r
465  */\r
466 Node.prototype.before = function( v ){\r
467         var parent, l, start;\r
468         if( !( parent = this.parent ) ) return this;\r
469         \r
470         l = arguments.length;\r
471         start = this.getOrder();\r
472         if( 1 < l ){\r
473                 for( ; l; ){\r
474                         parent.appendAt( start, arguments[ --l ] );\r
475                 };\r
476                 return this;\r
477         };\r
478         parent.appendAt( start, v );\r
479         return this;\r
480 };\r
481 \r
482 Node.prototype.after = function( v ){\r
483         var parent, l, i, start;\r
484         if( !( parent = this.parent ) ) return this;\r
485         \r
486         l = arguments.length;\r
487         start = this.getOrder() + 1;\r
488         if( parent._xnodes.length <= start ){\r
489                 if( 1 < l ){\r
490                         for( i = 0; i < l; ++i ){\r
491                                 parent.append( arguments[ i ] );\r
492                         };\r
493                         return this;\r
494                 };\r
495                 parent.append( v );\r
496                 return this;\r
497         };\r
498         if( 1 < l ){\r
499                 for( ; l; ){\r
500                         parent.appendAt( start, arguments[ --l ] );\r
501                 };\r
502                 return this;\r
503         };\r
504         parent.appendAt( start, v );\r
505         return this;\r
506 };\r
507 \r
508 Node.prototype.replace = function( v ){\r
509         if( !this.parent ) return this;\r
510         return arguments.length === 1 ? this.before( v ).remove() : this.before.apply( this, arguments ).remove();\r
511 };\r
512 \r
513 /* --------------------------------------\r
514  *  Remove\r
515  */\r
516 Node.prototype.remove = function(){\r
517         var parent = this.parent;\r
518         \r
519         if( !parent ) return this;\r
520 \r
521         parent._xnodes.splice( parent._xnodes.indexOf( this ), 1 );\r
522         if( this._root ){\r
523                 Node._reserveRemoval[ Node._reserveRemoval.length ] = this;\r
524                 this._reserveUpdate();\r
525         };\r
526         delete this.parent;\r
527         delete this._root;\r
528         return this;\r
529 };\r
530 \r
531 Node.prototype.empty = function(){\r
532         var xnodes = this._xnodes, i;\r
533         if( xnodes && ( i = xnodes.length ) ){\r
534                 for( ; i; ){\r
535                         xnodes[ --i ].destroy();\r
536                 };\r
537                 xnodes.length = 0;\r
538         };\r
539         return this;\r
540 };\r
541 \r
542 /* --------------------------------------\r
543  *  destory\r
544  */\r
545 Node.prototype.destroy = function( isChild ){\r
546         var xnodes = this._xnodes, i, elm;\r
547         \r
548         if( !this._state ) return;\r
549         \r
550         elm = this._rawNode || this._ie4getRawNode && this._ie4getRawNode();\r
551         \r
552         if( xnodes && ( i = xnodes.length ) ){\r
553                 //for( ; i; ){\r
554                 //      xnodes[ --i ].destroy( true );\r
555                 //};\r
556         };\r
557         elm && this._listeners && this.unlisten(); // イベントの退避\r
558 \r
559         delete Node._chashe[ this._uid ];\r
560         delete this._state;\r
561         \r
562         if( this._root ){\r
563                 !isChild && this.remove();\r
564         } else {\r
565                 this.parent && this.parent._xnodes.splice( this.parent._xnodes.indexOf( this ), 1 );\r
566                 elm && !isChild && this._actualRemove();\r
567                 this.kill();\r
568         };\r
569 };\r
570 \r
571 \r
572 \r
573 /* --------------------------------------\r
574  *  contains\r
575  */\r
576 Node.prototype.contains = function( v ){\r
577         var elm, type, xnodes, i;\r
578         if( !v || this._xnodeType !== 1 ) return false;\r
579         // contains ie4+\r
580         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
581                 return elm.contains( v );       \r
582         };\r
583         //if( document.compareDocumentPosition ){\r
584         //      \r
585         //};\r
586         xnodes = this._xnodes;\r
587         if( xnodes.indexOf( v ) !== -1 ) return true;\r
588         if( elm === v.parentNode ) return false;\r
589         for( i = xnodes.length; i; ){\r
590                 if( xnodes[ --i ].contains( v ) ) return true;\r
591         };\r
592         return false;\r
593 };\r
594 \r
595 /* --------------------------------------\r
596  *  getChild\r
597  */\r
598 Node.prototype.getChildAt = function( i ){\r
599         var xnodes = this._xnodeType === 1 && this._xnodes;\r
600         return xnodes && 0 <= i && i < xnodes.length && xnodes[ i ];\r
601 };\r
602 \r
603 \r
604 /* --------------------------------------\r
605  *  prevNode, nextNode, firstChild, lastChild\r
606  */\r
607 \r
608 Node.prototype.prevNode = function(){\r
609         var parent = this.parent, xnodes, index;\r
610         if( !parent ) return;\r
611         xnodes = parent._xnodes;\r
612         index = xnodes.indexOf( this );\r
613         if( 0 < index ) return xnodes[ index - 1 ];\r
614 };\r
615 Node.prototype.nextNode = function(){\r
616         var parent = this.parent, xnodes, index;\r
617         if( !parent ) return;\r
618         xnodes = parent._xnodes;\r
619         index  = xnodes.indexOf( this );\r
620         if( index + 1 < xnodes.length ) return xnodes[ index + 1 ];\r
621 };\r
622 Node.prototype.firstChild = function(){\r
623         return this.getChildAt( 0 );\r
624 };\r
625 Node.prototype.lastChild = function(){\r
626         return this.getChildAt( this._xnodes.length - 1 );\r
627 };\r
628 \r
629 /* --------------------------------------\r
630  *  getOrder\r
631  */\r
632 Node.prototype.getOrder = function(){\r
633         var parent = this.parent;\r
634         if( !parent ) return -1;\r
635         return parent._xnodes.indexOf( this );\r
636 };\r
637 \r
638 /* --------------------------------------\r
639  *  className, addClass, removeClass, hasClass\r
640  */\r
641 Node.prototype.className = function( v ){\r
642         var node, _, __;\r
643         // getter\r
644         if( v === undefined ) return this._className;\r
645         \r
646         // setter\r
647         if( this._className === v ) return this;\r
648         if( !v || typeof v !== 'string' ){\r
649                 delete this._className;\r
650         } else {\r
651                 // cleanup\r
652                 _  = ' ';\r
653                 __ = '  ';\r
654                 while( v.indexOf( __ ) !== -1 ){ v = v.split( __ ).join( _ ); };\r
655                 v.charAt( 0 ) === _ && ( v = v.substr( 1 ) );\r
656                 v.lastIndexOf( _ ) === 0 && ( v = v.substr( 0, v.length - 1 ) );\r
657                 \r
658                 if( this._className === v ) return this;\r
659                 v ? ( this._className = v ) : delete this._className;\r
660         };\r
661         this._dirty |= X.Dom.Dirty.CLASSNAME;\r
662         this._root && this._reserveUpdate();\r
663         return this;\r
664 };\r
665 Node.prototype.addClass = function( v ){\r
666         var names = v.split( ' ' ),\r
667                 i     = names.length,\r
668                 name;\r
669         v = '';\r
670         for( ; i; ){\r
671                 name = names[ --i ];\r
672                 if( !name ) continue;\r
673                 !this.hasClass( name ) && ( v += ( v ? ' ' : '' ) + name );\r
674         };\r
675         return v ? his.className( this._className + ( this._className ? ' ' : '' ) + v ) : this;\r
676 };\r
677 Node.prototype.removeClass = function( v ){\r
678         var _          = ' ',\r
679                 className  = this._className,\r
680                 names      = v.split( ' ' ),\r
681                 classNames, i, f, j;\r
682         if( !className ) return this;\r
683         for( classNames = className.split( _ ), i = classNames.length; i; ){\r
684                 className = classNames[ --i ];\r
685                 for( j = names.length; j; ){\r
686                         if( className === names[ --j ] ){\r
687                                 classNames.splice( i, 1 );\r
688                                 names.splice( j, 1 );\r
689                                 f = true;\r
690                                 break;\r
691                         };\r
692                 };\r
693         };\r
694         return f ? this.className( classNames.join( ' ' ) ) : this;\r
695 };\r
696 Node.prototype.toggleClass = function( v ){\r
697 \r
698 };\r
699 Node.prototype.hasClass = function( v ){\r
700         var _ = ' ',\r
701                 className = this._className,\r
702                 i, name;\r
703         if( className === v ) return true;\r
704         if( !className ) return false;\r
705         \r
706         className = _ + className + _;\r
707         if( className.indexOf( _ + v + _ ) !== -1 ) return true; // lucky hit\r
708         \r
709         for( v = v.split( _ ), i = v.length; i; ){\r
710                 name = v[ --i ];\r
711                 if( name === '' ) continue;\r
712                 if( className.indexOf( _ + name + _ ) === -1 ) return false;\r
713         };\r
714         return true;\r
715 };\r
716 \r
717 /* --------------------------------------\r
718  *  html, text\r
719  */\r
720 Node.prototype.html = function( html ){\r
721         var _ = '', xnodes, n, i, l;\r
722         // setter\r
723         if( html || html === '' ){\r
724                 if( this._xnodeType === 3 ){\r
725                         if( this._text !== html ){\r
726                                 this._text = html;\r
727                                 this._root && this._reserveUpdate();\r
728                                 this._dirty |= X.Dom.Dirty.CONTENT;\r
729                         };\r
730                         return this;\r
731                 };\r
732                 return this.empty().append.apply( this, X.Dom.parse( html, true ) );\r
733         };\r
734         // getter\r
735         if( this._xnodeType === 3 ){\r
736                 return this._text;\r
737         };\r
738         \r
739         if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
740                 delete this._cssText;\r
741         };\r
742         html = !Node._needOuter ? [] : [\r
743                 '<', this._tag,\r
744                 this._id ? ' id=' + this._id : _,\r
745                 this._className ? ' class="' + this._className + '"' : _,\r
746                 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
747                 this._cssText ? ' style="' + this._cssText + '"' : _,\r
748         '>' ];\r
749         \r
750         n = html.length;\r
751         if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
752                 Node._needOuter = true;\r
753                 for( i = 0; i < l; ++i ){\r
754                         html[ n ] = xnodes[ i ].html( undefined );\r
755                         ++n;\r
756                 };\r
757                 Node._needOuter = false;\r
758         };\r
759         !Node._needOuter || X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
760 \r
761         return html.join( _ );\r
762 };\r
763 \r
764 Node.prototype.text = function( text ){\r
765         var xnodes, texts, i, l;\r
766         // setter\r
767         if( text || text === '' ){\r
768                 if( this._xnodeType === 3 ){\r
769                         if( this._text !== text ){\r
770                                 this._text = text;\r
771                                 this._root && this._reserveUpdate();\r
772                                 this._dirty |= X.Dom.Dirty.CONTENT;\r
773                         };\r
774                         return this;\r
775                 };\r
776                 this.empty().createText( text );\r
777                 return this;    \r
778         };\r
779         // getter\r
780         if( this._xnodeType === 1 ){\r
781                 if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
782                         for( texts = [], i = 0; i < l; ++i ){\r
783                                 texts[ i ] = xnodes[ i ].text();\r
784                         };\r
785                         return texts.join( '' );\r
786                 };\r
787                 return '';\r
788         };\r
789         return this._text;\r
790 };\r
791 \r
792 Node.prototype.each = function( func ){\r
793         func.call( this, 0 );\r
794         return this;\r
795 };\r
796 \r
797 \r
798 /* --------------------------------------\r
799  *  Async commit update\r
800  * \r
801  * state:\r
802  *  0 : no_rawnode\r
803  *  1 : not_added\r
804  *  3 : dirty\r
805  *  4 : clean\r
806  * \r
807  * remove :\r
808  * root._reserveRemoval = [] に追加。commitUpdate で remove して state は not_added\r
809  * add :\r
810  * root._reserveRemoval にいたら消す, new_parent._xnodes に挿入 steta は not_added にして commitUpdate を待つ\r
811  */\r
812         \r
813 Node.prototype._reserveUpdate = function(){\r
814         var root = Node.root;\r
815         if( root && !root._updateTimerID ) root._updateTimerID = X.Timer.requestFrame( root, root._startUpdate );\r
816 };\r
817 \r
818 Node.prototype._startUpdate = function(){\r
819         var removal, i, xnode, tmp;\r
820         \r
821         if( this._updateTimerID ){\r
822                 //X.Timer.cancelFrame( this._updateTimerID ); // fire 中の cancel が動かない、、、\r
823                 this._updateTimerID = 0;\r
824         } else {\r
825                 return;\r
826         };\r
827 \r
828 \r
829         X.Dom._listeners && X.Dom._listeners[ X.Dom.Event.BEFORE_UPDATE ] && X.Dom.dispatch( { type : X.Dom.Event.BEFORE_UPDATE } );\r
830 \r
831         removal = Node._reserveRemoval;\r
832         \r
833         tmp = this._rawNode.style.visibility;\r
834         //this._rawNode.style.visibility = 'hidden';\r
835         \r
836         if( i = removal.length ){\r
837                 for( ; i; ){\r
838                         xnode = removal[ --i ];\r
839                         xnode._actualRemove();\r
840                         !this._state && xnode.kill();\r
841                 };\r
842                 removal.length = 0;             \r
843         };\r
844         \r
845         this._commitUpdate();\r
846         \r
847         X.Dom._listeners && X.Dom._listeners[ X.Dom.Event.AFTER_UPDATE ] && X.Dom.dispatch( { type : X.Dom.Event.AFTER_UPDATE } );\r
848         //this._rawNode.style.visibility = tmp;\r
849 };\r
850 \r
851 Node.prototype._commitUpdate =\r
852         document.getElementById ?\r
853                 ( function( parentElement, nextElement ){\r
854                         var elm = this._rawNode,\r
855                                 xnodes, l, i, frg, next, k, v;\r
856 \r
857                         if( !elm || ( parentElement && elm.parentNode !== parentElement ) || ( nextElement && elm.nextSibling !== nextElement ) ){\r
858                                 nextElement ?\r
859                                         parentElement.insertBefore( this._actualCreate(), nextElement ) :\r
860                                         parentElement.appendChild( this._actualCreate() );\r
861                                 this._afterActualCreate();\r
862                                 \r
863                                 \r
864                                 return elm || this._rawNode;\r
865                         } else\r
866                         if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ) {\r
867                                 \r
868                                 /*if( elm.childNodes.length !== l && ( frg = Node._useDocumentFragment ) ){\r
869                                         for( i = 0; i < l; ++i ){\r
870                                                 frg.appendChild( xnodes[ i ]._actualCreate( true ) );\r
871                                         };\r
872                                         elm.appendChild( frg );\r
873                                         for( i = 0; i < l; ++i ){\r
874                                                 xnodes[ i ]._afterActualCreate( true );\r
875                                         };\r
876                                 } else {*/\r
877                                         for( ; l; ){\r
878                                                 next = xnodes[ --l ]._commitUpdate( elm, next );\r
879                                         };\r
880                                 //};\r
881                         };\r
882 \r
883                         this._dirty && this._updateRawNode( elm );\r
884                         return elm;\r
885                 }) :\r
886         document.all ? \r
887                 ( function( parentElement, prevElement ){\r
888                         var elm    = this._rawNode || this._ie4getRawNode(),\r
889                                 xnodes, l, i, html, text, prev;\r
890 \r
891                         if( !elm ){\r
892                                 prevElement ?\r
893                                         prevElement.insertAdjacentHTML( 'AfterEnd', this._actualCreate() ) :\r
894                                         parentElement.insertAdjacentHTML( 'AfterBegin', this._actualCreate() );\r
895                                 this._afterActualCreate();\r
896                                 return this._rawNode || this._ie4getRawNode();\r
897                         };\r
898                         \r
899                         xnodes = this._xnodes;\r
900                         l      = xnodes ? xnodes.length : 0;\r
901                         \r
902                         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
903                                 html = [];\r
904                                 for( i = 0; i < l; ++i ){\r
905                                         html[ i ] = xnodes[ i ]._actualCreate();\r
906                                 };\r
907                                 elm.innerHTML = html.join( '' );\r
908                                 for( i = 0; i < l; ++i ){\r
909                                         xnodes[ i ]._afterActualCreate();\r
910                                 };\r
911                                 this._state &= ~X.Dom.State.IE4_ONLY_TEXT;\r
912                         } else\r
913                         if( this._state & X.Dom.State.IE4_ONLY_TEXT ){ // textNode が swap した場合の検出は、_root で行う\r
914                                 text = xnodes[ 0 ];\r
915                                 if( text._dirty || !text._root ){\r
916                                         elm.innerHTML = text._text;\r
917                                         delete text._dirty;\r
918                                         text._root = this._root;                                        \r
919                                 };\r
920                         } else\r
921                         if( l ){\r
922                                 for( i = 0; i < l; ++i ){\r
923                                         prev = xnodes[ i ]._commitUpdate( elm, prev );\r
924                                 };\r
925                         };\r
926                         this._dirty && this._updateRawNode( elm );\r
927                         return elm;\r
928                 }) :\r
929                 (function(){});\r
930 \r
931 Node.prototype._updateRawNode =\r
932         document.getElementById ?\r
933                 ( function( elm ){\r
934                         var attrs, rename, k, v;\r
935 \r
936                         // textNode\r
937                         if( this._dirty & X.Dom.Dirty.CONTENT ){\r
938                                 elm.data = X.Dom.chrReferanceTo( this._text );\r
939                                 delete this._dirty;\r
940                                 return;\r
941                         };\r
942                         // id\r
943                         if( this._dirty & X.Dom.Dirty.ID ){\r
944                                 if( X.UA.IE && X.UA.IE < 7 ){\r
945                                         elm.id = this._id;\r
946                                 } else {\r
947                                         this._id ? ( elm.id = this._id ) : elm.removeAttribute( 'id' );                                 \r
948                                 };\r
949                         };\r
950                         // className\r
951                         if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
952                                 if( X.UA.IE && X.UA.IE < 7 ){\r
953                                         elm.className = this._className;\r
954                                 } else {\r
955                                         this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );                                 \r
956                                 };\r
957                         };\r
958                         // style\r
959                         if( this._dirty & X.Dom.Dirty.CSS ){\r
960                                 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
961                                         elm.style.cssText = this._cssText;\r
962                                 } else {\r
963                                         elm.style.cssText = ''; // IE5.5以下 Safari3.2 で必要\r
964                                         elm.removeAttribute( 'style' );\r
965                                         delete this._cssText;\r
966                                 };\r
967                         };\r
968                         \r
969                         if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
970                                 this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
971                         };\r
972                         \r
973                         // attr\r
974                         if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
975                                 rename = X.Dom.Attr.renameForDOM;\r
976                                 for( k in attrs ){\r
977                                         if( 5 <= X.UA.IE && X.UA.IE < 5.5 ){\r
978                                                 if( this._tag === 'TEXTAREA' && k === 'value' ){\r
979                                                         elm.firstChild ?\r
980                                                                 ( elm.firstChild.data = attrs[ k ] ) :\r
981                                                                 elm.appendChild( document.createTextNode( attrs[ k ] ) );\r
982                                                         continue;\r
983                                                 };\r
984                                         };\r
985                                         ( v = attrs[ k ] ) === undefined ?\r
986                                                 elm.removeAttribute( rename[ k ] || k ) :\r
987                                                 ( elm[ rename[ k ] || k ] = v );\r
988                                 };\r
989                                 delete this._newAttrs;\r
990                         };\r
991                         \r
992                         delete this._dirty;\r
993                 }) :\r
994         document.all ? \r
995                 ( function( elm ){\r
996                         var attrs, rename, k, v;\r
997 \r
998                         // fake textNode\r
999                         if( this._dirty & X.Dom.Dirty.CONTENT ){\r
1000                                 elm.innerText = this._text;\r
1001                                 delete this._dirty;\r
1002                                 return;\r
1003                         };\r
1004                         \r
1005                 /*\r
1006                  * http://www.tohoho-web.com/js/element.htm\r
1007                  * title、className、id、lang、language には setAttribute でなく、element.id で直接読み書きできる\r
1008                  */     \r
1009                         // id\r
1010                         if( this._dirty & X.Dom.Dirty.CONTENT ) elm.setAttribute( 'id', this._id || ( 'ie4uid' + xnode._uid ) );\r
1011 \r
1012                         // className\r
1013                         if( this._dirty & X.Dom.Dirty.CLASSNAME ){\r
1014                                 this._className ? ( elm.className = this._className ) : elm.removeAttribute( 'class' );\r
1015                         };\r
1016                         // style\r
1017                         if( this._dirty & X.Dom.Dirty.CSS ){\r
1018                                 if( this._cssText || ( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
1019                                         elm.style.cssText = this._cssText;\r
1020                                 } else {\r
1021                                         elm.style.cssText = '';\r
1022                                         elm.removeAttribute( 'style' );\r
1023                                         delete this._cssText;\r
1024                                 };\r
1025                         };\r
1026                         \r
1027                         if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
1028                                 this._rawNode.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
1029                         };\r
1030                         \r
1031                         // attr\r
1032                         if( this._dirty & X.Dom.Dirty.ATTR && ( attrs = this._newAttrs || this._attrs ) ){\r
1033                                 rename = X.Dom.Attr.renameForDOM;\r
1034                                 for( k in attrs ){\r
1035                                         ( v = attrs[ k ] ) === undefined ?\r
1036                                                 elm.removeAttribute( rename[ k ] || k ) :\r
1037                                                 elm.setAttribute( rename[ k ] || k, v );\r
1038                                 };\r
1039                                 delete this._newAttrs;\r
1040                         };\r
1041                         \r
1042                         delete this._dirty;\r
1043                 }) :\r
1044                 (function(){});\r
1045 \r
1046 /* --------------------------------------\r
1047  *  Create\r
1048  * \r
1049  * http://d.hatena.ne.jp/uupaa/20080718/1216362040\r
1050  * DOM Rangeが使える環境(Firefox2+,Opera9+,Safari3+)なら、innerHTMLいらずで、ガーって書けます。\r
1051  * return document.createRange().createContextualFragment("<div><select><option></option></select></div>");\r
1052  * insertAdjacentHTML\r
1053  * \r
1054  * ie7 以下では iframe の frameborder や、input name は、createElement 後に setAttribute しても無視される\r
1055  * \r
1056  * fragument がある場合 children も足して\r
1057  * Mozilla: 1.0+, IE: 6.0+, Netscape: 2.0+, Safari: 1.0+, Opera: 7.0+\r
1058  * ie6 大丈夫?fragment の場合リークしないか?チェックが必要\r
1059  * http://msdn.microsoft.com/ja-jp/library/bb250448%28v=vs.85%29.aspx\r
1060  * \r
1061  * document.createElement of ie4 is only for OPTION & IMAGE.\r
1062  */\r
1063 Node.prototype._actualCreate =\r
1064         document.getElementById ? (function( isChild ){\r
1065                 var elm = this._rawNode,\r
1066                         xnodes, frg, i, l;\r
1067                 \r
1068                 if( this._xnodeType === 3 ){\r
1069                         if( elm ) return elm;\r
1070                         delete this._dirty;\r
1071                         return this._rawNode = document.createTextNode( X.Dom.chrReferanceTo( this._text ) );\r
1072                 };\r
1073                 \r
1074                 if( !elm ){\r
1075                         if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
1076                                 delete this._cssText;\r
1077                         };\r
1078                         this._isNew = true;\r
1079                         this._rawNode = elm =\r
1080                                 X.UA.IE && X.UA.IE < 9 ?\r
1081                                         document.createElement( [\r
1082                                                 '<', this._tag,\r
1083                                                         ' UID="', this._uid, '"',\r
1084                                                         this._id ? ' id="' + this._id + '"' : '',\r
1085                                                         this._className ? ' class="' + this._className + '"' : '',\r
1086                                                         this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
1087                                                         this._cssText ? ' style="' + this._cssText + '"' : '',\r
1088                                                 '>' ].join( '' ) ):\r
1089                                         document.createElement( this._tag );\r
1090                 };\r
1091                 if( Node._useDocumentFragment ){\r
1092                         if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
1093                                 !isChild && ( frg = Node._useDocumentFragment ).appendChild( elm );\r
1094                                 for( i = 0; i < l; ++i ){\r
1095                                         elm.appendChild( xnodes[ i ]._actualCreate( true ) );\r
1096                                 };\r
1097                                 return frg || elm;\r
1098                         };\r
1099                 };\r
1100                 \r
1101                 return elm;\r
1102         }) :\r
1103         document.all ? (function( isChild ){\r
1104                 var uid = this._uid,\r
1105                         html, xnodes, n, i, l;\r
1106                 \r
1107                 if( this._xnodeType === 3 ){\r
1108                         html = [ '<FONT id=ie4uid', uid, ' UID="', uid, '">', this._text, '</FONT>' ];// fake textNode\r
1109                         delete this._rawNode;\r
1110                 } else {\r
1111                         if( this._rawNode && !isChild ) this._actualRemove( true );\r
1112                         \r
1113                         if( this._dirty & X.Dom.Dirty.CSS && !( this._cssText = X.Dom.Style.objToCssText( this._css ) ) ){\r
1114                                 delete this._cssText;\r
1115                         };\r
1116                         \r
1117                         html = [\r
1118                                 '<', this._tag, ' id=', ( this._id || ( 'ie4uid' + uid ) ), ' UID="', uid, '"',\r
1119                                 this._className ? ' class="' + this._className + '"' : '',\r
1120                                 this._attrText || ( this._attrText = X.Dom.Attr.objToAttrText( this._attrs ) ),\r
1121                                 this._cssText ? ' style="' + this._cssText + '"' : '',\r
1122                         '>' ];\r
1123                         \r
1124                         n = html.length;\r
1125                         if( ( xnodes = this._xnodes ) && ( l = xnodes.length ) ){\r
1126                                 if( l === 1 && xnodes[ 0 ]._xnodeType === 3 ){\r
1127                                         // only textnode\r
1128                                         html[ n ] = xnodes[ 0 ]._text;\r
1129                                         ++n;\r
1130                                         this._state |= X.Dom.State.IE4_ONLY_TEXT;\r
1131                                 } else {\r
1132                                         for( i = 0; i < l; ++i ){\r
1133                                                 html[ n ] = xnodes[ i ]._actualCreate( true );\r
1134                                                 ++n;\r
1135                                         };                                      \r
1136                                 };\r
1137                         };\r
1138                         X.Dom.DTD.EMPTY[ this._tag.toLowerCase() ] || ( html[ n ] = '<\/' + this._tag + '>' );\r
1139                         \r
1140                         delete this._newAttrs;\r
1141                 };\r
1142                 \r
1143                 return html.join( '' );\r
1144         }) :\r
1145         (function(){});\r
1146 \r
1147 Node.prototype._afterActualCreate =\r
1148         document.getElementById ? (function(){\r
1149                 var elm = this._rawNode, xnodes, l, attrs, k, i;\r
1150                 \r
1151                 this._root  = this.parent._root;\r
1152                 \r
1153                 if( this._xnodeType === 3 ){\r
1154                         this._dirty && this._updateRawNode( elm );\r
1155                         return this;\r
1156                 };\r
1157                         \r
1158                 xnodes = this._xnodes;\r
1159                 l      = xnodes && xnodes.length;\r
1160                 \r
1161                 if( this._isNew ){\r
1162                         if( !Node._useDocumentFragment && l ){// docFrg が使えない場合、doc 追加後に子を追加\r
1163                                 for( i = 0; i < l; ++i ){\r
1164                                         elm.appendChild( xnodes[ i ]._actualCreate( true ) );\r
1165                                 };\r
1166                         };\r
1167                         if( !X.UA.IE || 8 < X.UA.IE ){\r
1168                                 elm.UID = this._uid;\r
1169                                 this._newAttrs = this._attrs;\r
1170                                 this._dirty = X.Dom.Dirty.ID | X.Dom.Dirty.CLASSNAME | X.Dom.Dirty.CSS | X.Dom.Dirty.ATTR | X.Dom.Dirty.IE_FILTER;\r
1171                                 this._updateRawNode( elm );\r
1172                         } else\r
1173                         if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
1174                                 elm.style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
1175                                 delete this._dirty;\r
1176                         };\r
1177                         this._restoreEvent();// イベントの復帰\r
1178                         delete this._isNew;\r
1179                 } else {\r
1180                         this._dirty && this._updateRawNode( elm );\r
1181                 };\r
1182                 \r
1183                 if( l ){\r
1184                         for( i = 0; i < l; ++i ){\r
1185                                 xnodes[ i ]._afterActualCreate();\r
1186                         };\r
1187                 };\r
1188                 \r
1189                 return this;\r
1190         }) :\r
1191         document.all ? (function(){\r
1192                 var xnodes, i;\r
1193                 this._root = this.parent._root;\r
1194                 \r
1195                 if( this._xnodeType !== 1 ) return this;\r
1196                 \r
1197                 if( ( xnodes = this._xnodes ) && ( i = xnodes.length ) ){\r
1198                         for( ; i; ){\r
1199                                 xnodes[ --i ]._afterActualCreate();\r
1200                         };\r
1201                 };\r
1202                 if( this._dirty & X.Dom.Dirty.IE_FILTER ){\r
1203                         this._ie4getRawNode().style.filter = X.Dom.Style.SPECIAL_FIX( this._css );\r
1204                 };\r
1205                 delete this._dirty;\r
1206                 return this._restoreEvent();// イベントの復帰\r
1207         }) :\r
1208         (function(){});\r
1209 \r
1210 Node.prototype._actualRemove =\r
1211         document.getElementById ?\r
1212                 ( function( isChild ){\r
1213                         var xnodes = this._xnodes,\r
1214                                 elm    = this._rawNode,\r
1215                                 child, i, l;\r
1216                         if( xnodes && ( l = xnodes.length ) ){\r
1217                                 for( i = 0; i < l; ++i ){\r
1218                                         child = xnodes[ i ];\r
1219                                         child._xnodeType === 1 && child._actualRemove( true );\r
1220                                 };\r
1221                         };\r
1222 \r
1223                         if( !elm ) return;\r
1224                         this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
1225                         // elm.parentNode.tagName for ie7\r
1226                         !isChild && elm.parentNode && elm.parentNode.tagName && elm.parentNode.removeChild( elm );\r
1227                 }) :\r
1228         document.all ?\r
1229                 ( function( isChild ){\r
1230                         var xnodes = this._xnodes,\r
1231                                 elm    = this._rawNode || this._ie4getRawNode(),\r
1232                                 i, l, xnode;\r
1233                         if( xnodes && ( l = xnodes.length ) ){\r
1234                                 for( i = 0; i < l; ++i ){\r
1235                                         xnodes[ i ]._actualRemove( true );\r
1236                                 };\r
1237                         };\r
1238 \r
1239                         if( !elm ) return;\r
1240                         this._xnodeType === 1 && this._migrateEvent();// イベントの退避\r
1241                         \r
1242                         elm.removeAttribute( 'id' ); // ?\r
1243                         document.all[ this._id || ( 'ie4uid' + this._uid ) ] = null; // ?\r
1244                         if( !isChild ) elm.outerHTML = '';\r
1245                         delete this._rawNode;\r
1246                 }) :\r
1247                 (function(){});\r
1248         \r
1249         \r
1250 //})( window, document );\r
1251 \r
1252 \r
1253 \r
1254 \r