contains: "jQuery.fn.text.apply([a]).indexOf(m[3])>=0",
// Visibility
- visible: 'a.type!="hidden"&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
- hidden: 'a.type=="hidden"||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
+ visible: '"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden"',
+ hidden: '"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden"',
// Form attributes
enabled: "!a.disabled",
selected: "a.selected||jQuery.attr(a,'selected')",
// Form elements
- text: "a.type=='text'",
- radio: "a.type=='radio'",
- checkbox: "a.type=='checkbox'",
- file: "a.type=='file'",
- password: "a.type=='password'",
- submit: "a.type=='submit'",
- image: "a.type=='image'",
- reset: "a.type=='reset'",
- button: 'a.type=="button"||jQuery.nodeName(a,"button")',
+ text: "'text'==a.type",
+ radio: "'radio'==a.type",
+ checkbox: "'checkbox'==a.type",
+ file: "'file'==a.type",
+ password: "'password'==a.type",
+ submit: "'submit'==a.type",
+ image: "'image'==a.type",
+ reset: "'reset'==a.type",
+ button: '"button"==a.type||jQuery.nodeName(a,"button")',
input: "/input|select|textarea|button/i.test(a.nodeName)"
},
".": "jQuery.className.has(a,m[2])",
_resort: function(m){
return ["", m[1], m[3], m[2], m[5]];
},
- _prefix: "z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);"
+ _prefix: "var z=a[m[3]];if(!z||/href|src/.test(m[3]))z=jQuery.attr(a,m[3]);"
},
"[": "jQuery.find(m[2],a).length"
},
// The regular expressions that power the parsing engine
parse: [
// Match: [@value='test'], [@foo]
- /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/i,
+ /^\[ *(@)([\w-]+) *([!*$^=]*) *('?"?)(.*?)\4 *\]/,
// Match: [div], [div p]
/^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
// Match: :contains('foo')
- /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/i,
+ /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
// Match: :even, :last-chlid, #id, .class
- /^([:.#]*)((?:[\w\u0128-\uFFFF*-]|\\.)+)/i
+ new RegExp("^([:.#]*)(" +
+ ( jQuery.chars = "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)" ) + "+)")
],
token: [
// An attempt at speeding up child selectors that
// point to a specific element tag
- var re = /^[\/>]\s*([\w*-]+)/i;
+ var re = new RegExp("^[/>]\\s*(" + jQuery.chars + "+)");
var m = re.exec(t);
if ( m ) {
// Perform our own iteration and filter
- jQuery.each( ret, function(){
- for ( var c = this.firstChild; c; c = c.nextSibling )
- if ( c.nodeType == 1 && ( jQuery.nodeName(c, m[1]) || m[1] == "*" ) )
+ for ( var i = 0; ret[i]; i++ )
+ for ( var c = ret[i].firstChild; c; c = c.nextSibling )
+ if ( c.nodeType == 1 && ( m[1] == "*" || jQuery.nodeName(c, m[1]) ) )
r.push( c );
- });
ret = r;
t = t.replace( re, "" );
foundToken = true;
} else {
// Look for pre-defined expression tokens
- for ( var i = 0; i < jQuery.token.length; i += 2 ) {
+ for ( var i = 0, tl = jQuery.token.length; i < tl; i += 2 ) {
// Attempt to match each, individual, token in
// the specified order
- var re = jQuery.token[i];
+ var re = jQuery.token[i], fn = jQuery.token[i+1];
var m = re.exec(t);
// If the token match was found
if ( m ) {
// Map it against the token's handler
- r = ret = jQuery.map( ret, jQuery.isFunction( jQuery.token[i+1] ) ?
- jQuery.token[i+1] :
- function(a){ return eval(jQuery.token[i+1]); });
+ r = ret = jQuery.map( ret, jQuery.isFunction( fn ) ?
+ fn : new Function( "a", "return " + fn ) );
// And remove the token
t = jQuery.trim( t.replace( re, "" ) );
// Handle multiple expressions
if ( !t.indexOf(",") ) {
// Clean the result set
- if ( ret[0] == context ) ret.shift();
+ if ( context == ret[0] ) ret.shift();
// Merge the result sets
done = jQuery.merge( done, ret );
} else {
// Optomize for the case nodeName#idName
- var re2 = /^(\w+)(#)((?:[\w\u0128-\uFFFF*-]|\\.)+)/i;
+ var re2 = new RegExp("^(" + jQuery.chars + "+)(#)(" + jQuery.chars + "+)");
var m = re2.exec(t);
// Re-organize the results, so that they're consistent
} else {
// Otherwise, do a traditional filter check for
// ID, class, and element selectors
- re2 = /^([#.]?)((?:[\w\u0128-\uFFFF*-]|\\.)*)/i;
+ re2 = new RegExp("^([#.]?)(" + jQuery.chars + "*)");
m = re2.exec(t);
}
// Do a quick check for the existence of the actual ID attribute
// to avoid selecting by the name attribute in IE
- if ( jQuery.browser.msie && oid && oid.id != m[2] )
+ // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
+ if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
// Do a quick check for node name (where applicable) so
// that div#foo searches will be really fast
ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
-
} else {
- // We need to find all descendant elements, it is more
- // efficient to use getAll() when we are already further down
- // the tree - we try to recognize that here
- for ( var i = 0, rl = ret.length; i < rl; i++ ) {
+ // We need to find all descendant elements
+ for ( var i = 0; ret[i]; i++ ) {
// Grab the tag name being searched for
var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
// It's faster to filter by class and be done with it
if ( m[1] == "." )
- r = jQuery.grep( r, function(e) {
- return jQuery.className.has(e, m[2]);
- });
+ r = jQuery.classFilter( r, m[2] );
// Same with ID filtering
if ( m[1] == "#" ) {
- // Remember, then wipe out, the result set
- var tmp = r;
- r = [];
-
- // Then try to find the element with the ID
- jQuery.each( tmp, function(){
- if ( this.getAttribute("id") == m[2] ) {
- r = [ this ];
- return false;
+ var tmp = [];
+
+ // Try to find the element with the ID
+ for ( var i = 0; r[i]; i++ )
+ if ( r[i].getAttribute("id") == m[2] ) {
+ tmp = [ r[i] ];
+ break;
}
- });
+
+ r = tmp;
}
ret = r;
ret = [];
// Remove the root context
- if ( ret && ret[0] == context )
+ if ( ret && context == ret[0] )
ret.shift();
// And combine the results
return done;
},
+ classFilter: function(r,m,not){
+ m = " " + m + " ";
+ var tmp = [];
+ for ( var i = 0; r[i]; i++ ) {
+ var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
+ if ( !not && pass || not && !pass )
+ tmp.push( r[i] );
+ }
+ return tmp;
+ },
+
filter: function(t,r,not) {
var last;
var p = jQuery.parse, m;
- jQuery.each( p, function(i,re){
-
- // Look for, and replace, string-like sequences
- // and finally build a regexp out of it
- m = re.exec( t );
+ for ( var i = 0; p[i]; i++ ) {
+ m = p[i].exec( t );
if ( m ) {
// Remove what we just matched
m[2] = m[2].replace(/\\/g, "");
- return false;
+ break;
}
- });
+ }
if ( !m )
- continue;
+ break;
// :not() is a special case that can be optimized by
// keeping it out of the expression list
if ( m[1] == ":" && m[2] == "not" )
r = jQuery.filter(m[3], r, true).r;
+ // We can get a big speed boost by filtering by class here
+ else if ( m[1] == "." )
+ r = jQuery.classFilter(r, m[2], not);
+
// Otherwise, find the expression to execute
else {
var f = jQuery.expr[m[1]];
for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType == 1 ) num++;
if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
- result == "odd" && num % 2 == 1 && cur == elem ) return cur;
+ result == "odd" && num % 2 == 1 && cur == elem ) break;
}
+ return cur;
},
/**