X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector.js;h=d580c5ae5d0ade96abec0d8f4d9ce54eb6a3bfb4;hb=f38648c7cd3a37f4070b77b2c92151f68aa66fef;hp=6b68cb28bc1352a62b81a3e7597a3380e1696e63;hpb=db10da345e84e86d66a613e33e97916a7facb94f;p=jquery.git diff --git a/src/selector.js b/src/selector.js index 6b68cb2..d580c5a 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1,12 +1,12 @@ /*! - * Sizzle CSS Selector Engine - v0.9.1 + * 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/ */ (function(){ -var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]+['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g, +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g, done = 0, toString = Object.prototype.toString; @@ -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]); @@ -495,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; @@ -564,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 === "*=" ? @@ -653,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; }; } @@ -701,7 +703,8 @@ try { // Check to see if an attribute returns normalized href attributes div.innerHTML = ""; - 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); }; @@ -709,12 +712,21 @@ try { })(); if ( document.querySelectorAll ) (function(){ - var oldSizzle = Sizzle; + var oldSizzle = Sizzle, div = document.createElement("div"); + div.innerHTML = "

"; + + // 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){} @@ -729,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 = "
"; + + // 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++ ) {