Commit 6f4b08cd authored by John Resig's avatar John Resig

Added support for sorting in Safari - when querySelectorAll isn't able to be used.

parent d75c899f
...@@ -75,7 +75,9 @@ jQuery.fn = jQuery.prototype = { ...@@ -75,7 +75,9 @@ jQuery.fn = jQuery.prototype = {
this.context = selector.context; this.context = selector.context;
} }
return this.setArray(jQuery.makeArray(selector)); return this.setArray(jQuery.isArray( selector ) ?
selector :
jQuery.makeArray(selector));
}, },
// Start with an empty selector // Start with an empty selector
...@@ -95,7 +97,7 @@ jQuery.fn = jQuery.prototype = { ...@@ -95,7 +97,7 @@ jQuery.fn = jQuery.prototype = {
return num === undefined ? return num === undefined ?
// Return a 'clean' array // Return a 'clean' array
jQuery.makeArray( this ) : Array.prototype.slice.call( this ) :
// Return just the object // Return just the object
this[ num ]; this[ num ];
......
...@@ -679,6 +679,17 @@ if ( document.documentElement.compareDocumentPosition ) { ...@@ -679,6 +679,17 @@ if ( document.documentElement.compareDocumentPosition ) {
} }
return ret; return ret;
}; };
} else if ( Array.prototype.indexOf ) {
var indexOf = Array.prototype.indexOf,
allSort = document.getElementsByTagName("*");
sortOrder = function( a, b ) {
var ret = indexOf.call( allSort, a ) - indexOf.call( allSort, b );
if ( ret === 0 ) {
hasDuplicate = true;
}
return ret;
};
} }
// Check to see if the browser returns elements by name when // Check to see if the browser returns elements by name when
......
module("selector"); module("selector");
test("element", function() { test("element", function() {
expect(13); expect(14);
reset(); reset();
ok( jQuery("*").size() >= 30, "Select all" ); ok( jQuery("*").size() >= 30, "Select all" );
...@@ -24,6 +24,7 @@ test("element", function() { ...@@ -24,6 +24,7 @@ test("element", function() {
isSet( jQuery("p"), jQuery("p, div p"), "Check for duplicates: p, div p" ); isSet( jQuery("p"), jQuery("p, div p"), "Check for duplicates: p, div p" );
t( "Checking sort order", "h2, h1", ["header", "banner", "userAgent"] ); t( "Checking sort order", "h2, h1", ["header", "banner", "userAgent"] );
t( "Checking sort order", "h2:first, h1:first", ["header", "banner"] );
t( "Checking sort order", "p, p a", ["firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first"] ); t( "Checking sort order", "p, p a", ["firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first"] );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment