Commit 0db70aa1 authored by Michał Gołębiowski's avatar Michał Gołębiowski Committed by Dave Methvin

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
parent 12a10172
...@@ -56,6 +56,7 @@ module.exports = function( grunt ) { ...@@ -56,6 +56,7 @@ module.exports = function( grunt ) {
"src/event.js", "src/event.js",
"src/traversing.js", "src/traversing.js",
"src/manipulation.js", "src/manipulation.js",
{ flag: "wrap", src: "src/wrap.js" },
{ flag: "css", src: "src/css.js" }, { flag: "css", src: "src/css.js" },
"src/serialize.js", "src/serialize.js",
{ flag: "event-alias", src: "src/event-alias.js" }, { flag: "event-alias", src: "src/event-alias.js" },
......
...@@ -84,6 +84,7 @@ For example, an app that only used JSONP for `$.ajax()` and did not need to calc ...@@ -84,6 +84,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")`. - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
- **event-alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`. - **event-alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`.
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods. - **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
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. 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.
......
...@@ -60,71 +60,6 @@ jQuery.fn.extend({ ...@@ -60,71 +60,6 @@ jQuery.fn.extend({
}, null, value, arguments.length ); }, null, value, arguments.length );
}, },
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();
},
append: function() { append: function() {
return this.domManip( arguments, function( elem ) { return this.domManip( arguments, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
......
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();
}
});
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
<script src="unit/selector.js"></script> <script src="unit/selector.js"></script>
<script src="unit/traversing.js"></script> <script src="unit/traversing.js"></script>
<script src="unit/manipulation.js"></script> <script src="unit/manipulation.js"></script>
<script src="unit/wrap.js"></script>
<script src="unit/css.js"></script> <script src="unit/css.js"></script>
<script src="unit/serialize.js"></script> <script src="unit/serialize.js"></script>
<script src="unit/ajax.js"></script> <script src="unit/ajax.js"></script>
......
...@@ -680,11 +680,6 @@ test("length", function() { ...@@ -680,11 +680,6 @@ test("length", function() {
equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" ); equal( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
}); });
test("size()", function() {
expect(1);
equal( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
});
test("get()", function() { test("get()", function() {
expect(1); expect(1);
deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); deepEqual( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
......
...@@ -579,7 +579,7 @@ test( "show() resolves correct default display for detached nodes", function(){ ...@@ -579,7 +579,7 @@ test( "show() resolves correct default display for detached nodes", function(){
equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" ); equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" );
tr.remove(); tr.remove();
span = span = jQuery("<span/>").hide().show(); span = jQuery("<span/>").hide().show();
equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" ); equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" );
span.remove(); span.remove();
}); });
......
module("deprecated"); module("deprecated", { teardown: moduleTeardown });
if ( jQuery.fn.size ) {
test("size()", function() {
expect(1);
equal( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
});
}
This diff is collapsed.
...@@ -143,14 +143,14 @@ test("is() with :has() selectors", function() { ...@@ -143,14 +143,14 @@ test("is() with :has() selectors", function() {
test("is() with positional selectors", function() { test("is() with positional selectors", function() {
expect(24); expect(24);
jQuery(
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
).appendTo( "#qunit-fixture" );
var isit = function(sel, match, expect) { var isit = function(sel, match, expect) {
equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" ); equal( jQuery( sel ).is( match ), expect, "jQuery('" + sel + "').is('" + match + "')" );
}; };
jQuery(
"<p id='posp'><a class='firsta' href='#'><em>first</em></a><a class='seconda' href='#'><b>test</b></a><em></em></p>"
).appendTo( "#qunit-fixture" );
isit( "#posp", "#posp:first", true ); isit( "#posp", "#posp:first", true );
isit( "#posp", "#posp:eq(2)", false ); isit( "#posp", "#posp:eq(2)", false );
isit( "#posp", "#posp a:first", false ); isit( "#posp", "#posp a:first", false );
...@@ -272,21 +272,21 @@ test("filter(jQuery)", function() { ...@@ -272,21 +272,21 @@ test("filter(jQuery)", function() {
test("filter() with positional selectors", function() { test("filter() with positional selectors", function() {
expect(19); expect(19);
jQuery( "" +
"<p id='posp'>" +
"<a class='firsta' href='#'>" +
"<em>first</em>" +
"</a>" +
"<a class='seconda' href='#'>" +
"<b>test</b>" +
"</a>" +
"<em></em>" +
"</p>" ).appendTo( "#qunit-fixture" );
var filterit = function(sel, filter, length) { var filterit = function(sel, filter, length) {
equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
}; };
jQuery( "" +
"<p id='posp'>" +
"<a class='firsta' href='#'>" +
"<em>first</em>" +
"</a>" +
"<a class='seconda' href='#'>" +
"<b>test</b>" +
"</a>" +
"<em></em>" +
"</p>" ).appendTo( "#qunit-fixture" );
filterit( "#posp", "#posp:first", 1); filterit( "#posp", "#posp:first", 1);
filterit( "#posp", "#posp:eq(2)", 0 ); filterit( "#posp", "#posp:eq(2)", 0 );
filterit( "#posp", "#posp a:first", 0 ); filterit( "#posp", "#posp a:first", 0 );
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment