X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fselector.js;h=7840442da31a75f9dc35be5c9d60b0f7195768c4;hb=06eb4d3223c4eee4223fbb084033dadfeae12f34;hp=bfd8bef1ec76e833592dd970f48861d6a8ae7b4a;hpb=bd4154879270c872e331054a9c481ca0d318517c;p=jquery.git diff --git a/src/selector.js b/src/selector.js index bfd8bef..7840442 100644 --- a/src/selector.js +++ b/src/selector.js @@ -64,7 +64,7 @@ jQuery.extend({ animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;} } }, - + // The regular expressions that power the parsing engine parse: [ // Match: [@value='test'], [@foo] @@ -73,7 +73,7 @@ jQuery.extend({ // Match: :contains('foo') /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, - // Match: :even, :last-chlid, #id, .class + // Match: :even, :last-child, #id, .class new RegExp("^([:.#]*)(" + chars + "+)") ], @@ -118,7 +118,7 @@ jQuery.extend({ // An attempt at speeding up child selectors that // point to a specific element tag re = quickChild, - + m = re.exec(t); if ( m ) { @@ -151,12 +151,12 @@ jQuery.extend({ var id = jQuery.data(n); if ( m == "~" && merge[id] ) break; - + if (!nodeName || n.nodeName.toUpperCase() == nodeName ) { if ( m == "~" ) merge[id] = true; r.push( n ); } - + if ( m == "+" ) break; } } @@ -190,7 +190,7 @@ jQuery.extend({ // Optimize for the case nodeName#idName var re2 = quickID; var m = re2.exec(t); - + // Re-organize the results, so that they're consistent if ( m ) { m = [ 0, m[2], m[3], m[1] ]; @@ -210,7 +210,7 @@ jQuery.extend({ if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) { // Optimization for HTML document case var oid = elem.getElementById(m[2]); - + // Do a quick check for the existence of the actual ID attribute // to avoid selecting by the name attribute in IE // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form @@ -331,31 +331,25 @@ jQuery.extend({ r = jQuery.classFilter(r, m[2], not); else if ( m[1] == "[" ) { - var type = m[3]; - - // special case, filter by exact name - if ( !not && m[2] == 'name' && type == '=' ) - r = jQuery.grep( document.getElementsByName(m[5]), function(elem){ - return jQuery.inArray( elem, r ) != -1; - }); - else { - for ( var i = 0, rl = r.length, tmp = []; i < rl; i++ ) { - var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; - - if ( z == null || /href|src|selected/.test(m[2]) ) - z = jQuery.attr(a,m[2]) || ''; - - if ( (type == "" && !!z || - type == "=" && z == m[5] || - type == "!=" && z != m[5] || - type == "^=" && z && !z.indexOf(m[5]) || - type == "$=" && z.substr(z.length - m[5].length) == m[5] || - (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not ) - tmp.push( a ); - } - r = tmp; + var tmp = [], type = m[3]; + + for ( var i = 0, rl = r.length; i < rl; i++ ) { + var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; + + if ( z == null || /href|src|selected/.test(m[2]) ) + z = jQuery.attr(a,m[2]) || ''; + + if ( (type == "" && !!z || + type == "=" && z == m[5] || + type == "!=" && z != m[5] || + type == "^=" && z && !z.indexOf(m[5]) || + type == "$=" && z.substr(z.length - m[5].length) == m[5] || + (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not ) + tmp.push( a ); } + r = tmp; + // We can get a speed boost by handling nth-child here } else if ( m[1] == ":" && m[2] == "nth-child" ) { var merge = {}, tmp = [], @@ -365,7 +359,7 @@ jQuery.extend({ !/\D/.test(m[3]) && "0n+" + m[3] || m[3]), // calculate the numbers (first)n+(last) including if they are negative first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0; - + // loop through all the elements left in the jQuery object for ( var i = 0, rl = r.length; i < rl; i++ ) { var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode); @@ -425,7 +419,7 @@ jQuery.extend({ } return matched; }, - + nth: function(cur,result,dir,elem){ result = result || 1; var num = 0; @@ -436,12 +430,12 @@ jQuery.extend({ return cur; }, - + sibling: function( n, elem ) { var r = []; for ( ; n; n = n.nextSibling ) { - if ( n.nodeType == 1 && (!elem || n != elem) ) + if ( n.nodeType == 1 && n != elem ) r.push( n ); }