]> source.dussan.org Git - jquery.git/commitdiff
Selector: Define jQuery.uniqueSort in selector-native too
authorMarek Lewandowski <m.lewandowski@cksource.com>
Mon, 13 Jul 2015 12:39:52 +0000 (14:39 +0200)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 14 Jul 2015 13:18:57 +0000 (09:18 -0400)
Fixes gh-2466
Closes gh-2467

src/selector-native.js

index 5717918bcd79d3fab5f6c54d5145afde061f85e9..2d5cb30263358289c9615437ea2da6453a29e8ba 100644 (file)
@@ -67,6 +67,28 @@ var hasDuplicate,
 
                // Not directly comparable, sort on existence of method
                return a.compareDocumentPosition ? -1 : 1;
+       },
+       uniqueSort = function( results ) {
+               var elem,
+                       duplicates = [],
+                       i = 0,
+                       j = 0;
+
+               hasDuplicate = false;
+               results.sort( sortOrder );
+
+               if ( hasDuplicate ) {
+                       while ( (elem = results[i++]) ) {
+                               if ( elem === results[ i ] ) {
+                                       j = duplicates.push( i );
+                               }
+                       }
+                       while ( j-- ) {
+                               results.splice( duplicates[ j ], 1 );
+                       }
+               }
+
+               return results;
        };
 
 jQuery.extend({
@@ -99,28 +121,8 @@ jQuery.extend({
 
                return results;
        },
-       unique: function( results ) {
-               var elem,
-                       duplicates = [],
-                       i = 0,
-                       j = 0;
-
-               hasDuplicate = false;
-               results.sort( sortOrder );
-
-               if ( hasDuplicate ) {
-                       while ( (elem = results[i++]) ) {
-                               if ( elem === results[ i ] ) {
-                                       j = duplicates.push( i );
-                               }
-                       }
-                       while ( j-- ) {
-                               results.splice( duplicates[ j ], 1 );
-                       }
-               }
-
-               return results;
-       },
+       uniqueSort: uniqueSort,
+       unique: uniqueSort,
        text: function( elem ) {
                var node,
                        ret = "",