Selector: add jQuery.uniqueSort; deprecate jQuery.unique

Fixes gh-2228
This commit is contained in:
Timmy Willison 2015-05-04 15:27:12 -07:00
parent 7a6931de68
commit e1090c3d2b
5 changed files with 9 additions and 9 deletions

View File

@ -6,7 +6,7 @@ define([
jQuery.find = Sizzle; jQuery.find = Sizzle;
jQuery.expr = Sizzle.selectors; jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.pseudos; jQuery.expr[":"] = jQuery.expr.pseudos;
jQuery.unique = Sizzle.uniqueSort; jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;
jQuery.text = Sizzle.getText; jQuery.text = Sizzle.getText;
jQuery.isXMLDoc = Sizzle.isXML; jQuery.isXMLDoc = Sizzle.isXML;
jQuery.contains = Sizzle.contains; jQuery.contains = Sizzle.contains;

View File

@ -85,7 +85,7 @@ jQuery.fn.extend({
} }
} }
return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched ); return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
}, },
// Determine the position of an element within the set // Determine the position of an element within the set
@ -111,7 +111,7 @@ jQuery.fn.extend({
add: function( selector, context ) { add: function( selector, context ) {
return this.pushStack( return this.pushStack(
jQuery.unique( jQuery.uniqueSort(
jQuery.merge( this.get(), jQuery( selector, context ) ) jQuery.merge( this.get(), jQuery( selector, context ) )
) )
); );
@ -182,7 +182,7 @@ jQuery.each({
if ( this.length > 1 ) { if ( this.length > 1 ) {
// Remove duplicates // Remove duplicates
if ( !guaranteedUnique[ name ] ) { if ( !guaranteedUnique[ name ] ) {
jQuery.unique( matched ); jQuery.uniqueSort( matched );
} }
// Reverse order for parents* and prev-derivatives // Reverse order for parents* and prev-derivatives

View File

@ -72,7 +72,7 @@ jQuery.fn.extend({
jQuery.find( selector, self[ i ], ret ); jQuery.find( selector, self[ i ], ret );
} }
return this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); return this.pushStack( len > 1 ? jQuery.uniqueSort( ret ) : ret );
}, },
filter: function( selector ) { filter: function( selector ) {
return this.pushStack( winnow(this, selector || [], false) ); return this.pushStack( winnow(this, selector || [], false) );

View File

@ -386,7 +386,7 @@ test( "jQuery.contains", function() {
ok( !jQuery.contains(document, detached), "document container (negative)" ); ok( !jQuery.contains(document, detached), "document container (negative)" );
}); });
test("jQuery.unique", function() { test("jQuery.uniqueSort", function() {
expect( 14 ); expect( 14 );
function Arrayish( arr ) { function Arrayish( arr ) {
@ -460,8 +460,8 @@ test("jQuery.unique", function() {
jQuery.each( tests, function( label, test ) { jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length; var length = test.length || test.input.length;
deepEqual( jQuery.unique( test.input ).slice( 0, length ), test.expected, label + " (array)" ); deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
deepEqual( jQuery.unique( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" ); deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
}); });
}); });

View File

@ -696,7 +696,7 @@ test("sort direction", function() {
jQuery.each( methodDirections, function( method, reversed ) { jQuery.each( methodDirections, function( method, reversed ) {
var actual = elems[ method ]().get(), var actual = elems[ method ]().get(),
forward = jQuery.unique( [].concat( actual ) ); forward = jQuery.uniqueSort( [].concat( actual ) );
deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method ); deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method );
}); });
}); });