~noskcaj/ubuntu/utopic/jquery/merge

« back to all changes in this revision

Viewing changes to src/manipulation.js

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo Jorge Vieira (metal)
  • Date: 2011-05-29 20:21:27 UTC
  • mfrom: (0.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20110529202127-yo710urpsj87oqnh
Tags: 1.6.1-1
New upstream release (Closes: #628052)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        rnocache = /<(?:script|object|embed|option|style)/i,
10
10
        // checked="checked" or checked
11
11
        rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
 
12
        rscriptType = /\/(java|ecma)script/i,
 
13
        rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
12
14
        wrapMap = {
13
15
                option: [ 1, "<select multiple='multiple'>", "</select>" ],
14
16
                legend: [ 1, "<fieldset>", "</fieldset>" ],
69
71
                                }
70
72
 
71
73
                                return elem;
72
 
                        }).append(this);
 
74
                        }).append( this );
73
75
                }
74
76
 
75
77
                return this;
261
263
                                }
262
264
                        });
263
265
                } else {
264
 
                        return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
 
266
                        return this.length ?
 
267
                                this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
 
268
                                this;
265
269
                }
266
270
        },
267
271
 
375
379
        }
376
380
}
377
381
 
378
 
function cloneFixAttributes(src, dest) {
 
382
function cloneFixAttributes( src, dest ) {
 
383
        var nodeName;
 
384
 
379
385
        // We do not need to do anything for non-Elements
380
386
        if ( dest.nodeType !== 1 ) {
381
387
                return;
382
388
        }
383
389
 
384
 
        var nodeName = dest.nodeName.toLowerCase();
385
 
 
386
390
        // clearAttributes removes the attributes, which we don't want,
387
391
        // but also removes the attachEvent events, which we *do* want
388
 
        dest.clearAttributes();
 
392
        if ( dest.clearAttributes ) {
 
393
                dest.clearAttributes();
 
394
        }
389
395
 
390
396
        // mergeAttributes, in contrast, only merges back on the
391
397
        // original attributes, not the events
392
 
        dest.mergeAttributes(src);
 
398
        if ( dest.mergeAttributes ) {
 
399
                dest.mergeAttributes( src );
 
400
        }
 
401
 
 
402
        nodeName = dest.nodeName.toLowerCase();
393
403
 
394
404
        // IE6-8 fail to clone children inside object elements that use
395
405
        // the proprietary classid attribute value (rather than the type
439
449
                args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
440
450
 
441
451
                cacheable = true;
 
452
 
442
453
                cacheresults = jQuery.fragments[ args[0] ];
443
 
                if ( cacheresults ) {
444
 
                        if ( cacheresults !== 1 ) {
445
 
                                fragment = cacheresults;
446
 
                        }
 
454
                if ( cacheresults && cacheresults !== 1 ) {
 
455
                        fragment = cacheresults;
447
456
                }
448
457
        }
449
458
 
492
501
function getAll( elem ) {
493
502
        if ( "getElementsByTagName" in elem ) {
494
503
                return elem.getElementsByTagName( "*" );
495
 
        
 
504
 
496
505
        } else if ( "querySelectorAll" in elem ) {
497
506
                return elem.querySelectorAll( "*" );
498
507
 
501
510
        }
502
511
}
503
512
 
 
513
// Used in clean, fixes the defaultChecked property
 
514
function fixDefaultChecked( elem ) {
 
515
        if ( elem.type === "checkbox" || elem.type === "radio" ) {
 
516
                elem.defaultChecked = elem.checked;
 
517
        }
 
518
}
 
519
// Finds all inputs and passes them to fixDefaultChecked
 
520
function findInputs( elem ) {
 
521
        if ( jQuery.nodeName( elem, "input" ) ) {
 
522
                fixDefaultChecked( elem );
 
523
        } else if ( elem.getElementsByTagName ) {
 
524
                jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
 
525
        }
 
526
}
 
527
 
504
528
jQuery.extend({
505
529
        clone: function( elem, dataAndEvents, deepDataAndEvents ) {
506
530
                var clone = elem.cloneNode(true),
547
571
 
548
572
                // Return the cloned set
549
573
                return clone;
550
 
},
 
574
        },
 
575
 
551
576
        clean: function( elems, context, fragment, scripts ) {
 
577
                var checkScriptType;
 
578
 
552
579
                context = context || document;
553
580
 
554
581
                // !context.createElement fails in IE with an error but returns typeof 'object'
556
583
                        context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
557
584
                }
558
585
 
559
 
                var ret = [];
 
586
                var ret = [], j;
560
587
 
561
588
                for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
562
589
                        if ( typeof elem === "number" ) {
568
595
                        }
569
596
 
570
597
                        // Convert html string into DOM nodes
571
 
                        if ( typeof elem === "string" && !rhtml.test( elem ) ) {
572
 
                                elem = context.createTextNode( elem );
573
 
 
574
 
                        } else if ( typeof elem === "string" ) {
575
 
                                // Fix "XHTML"-style tags in all browsers
576
 
                                elem = elem.replace(rxhtmlTag, "<$1></$2>");
577
 
 
578
 
                                // Trim whitespace, otherwise indexOf won't work as expected
579
 
                                var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
580
 
                                        wrap = wrapMap[ tag ] || wrapMap._default,
581
 
                                        depth = wrap[0],
582
 
                                        div = context.createElement("div");
583
 
 
584
 
                                // Go to html and back, then peel off extra wrappers
585
 
                                div.innerHTML = wrap[1] + elem + wrap[2];
586
 
 
587
 
                                // Move to the right depth
588
 
                                while ( depth-- ) {
589
 
                                        div = div.lastChild;
590
 
                                }
591
 
 
592
 
                                // Remove IE's autoinserted <tbody> from table fragments
593
 
                                if ( !jQuery.support.tbody ) {
594
 
 
595
 
                                        // String was a <table>, *may* have spurious <tbody>
596
 
                                        var hasBody = rtbody.test(elem),
597
 
                                                tbody = tag === "table" && !hasBody ?
598
 
                                                        div.firstChild && div.firstChild.childNodes :
599
 
 
600
 
                                                        // String was a bare <thead> or <tfoot>
601
 
                                                        wrap[1] === "<table>" && !hasBody ?
602
 
                                                                div.childNodes :
603
 
                                                                [];
604
 
 
605
 
                                        for ( var j = tbody.length - 1; j >= 0 ; --j ) {
606
 
                                                if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
607
 
                                                        tbody[ j ].parentNode.removeChild( tbody[ j ] );
 
598
                        if ( typeof elem === "string" ) {
 
599
                                if ( !rhtml.test( elem ) ) {
 
600
                                        elem = context.createTextNode( elem );
 
601
                                } else {
 
602
                                        // Fix "XHTML"-style tags in all browsers
 
603
                                        elem = elem.replace(rxhtmlTag, "<$1></$2>");
 
604
 
 
605
                                        // Trim whitespace, otherwise indexOf won't work as expected
 
606
                                        var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
 
607
                                                wrap = wrapMap[ tag ] || wrapMap._default,
 
608
                                                depth = wrap[0],
 
609
                                                div = context.createElement("div");
 
610
 
 
611
                                        // Go to html and back, then peel off extra wrappers
 
612
                                        div.innerHTML = wrap[1] + elem + wrap[2];
 
613
 
 
614
                                        // Move to the right depth
 
615
                                        while ( depth-- ) {
 
616
                                                div = div.lastChild;
 
617
                                        }
 
618
 
 
619
                                        // Remove IE's autoinserted <tbody> from table fragments
 
620
                                        if ( !jQuery.support.tbody ) {
 
621
 
 
622
                                                // String was a <table>, *may* have spurious <tbody>
 
623
                                                var hasBody = rtbody.test(elem),
 
624
                                                        tbody = tag === "table" && !hasBody ?
 
625
                                                                div.firstChild && div.firstChild.childNodes :
 
626
 
 
627
                                                                // String was a bare <thead> or <tfoot>
 
628
                                                                wrap[1] === "<table>" && !hasBody ?
 
629
                                                                        div.childNodes :
 
630
                                                                        [];
 
631
 
 
632
                                                for ( j = tbody.length - 1; j >= 0 ; --j ) {
 
633
                                                        if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
 
634
                                                                tbody[ j ].parentNode.removeChild( tbody[ j ] );
 
635
                                                        }
608
636
                                                }
609
637
                                        }
610
638
 
611
 
                                }
612
 
 
613
 
                                // IE completely kills leading whitespace when innerHTML is used
614
 
                                if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
615
 
                                        div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
616
 
                                }
617
 
 
618
 
                                elem = div.childNodes;
 
639
                                        // IE completely kills leading whitespace when innerHTML is used
 
640
                                        if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
 
641
                                                div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
 
642
                                        }
 
643
 
 
644
                                        elem = div.childNodes;
 
645
                                }
 
646
                        }
 
647
 
 
648
                        // Resets defaultChecked for any radios and checkboxes
 
649
                        // about to be appended to the DOM in IE 6/7 (#8060)
 
650
                        var len;
 
651
                        if ( !jQuery.support.appendChecked ) {
 
652
                                if ( elem[0] && typeof (len = elem.length) === "number" ) {
 
653
                                        for ( j = 0; j < len; j++ ) {
 
654
                                                findInputs( elem[j] );
 
655
                                        }
 
656
                                } else {
 
657
                                        findInputs( elem );
 
658
                                }
619
659
                        }
620
660
 
621
661
                        if ( elem.nodeType ) {
626
666
                }
627
667
 
628
668
                if ( fragment ) {
 
669
                        checkScriptType = function( elem ) {
 
670
                                return !elem.type || rscriptType.test( elem.type );
 
671
                        };
629
672
                        for ( i = 0; ret[i]; i++ ) {
630
673
                                if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
631
674
                                        scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
632
675
 
633
676
                                } else {
634
677
                                        if ( ret[i].nodeType === 1 ) {
635
 
                                                ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
 
678
                                                var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType );
 
679
 
 
680
                                                ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
636
681
                                        }
637
682
                                        fragment.appendChild( ret[i] );
638
683
                                }
694
739
                        dataType: "script"
695
740
                });
696
741
        } else {
697
 
                jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
 
742
                jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
698
743
        }
699
744
 
700
745
        if ( elem.parentNode ) {