Expr.prefilter is a method for preprocessing attr, child, pseudo three selectors in the Tokenize method. As follows:
Expr.prefilter: {"ATTR": function (Match) {* * * * Complete the following tasks: * 1, property name decoding * 2, property value decoding * 3, if the judge is ~=, then add a space on both sides of the property value * 4, return the final Mtach object * * Match[1] represents the property name, * Match[1].replace (RuneScape, Funescape): Decodes the hexadecimal number in the property name to * Single-byte Unicode Character or double-byte Unicode characters (Chinese or other text that requires two bytes) * For a detailed description of regular expressions, refer to my "detailed jquery selector Regular expression" article/match[1] = Match[1].replace (runescape
, Funescape); * * to decode the property value * Match[4]: Represents the attribute value placed in single or double quotes * Match[5]: Denotes an attribute value not enclosed in quotes * * match[3] = (Match[4] | | match[5 | | |
""). Replace (RuneScape, funescape); * * ~= meaning is a word match, the definition of the word in the consortium is blank for the different words of the separator * so in match[3] on both sides of the space, you can use indexof, the correct identification of the existence of the word * * if (match[2] = = "~=
") {match[3] =" "+ match[3] +" ";
* * * Returns useful first four elements results */return Match.slice (0, 4);
"Child": function (Match) {/* * completes the following tasks: * 1, the character before the child and Of-type in the command into lowercase characters * 2, for the selector at the beginning of the nth check the validity of the data in parentheses * 3, Match[4] and match[5] Each store x and b,x in xn+b and b allow negative * 4, return the final match object * * Match[1]: (only|first|last|nth|nth-last) = A/match[1] = Match[1].tolowercase (); * * * for Nth-child, Nth-of-type, Nth-last-child, nth-last-of-type Four types of parentheses to set valid data * while others do not allow any data in parentheses/if (MATCH[1].SL Ice (0, 3) = = "Nth") {/* * If there are no valid parameters in the selector bracket, throw an exception * For example: If the selector is nth or nth (ABC) is an illegal selector/if (!match[3)) {S
Izzle.error (Match[0]); * * below, take nth-child () as an example to introduce the syntax to better understand the role of the following code * Nth-child allows several uses as follows: *: Nth-child (even) *: Nth-chi LD (ODD) *: Nth-child (3n) *: Nth-child (+2n+1) *: Nth-child (2n-1) * The match[4 on the left of the assignment number in the following code, MATCH[5] is used to record separately Number of n before and after n in brackets, including positive and negative * for: Nth-child (even) and: Nth-child (Odd), match[4] NULL, * so return 2 * (match[3) = = "even" | | match[3] = = = "odd") calculation results * Because in JS true=1,false=0, so (match[3] = = = "even" | | match[3] = = "Odd") equals 1 * Therefore, 2 * (match[3) = = = "even" | | MATCH[3] = = = "Odd") evaluates to 2 * * * The effect of the "+" on the right side of the equals sign is to force type conversion, convert the string to a numeric type/match[4] = + (Match[4]? Match[5] + (m ATCH[6] | | 1): 2 * (match[3] = = "even" | | maTCH[3] = = = "Odd"));
MATCH[5] = + ((match[7] + match[8]) | | match[3] = = "odd"); else if (match[3]) {* * * * * Throw an exception if the other child type selector with parentheses is not indicated by Nth * Here jquery is not judged strictly according to the rules of the consortium because it allows: the shape of the First-child ()
Type existence * i.e. for jquery: First-child () is equivalent to: First-child, is the legal selector/Sizzle.error (match[0));
return match;
The "PSEUDO": function (Match) {* * * completes the following tasks: * 1, get the pseudo class in quotation marks in the value of * 2, for the value of non quotation marks, if there is a pseudo class nesting, further resolve to determine the actual end of the current pseudo-class position,
* Gets the full string and value * 3 of the current pseudo class, and returns a copy of the top three items in match.
* * Unquoted represents values that are not enclosed in quotes in parentheses, * to: EQ (2) For example, unquoted=2/var excess, unquoted =!match[5] && match[2];
* * Because pseudo and child matching regular expressions have intersection, you need to ignore the part belonging to the child/if (matchexpr["Child"].test (match[0)) {return null;
* * * If the value in parentheses is enclosed in quotation marks (Match[3]), the * assigns the value (MATCH[4) except the quote to MATCH[2].
* Match[3] represents quotation marks.
*/if (match[3] && match[4]!== undefined) {match[2] = match[4]; else if (unquoted/* Rpseudo.test (unquoted): Used to test whether the unquoted contains pseudo classes, * If a pseudo class is included,Indicates the possibility of pseudo class nesting, which requires further parsing of unquoted * For example:: Not (: eq (3)) * * && rpseudo.test (unquoted) && * * Get unquoted the last character position in a continuous and effective selector/* (excess = Tokenize (unquoted, True)) && * * UNQ
Uoted.indexof (")", unquoted.length-excess) * where ")" is located after the last character of the previously obtained continuously valid selector, * usually after the current position. * Minus Unquoted.length, which is used to obtain the final position of the valid complete pseudo-class string in match[0], * Note that at this point excess is a negative */* * * * (excess = Unquoted.indexo F (")", unquoted.length-excess)-unquoted.length) {//Get valid Full pseudo class match[0] and pseudo-bracket data match[2] match[0] =
Match[0].slice (0, excess);
MATCH[2] = unquoted.slice (0, excess);
//Returns a copy of the top three elements of match return Match.slice (0, 3); }
}