Skip to content
Permalink
Browse files

Fix #13741. Make wrap/unwrap methods optional. Close gh-1222.

  • Loading branch information...
dmethvin committed Apr 5, 2013
1 parent 1114611 commit 5031c9db4bf22cc04472346eeee8f25a61c5ee68
Showing with 271 additions and 247 deletions.
  1. +1 −0 Gruntfile.js
  2. +1 −0 README.md
  3. +0 −68 src/manipulation.js
  4. +69 −0 src/wrap.js
  5. +200 −179 test/unit/manipulation.js
@@ -51,6 +51,7 @@ module.exports = function( grunt ) {
"src/event.js",
"src/traversing.js",
"src/manipulation.js",
{ flag: "wrap", src: "src/wrap.js" },
{ flag: "css", src: "src/css.js" },
"src/serialize.js",
{ flag: "event-alias", src: "src/event-alias.js" },
@@ -86,6 +86,7 @@ For example, an app that only used JSONP for `$.ajax()` and did not need to calc
- **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
- **event-alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`.
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
- **sizzle**: The Sizzle selector engine. When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the selector-native.js file for details.

The grunt build process is aware of dependencies across modules. If you explicitly remove a module, its dependent modules will be removed as well. For example, excluding the css module also excludes effects, since the effects module uses `.css()` to animate CSS properties. These dependencies are listed in Gruntfile.js and the build process shows a message for each dependent module it excludes.
@@ -37,74 +37,6 @@ jQuery.fn.extend({
}, null, value, arguments.length );
},

wrapAll: function( html ) {
var wrap;

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
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.firstElementChild ) {
elem = elem.firstElementChild;
}

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();
},

append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
@@ -0,0 +1,69 @@
jQuery.fn.extend({
wrapAll: function( html ) {
var wrap;

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
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.firstElementChild ) {
elem = elem.firstElementChild;
}

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();
}
});
Oops, something went wrong.

0 comments on commit 5031c9d

Please sign in to comment.
You can’t perform that action at this time.