aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-02-14 18:10:45 +0000
committerJohn Resig <jeresig@gmail.com>2009-02-14 18:10:45 +0000
commit6f4b08cdf9cb334f8531fe06a20153defb7f95b6 (patch)
tree31cc0efc820879efb8889d89f4944c72bc65af08
parentd75c899fe78c52d89e5fb757ded979aca126d37b (diff)
downloadjquery-6f4b08cdf9cb334f8531fe06a20153defb7f95b6.tar.gz
jquery-6f4b08cdf9cb334f8531fe06a20153defb7f95b6.zip
Added support for sorting in Safari - when querySelectorAll isn't able to be used.
-rw-r--r--src/core.js6
-rw-r--r--src/selector.js11
-rw-r--r--test/unit/selector.js3
3 files changed, 17 insertions, 3 deletions
diff --git a/src/core.js b/src/core.js
index b3142d0c6..e0428c424 100644
--- a/src/core.js
+++ b/src/core.js
@@ -75,7 +75,9 @@ jQuery.fn = jQuery.prototype = {
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
@@ -95,7 +97,7 @@ jQuery.fn = jQuery.prototype = {
return num === undefined ?
// Return a 'clean' array
- jQuery.makeArray( this ) :
+ Array.prototype.slice.call( this ) :
// Return just the object
this[ num ];
diff --git a/src/selector.js b/src/selector.js
index 5712f572b..6b3b2da07 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -679,6 +679,17 @@ if ( document.documentElement.compareDocumentPosition ) {
}
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
diff --git a/test/unit/selector.js b/test/unit/selector.js
index 2ab7e6a3a..715823a6f 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -1,7 +1,7 @@
module("selector");
test("element", function() {
- expect(13);
+ expect(14);
reset();
ok( jQuery("*").size() >= 30, "Select all" );
@@ -24,6 +24,7 @@ test("element", function() {
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: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"] );
});