Side navigation
Ticket #1960: filterByName2.diff
File filterByName2.diff, 1.8 KB (added by flesler, April 22, 2008 11:58PM UTC)
Somewhat shorter, skips not's
Index: src/selector.js
===================================================================
--- src/selector.js (revision 5279)
+++ src/selector.js (working copy)
@@ -331,24 +331,30 @@
r = jQuery.classFilter(r, m[2], not);
else if ( m[1] == "[" ) {
- var tmp = [], type = m[3];
+ var 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 );
+ if( !not && m[2] == 'name' && type == '=' )//special case, filter by exact name
+ 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;
}
-
- r = tmp;
// We can get a speed boost by handling nth-child here
} else if ( m[1] == ":" && m[2] == "nth-child" ) {
Download in other formats:
Original Format
File filterByName2.diff, 1.8 KB (added by flesler, April 22, 2008 11:58PM UTC)
Somewhat shorter, skips not's
Index: src/selector.js
===================================================================
--- src/selector.js (revision 5279)
+++ src/selector.js (working copy)
@@ -331,24 +331,30 @@
r = jQuery.classFilter(r, m[2], not);
else if ( m[1] == "[" ) {
- var tmp = [], type = m[3];
+ var 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 );
+ if( !not && m[2] == 'name' && type == '=' )//special case, filter by exact name
+ 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;
}
-
- r = tmp;
// We can get a speed boost by handling nth-child here
} else if ( m[1] == ":" && m[2] == "nth-child" ) {