From 5266f23cf49c9329bddce4d4af6cb5fbbd1e0383 Mon Sep 17 00:00:00 2001 From: Michał Gołębiowski-Owczarek Date: Mon, 28 Nov 2022 18:10:33 +0100 Subject: Selector: Implement the `uniqueSort` chainable method Some APIs, like `.prevAll()`, return elements in the reversed order, causing confusing behavior when used with wrapping methods (see gh-5149 for more info) To provide an easy workaround, this commit implements a chainable `uniqueSort` method on jQuery objects, an equivalent of `jQuery.uniqueSort`. Fixes gh-5166 Closes gh-5168 --- src/selector/uniqueSort.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/selector') diff --git a/src/selector/uniqueSort.js b/src/selector/uniqueSort.js index e9438485c..91c7193e9 100644 --- a/src/selector/uniqueSort.js +++ b/src/selector/uniqueSort.js @@ -2,6 +2,7 @@ import jQuery from "../core.js"; import document from "../var/document.js"; import sort from "../var/sort.js"; import splice from "../var/splice.js"; +import slice from "../var/slice.js"; var hasDuplicate; @@ -87,3 +88,7 @@ jQuery.uniqueSort = function( results ) { return results; }; + +jQuery.fn.uniqueSort = function() { + return this.pushStack( jQuery.uniqueSort( slice.apply( this ) ) ); +}; -- cgit v1.2.3