X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector.js;h=5425d94821db4d0c2b4adf53018aa4f4e0b36469;hb=d1a34f79081dfcfcfe851412dafd172428a6d92a;hp=6a629bd59bf12a5e3499c96543e6b956241e9d4b;hpb=f9a584972365bda0631116ec6fe07df9b6f9c372;p=jquery.git diff --git a/src/selector.js b/src/selector.js index 6a629bd..5425d94 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1,5 +1,5 @@ /*! - * 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/ @@ -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]); @@ -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); }; @@ -721,7 +724,9 @@ if ( document.querySelectorAll ) (function(){ 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){}