mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
Fix #13741. Make wrap/unwrap methods optional; close gh-1236.
move size() test to unit/deprecated; don't use size() in other tests; make 2 unit tests actually fire; code cleanup
This commit is contained in:
committed by
Dave Methvin
parent
12a1017290
commit
0db70aa1fa
66
src/wrap.js
Normal file
66
src/wrap.js
Normal file
@@ -0,0 +1,66 @@
|
||||
jQuery.fn.extend({
|
||||
wrapAll: function( html ) {
|
||||
if ( jQuery.isFunction( html ) ) {
|
||||
return this.each(function(i) {
|
||||
jQuery(this).wrapAll( html.call(this, i) );
|
||||
});
|
||||
}
|
||||
|
||||
if ( this[0] ) {
|
||||
// The elements to wrap the target around
|
||||
var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
|
||||
|
||||
if ( this[0].parentNode ) {
|
||||
wrap.insertBefore( this[0] );
|
||||
}
|
||||
|
||||
wrap.map(function() {
|
||||
var elem = this;
|
||||
|
||||
while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
|
||||
elem = elem.firstChild;
|
||||
}
|
||||
|
||||
return elem;
|
||||
}).append( this );
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
wrapInner: function( html ) {
|
||||
if ( jQuery.isFunction( html ) ) {
|
||||
return this.each(function(i) {
|
||||
jQuery(this).wrapInner( html.call(this, i) );
|
||||
});
|
||||
}
|
||||
|
||||
return this.each(function() {
|
||||
var self = jQuery( this ),
|
||||
contents = self.contents();
|
||||
|
||||
if ( contents.length ) {
|
||||
contents.wrapAll( html );
|
||||
|
||||
} else {
|
||||
self.append( html );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
wrap: function( html ) {
|
||||
var isFunction = jQuery.isFunction( html );
|
||||
|
||||
return this.each(function(i) {
|
||||
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
|
||||
});
|
||||
},
|
||||
|
||||
unwrap: function() {
|
||||
return this.parent().each(function() {
|
||||
if ( !jQuery.nodeName( this, "body" ) ) {
|
||||
jQuery( this ).replaceWith( this.childNodes );
|
||||
}
|
||||
}).end();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user