From e1090c3d2b2a988a5b41f1f1ed9f8d6dcae02200 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 4 May 2015 15:27:12 -0700 Subject: [PATCH] Selector: add jQuery.uniqueSort; deprecate jQuery.unique Fixes gh-2228 --- src/selector-sizzle.js | 2 +- src/traversing.js | 6 +++--- src/traversing/findFilter.js | 2 +- test/unit/selector.js | 6 +++--- test/unit/traversing.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/selector-sizzle.js b/src/selector-sizzle.js index 7d3926b1a..c091f1821 100644 --- a/src/selector-sizzle.js +++ b/src/selector-sizzle.js @@ -6,7 +6,7 @@ define([ jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.pseudos; -jQuery.unique = Sizzle.uniqueSort; +jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort; jQuery.text = Sizzle.getText; jQuery.isXMLDoc = Sizzle.isXML; jQuery.contains = Sizzle.contains; diff --git a/src/traversing.js b/src/traversing.js index d9ff0aeac..19f8d24e7 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -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 @@ -111,7 +111,7 @@ jQuery.fn.extend({ add: function( selector, context ) { return this.pushStack( - jQuery.unique( + jQuery.uniqueSort( jQuery.merge( this.get(), jQuery( selector, context ) ) ) ); @@ -182,7 +182,7 @@ jQuery.each({ if ( this.length > 1 ) { // Remove duplicates if ( !guaranteedUnique[ name ] ) { - jQuery.unique( matched ); + jQuery.uniqueSort( matched ); } // Reverse order for parents* and prev-derivatives diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index eee3b6bee..128df2cb4 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -72,7 +72,7 @@ jQuery.fn.extend({ 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 ) { return this.pushStack( winnow(this, selector || [], false) ); diff --git a/test/unit/selector.js b/test/unit/selector.js index 12c26f1cb..ee117ca8f 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -386,7 +386,7 @@ test( "jQuery.contains", function() { ok( !jQuery.contains(document, detached), "document container (negative)" ); }); -test("jQuery.unique", function() { +test("jQuery.uniqueSort", function() { expect( 14 ); function Arrayish( arr ) { @@ -460,8 +460,8 @@ test("jQuery.unique", function() { jQuery.each( tests, function( label, test ) { var length = test.length || test.input.length; - deepEqual( jQuery.unique( 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( test.input ).slice( 0, length ), test.expected, label + " (array)" ); + deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" ); }); }); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index b80b673ff..08b384a7e 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -696,7 +696,7 @@ test("sort direction", function() { jQuery.each( methodDirections, function( method, reversed ) { 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 ); }); });