"jquery Source" Select method

Source: Internet
Author: User

1 /**2 * The Select method is one of the core methods of the Sizzle selector package, which mainly accomplishes the following tasks:3 * 1, call the Tokenize method to complete the resolution of the selector4 * 2, for no initial set (that is, seed is not assigned) and is a single block selector (that is, there is no comma in the selector string),5 * Complete the following items:6 * 1) for the first selector is the ID type and the context is document, the direct fetch object overrides the incoming context object7 * 2) If the selector is a single selector and is an ID, class, tag type, the matching DOM element is directly fetched and returned8 * 3) Gets the last ID, class, Tag type selector matching DOM element assigned to the initial set (i.e. the seed variable)9 * 3, get "precompiled" code by calling the compile method and execute, get and return the matching DOM elementTen  *   One * @param selector has gone to turn the trailing blank selector string A * @param context executes the initial contexts (that is, the collection of DOM elements) that match. If the context is not assigned, the document is taken.  - * @param results has been matched to the final result of the part. If results is not assigned, an empty array is assigned.  - * @param seed Initial Collection the  */ -select = Sizzle.select =function(selector, context, results, seed) { -     varI, tokens, token, type, find, -Compiled =typeofselector = = = "function" &&Selector, +         //in the absence of seed, the Tokensize method is called for lexical parsing, and the results are placed in match -         //Seed -Seed collection (the Finder searches for a qualifying label) and puts it into this initial set of seed +Match =!seed && tokenize ((selector = Compiled.selector | |selector)); A  atResults = Results | | []; -  -     //Try to minimize operations if there are no seed and only one group -     //There is only one set of selectors, that is, no commas in the selector -     if(Match.length = = 1 ) { -  in         //Take a shortcut and set the context if the root selector are an ID -         //Create a new collection to assign to tokens to ensure that the original collection is not changed totokens = Match[0] = Match[0].slice (0 ); +         /*  - * If the selector starts with an ID type and the second is a relationship (that is, +~> or a space), the * Gets the ID belongs to the object as the context continues to complete subsequent matches *              *   $ * The conditions are judged as follows:Panax Notoginseng * tokens.length > 2: If tokens has more than two selectors - * (token = tokens[0]). Type = = = "id": the type of the first selector is the ID (that is, beginning with #), the * Support.getbyid: Support getElementById function + * Context.nodetype = = = 9:context object is document A * documentishtml: HTML code is currently being processed the * Expr.relative[tokens[1].type]: The second tokens element is a relationship (that is, a +~> or a space) + * If all of the above conditions are met, execute the statement body within the IF -         */   $         if(Tokens.length > 2 && (token = tokens[0]). Type = = = "ID" && $Support.getbyid && Context.nodetype = = = 9 && documentishtml && -expr.relative[tokens[1].type]) { -  the             //find an element with ID Matches[1] -Context = (expr.find["ID"] (Token.matches[0].replace (RuneScape, Funescape), context) | | []) [0];Wuyi             if( !context) { the                 returnresults; -  Wu             //precompiled Matchers'll still verify ancestry, so step up a level -}Else if(compiled) { AboutContext =Context.parentnode; $             } -  -             //Remove the first selector from the selector -selector =Selector.slice (Tokens.shift (). value.length); A         } +  the         //Fetch A seed set for right-to-left matching -         //Where: "Needscontext" = new RegExp ("^" + whitespace + "*[>+~]|:( Even|odd|eq|gt|lt|nth|first|last) (?: \ \ ("+ Whitespace +" * (?:-\ \d) \\d*) "+ whitespace +" *\\) |) (? =[^-]|$) "," I ") $         //That is, if there are no structural pseudo-classes, these need to be filtered in another way, after which the article is dissected in detail.  the         //so, starting with the last rule, find the Seed collection first. thei = matchexpr["Needscontext"].test (selector)? 0: tokens.length; the          while(i-- ) { thetoken =Tokens[i]; -  in             //Abort If we hit a combinator the             //terminates loop,> + ~ null if a relationship selector is encountered the             if(expr.relative[(type =Token.type)]) { About                  Break; the             } the             /* the let's see if there's a finder. Find, the Finder is the browser some native Dom interface, simple expression is the following object + Expr.find = { - ' ID ': Context.getelementbyid, the ' CLASS ': Context.getelementsbyclassname,Bayi ' NAME ': Context.getelementsbyname, the ' TAG ': Context.getelementsbytagname the                 } -             */ -             if(Find =expr.find[type])) { the                 //Search, expanding context for leading sibling combinators the                 //try to search through this finder to match the initial set of eligible seed the                 if(seed =Find ( theToken.matches[0].replace (RuneScape, funescape), -Rsibling.test (Tokens[0].type) && testContext (context.parentnode) | |Context the                 )) ) { the  the                     //If seed is empty or no tokens remain, we can return early94                     //Delete this label theTokens.splice (i, 1 ); theselector = Seed.length &&Toselector (tokens); the                     //if the current selector is empty, push seed into results and return the result98                     if( !selector) { About push.apply (results, seed); -                         returnresults;101                     }102                     //The eligible seed collection has been found, and there are other rules at the front, jumping out103                      Break;104                 } the             }106         }107     }108 109     //Compile and execute a filtering function if one is not provided the     //provide ' match ' to avoid retokenization if we modified the selector above111(Compiled | |compile (selector, match)) ( the seed,113 context, the!documentishtml, the results, theRsibling.test (selector) && testContext (context.parentnode) | |Context117     );118     returnresults;119};

"jquery Source" Select method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.