aboutsummaryrefslogtreecommitdiffstats
path: root/src/selector
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2022-11-28 18:10:33 +0100
committerGitHub <noreply@github.com>2022-11-28 18:10:33 +0100
commit5266f23cf49c9329bddce4d4af6cb5fbbd1e0383 (patch)
treea0f3c1e54f130b28240b43e767ff859e935981c7 /src/selector
parent716130e094caf780100a39cfd4526adbd7673b12 (diff)
downloadjquery-5266f23cf49c9329bddce4d4af6cb5fbbd1e0383.tar.gz
jquery-5266f23cf49c9329bddce4d4af6cb5fbbd1e0383.zip
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
Diffstat (limited to 'src/selector')
-rw-r--r--src/selector/uniqueSort.js5
1 files changed, 5 insertions, 0 deletions
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 ) ) );
+};