Added logic for not using getElementsByClassName in different failure states. Fixes...
[jquery.git] / src / selector.js
index 0cce515..9fb674e 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Sizzle CSS Selector Engine - v0.9.2
+ * Sizzle CSS Selector Engine - v0.9.3
  *  Copyright 2009, The Dojo Foundation
  *  Released under the MIT, BSD, and GPL Licenses.
  *  More information: http://sizzlejs.com/
@@ -655,15 +655,15 @@ try {
        // The workaround has to do additional checks after a getElementById
        // Which slows things down for other browsers (hence the branching)
        if ( !!document.getElementById( id ) ) {
-               Expr.find.ID = function(match, context){
-                       if ( context.getElementById ) {
+               Expr.find.ID = function(match, context, isXML){
+                       if ( typeof context.getElementById !== "undefined" && !isXML ) {
                                var m = context.getElementById(match[1]);
-                               return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
+                               return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
                        }
                };
 
                Expr.filter.ID = function(elem, match){
-                       var node = elem.getAttributeNode && elem.getAttributeNode("id");
+                       var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
                        return elem.nodeType === 1 && node && node.nodeValue === match;
                };
        }
@@ -703,7 +703,8 @@ try {
 
        // Check to see if an attribute returns normalized href attributes
        div.innerHTML = "<a href='#'></a>";
-       if ( div.firstChild && div.firstChild.getAttribute("href") !== "#" ) {
+       if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
+                       div.firstChild.getAttribute("href") !== "#" ) {
                Expr.attrHandle.href = function(elem){
                        return elem.getAttribute("href", 2);
                };
@@ -740,12 +741,25 @@ if ( document.querySelectorAll ) (function(){
        Sizzle.matches = oldSizzle.matches;
 })();
 
-if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) {
+if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){
+       var div = document.createElement("div");
+       div.innerHTML = "<div class='test e'></div><div class='test'></div>";
+
+       // Opera can't find a second classname (in 9.6)
+       if ( div.getElementsByClassName("e").length === 0 )
+               return;
+
+       // Safari caches class attributes, doesn't catch changes (in 3.2)
+       div.lastChild.className = "e";
+
+       if ( div.getElementsByClassName("e").length === 1 )
+               return;
+
        Expr.order.splice(1, 0, "CLASS");
        Expr.find.CLASS = function(match, context) {
                return context.getElementsByClassName(match[1]);
        };
-}
+})();
 
 function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
        for ( var i = 0, l = checkSet.length; i < l; i++ ) {