17. jquery Source Parsing Entry method Sizzle (1)

Source: Internet
Author: User
Tags set set

The function Sizzle (selector,context,results,seed) is used to find a collection of elements that match the selector expression Selector. The function is the entry for the selector engine .
the 6 key steps performed by the function sizzle are as follows:
1. Parse the selector expression and parse out the block expression and the relationship.
2. If there is a location pseudo-class, look from left to right:
A. Find the collection of elements that match the first block expression, and get the first set of context elements.
B. Iterate through the remaining block expressions and inter-block relationships, shrinking the context element collection.
3. Otherwise look from right to left:
A. Find the collection of elements that match the last block expression, and get the candidate set, the mapping set.
B. Traverse the remaining block expressions and the inter-block relationships to perform block-to-chunk relationship filtering on the mapping set.
4. Filter the candidate sets based on the mapping set, placing the final matched elements into the result set.
5. If there is a side-by-side selector expression, the recursive sizzle () finds a matching collection of elements and merges, sorts, and resets.
6. Finally, the result set is returned.


3967 defines the sizzle.
An selector:css selector expression.
Context: Contextual environment.
Results: An optional array or array of classes, sizzle will add the found element to it.
Seed: An optional collection of elements. The function sizzle filters the collection of elements that match the selector expression from the collection of elements.

3968 rows: If the parameter results is not passed in, the default is an empty array [].
3969 Line: If the context is not passed in, the current document object is assumed to be default.
3971 rows: The backup context. Because if the parameter selector starts with #id, the context may be modified to match the #id element. The origcontext used here is for situations where a side-by-side selector expression exists.
3973 rows: If the parameter context is not an element and is not a document object, it is returned directly [];
3977 rows: If the argument selector is an empty string, or is not a string, the results is returned directly.

M: used to store the result of the regular chunker each match selector expression selector.

set: Right-to-left lookup mode, the variable set becomes the "candidate set", the last block expression matches the element collection, the other block expression and the inter-block relationship will set the candidate set by row filter, for left-to-right lookup, the variable set is the current block expression matching element collection, is also the context of the next block expression.
Checkset: For right-to-left lookups, Checkset is called a "map set," whose initial value is a copy of the set of candidates, and other block expressions and inter-block relationships are filtered through the map set Checkset, filtering the elements of which are replaced with the parent element based on the inter-block relationship. The ancestor element or sibling element, then replaces the element that does not match the block expression with false, and finally filters the set of candidates based on the mapping set Checkset, and for right-to-left lookups, the fact is that the variable checkset is not involved in the lookup process, but only in the function sizzle () Finally, in order to uniformly filter and merge the code that matches the elements, the variable Checkse and set point to the same array.
Extra: Used to store other side-by-side selector expressions after the first comma in a selector expression. If there is a side-by-side selector expression, the function sizzle () is recursively called to find a collection of matching elements and performs a merge, sort, and redo operation.
ret: Used only in right-to-left execution, to hold the Find selector Sizzle.find (expr,context,isxml) for the last block expression.
pop: Used only in right-to-left lookups, representing a single block expression.
prune: Used only in right-to-left lookups, indicates whether the candidate set set needs to be filtered, is true by default, indicates that a filter is required, and if there is only one block expression in the selector expression, the variable prune is false.
Contextxml: Indicates whether the contextual context is an XML document.
Parts: Stores the regular chunker The block expression and the inter-block relationship extracted from the selector expression.
Sofar: Used to save regular chunker each time the remainder of the block expression or inter-block relationship is extracted from the selector expression, the initial value is the complete selector expression.

3989~3990: Regular Chunker each time the remainder of the selector expression is matched, the first matching position of the regular chunker is reset by matching an empty character, so that each match is matched from the beginning. Directly set "chunker.lastindex=0;" can also achieve the same effect.
3992~4001: If the regular chunker can match the remainder of the selector expression, assign the third grouping (that is, the remainder after the current match) to the variable Sofar, and continue the match the next time the Do-while loop, or you can filter out some of the garbage characters (such as spaces) At the same time, the block expression or inter-block relationship in the first grouping is inserted into the array parts, and if the second grouping is not an empty string, then a comma is encountered, indicating that next is a side-by-side selector expression, the third group is saved in the variable extra, and then the loop is ended.

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.