@@ -432,6 +432,60 @@ <h1>Test for diffDOM</h1>
432432
433433
434434 < script >
435+ function nodeToObj ( node ) {
436+ var objNode = { } , i ;
437+
438+ if ( node . nodeType === 3 ) {
439+ objNode . t = node . data ;
440+ } else if ( node . nodeType === 8 ) {
441+ objNode . co = node . data ;
442+ } else {
443+ objNode . nn = node . nodeName ;
444+ if ( node . attributes && node . attributes . length > 0 ) {
445+ objNode . a = [ ] ;
446+ for ( i = 0 ; i < node . attributes . length ; i ++ ) {
447+ objNode . a . push ( [ node . attributes [ i ] . name , node . attributes [ i ] . value ] ) ;
448+ }
449+ }
450+ if ( node . childNodes && node . childNodes . length > 0 ) {
451+ objNode . c = [ ] ;
452+ for ( i = 0 ; i < node . childNodes . length ; i ++ ) {
453+ objNode . c . push ( nodeToObj ( node . childNodes [ i ] ) ) ;
454+ }
455+ }
456+ }
457+ return objNode ;
458+ }
459+
460+ function objToNode ( objNode , insideSvg ) {
461+ var node , i ;
462+ if ( objNode . hasOwnProperty ( 't' ) ) {
463+ node = document . createTextNode ( objNode . t ) ;
464+ } else if ( objNode . hasOwnProperty ( 'co' ) ) {
465+ node = document . createComment ( objNode . co ) ;
466+ } else {
467+ if ( objNode . nn === 'svg' || insideSvg ) {
468+ node = document . createElementNS ( 'http://www.w3.org/2000/svg' , objNode . nn ) ;
469+ insideSvg = true ;
470+ } else {
471+ node = document . createElement ( objNode . nn ) ;
472+ }
473+ if ( objNode . a ) {
474+ for ( i = 0 ; i < objNode . a . length ; i ++ ) {
475+ node . setAttribute ( objNode . a [ i ] [ 0 ] , objNode . a [ i ] [ 1 ] ) ;
476+ }
477+ }
478+ if ( objNode . c ) {
479+ for ( i = 0 ; i < objNode . c . length ; i ++ ) {
480+ node . appendChild ( objToNode ( objNode . c [ i ] , insideSvg ) ) ;
481+ }
482+ }
483+ }
484+ return node ;
485+ }
486+
487+
488+
435489 function reportDiv ( ) {
436490 document . body . appendChild ( document . createElement ( 'div' ) ) ;
437491 }
0 commit comments