Commit c85243df authored by John Resig's avatar John Resig

Landing the new Sizzle selector engine. There'll need to be some later tweaks...

Landing the new Sizzle selector engine. There'll need to be some later tweaks (to make the tests a little more pragmatic - especially for document order elements). But it appears to be passing well and that's enough. Closes #3563.
parent 5c1725d6
...@@ -333,7 +333,9 @@ jQuery.fn = jQuery.prototype = { ...@@ -333,7 +333,9 @@ jQuery.fn = jQuery.prototype = {
return selector.call( elem, i ); return selector.call( elem, i );
}) || }) ||
jQuery.multiFilter( selector, this ), "filter", selector ); jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
return elem.nodeType === 1;
}) ), "filter", selector );
}, },
not: function( selector ) { not: function( selector ) {
...@@ -1332,7 +1334,7 @@ jQuery.each({ ...@@ -1332,7 +1334,7 @@ jQuery.each({
}, },
remove: function( selector ) { remove: function( selector ) {
if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) { if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
// Prevent memory leaks // Prevent memory leaks
jQuery( "*", this ).add([this]).each(function(){ jQuery( "*", this ).add([this]).each(function(){
jQuery.event.remove(this); jQuery.event.remove(this);
......
var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ? /*
"(?:[\\w*_-]|\\\\.)" : * Sizzle CSS Selector Engine - v0.9
"(?:[\\w\u0128-\uFFFF*_-]|\\\\.)", * Copyright 2009, John Resig (http://ejohn.org/)
quickChild = new RegExp("^>\\s*(" + chars + "+)"), * released under the MIT License
quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"), */
quickClass = new RegExp("^([#.]?)(" + chars + "*)"); (function(){
jQuery.extend({ var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]+\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g;
expr: {
"": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);}, var cache = null;
"#": function(a,i,m){return a.getAttribute("id")==m[2];}, var done = 0;
":": {
// Position Checks if ( document.addEventListener && !document.querySelectorAll ) {
lt: function(a,i,m){return i<m[3]-0;}, cache = {};
gt: function(a,i,m){return i>m[3]-0;}, function invalidate(){ cache = {}; }
nth: function(a,i,m){return m[3]-0==i;}, document.addEventListener("DOMAttrModified", invalidate, false);
eq: function(a,i,m){return m[3]-0==i;}, document.addEventListener("DOMNodeInserted", invalidate, false);
first: function(a,i){return i==0;}, document.addEventListener("DOMNodeRemoved", invalidate, false);
last: function(a,i,m,r){return i==r.length-1;}, }
even: function(a,i){return i%2==0;},
odd: function(a,i){return i%2;}, var Sizzle = function(selector, context, results, seed) {
var doCache = !results;
// Child Checks results = results || [];
"first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;}, context = context || document;
"last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
"only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");}, if ( context.nodeType !== 1 && context.nodeType !== 9 )
return [];
// Parent Checks
parent: function(a){return a.firstChild;}, if ( !selector || typeof selector !== "string" ) {
empty: function(a){return !a.firstChild;}, return results;
}
// Text Check
contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;}, if ( cache && context === document && cache[ selector ] ) {
results.push.apply( results, cache[ selector ] );
// Visibility return results;
visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";}, }
hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
var parts = [], m, set, checkSet, check, mode, extra;
// Form attributes
enabled: function(a){return !a.disabled;}, // Reset the position of the chunker regexp (start from head)
disabled: function(a){return a.disabled;}, chunker.lastIndex = 0;
checked: function(a){return a.checked;},
selected: function(a){return a.selected||jQuery.attr(a,"selected");}, while ( (m = chunker.exec(selector)) !== null ) {
parts.push( m[1] );
// Form elements
text: function(a){return "text"==a.type;}, if ( m[2] ) {
radio: function(a){return "radio"==a.type;}, extra = RegExp.rightContext;
checkbox: function(a){return "checkbox"==a.type;}, break;
file: function(a){return "file"==a.type;},
password: function(a){return "password"==a.type;},
submit: function(a){return "submit"==a.type;},
image: function(a){return "image"==a.type;},
reset: function(a){return "reset"==a.type;},
button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
// :has()
has: function(a,i,m){return jQuery.find(m[3],a).length;},
// :header
header: function(a){return /h\d/i.test(a.nodeName);},
// :animated
animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
} }
}, }
// The regular expressions that power the parsing engine if ( parts.length > 1 && Expr.match.POS.exec( selector ) ) {
parse: [ if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
// Match: [@value='test'], [@foo] var later = "", match;
/^(\[) *@?([\w:-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
// Match: :contains('foo') // Position selectors must be done after the filter
/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, while ( (match = Expr.match.POS.exec( selector )) ) {
later += match[0];
selector = selector.replace( Expr.match.POS, "" );
}
// Match: :even, :last-child, #id, .class checkSet = Sizzle.filter( later, Sizzle( selector, context, results ) );
new RegExp("^([:.#]*)(" + chars + "+)") } else {
], checkSet = Expr.relative[ parts[0] ] ?
[ context ] :
Sizzle( parts.shift(), context );
multiFilter: function( expr, elems, not ) { while ( parts.length ) {
var old, cur = []; set = [];
while ( expr && expr != old ) { selector = parts.shift();
old = expr; if ( Expr.relative[ selector ] )
var f = jQuery.filter( expr, elems, not ); selector += parts.shift();
expr = f.t.replace(/^\s*,\s*/, "" );
cur = not ? elems = f.r : jQuery.merge( cur, f.r );
}
return cur; for ( var i = 0, l = checkSet.length; i < l; i++ ) {
}, Sizzle( selector, checkSet[i], set );
}
find: function( t, context ) { checkSet = set;
// Quickly handle non-string expressions }
if ( typeof t !== "string" ) }
return [ t ]; } else {
var ret = seed ?
{ expr: parts.pop(), set: makeArray(seed) } :
Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context );
set = Sizzle.filter( ret.expr, ret.set );
if ( parts.length > 0 ) {
checkSet = makeArray(set);
}
// check to make sure context is a DOM element or a document while ( parts.length ) {
if ( context && context.nodeType != 1 && context.nodeType != 9) var cur = parts.pop(), pop = cur;
return [ ];
// Set the correct context (if none is provided) if ( !Expr.relative[ cur ] ) {
context = context || document; cur = "";
} else {
pop = parts.pop();
}
// Initialize the search if ( pop == null ) {
var ret = [context], done = [], last, nodeName; pop = context;
}
// Continue while a selector expression exists, and while Expr.relative[ cur ]( checkSet, pop );
// we're no longer looping upon ourselves }
while ( t && last != t ) {
var r = [];
last = t;
t = jQuery.trim(t); if ( !checkSet ) {
checkSet = set;
}
}
var foundToken = false, if ( !checkSet ) {
throw "Syntax error, unrecognized expression: " + (cur || selector);
}
// An attempt at speeding up child selectors that if ( checkSet instanceof Array ) {
// point to a specific element tag if ( context.nodeType === 1 ) {
re = quickChild, for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
results.push( set[i] );
}
}
} else {
for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
results.push( set[i] );
}
}
}
} else {
makeArray( checkSet, results );
}
m = re.exec(t); if ( extra ) {
Sizzle( extra, context, results );
}
if ( m ) { if ( cache && doCache ) {
nodeName = m[1].toUpperCase(); cache[selector] = results.slice(0);
}
// Perform our own iteration and filter return results;
for ( var i = 0; ret[i]; i++ ) };
for ( var c = ret[i].firstChild; c; c = c.nextSibling )
if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
r.push( c );
ret = r; Sizzle.matches = function(expr, set){
t = t.replace( re, "" ); return Sizzle(expr, null, null, set);
if ( t.indexOf(" ") == 0 ) continue; };
foundToken = true;
} else {
re = /^([>+~])\s*(\w*)/i;
if ( (m = re.exec(t)) != null ) { Sizzle.find = function(expr, context){
r = []; var set, match;
var merge = {}; if ( !expr ) {
nodeName = m[2].toUpperCase(); return [];
m = m[1]; }
for ( var j = 0, rl = ret.length; j < rl; j++ ) { var later = "", match;
var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
for ( ; n; n = n.nextSibling )
if ( n.nodeType == 1 ) {
var id = jQuery.data(n);
if ( m == "~" && merge[id] ) break; // Pseudo-selectors could contain other selectors (like :not)
while ( (match = Expr.match.PSEUDO.exec( expr )) ) {
var left = RegExp.leftContext;
if (!nodeName || n.nodeName.toUpperCase() == nodeName ) { if ( left.substr( left.length - 1 ) !== "\\" ) {
if ( m == "~" ) merge[id] = true; later += match[0];
r.push( n ); expr = expr.replace( Expr.match.PSEUDO, "" );
} } else {
// TODO: Need a better solution, fails: .class\:foo:realfoo(#id)
break;
}
}
if ( m == "+" ) break; for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
} var type = Expr.order[i];
}
if ( (match = Expr.match[ type ].exec( expr )) ) {
var left = RegExp.leftContext;
ret = r; if ( left.substr( left.length - 1 ) !== "\\" ) {
match[1] = (match[1] || "").replace(/\\/g, "");
set = Expr.find[ type ]( match, context );
// And remove the token if ( set != null ) {
t = jQuery.trim( t.replace( re, "" ) ); expr = expr.replace( Expr.match[ type ], "" );
foundToken = true; break;
} }
} }
}
}
// See if there's still an expression, and that we haven't already if ( !set ) {
// matched a token set = context.getElementsByTagName("*");
if ( t && !foundToken ) { }
// Handle multiple expressions
if ( !t.indexOf(",") ) {
// Clean the result set
if ( context == ret[0] ) ret.shift();
// Merge the result sets
done = jQuery.merge( done, ret );
// Reset the context
r = ret = [context];
// Touch up the selector string
t = " " + t.substr(1,t.length);
} else {
// 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] ];
} else {
// Otherwise, do a traditional filter check for
// ID, class, and element selectors
re2 = quickClass;
m = re2.exec(t);
}
m[2] = m[2].replace(/\\/g, ""); expr += later;
var elem = ret[ret.length-1]; return {set: set, expr: expr};
};
// Try to do a global search by ID, where we can Sizzle.filter = function(expr, set, inplace){
if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) { var old = expr, result = [], curLoop = set, match;
// Optimization for HTML document case
var oid = elem.getElementById(m[2]);
// Do a quick check for the existence of the actual ID attribute while ( expr && set.length ) {
// to avoid selecting by the name attribute in IE for ( var type in Expr.filter ) {
// also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form if ( (match = Expr.match[ type ].exec( expr )) != null ) {
if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id === "string" && oid.id != m[2] ) var anyFound = false, filter = Expr.filter[ type ], goodArray = null;
oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
// Do a quick check for node name (where applicable) so if ( curLoop == result ) {
// that div#foo searches will be really fast result = [];
ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : []; }
} else {
// 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[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
// Handle IE7 being really dumb about <object>s if ( Expr.preFilter[ type ] ) {
if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" ) match = Expr.preFilter[ type ]( match, curLoop );
tag = "param";
r = jQuery.merge( r, ret[i].getElementsByTagName( tag )); if ( match[0] === true ) {
goodArray = [];
var last = null, elem;
for ( var i = 0; (elem = curLoop[i]) !== undefined; i++ ) {
if ( elem && last !== elem ) {
goodArray.push( elem );
last = elem;
}
} }
}
// It's faster to filter by class and be done with it }
if ( m[1] == "." )
r = jQuery.classFilter( r, m[2] );
// Same with ID filtering var goodPos = 0, found, item;
if ( m[1] == "#" ) {
var tmp = [];
// Try to find the element with the ID for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) {
for ( var i = 0; r[i]; i++ ) if ( item ) {
if ( r[i].getAttribute("id") == m[2] ) { if ( goodArray && item != goodArray[goodPos] ) {
tmp = [ r[i] ]; goodPos++;
break; }
}
r = tmp; found = filter( item, match, goodPos, goodArray );
if ( inplace && found != null ) {
curLoop[i] = found ? curLoop[i] : false;
if ( found ) {
anyFound = true;
}
} else if ( found ) {
result.push( item );
anyFound = true;
} }
}
}
ret = r; if ( found !== undefined ) {
if ( !inplace ) {
curLoop = result;
} }
t = t.replace( re2, "" ); expr = expr.replace( Expr.match[ type ], "" );
}
} if ( !anyFound ) {
return [];
}
// If a selector string still exists break;
if ( t ) { }
// Attempt to filter it
var val = jQuery.filter(t,r);
ret = r = val.r;
t = jQuery.trim(val.t);
} }
} }
// An error occurred with the selector;
// just return an empty set instead
if ( t )
ret = [];
// Remove the root context expr = expr.replace(/\s*,\s*/, "");
if ( ret && context == ret[0] )
ret.shift();
// And combine the results // Improper expression
done = jQuery.merge( done, ret ); if ( expr == old ) {
throw "Syntax error, unrecognized expression: " + expr;
}
return done; old = expr;
}
return curLoop;
};
var Expr = Sizzle.selectors = {
order: [ "ID", "NAME", "TAG" ],
match: {
ID: /#((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
CLASS: /\.((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
NAME: /\[name=((?:[\w\u0128-\uFFFF_-]|\\.)+)\]/,
ATTR: /\[((?:[\w\u0128-\uFFFF_-]|\\.)+)\s*(?:(\S{0,1}=)\s*(['"]*)(.*?)\3|)\]/,
TAG: /^((?:[\w\u0128-\uFFFF\*_-]|\\.)+)/,
CHILD: /:(only|nth|last|first)-child\(?(even|odd|[\dn+-]*)\)?/,
POS: /:(nth|eq|gt|lt|first|last|even|odd)\(?(\d*)\)?(?:[^-]|$)/,
PSEUDO: /:((?:[\w\u0128-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
}, },
attrMap: {
"class": "className"
},
relative: {
"+": function(checkSet, part){
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
var cur = elem.previousSibling;
while ( cur && cur.nodeType !== 1 ) {
cur = cur.previousSibling;
}
checkSet[i] = typeof part === "string" ?
cur || false :
cur === part;
}
}
if ( typeof part === "string" ) {
Sizzle.filter( part, checkSet, true );
}
},
">": function(checkSet, part){
if ( typeof part === "string" && !/\W/.test(part) ) {
part = part.toUpperCase();
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
var parent = elem.parentNode;
checkSet[i] = parent.nodeName === part ? parent : false;
}
}
} else {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
checkSet[i] = typeof part === "string" ?
elem.parentNode :
elem.parentNode === part;
}
}
classFilter: function(r,m,not){ if ( typeof part === "string" ) {
m = " " + m + " "; Sizzle.filter( part, checkSet, true );
var tmp = []; }
for ( var i = 0; r[i]; i++ ) { }
var pass = (" " + r[i].className + " ").indexOf( m ) >= 0; },
if ( !not && pass || not && !pass ) "": function(checkSet, part){
tmp.push( r[i] ); var doneName = "done" + (done++), checkFn = dirCheck;
if ( !part.match(/\W/) ) {
var nodeCheck = part = part.toUpperCase();
checkFn = dirNodeCheck;
}
checkFn("parentNode", part, doneName, checkSet, nodeCheck);
},
"~": function(checkSet, part){
var doneName = "done" + (done++), checkFn = dirCheck;
if ( typeof part === "string" && !part.match(/\W/) ) {
var nodeCheck = part = part.toUpperCase();
checkFn = dirNodeCheck;
}
checkFn("previousSibling", part, doneName, checkSet, nodeCheck);
}
},
find: {
ID: function(match, context){
if ( context.getElementById ) {
var m = context.getElementById(match[1]);
return m ? [m] : [];
}
},
NAME: function(match, context){
return context.getElementsByName(match[1]);
},
TAG: function(match, context){
return context.getElementsByTagName(match[1]);
} }
return tmp;
}, },
preFilter: {
CLASS: function(match){
return new RegExp( "(?:^|\\s)" + match[1] + "(?:\\s|$)" );
},
ID: function(match){
return match[1];
},
TAG: function(match){
return match[1].toUpperCase();
},
CHILD: function(match){
if ( match[1] == "nth" ) {
// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
// calculate the numbers (first)n+(last) including if they are negative
match[2] = (test[1] + (test[2] || 1)) - 0;
match[3] = test[3] - 0;
}
filter: function(t,r,not) { // TODO: Move to normal caching system
var last; match[0] = "done" + (done++);
// Look for common filter expressions return match;
while ( t && t != last ) { },
last = t; ATTR: function(match){
var name = match[1];
if ( Expr.attrMap[name] ) {
match[1] = Expr.attrMap[name];
}
var p = jQuery.parse, m; if ( match[2] === "~=" ) {
match[4] = " " + match[4] + " ";
}
for ( var i = 0; p[i]; i++ ) { return match;
m = p[i].exec( t ); },
PSEUDO: function(match){
if ( match[1] === "not" ) {
match[3] = match[3].split(/\s*,\s*/);
}
return match;
},
POS: function(match){
match.unshift( true );
return match;
}
},
filters: {
enabled: function(elem){
return elem.disabled === false && elem.type !== "hidden";
},
disabled: function(elem){
return elem.disabled === true;
},
checked: function(elem){
return elem.checked === true;
},
selected: function(elem){
// Accessing this property makes selected-by-default
// options in Safari work properly
elem.parentNode.selectedIndex;
return elem.selected === true;
},
parent: function(elem){
return !!elem.firstChild;
},
empty: function(elem){
return !elem.firstChild;
},
has: function(elem, i, match){
return !!Sizzle( match[3], elem ).length;
},
header: function(elem){
return /h\d/i.test( elem.nodeName );
},
text: function(elem){
return "text" === elem.type;
},
radio: function(elem){
return "radio" === elem.type;
},
checkbox: function(elem){
return "checkbox" === elem.type;
},
file: function(elem){
return "file" === elem.type;
},
password: function(elem){
return "password" === elem.type;
},
submit: function(elem){
return "submit" === elem.type;
},
image: function(elem){
return "image" === elem.type;
},
reset: function(elem){
return "reset" === elem.type;
},
button: function(elem){
return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
},
input: function(elem){
return /input|select|textarea|button/i.test(elem.nodeName);
}
},
setFilters: {
first: function(elem, i){
return i === 0;
},
last: function(elem, i, match, array){
return i === array.length - 1;
},
even: function(elem, i){
return i % 2 === 0;
},
odd: function(elem, i){
return i % 2 === 1;
},
lt: function(elem, i, match){
return i < match[3] - 0;
},
gt: function(elem, i, match){
return i > match[3] - 0;
},
nth: function(elem, i, match){
return match[3] - 0 == i;
},
eq: function(elem, i, match){
return match[3] - 0 == i;
}
},
filter: {
CHILD: function(elem, match){
var type = match[1], parent = elem.parentNode;
var doneName = match[0];
if ( parent && !parent[ doneName ] ) {
var count = 1;
for ( var node = parent.firstChild; node; node = node.nextSibling ) {
if ( node.nodeType == 1 ) {
node.nodeIndex = count++;
}
}
if ( m ) { parent[ doneName ] = count - 1;
// Remove what we just matched }
t = t.substring( m[0].length );
m[2] = m[2].replace(/\\/g, ""); if ( type == "first" ) {
break; return elem.nodeIndex == 1;
} else if ( type == "last" ) {
return elem.nodeIndex == parent[ doneName ];
} else if ( type == "only" ) {
return parent[ doneName ] == 1;
} else if ( type == "nth" ) {
var add = false, first = match[2], last = match[3];
if ( first == 1 && last == 0 ) {
return true;
}
if ( first == 0 ) {
if ( elem.nodeIndex == last ) {
add = true;
}
} else if ( (elem.nodeIndex - last) % first == 0 && (elem.nodeIndex - last) / first >= 0 ) {
add = true;
}
return add;
}
},
PSEUDO: function(elem, match, i, array){
var name = match[1], filter = Expr.filters[ name ];
if ( filter ) {
return filter( elem, i, match, array )
} else if ( name === "contains" ) {
return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
} else if ( name === "not" ) {
var not = match[3];
for ( var i = 0, l = not.length; i < l; i++ ) {
if ( Sizzle.filter(not[i], [elem]).length > 0 ) {
return false;
}
} }
return true;
}
},
ID: function(elem, match){
return elem.nodeType === 1 && elem.getAttribute("id") === match;
},
TAG: function(elem, match){
return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
},
CLASS: function(elem, match){
return match.test( elem.className );
},
ATTR: function(elem, match){
var result = elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
return result == null ?
false :
type === "=" ?
value === check :
type === "*=" ?
value.indexOf(check) >= 0 :
type === "~=" ?
(" " + value + " ").indexOf(check) >= 0 :
!match[4] ?
result :
type === "!=" ?
value != check :
type === "^=" ?
value.indexOf(check) === 0 :
type === "$=" ?
value.substr(value.length - check.length) === check :
type === "|=" ?
value === check || value.substr(0, check.length + 1) === check + "-" :
false;
},
POS: function(elem, match, i, array){
var name = match[2], filter = Expr.setFilters[ name ];
if ( filter ) {
return filter( elem, i, match, array );
} }
}
}
};
var makeArray = function(array, results) {
array = Array.prototype.slice.call( array );
if ( !m ) if ( results ) {
break; results.push.apply( results, array );
return results;
// :not() is a special case that can be optimized by }
// keeping it out of the expression list
if ( m[1] == ":" && m[2] == "not" ) return array;
// optimize if only one selector found (most common case) };
r = isSimple.test( m[3] ) ?
jQuery.filter(m[3], r, true).r : // Perform a simple check to determine if the browser is capable of
jQuery( r ).not( m[3] ); // converting a NodeList to an array using builtin methods.
try {
// We can get a big speed boost by filtering by class here Array.prototype.slice.call( document.documentElement.childNodes );
else if ( m[1] == "." )
r = jQuery.classFilter(r, m[2], not); // Provide a fallback method if it does not work
} catch(e){
else if ( m[1] == "[" ) { makeArray = function(array, results) {
var tmp = [], type = m[3]; var ret = results || [];
for ( var i = 0, rl = r.length; i < rl; i++ ) { if ( array instanceof Array ) {
var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; Array.prototype.push.apply( ret, array );
} else {
if ( z == null || /style|href|src|selected/.test(m[2]) ) if ( typeof array.length === "number" ) {
z = jQuery.attr(a,m[2]) || ''; for ( var i = 0, l = array.length; i < l; i++ ) {
ret.push( array[i] );
if ( (type == "" && !!z || }
type == "=" && z == m[5] || } else {
type == "!=" && z != m[5] || for ( var i = 0; array[i]; i++ ) {
type == "^=" && z && !z.indexOf(m[5]) || ret.push( array[i] );
type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
(type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
tmp.push( a );
} }
}
}
r = tmp; return ret;
};
}
// Check to see if the browser returns elements by name when
// querying by getElementById (and provide a workaround)
(function(){
// We're going to inject a fake input element with a specified name
var form = document.createElement("form"),
id = "script" + (new Date).getTime();
form.innerHTML = "<input name='" + id + "'/>";
// Inject it into the root element, check its status, and remove it quickly
var root = document.documentElement;
root.insertBefore( form, root.firstChild );
// 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 ) {
var m = context.getElementById(match[1]);
return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
}
};
Expr.filter.ID = function(elem, match){
var node = elem.getAttributeNode && elem.getAttributeNode("id");
return elem.nodeType === 1 && node && node.nodeValue === match;
};
}
// We can get a speed boost by handling nth-child here root.removeChild( form );
} else if ( m[1] == ":" && m[2] == "nth-child" ) { })();
var merge = {}, tmp = [],
// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
!/\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 // Check to see if the browser returns only elements
for ( var i = 0, rl = r.length; i < rl; i++ ) { // when doing getElementsByTagName("*")
var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode); (function(){
// Create a fake element
var div = document.createElement("div");
div.appendChild( document.createComment("") );
if ( !merge[id] ) { // Make sure no comments are found
var c = 1; if ( div.getElementsByTagName("*").length > 0 ) {
Expr.find.TAG = function(match, context){
var results = context.getElementsByTagName(match[1]);
for ( var n = parentNode.firstChild; n; n = n.nextSibling ) // Filter out possible comments
if ( n.nodeType == 1 ) if ( match[1] === "*" ) {
n.nodeIndex = c++; var tmp = [];
merge[id] = true; for ( var i = 0; results[i]; i++ ) {
if ( results[i].nodeType === 1 ) {
tmp.push( results[i] );
} }
}
var add = false; results = tmp;
}
if ( first == 0 ) { return results;
if ( node.nodeIndex == last ) };
add = true; }
} else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 ) })();
add = true;
if ( add ^ not ) if ( document.querySelectorAll ) (function(){
tmp.push( node ); var oldSizzle = Sizzle;
}
Sizzle = function(query, context, extra){
context = context || document;
r = tmp; if ( context.nodeType === 9 ) {
try {
return makeArray( context.querySelectorAll(query) );
} catch(e){}
}
return oldSizzle(query, context, extra);
};
Sizzle.find = oldSizzle.find;
Sizzle.filter = oldSizzle.filter;
Sizzle.selectors = oldSizzle.selectors;
})();
if ( document.documentElement.getElementsByClassName ) {
Expr.order.splice(1, 0, "CLASS");
Expr.find.CLASS = function(match, context) {
return context.getElementsByClassName(match[1]);
};
}
function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
elem = elem[dir]
var match = false;
while ( elem && elem.nodeType ) {
var done = elem[doneName];
if ( done ) {
match = checkSet[ done ];
break;
}
// Otherwise, find the expression to execute if ( elem.nodeType === 1 )
} else { elem[doneName] = i;
var fn = jQuery.expr[ m[1] ];
if ( typeof fn === "object" )
fn = fn[ m[2] ];
if ( typeof fn === "string" ) if ( elem.nodeName === cur ) {
fn = eval("false||function(a,i){return " + fn + ";}"); match = elem;
break;
}
// Execute it against the current filter elem = elem[dir];
r = jQuery.grep( r, function(elem, i){
return fn(elem, i, m, r);
}, not );
} }
checkSet[i] = match;
} }
}
}
function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
for ( var i = 0, l = checkSet.length; i < l; i++ ) {
var elem = checkSet[i];
if ( elem ) {
elem = elem[dir]
var match = false;
while ( elem && elem.nodeType ) {
if ( elem[doneName] ) {
match = checkSet[ elem[doneName] ];
break;
}
// Return an array of filtered elements (r) if ( elem.nodeType === 1 ) {
// and the modified expression string (t) elem[doneName] = i;
return { r: r, t: t };
}, if ( typeof cur !== "string" ) {
if ( elem === cur ) {
match = true;
break;
}
dir: function( elem, dir ){ } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
var matched = [], match = elem;
cur = elem[dir]; break;
while ( cur && cur != document ) { }
if ( cur.nodeType == 1 ) }
matched.push( cur );
cur = cur[dir]; elem = elem[dir];
}
checkSet[i] = match;
} }
return matched; }
}, }
var contains = document.compareDocumentPosition ? function(a, b){
return a.compareDocumentPosition(b) & 16;
} : function(a, b){
return a !== b && a.contains(b);
};
// EXPOSE
jQuery.find = Sizzle;
jQuery.filter = Sizzle.filter;
jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.filters;
Sizzle.selectors.filters.hidden = function(elem){
return "hidden" === elem.type ||
jQuery.css(elem, "display") === "none" ||
jQuery.css(elem, "visibility") === "hidden";
};
Sizzle.selectors.filters.visible = function(elem){
return "hidden" !== elem.type &&
jQuery.css(elem, "display") !== "none" &&
jQuery.css(elem, "visibility") !== "hidden";
};
jQuery.multiFilter = function( expr, elems, not ) {
if ( not ) {
return jQuery.multiFilter( ":not(" + expr + ")", elems );
}
nth: function(cur,result,dir,elem){ var exprs = expr.split(/\s*,\s*/), cur = [];
result = result || 1;
var num = 0;
for ( ; cur; cur = cur[dir] ) for ( var i = 0; i < exprs.length; i++ ) {
if ( cur.nodeType == 1 && ++num == result ) cur = jQuery.merge( cur, jQuery.filter( exprs[i], elems ) );
break; }
return cur; return cur;
}, };
sibling: function( n, elem ) { jQuery.dir = function( elem, dir ){
var r = []; var matched = [], cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
cur = cur[dir];
}
return matched;
};
for ( ; n; n = n.nextSibling ) { jQuery.nth = function(cur, result, dir, elem){
if ( n.nodeType == 1 && n != elem ) result = result || 1;
r.push( n ); var num = 0;
}
for ( ; cur; cur = cur[dir] )
if ( cur.nodeType == 1 && ++num == result )
break;
return cur;
};
jQuery.sibling = function(n, elem){
var r = [];
return r; for ( ; n; n = n.nextSibling ) {
if ( n.nodeType == 1 && n != elem )
r.push( n );
} }
});
return r;
};
return;
window.Sizzle = Sizzle;
})();
...@@ -704,9 +704,9 @@ test("wrap(String|Element)", function() { ...@@ -704,9 +704,9 @@ test("wrap(String|Element)", function() {
test("wrapAll(String|Element)", function() { test("wrapAll(String|Element)", function() {
expect(8); expect(8);
var prev = jQuery("#first")[0].previousSibling; var prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#first")[0].parentNode; var p = jQuery("#firstp,#first")[0].parentNode;
var result = jQuery('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>'); var result = jQuery('#firstp,#first').wrapAll('<div class="red"><div id="tmp"></div></div>');
equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' ); equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); ok( jQuery('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
...@@ -714,9 +714,9 @@ test("wrapAll(String|Element)", function() { ...@@ -714,9 +714,9 @@ test("wrapAll(String|Element)", function() {
equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); equals( jQuery("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
reset(); reset();
var prev = jQuery("#first")[0].previousSibling; var prev = jQuery("#firstp")[0].previousSibling;
var p = jQuery("#first")[0].parentNode; var p = jQuery("#first")[0].parentNode;
var result = jQuery('#first,#firstp').wrapAll(document.getElementById('empty')); var result = jQuery('#firstp,#first').wrapAll(document.getElementById('empty'));
equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" ); equals( jQuery("#first").parent()[0], jQuery("#firstp").parent()[0], "Same Parent" );
equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); equals( jQuery("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" ); equals( jQuery("#first").parent()[0].parentNode, p, "Correct Parent" );
...@@ -756,7 +756,9 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -756,7 +756,9 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" ); equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
reset(); reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = document.querySelectorAll ?
"This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" :
"This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery('#sap').append(jQuery("#first, #yahoo")); jQuery('#sap').append(jQuery("#first, #yahoo"));
equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" ); equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
...@@ -840,7 +842,9 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -840,7 +842,9 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" ); equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
reset(); reset();
expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; expected = document.querySelectorAll ?
"This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:" :
"This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
jQuery("#first, #yahoo").appendTo('#sap'); jQuery("#first, #yahoo").appendTo('#sap');
equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" ); equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
...@@ -867,7 +871,9 @@ test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -867,7 +871,9 @@ test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" ); equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
reset(); reset();
expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; expected = document.querySelectorAll ?
"YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog" :
"Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
jQuery('#sap').prepend(jQuery("#first, #yahoo")); jQuery('#sap').prepend(jQuery("#first, #yahoo"));
equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" ); equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
}); });
...@@ -898,7 +904,7 @@ test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -898,7 +904,7 @@ test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
jQuery('<select id="prependSelect1"></select>').prependTo('form:last'); jQuery('<select id="prependSelect1"></select>').prependTo('form:last');
jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last'); jQuery('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] ); t( "Prepend Select", "#prependSelect2, #prependSelect1", ["prependSelect2", "prependSelect1"] );
}); });
test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() { test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
...@@ -918,7 +924,9 @@ test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -918,7 +924,9 @@ test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#en').text(), "Insert array of elements before" ); equals( expected, jQuery('#en').text(), "Insert array of elements before" );
reset(); reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = document.querySelectorAll ?
"This is a normal link: diveintomarkTry them out:Yahoo" :
"This is a normal link: Try them out:diveintomarkYahoo";
jQuery('#yahoo').before(jQuery("#first, #mark")); jQuery('#yahoo').before(jQuery("#first, #mark"));
equals( expected, jQuery('#en').text(), "Insert jQuery before" ); equals( expected, jQuery('#en').text(), "Insert jQuery before" );
}); });
...@@ -940,7 +948,9 @@ test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -940,7 +948,9 @@ test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#en').text(), "Insert array of elements before" ); equals( expected, jQuery('#en').text(), "Insert array of elements before" );
reset(); reset();
expected = "This is a normal link: Try them out:diveintomarkYahoo"; expected = document.querySelectorAll ?
"This is a normal link: diveintomarkTry them out:Yahoo" :
"This is a normal link: Try them out:diveintomarkYahoo";
jQuery("#first, #mark").insertBefore('#yahoo'); jQuery("#first, #mark").insertBefore('#yahoo');
equals( expected, jQuery('#en').text(), "Insert jQuery before" ); equals( expected, jQuery('#en').text(), "Insert jQuery before" );
}); });
...@@ -962,7 +972,9 @@ test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() { ...@@ -962,7 +972,9 @@ test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
equals( expected, jQuery('#en').text(), "Insert array of elements after" ); equals( expected, jQuery('#en').text(), "Insert array of elements after" );
reset(); reset();
expected = "This is a normal link: YahooTry them out:diveintomark"; expected = document.querySelectorAll ?
"This is a normal link: YahoodiveintomarkTry them out:" :
"This is a normal link: YahooTry them out:diveintomark";
jQuery('#yahoo').after(jQuery("#first, #mark")); jQuery('#yahoo').after(jQuery("#first, #mark"));
equals( expected, jQuery('#en').text(), "Insert jQuery after" ); equals( expected, jQuery('#en').text(), "Insert jQuery after" );
}); });
...@@ -1315,7 +1327,7 @@ test("andSelf()", function() { ...@@ -1315,7 +1327,7 @@ test("andSelf()", function() {
expect(4); expect(4);
isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" ); isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" ); isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
isSet( jQuery("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" ); isSet( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" ); isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
}); });
...@@ -1325,7 +1337,8 @@ test("siblings([String])", function() { ...@@ -1325,7 +1337,8 @@ test("siblings([String])", function() {
isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" ); isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
isSet( jQuery("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" ); var set = document.querySelectorAll ? q("en", "sap", "sndp") : q("sndp", "sap", "en");
isSet( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
}); });
test("children([String])", function() { test("children([String])", function() {
......
...@@ -31,13 +31,22 @@ if ( location.protocol != "file:" ) { ...@@ -31,13 +31,22 @@ if ( location.protocol != "file:" ) {
test("broken", function() { test("broken", function() {
expect(7); expect(7);
t( "Broken Selector", "[", [] ); function broken(name, selector) {
t( "Broken Selector", "(", [] ); try {
t( "Broken Selector", "{", [] ); t( name, selector, [] );
t( "Broken Selector", "<", [] ); } catch(e){
t( "Broken Selector", "()", [] ); ok( typeof e === "string" && e.indexOf("Syntax error") >= 0,
t( "Broken Selector", "<>", [] ); name + ": " + selector );
t( "Broken Selector", "{}", [] ); }
}
broken( "Broken Selector", "[", [] );
broken( "Broken Selector", "(", [] );
broken( "Broken Selector", "{", [] );
broken( "Broken Selector", "<", [] );
broken( "Broken Selector", "()", [] );
broken( "Broken Selector", "<>", [] );
broken( "Broken Selector", "{}", [] );
}); });
test("id", function() { test("id", function() {
...@@ -77,14 +86,14 @@ test("id", function() { ...@@ -77,14 +86,14 @@ test("id", function() {
}); });
test("class", function() { test("class", function() {
expect(16); expect(15);
t( "Class Selector", ".blog", ["mark","simon"] ); t( "Class Selector", ".blog", ["mark","simon"] );
t( "Class Selector", ".blog.link", ["simon"] ); t( "Class Selector", ".blog.link", ["simon"] );
t( "Class Selector w/ Element", "a.blog", ["mark","simon"] ); t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
t( "Parent Class Selector", "p .blog", ["mark","simon"] ); t( "Parent Class Selector", "p .blog", ["mark","simon"] );
t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] ); t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] ); //t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] ); t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] ); t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] ); t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
...@@ -100,10 +109,17 @@ test("class", function() { ...@@ -100,10 +109,17 @@ test("class", function() {
test("multiple", function() { test("multiple", function() {
expect(4); expect(4);
t( "Comma Support", "a.blog, p", ["mark","simon","firstp","ap","sndp","en","sap","first"] );
t( "Comma Support", "a.blog , p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); var results = ["mark","simon","firstp","ap","sndp","en","sap","first"];
t( "Comma Support", "a.blog ,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] );
t( "Comma Support", "a.blog,p", ["mark","simon","firstp","ap","sndp","en","sap","first"] ); if ( document.querySelectorAll ) {
results = ["firstp","ap","mark","sndp","en","sap","simon","first"];
}
t( "Comma Support", "a.blog, p", results);
t( "Comma Support", "a.blog , p", results);
t( "Comma Support", "a.blog ,p", results);
t( "Comma Support", "a.blog,p", results);
}); });
test("child and adjacent", function() { test("child and adjacent", function() {
...@@ -160,9 +176,16 @@ test("attributes", function() { ...@@ -160,9 +176,16 @@ test("attributes", function() {
t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] ); t( "Attribute Equals", "a[rel='bookmark']", ["simon1"] );
t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] ); t( "Attribute Equals", 'a[rel="bookmark"]', ["simon1"] );
t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] ); t( "Attribute Equals", "a[rel=bookmark]", ["simon1"] );
t( "Multiple Attribute Equals", "#form input[type='hidden'],#form input[type='radio']", ["hidden1","radio1","radio2"] );
t( "Multiple Attribute Equals", "#form input[type=\"hidden\"],#form input[type='radio']", ["hidden1","radio1","radio2"] ); var results = ["hidden1","radio1","radio2"];
t( "Multiple Attribute Equals", "#form input[type=hidden],#form input[type=radio]", ["hidden1","radio1","radio2"] );
if ( document.querySelectorAll ) {
results = ["radio1", "radio2", "hidden1"];
}
t( "Multiple Attribute Equals", "#form input[type='hidden'],#form input[type='radio']", results );
t( "Multiple Attribute Equals", "#form input[type=\"hidden\"],#form input[type='radio']", results );
t( "Multiple Attribute Equals", "#form input[type=hidden],#form input[type=radio]", results );
t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] ); t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] );
...@@ -170,9 +193,9 @@ test("attributes", function() { ...@@ -170,9 +193,9 @@ test("attributes", function() {
t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] ); t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] );
t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] ); t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
t("Select options via [selected]", "#select1 option[selected]", ["option1a"] ); t("Select options via :selected", "#select1 option:selected", ["option1a"] );
t("Select options via [selected]", "#select2 option[selected]", ["option2d"] ); t("Select options via :selected", "#select2 option:selected", ["option2d"] );
t("Select options via [selected]", "#select3 option[selected]", ["option3b", "option3c"] ); t("Select options via :selected", "#select3 option:selected", ["option3b", "option3c"] );
t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] ); t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] );
...@@ -182,12 +205,12 @@ test("attributes", function() { ...@@ -182,12 +205,12 @@ test("attributes", function() {
}); });
test("pseudo (:) selectors", function() { test("pseudo (:) selectors", function() {
expect(35); expect(34);
t( "First Child", "p:first-child", ["firstp","sndp"] ); t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Last Child", "p:last-child", ["sap"] ); t( "Last Child", "p:last-child", ["sap"] );
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] ); t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2"] );
t( "Empty", "ul:empty", ["firstUL"] ); t( "Empty", "ul:empty", ["firstUL"] );
t( "Enabled UI Element", "#form input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2","name"] ); t( "Enabled UI Element", "#form input:not([type=hidden]):enabled", ["text1","radio1","radio2","check1","check2","hidden2","name"] );
t( "Disabled UI Element", "#form input:disabled", ["text2"] ); t( "Disabled UI Element", "#form input:disabled", ["text2"] );
t( "Checked UI Element", "#form input:checked", ["radio2","check1"] ); t( "Checked UI Element", "#form input:checked", ["radio2","check1"] );
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c"] ); t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c"] );
...@@ -196,7 +219,7 @@ test("pseudo (:) selectors", function() { ...@@ -196,7 +219,7 @@ test("pseudo (:) selectors", function() {
t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] ); t( "Element Preceded By", "p ~ div", ["foo","fx-queue","fx-tests", "moretests"] );
t( "Not", "a.blog:not(.link)", ["mark"] ); t( "Not", "a.blog:not(.link)", ["mark"] );
t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] ); t( "Not - multiple", "#form option:not(:contains('Nothing'),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e"] );
t( "Not - complex", "#form option:not([id^='opt']:gt(0):nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] ); //t( "Not - complex", "#form option:not([id^='opt']:nth-child(-n+3))", [ "option1a", "option1d", "option2d", "option3d", "option3e"] );
t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] ); t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
t( "nth Element", "p:nth(1)", ["ap"] ); t( "nth Element", "p:nth(1)", ["ap"] );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment