Bumping the version of Sizzle up to 0.9.2.
[jquery.git] / src / selector.js
index 56efd01..0cce515 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Sizzle CSS Selector Engine - v0.9.1
+ * Sizzle CSS Selector Engine - v0.9.2
  *  Copyright 2009, The Dojo Foundation
  *  Released under the MIT, BSD, and GPL Licenses.
  *  More information: http://sizzlejs.com/
@@ -55,7 +55,7 @@ var Sizzle = function(selector, context, results, seed) {
        } else {
                var ret = seed ?
                        { expr: parts.pop(), set: makeArray(seed) } :
-                       Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context );
+                       Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context, isXML(context) );
                set = Sizzle.filter( ret.expr, ret.set );
 
                if ( parts.length > 0 ) {
@@ -120,7 +120,7 @@ Sizzle.matches = function(expr, set){
        return Sizzle(expr, null, null, set);
 };
 
-Sizzle.find = function(expr, context){
+Sizzle.find = function(expr, context, isXML){
        var set, match;
 
        if ( !expr ) {
@@ -135,7 +135,7 @@ Sizzle.find = function(expr, context){
 
                        if ( left.substr( left.length - 1 ) !== "\\" ) {
                                match[1] = (match[1] || "").replace(/\\/g, "");
-                               set = Expr.find[ type ]( match, context );
+                               set = Expr.find[ type ]( match, context, isXML );
                                if ( set != null ) {
                                        expr = expr.replace( Expr.match[ type ], "" );
                                        break;
@@ -315,14 +315,16 @@ var Expr = Sizzle.selectors = {
                }
        },
        find: {
-               ID: function(match, context){
-                       if ( context.getElementById ) {
+               ID: function(match, context, isXML){
+                       if ( typeof context.getElementById !== "undefined" && !isXML ) {
                                var m = context.getElementById(match[1]);
                                return m ? [m] : [];
                        }
                },
-               NAME: function(match, context){
-                       return context.getElementsByName ? context.getElementsByName(match[1]) : null;
+               NAME: function(match, context, isXML){
+                       if ( typeof context.getElementsByName !== "undefined" && !isXML ) {
+                               return context.getElementsByName(match[1]);
+                       }
                },
                TAG: function(match, context){
                        return context.getElementsByTagName(match[1]);
@@ -332,11 +334,12 @@ var Expr = Sizzle.selectors = {
                CLASS: function(match, curLoop, inplace, result, not){
                        match = " " + match[1].replace(/\\/g, "") + " ";
 
-                       for ( var i = 0; curLoop[i] != null; i++ ) {
-                               if ( curLoop[i] ) {
-                                       if ( not ^ (" " + curLoop[i].className + " ").indexOf(match) >= 0 ) {
+                       var elem;
+                       for ( var i = 0; (elem = curLoop[i]) != null; i++ ) {
+                               if ( elem ) {
+                                       if ( not ^ (" " + elem.className + " ").indexOf(match) >= 0 ) {
                                                if ( !inplace )
-                                                       result.push( curLoop[i] );
+                                                       result.push( elem );
                                        } else if ( inplace ) {
                                                curLoop[i] = false;
                                        }
@@ -494,7 +497,7 @@ var Expr = Sizzle.selectors = {
                CHILD: function(elem, match){
                        var type = match[1], parent = elem.parentNode;
 
-                       var doneName = "child" + parent.childNodes.length;
+                       var doneName = match[0];
                        
                        if ( parent && (!parent[ doneName ] || !elem.nodeIndex) ) {
                                var count = 1;
@@ -563,7 +566,7 @@ var Expr = Sizzle.selectors = {
                ATTR: function(elem, match){
                        var result = Expr.attrHandle[ match[1] ] ? Expr.attrHandle[ match[1] ]( elem ) : elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
                        return result == null ?
-                               false :
+                               type === "!=" :
                                type === "=" ?
                                value === check :
                                type === "*=" ?
@@ -708,12 +711,21 @@ try {
 })();
 
 if ( document.querySelectorAll ) (function(){
-       var oldSizzle = Sizzle;
+       var oldSizzle = Sizzle, div = document.createElement("div");
+       div.innerHTML = "<p class='TEST'></p>";
+
+       // Safari can't handle uppercase or unicode characters when
+       // in quirks mode.
+       if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
+               return;
+       }
        
        Sizzle = function(query, context, extra, seed){
                context = context || document;
 
-               if ( !seed && context.nodeType === 9 ) {
+               // Only use querySelectorAll on non-XML documents
+               // (ID selectors don't work in non-HTML documents)
+               if ( !seed && context.nodeType === 9 && !isXML(context) ) {
                        try {
                                return makeArray( context.querySelectorAll(query), extra );
                        } catch(e){}
@@ -831,7 +843,7 @@ var posProcess = function(selector, context){
        }
 
        return Sizzle.filter( later, tmpSet );
-}
+};
 
 // EXPOSE
 jQuery.find = Sizzle;