aboutsummaryrefslogtreecommitdiffstats
path: root/src/manipulation.js
diff options
context:
space:
mode:
authorOleg <markelog@gmail.com>2013-09-17 13:24:27 +0400
committerOleg <markelog@gmail.com>2013-09-17 13:24:27 +0400
commit642e9a45579cfa90861b8ea71a95dd077775caaf (patch)
tree4a07b3d4ed45da3bb54559ec63e9b5e9c519ec89 /src/manipulation.js
parent80538b04fd4ce8bd531d3d1fb60236a315c82d80 (diff)
downloadjquery-642e9a45579cfa90861b8ea71a95dd077775caaf.tar.gz
jquery-642e9a45579cfa90861b8ea71a95dd077775caaf.zip
Simplify replaceWith method. Closes gh-1276
Diffstat (limited to 'src/manipulation.js')
-rw-r--r--src/manipulation.js32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 7e5ec07cc..afaaa30ea 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -442,38 +442,28 @@ jQuery.fn.extend({
},
replaceWith: function() {
- var
- // Snapshot the DOM in case .domManip sweeps something relevant into its fragment
- args = jQuery.map( this, function( elem ) {
- return [ elem.nextSibling, elem.parentNode ];
- }),
- i = 0;
+ var arg = arguments[ 0 ];
// Make the changes, replacing each context element with the new content
this.domManip( arguments, function( elem ) {
- var next = args[ i++ ],
- parent = args[ i++ ];
+ arg = this.parentNode;
- if ( parent ) {
- // Don't use the snapshot next if it has moved (#13810)
- if ( next && next.parentNode !== parent ) {
- next = this.nextSibling;
- }
- jQuery( this ).remove();
- parent.insertBefore( elem, next );
+ jQuery.cleanData( getAll( this ) );
+
+ if ( arg ) {
+ arg.replaceChild( elem, this );
}
- // Allow new content to include elements from the context set
- }, true );
+ });
// Force removal if there was no new content (e.g., from empty arguments)
- return i ? this : this.remove();
+ return arg && (arg.length || arg.nodeType) ? this : this.remove();
},
detach: function( selector ) {
return this.remove( selector, true );
},
- domManip: function( args, callback, allowIntersection ) {
+ domManip: function( args, callback ) {
// Flatten any nested arrays
args = concat.apply( [], args );
@@ -495,12 +485,12 @@ jQuery.fn.extend({
if ( isFunction ) {
args[ 0 ] = value.call( this, index, self.html() );
}
- self.domManip( args, callback, allowIntersection );
+ self.domManip( args, callback );
});
}
if ( l ) {
- fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, !allowIntersection && this );
+ fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
first = fragment.firstChild;
if ( fragment.childNodes.length === 1 ) {