Expose the sort/unique code from Sizzle as Sizzle.uniqueSort().

This commit is contained in:
John Resig 2009-02-25 15:19:08 +00:00
parent 85e0945718
commit 1c5db3baba

View file

@ -124,22 +124,25 @@ var Sizzle = function(selector, context, results, seed) {
if ( extra ) { if ( extra ) {
Sizzle( extra, origContext, results, seed ); Sizzle( extra, origContext, results, seed );
Sizzle.uniqueSort( results );
}
if ( sortOrder ) { return results;
hasDuplicate = false; };
results.sort(sortOrder);
if ( hasDuplicate ) { Sizzle.uniqueSort = function(results){
for ( var i = 1; i < results.length; i++ ) { if ( sortOrder ) {
if ( results[i] === results[i-1] ) { hasDuplicate = false;
results.splice(i--, 1); results.sort(sortOrder);
}
if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[i-1] ) {
results.splice(i--, 1);
} }
} }
} }
} }
return results;
}; };
Sizzle.matches = function(expr, set){ Sizzle.matches = function(expr, set){