Optimized the clean() code to no longer use .trim() (speeds up working against long...
[jquery.git] / src / selector.js
index cf4ff9d..7c0bf40 100644 (file)
@@ -6,7 +6,7 @@
  */
 (function(){
 
-var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]+['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g,
+var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g,
        done = 0,
        toString = Object.prototype.toString;
 
@@ -564,7 +564,16 @@ var Expr = Sizzle.selectors = {
                        return match.test( elem.className );
                },
                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];
+                       var name = match[1],
+                               result = Expr.attrHandle[ name ] ?
+                                       Expr.attrHandle[ name ]( elem ) :
+                                       elem[ name ] != null ?
+                                               elem[ name ] :
+                                               elem.getAttribute( name ),
+                               value = result + "",
+                               type = match[2],
+                               check = match[4];
+
                        return result == null ?
                                type === "!=" :
                                type === "=" ?
@@ -573,8 +582,8 @@ var Expr = Sizzle.selectors = {
                                value.indexOf(check) >= 0 :
                                type === "~=" ?
                                (" " + value + " ").indexOf(check) >= 0 :
-                               !match[4] ?
-                               result :
+                               !check ?
+                               value && result !== false :
                                type === "!=" ?
                                value != check :
                                type === "^=" ?
@@ -703,7 +712,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 +750,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++ ) {