Path: blob/trunk/third_party/js/sizzle/sizzle-raw.js
2868 views
/*!1* Sizzle CSS Selector Engine2* Copyright 2011, The Dojo Foundation3* Released under the MIT, BSD, and GPL Licenses.4* More information: http://sizzlejs.com/5*/6(function(){78var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,9expando = "sizcache" + (Math.random() + '').replace('.', ''),10done = 0,11toString = Object.prototype.toString,12hasDuplicate = false,13baseHasDuplicate = true,14rBackslash = /\\/g,15rReturn = /\r\n/g,16rNonWord = /\W/;1718// Here we check if the JavaScript engine is using some sort of19// optimization where it does not always call our comparision20// function. If that is the case, discard the hasDuplicate value.21// Thus far that includes Google Chrome.22[0, 0].sort(function() {23baseHasDuplicate = false;24return 0;25});2627var Sizzle = function( selector, context, results, seed ) {28results = results || [];29context = context || document;3031var origContext = context;3233if ( context.nodeType !== 1 && context.nodeType !== 9 ) {34return [];35}3637if ( !selector || typeof selector !== "string" ) {38return results;39}4041var m, set, checkSet, extra, ret, cur, pop, i,42prune = true,43contextXML = Sizzle.isXML( context ),44parts = [],45soFar = selector;4647// Reset the position of the chunker regexp (start from head)48do {49chunker.exec( "" );50m = chunker.exec( soFar );5152if ( m ) {53soFar = m[3];5455parts.push( m[1] );5657if ( m[2] ) {58extra = m[3];59break;60}61}62} while ( m );6364if ( parts.length > 1 && origPOS.exec( selector ) ) {6566if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {67set = posProcess( parts[0] + parts[1], context, seed );6869} else {70set = Expr.relative[ parts[0] ] ?71[ context ] :72Sizzle( parts.shift(), context );7374while ( parts.length ) {75selector = parts.shift();7677if ( Expr.relative[ selector ] ) {78selector += parts.shift();79}8081set = posProcess( selector, set, seed );82}83}8485} else {86// Take a shortcut and set the context if the root selector is an ID87// (but not if it'll be faster if the inner selector is an ID)88if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&89Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {9091ret = Sizzle.find( parts.shift(), context, contextXML );92context = ret.expr ?93Sizzle.filter( ret.expr, ret.set )[0] :94ret.set[0];95}9697if ( context ) {98ret = seed ?99{ expr: parts.pop(), set: makeArray(seed) } :100Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );101102set = ret.expr ?103Sizzle.filter( ret.expr, ret.set ) :104ret.set;105106if ( parts.length > 0 ) {107checkSet = makeArray( set );108109} else {110prune = false;111}112113while ( parts.length ) {114cur = parts.pop();115pop = cur;116117if ( !Expr.relative[ cur ] ) {118cur = "";119} else {120pop = parts.pop();121}122123if ( pop == null ) {124pop = context;125}126127Expr.relative[ cur ]( checkSet, pop, contextXML );128}129130} else {131checkSet = parts = [];132}133}134135if ( !checkSet ) {136checkSet = set;137}138139if ( !checkSet ) {140Sizzle.error( cur || selector );141}142143if ( toString.call(checkSet) === "[object Array]" ) {144if ( !prune ) {145results.push.apply( results, checkSet );146147} else if ( context && context.nodeType === 1 ) {148for ( i = 0; checkSet[i] != null; i++ ) {149if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {150results.push( set[i] );151}152}153154} else {155for ( i = 0; checkSet[i] != null; i++ ) {156if ( checkSet[i] && checkSet[i].nodeType === 1 ) {157results.push( set[i] );158}159}160}161162} else {163makeArray( checkSet, results );164}165166if ( extra ) {167Sizzle( extra, origContext, results, seed );168Sizzle.uniqueSort( results );169}170171return results;172};173174Sizzle.uniqueSort = function( results ) {175if ( sortOrder ) {176hasDuplicate = baseHasDuplicate;177results.sort( sortOrder );178179if ( hasDuplicate ) {180for ( var i = 1; i < results.length; i++ ) {181if ( results[i] === results[ i - 1 ] ) {182results.splice( i--, 1 );183}184}185}186}187188return results;189};190191Sizzle.matches = function( expr, set ) {192return Sizzle( expr, null, null, set );193};194195Sizzle.matchesSelector = function( node, expr ) {196return Sizzle( expr, null, null, [node] ).length > 0;197};198199Sizzle.find = function( expr, context, isXML ) {200var set, i, len, match, type, left;201202if ( !expr ) {203return [];204}205206for ( i = 0, len = Expr.order.length; i < len; i++ ) {207type = Expr.order[i];208209if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {210left = match[1];211match.splice( 1, 1 );212213if ( left.substr( left.length - 1 ) !== "\\" ) {214match[1] = (match[1] || "").replace( rBackslash, "" );215set = Expr.find[ type ]( match, context, isXML );216217if ( set != null ) {218expr = expr.replace( Expr.match[ type ], "" );219break;220}221}222}223}224225if ( !set ) {226set = typeof context.getElementsByTagName !== "undefined" ?227context.getElementsByTagName( "*" ) :228[];229}230231return { set: set, expr: expr };232};233234Sizzle.filter = function( expr, set, inplace, not ) {235var match, anyFound,236type, found, item, filter, left,237i, pass,238old = expr,239result = [],240curLoop = set,241isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );242243while ( expr && set.length ) {244for ( type in Expr.filter ) {245if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {246filter = Expr.filter[ type ];247left = match[1];248249anyFound = false;250251match.splice(1,1);252253if ( left.substr( left.length - 1 ) === "\\" ) {254continue;255}256257if ( curLoop === result ) {258result = [];259}260261if ( Expr.preFilter[ type ] ) {262match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );263264if ( !match ) {265anyFound = found = true;266267} else if ( match === true ) {268continue;269}270}271272if ( match ) {273for ( i = 0; (item = curLoop[i]) != null; i++ ) {274if ( item ) {275found = filter( item, match, i, curLoop );276pass = not ^ found;277278if ( inplace && found != null ) {279if ( pass ) {280anyFound = true;281282} else {283curLoop[i] = false;284}285286} else if ( pass ) {287result.push( item );288anyFound = true;289}290}291}292}293294if ( found !== undefined ) {295if ( !inplace ) {296curLoop = result;297}298299expr = expr.replace( Expr.match[ type ], "" );300301if ( !anyFound ) {302return [];303}304305break;306}307}308}309310// Improper expression311if ( expr === old ) {312if ( anyFound == null ) {313Sizzle.error( expr );314315} else {316break;317}318}319320old = expr;321}322323return curLoop;324};325326Sizzle.error = function( msg ) {327throw new Error( "Syntax error, unrecognized expression: " + msg );328};329330/**331* Utility function for retreiving the text value of an array of DOM nodes332* @param {Array|Element} elem333*/334var getText = Sizzle.getText = function( elem ) {335var i, node,336nodeType = elem.nodeType,337ret = "";338339if ( nodeType ) {340if ( nodeType === 1 || nodeType === 9 ) {341// Use textContent || innerText for elements342if ( typeof elem.textContent === 'string' ) {343return elem.textContent;344} else if ( typeof elem.innerText === 'string' ) {345// Replace IE's carriage returns346return elem.innerText.replace( rReturn, '' );347} else {348// Traverse it's children349for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {350ret += getText( elem );351}352}353} else if ( nodeType === 3 || nodeType === 4 ) {354return elem.nodeValue;355}356} else {357358// If no nodeType, this is expected to be an array359for ( i = 0; (node = elem[i]); i++ ) {360// Do not traverse comment nodes361if ( node.nodeType !== 8 ) {362ret += getText( node );363}364}365}366return ret;367};368369var Expr = Sizzle.selectors = {370order: [ "ID", "NAME", "TAG" ],371372match: {373ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,374CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,375NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,376ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,377TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,378CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,379POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,380PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/381},382383leftMatch: {},384385attrMap: {386"class": "className",387"for": "htmlFor"388},389390attrHandle: {391href: function( elem ) {392return elem.getAttribute( "href" );393},394type: function( elem ) {395return elem.getAttribute( "type" );396}397},398399relative: {400"+": function(checkSet, part){401var isPartStr = typeof part === "string",402isTag = isPartStr && !rNonWord.test( part ),403isPartStrNotTag = isPartStr && !isTag;404405if ( isTag ) {406part = part.toLowerCase();407}408409for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {410if ( (elem = checkSet[i]) ) {411while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}412413checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?414elem || false :415elem === part;416}417}418419if ( isPartStrNotTag ) {420Sizzle.filter( part, checkSet, true );421}422},423424">": function( checkSet, part ) {425var elem,426isPartStr = typeof part === "string",427i = 0,428l = checkSet.length;429430if ( isPartStr && !rNonWord.test( part ) ) {431part = part.toLowerCase();432433for ( ; i < l; i++ ) {434elem = checkSet[i];435436if ( elem ) {437var parent = elem.parentNode;438checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;439}440}441442} else {443for ( ; i < l; i++ ) {444elem = checkSet[i];445446if ( elem ) {447checkSet[i] = isPartStr ?448elem.parentNode :449elem.parentNode === part;450}451}452453if ( isPartStr ) {454Sizzle.filter( part, checkSet, true );455}456}457},458459"": function(checkSet, part, isXML){460var nodeCheck,461doneName = done++,462checkFn = dirCheck;463464if ( typeof part === "string" && !rNonWord.test( part ) ) {465part = part.toLowerCase();466nodeCheck = part;467checkFn = dirNodeCheck;468}469470checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );471},472473"~": function( checkSet, part, isXML ) {474var nodeCheck,475doneName = done++,476checkFn = dirCheck;477478if ( typeof part === "string" && !rNonWord.test( part ) ) {479part = part.toLowerCase();480nodeCheck = part;481checkFn = dirNodeCheck;482}483484checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );485}486},487488find: {489ID: function( match, context, isXML ) {490if ( typeof context.getElementById !== "undefined" && !isXML ) {491var m = context.getElementById(match[1]);492// Check parentNode to catch when Blackberry 4.6 returns493// nodes that are no longer in the document #6963494return m && m.parentNode ? [m] : [];495}496},497498NAME: function( match, context ) {499if ( typeof context.getElementsByName !== "undefined" ) {500var ret = [],501results = context.getElementsByName( match[1] );502503for ( var i = 0, l = results.length; i < l; i++ ) {504if ( results[i].getAttribute("name") === match[1] ) {505ret.push( results[i] );506}507}508509return ret.length === 0 ? null : ret;510}511},512513TAG: function( match, context ) {514if ( typeof context.getElementsByTagName !== "undefined" ) {515return context.getElementsByTagName( match[1] );516}517}518},519preFilter: {520CLASS: function( match, curLoop, inplace, result, not, isXML ) {521match = " " + match[1].replace( rBackslash, "" ) + " ";522523if ( isXML ) {524return match;525}526527for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {528if ( elem ) {529if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {530if ( !inplace ) {531result.push( elem );532}533534} else if ( inplace ) {535curLoop[i] = false;536}537}538}539540return false;541},542543ID: function( match ) {544return match[1].replace( rBackslash, "" );545},546547TAG: function( match, curLoop ) {548return match[1].replace( rBackslash, "" ).toLowerCase();549},550551CHILD: function( match ) {552if ( match[1] === "nth" ) {553if ( !match[2] ) {554Sizzle.error( match[0] );555}556557match[2] = match[2].replace(/^\+|\s*/g, '');558559// parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'560var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(561match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||562!/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);563564// calculate the numbers (first)n+(last) including if they are negative565match[2] = (test[1] + (test[2] || 1)) - 0;566match[3] = test[3] - 0;567}568else if ( match[2] ) {569Sizzle.error( match[0] );570}571572// TODO: Move to normal caching system573match[0] = done++;574575return match;576},577578ATTR: function( match, curLoop, inplace, result, not, isXML ) {579var name = match[1] = match[1].replace( rBackslash, "" );580581if ( !isXML && Expr.attrMap[name] ) {582match[1] = Expr.attrMap[name];583}584585// Handle if an un-quoted value was used586match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );587588if ( match[2] === "~=" ) {589match[4] = " " + match[4] + " ";590}591592return match;593},594595PSEUDO: function( match, curLoop, inplace, result, not ) {596if ( match[1] === "not" ) {597// If we're dealing with a complex expression, or a simple one598if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {599match[3] = Sizzle(match[3], null, null, curLoop);600601} else {602var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);603604if ( !inplace ) {605result.push.apply( result, ret );606}607608return false;609}610611} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {612return true;613}614615return match;616},617618POS: function( match ) {619match.unshift( true );620621return match;622}623},624625filters: {626enabled: function( elem ) {627return elem.disabled === false && elem.type !== "hidden";628},629630disabled: function( elem ) {631return elem.disabled === true;632},633634checked: function( elem ) {635return elem.checked === true;636},637638selected: function( elem ) {639// Accessing this property makes selected-by-default640// options in Safari work properly641if ( elem.parentNode ) {642elem.parentNode.selectedIndex;643}644645return elem.selected === true;646},647648parent: function( elem ) {649return !!elem.firstChild;650},651652empty: function( elem ) {653return !elem.firstChild;654},655656has: function( elem, i, match ) {657return !!Sizzle( match[3], elem ).length;658},659660header: function( elem ) {661return (/h\d/i).test( elem.nodeName );662},663664text: function( elem ) {665var attr = elem.getAttribute( "type" ), type = elem.type;666// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)667// use getAttribute instead to test this case668return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );669},670671radio: function( elem ) {672return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;673},674675checkbox: function( elem ) {676return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;677},678679file: function( elem ) {680return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;681},682683password: function( elem ) {684return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;685},686687submit: function( elem ) {688var name = elem.nodeName.toLowerCase();689return (name === "input" || name === "button") && "submit" === elem.type;690},691692image: function( elem ) {693return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;694},695696reset: function( elem ) {697var name = elem.nodeName.toLowerCase();698return (name === "input" || name === "button") && "reset" === elem.type;699},700701button: function( elem ) {702var name = elem.nodeName.toLowerCase();703return name === "input" && "button" === elem.type || name === "button";704},705706input: function( elem ) {707return (/input|select|textarea|button/i).test( elem.nodeName );708},709710focus: function( elem ) {711return elem === elem.ownerDocument.activeElement;712}713},714setFilters: {715first: function( elem, i ) {716return i === 0;717},718719last: function( elem, i, match, array ) {720return i === array.length - 1;721},722723even: function( elem, i ) {724return i % 2 === 0;725},726727odd: function( elem, i ) {728return i % 2 === 1;729},730731lt: function( elem, i, match ) {732return i < match[3] - 0;733},734735gt: function( elem, i, match ) {736return i > match[3] - 0;737},738739nth: function( elem, i, match ) {740return match[3] - 0 === i;741},742743eq: function( elem, i, match ) {744return match[3] - 0 === i;745}746},747filter: {748PSEUDO: function( elem, match, i, array ) {749var name = match[1],750filter = Expr.filters[ name ];751752if ( filter ) {753return filter( elem, i, match, array );754755} else if ( name === "contains" ) {756return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;757758} else if ( name === "not" ) {759var not = match[3];760761for ( var j = 0, l = not.length; j < l; j++ ) {762if ( not[j] === elem ) {763return false;764}765}766767return true;768769} else {770Sizzle.error( name );771}772},773774CHILD: function( elem, match ) {775var first, last,776doneName, parent, cache,777count, diff,778type = match[1],779node = elem;780781switch ( type ) {782case "only":783case "first":784while ( (node = node.previousSibling) ) {785if ( node.nodeType === 1 ) {786return false;787}788}789790if ( type === "first" ) {791return true;792}793794node = elem;795796/* falls through */797case "last":798while ( (node = node.nextSibling) ) {799if ( node.nodeType === 1 ) {800return false;801}802}803804return true;805806case "nth":807first = match[2];808last = match[3];809810if ( first === 1 && last === 0 ) {811return true;812}813814doneName = match[0];815parent = elem.parentNode;816817if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {818count = 0;819820for ( node = parent.firstChild; node; node = node.nextSibling ) {821if ( node.nodeType === 1 ) {822node.nodeIndex = ++count;823}824}825826parent[ expando ] = doneName;827}828829diff = elem.nodeIndex - last;830831if ( first === 0 ) {832return diff === 0;833834} else {835return ( diff % first === 0 && diff / first >= 0 );836}837}838},839840ID: function( elem, match ) {841return elem.nodeType === 1 && elem.getAttribute("id") === match;842},843844TAG: function( elem, match ) {845return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;846},847848CLASS: function( elem, match ) {849return (" " + (elem.className || elem.getAttribute("class")) + " ")850.indexOf( match ) > -1;851},852853ATTR: function( elem, match ) {854var name = match[1],855result = Sizzle.attr ?856Sizzle.attr( elem, name ) :857Expr.attrHandle[ name ] ?858Expr.attrHandle[ name ]( elem ) :859elem[ name ] != null ?860elem[ name ] :861elem.getAttribute( name ),862value = result + "",863type = match[2],864check = match[4];865866return result == null ?867type === "!=" :868!type && Sizzle.attr ?869result != null :870type === "=" ?871value === check :872type === "*=" ?873value.indexOf(check) >= 0 :874type === "~=" ?875(" " + value + " ").indexOf(check) >= 0 :876!check ?877value && result !== false :878type === "!=" ?879value !== check :880type === "^=" ?881value.indexOf(check) === 0 :882type === "$=" ?883value.substr(value.length - check.length) === check :884type === "|=" ?885value === check || value.substr(0, check.length + 1) === check + "-" :886false;887},888889POS: function( elem, match, i, array ) {890var name = match[2],891filter = Expr.setFilters[ name ];892893if ( filter ) {894return filter( elem, i, match, array );895}896}897}898};899900var origPOS = Expr.match.POS,901fescape = function(all, num){902return "\\" + (num - 0 + 1);903};904905for ( var type in Expr.match ) {906Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );907Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );908}909// Expose origPOS910// "global" as in regardless of relation to brackets/parens911Expr.match.globalPOS = origPOS;912913var makeArray = function( array, results ) {914array = Array.prototype.slice.call( array, 0 );915916if ( results ) {917results.push.apply( results, array );918return results;919}920921return array;922};923924// Perform a simple check to determine if the browser is capable of925// converting a NodeList to an array using builtin methods.926// Also verifies that the returned array holds DOM nodes927// (which is not the case in the Blackberry browser)928try {929Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;930931// Provide a fallback method if it does not work932} catch( e ) {933makeArray = function( array, results ) {934var i = 0,935ret = results || [];936937if ( toString.call(array) === "[object Array]" ) {938Array.prototype.push.apply( ret, array );939940} else {941if ( typeof array.length === "number" ) {942for ( var l = array.length; i < l; i++ ) {943ret.push( array[i] );944}945946} else {947for ( ; array[i]; i++ ) {948ret.push( array[i] );949}950}951}952953return ret;954};955}956957var sortOrder, siblingCheck;958959if ( document.documentElement.compareDocumentPosition ) {960sortOrder = function( a, b ) {961if ( a === b ) {962hasDuplicate = true;963return 0;964}965966if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {967return a.compareDocumentPosition ? -1 : 1;968}969970return a.compareDocumentPosition(b) & 4 ? -1 : 1;971};972973} else {974sortOrder = function( a, b ) {975// The nodes are identical, we can exit early976if ( a === b ) {977hasDuplicate = true;978return 0;979980// Fallback to using sourceIndex (in IE) if it's available on both nodes981} else if ( a.sourceIndex && b.sourceIndex ) {982return a.sourceIndex - b.sourceIndex;983}984985var al, bl,986ap = [],987bp = [],988aup = a.parentNode,989bup = b.parentNode,990cur = aup;991992// If the nodes are siblings (or identical) we can do a quick check993if ( aup === bup ) {994return siblingCheck( a, b );995996// If no parents were found then the nodes are disconnected997} else if ( !aup ) {998return -1;9991000} else if ( !bup ) {1001return 1;1002}10031004// Otherwise they're somewhere else in the tree so we need1005// to build up a full list of the parentNodes for comparison1006while ( cur ) {1007ap.unshift( cur );1008cur = cur.parentNode;1009}10101011cur = bup;10121013while ( cur ) {1014bp.unshift( cur );1015cur = cur.parentNode;1016}10171018al = ap.length;1019bl = bp.length;10201021// Start walking down the tree looking for a discrepancy1022for ( var i = 0; i < al && i < bl; i++ ) {1023if ( ap[i] !== bp[i] ) {1024return siblingCheck( ap[i], bp[i] );1025}1026}10271028// We ended someplace up the tree so do a sibling check1029return i === al ?1030siblingCheck( a, bp[i], -1 ) :1031siblingCheck( ap[i], b, 1 );1032};10331034siblingCheck = function( a, b, ret ) {1035if ( a === b ) {1036return ret;1037}10381039var cur = a.nextSibling;10401041while ( cur ) {1042if ( cur === b ) {1043return -1;1044}10451046cur = cur.nextSibling;1047}10481049return 1;1050};1051}10521053// Check to see if the browser returns elements by name when1054// querying by getElementById (and provide a workaround)1055(function(){1056// We're going to inject a fake input element with a specified name1057var form = document.createElement("div"),1058id = "script" + (new Date()).getTime(),1059root = document.documentElement;10601061form.innerHTML = "<a name='" + id + "'/>";10621063// Inject it into the root element, check its status, and remove it quickly1064root.insertBefore( form, root.firstChild );10651066// The workaround has to do additional checks after a getElementById1067// Which slows things down for other browsers (hence the branching)1068if ( document.getElementById( id ) ) {1069Expr.find.ID = function( match, context, isXML ) {1070if ( typeof context.getElementById !== "undefined" && !isXML ) {1071var m = context.getElementById(match[1]);10721073return m ?1074m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?1075[m] :1076undefined :1077[];1078}1079};10801081Expr.filter.ID = function( elem, match ) {1082var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");10831084return elem.nodeType === 1 && node && node.nodeValue === match;1085};1086}10871088root.removeChild( form );10891090// release memory in IE1091root = form = null;1092})();10931094(function(){1095// Check to see if the browser returns only elements1096// when doing getElementsByTagName("*")10971098// Create a fake element1099var div = document.createElement("div");1100div.appendChild( document.createComment("") );11011102// Make sure no comments are found1103if ( div.getElementsByTagName("*").length > 0 ) {1104Expr.find.TAG = function( match, context ) {1105var results = context.getElementsByTagName( match[1] );11061107// Filter out possible comments1108if ( match[1] === "*" ) {1109var tmp = [];11101111for ( var i = 0; results[i]; i++ ) {1112if ( results[i].nodeType === 1 ) {1113tmp.push( results[i] );1114}1115}11161117results = tmp;1118}11191120return results;1121};1122}11231124// Check to see if an attribute returns normalized href attributes1125div.innerHTML = "<a href='#'></a>";11261127if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&1128div.firstChild.getAttribute("href") !== "#" ) {11291130Expr.attrHandle.href = function( elem ) {1131return elem.getAttribute( "href", 2 );1132};1133}11341135// release memory in IE1136div = null;1137})();11381139if ( document.querySelectorAll ) {1140(function(){1141var oldSizzle = Sizzle,1142div = document.createElement("div"),1143id = "__sizzle__";11441145div.innerHTML = "<p class='TEST'></p>";11461147// Safari can't handle uppercase or unicode characters when1148// in quirks mode.1149if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {1150return;1151}11521153Sizzle = function( query, context, extra, seed ) {1154context = context || document;11551156// Only use querySelectorAll on non-XML documents1157// (ID selectors don't work in non-HTML documents)1158if ( !seed && !Sizzle.isXML(context) ) {1159// See if we find a selector to speed up1160var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );11611162if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {1163// Speed-up: Sizzle("TAG")1164if ( match[1] ) {1165return makeArray( context.getElementsByTagName( query ), extra );11661167// Speed-up: Sizzle(".CLASS")1168} else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {1169return makeArray( context.getElementsByClassName( match[2] ), extra );1170}1171}11721173if ( context.nodeType === 9 ) {1174// Speed-up: Sizzle("body")1175// The body element only exists once, optimize finding it1176if ( query === "body" && context.body ) {1177return makeArray( [ context.body ], extra );11781179// Speed-up: Sizzle("#ID")1180} else if ( match && match[3] ) {1181var elem = context.getElementById( match[3] );11821183// Check parentNode to catch when Blackberry 4.6 returns1184// nodes that are no longer in the document #69631185if ( elem && elem.parentNode ) {1186// Handle the case where IE and Opera return items1187// by name instead of ID1188if ( elem.id === match[3] ) {1189return makeArray( [ elem ], extra );1190}11911192} else {1193return makeArray( [], extra );1194}1195}11961197try {1198return makeArray( context.querySelectorAll(query), extra );1199} catch(qsaError) {}12001201// qSA works strangely on Element-rooted queries1202// We can work around this by specifying an extra ID on the root1203// and working up from there (Thanks to Andrew Dupont for the technique)1204// IE 8 doesn't work on object elements1205} else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {1206var oldContext = context,1207old = context.getAttribute( "id" ),1208nid = old || id,1209hasParent = context.parentNode,1210relativeHierarchySelector = /^\s*[+~]/.test( query );12111212if ( !old ) {1213context.setAttribute( "id", nid );1214} else {1215nid = nid.replace( /'/g, "\\$&" );1216}1217if ( relativeHierarchySelector && hasParent ) {1218context = context.parentNode;1219}12201221try {1222if ( !relativeHierarchySelector || hasParent ) {1223return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );1224}12251226} catch(pseudoError) {1227} finally {1228if ( !old ) {1229oldContext.removeAttribute( "id" );1230}1231}1232}1233}12341235return oldSizzle(query, context, extra, seed);1236};12371238for ( var prop in oldSizzle ) {1239Sizzle[ prop ] = oldSizzle[ prop ];1240}12411242// release memory in IE1243div = null;1244})();1245}12461247(function(){1248var html = document.documentElement,1249matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;12501251if ( matches ) {1252// Check to see if it's possible to do matchesSelector1253// on a disconnected node (IE 9 fails this)1254var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),1255pseudoWorks = false;12561257try {1258// This should fail with an exception1259// Gecko does not error, returns false instead1260matches.call( document.documentElement, "[test!='']:sizzle" );12611262} catch( pseudoError ) {1263pseudoWorks = true;1264}12651266Sizzle.matchesSelector = function( node, expr ) {1267// Make sure that attribute selectors are quoted1268expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");12691270if ( !Sizzle.isXML( node ) ) {1271try {1272if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {1273var ret = matches.call( node, expr );12741275// IE 9's matchesSelector returns false on disconnected nodes1276if ( ret || !disconnectedMatch ||1277// As well, disconnected nodes are said to be in a document1278// fragment in IE 9, so check for that1279node.document && node.document.nodeType !== 11 ) {1280return ret;1281}1282}1283} catch(e) {}1284}12851286return Sizzle(expr, null, null, [node]).length > 0;1287};1288}1289})();12901291(function(){1292var div = document.createElement("div");12931294div.innerHTML = "<div class='test e'></div><div class='test'></div>";12951296// Opera can't find a second classname (in 9.6)1297// Also, make sure that getElementsByClassName actually exists1298if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {1299return;1300}13011302// Safari caches class attributes, doesn't catch changes (in 3.2)1303div.lastChild.className = "e";13041305if ( div.getElementsByClassName("e").length === 1 ) {1306return;1307}13081309Expr.order.splice(1, 0, "CLASS");1310Expr.find.CLASS = function( match, context, isXML ) {1311if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {1312return context.getElementsByClassName(match[1]);1313}1314};13151316// release memory in IE1317div = null;1318})();13191320function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {1321for ( var i = 0, l = checkSet.length; i < l; i++ ) {1322var elem = checkSet[i];13231324if ( elem ) {1325var match = false;13261327elem = elem[dir];13281329while ( elem ) {1330if ( elem[ expando ] === doneName ) {1331match = checkSet[elem.sizset];1332break;1333}13341335if ( elem.nodeType === 1 && !isXML ){1336elem[ expando ] = doneName;1337elem.sizset = i;1338}13391340if ( elem.nodeName.toLowerCase() === cur ) {1341match = elem;1342break;1343}13441345elem = elem[dir];1346}13471348checkSet[i] = match;1349}1350}1351}13521353function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {1354for ( var i = 0, l = checkSet.length; i < l; i++ ) {1355var elem = checkSet[i];13561357if ( elem ) {1358var match = false;13591360elem = elem[dir];13611362while ( elem ) {1363if ( elem[ expando ] === doneName ) {1364match = checkSet[elem.sizset];1365break;1366}13671368if ( elem.nodeType === 1 ) {1369if ( !isXML ) {1370elem[ expando ] = doneName;1371elem.sizset = i;1372}13731374if ( typeof cur !== "string" ) {1375if ( elem === cur ) {1376match = true;1377break;1378}13791380} else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {1381match = elem;1382break;1383}1384}13851386elem = elem[dir];1387}13881389checkSet[i] = match;1390}1391}1392}13931394if ( document.documentElement.contains ) {1395Sizzle.contains = function( a, b ) {1396return a !== b && (a.contains ? a.contains(b) : true);1397};13981399} else if ( document.documentElement.compareDocumentPosition ) {1400Sizzle.contains = function( a, b ) {1401return !!(a.compareDocumentPosition(b) & 16);1402};14031404} else {1405Sizzle.contains = function() {1406return false;1407};1408}14091410Sizzle.isXML = function( elem ) {1411// documentElement is verified for cases where it doesn't yet exist1412// (such as loading iframes in IE - #4833)1413var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;14141415return documentElement ? documentElement.nodeName !== "HTML" : false;1416};14171418var posProcess = function( selector, context, seed ) {1419var match,1420tmpSet = [],1421later = "",1422root = context.nodeType ? [context] : context;14231424// Position selectors must be done after the filter1425// And so must :not(positional) so we move all PSEUDOs to the end1426while ( (match = Expr.match.PSEUDO.exec( selector )) ) {1427later += match[0];1428selector = selector.replace( Expr.match.PSEUDO, "" );1429}14301431selector = Expr.relative[selector] ? selector + "*" : selector;14321433for ( var i = 0, l = root.length; i < l; i++ ) {1434Sizzle( selector, root[i], tmpSet, seed );1435}14361437return Sizzle.filter( later, tmpSet );1438};14391440// EXPOSE14411442window.Sizzle = Sizzle;14431444})();144514461447