GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Home Home
Michał Gołębiowski-Owczarek edited this page
Project Home Page | Source Repository | Google Group Discussion Note: Browser support may differ between standalone Sizzle and libraries that include Sizzle. Please report issues on Sizzle's issue tracker, rather than the trackers for disparate libraries.
1Workarounds for Internet Explorer 6 are still in the code but the browser is no longer actively tested.
To report a bug in any of these browsers, please add an issue with a test case from jsfiddle or jsbin. Sizzle supports virtually all CSS 3 Selectors, including escaped selectors ( As such, the following pseudo-selectors are not supported:
Note: These CSS3 pseudo-selectors were unsupported prior to version 1.9:
Note: In this context,
In this context, "positional" refers to an element's placement in the collection after a selection, based on document order. For example, Note: Positional indexes begin at zero.
The Sizzle API consists of 3 parts:
The main function for finding elements. Uses returns (Array): All elements matching the selector Parameters selector: A CSS selector context: An element, document, or document fragment to use as the context for finding elements. Defaults to results: An array or an array-like object, to which Sizzle will append results. For example, jQuery passes a jQuery collection. An "array-like object" is an object with a nonnegative numeric Uses native returns(Boolean): Whether the given element matches the selector Parameters element: A selector: A CSS selector returns(Array): Elements in the array that match the given selector Parameters selector: A CSS selector elements: An array of This contains the regular expressions used to parse a selector into different parts, to be used for finding and filtering. The name of each of the regular expressions should correspond to the names specified in the In order to add a new find function:
A method for finding some elements on a page. The specified function will be called no more than once per selector.
In order to add a new filtering statement:
An optional pre-filter function which allows filtering of the matched array against the corresponding regular expression, which will return a new matched array. This matched array will eventually be passed and flattened as arguments against the corresponding filter function. This is intended to clean up some of the repetitive processing that occurs in a filter function. Note: The arguments for a filter method are the element and the captures from the regex corresponding to this filter (indicated above by what is in the match, starting at index 1). The return result must be boolean: true if the element matches the selector, false if not. Handle an attribute which requires specialized processing (such as The most common extension to a selector engine: adding a new pseudo. The return result from this function must be boolean: true if the element matches the selector, false if not. For example, this defines a simple var $test = jQuery( document ); Sizzle.selectors.pseudos.fixed = function( elem ) { $test[ 0 ] = elem; return $test.css( "position" ) === "fixed"; };
Note: In jQuery 1.8 and earlier, the API for creating custom pseudos with arguments was broken. In jQuery 1.8.1+, the API is backwards-compatible. Regardless, the use of Now that the parser compiles a single function containing other functions, custom pseudo-selectors with arguments are much cleaner. For example, within Sizzle, the implementation of the Sizzle.selectors.pseudos.not = Sizzle.selectors.createPseudo(function( subSelector ) { var matcher = Sizzle.compile( subSelector ); return function( elem ) { return !matcher( elem ); }; }); In order to write a custom selector with arguments that can take advantage of the new API, yet still support all versions of Sizzle, check for the The following example uses jQuery syntax. Live example // An implementation of a case-insensitive contains pseudo // made for all versions of jQuery (function( $ ) { function icontains( elem, text ) { return ( elem.textContent || elem.innerText || $( elem ).text() || "" ).toLowerCase().indexOf( (text || "").toLowerCase() ) > -1; } $.expr.pseudos.icontains = $.expr.createPseudo ? $.expr.createPseudo(function( text ) { return function( elem ) { return icontains( elem, text ); }; }) : function( elem, i, match ) { return icontains( elem, match[3] ); }; })( jQuery ); These filters are run after a previous part of a selector has already returned results. For example, the code for the var first = function( elements, argument, not ) { // No argument for first return not ? elements.slice( 1 ) : [ elements[0] ]; }; Sizzle.selectors.setFilters.first = first; It is easy to extend Sizzle -- even Sizzle's Sizzle.selectors.match.POS = new RegExp( oldPOS.source.replace("first", "uno"), "gi" ); Sizzle.selectors.setFilters.uno = Sizzle.selectors.setFilters.first; delete Sizzle.selectors.setFilters.first; Sizzle("div:uno"); // ==> [ <div> ] Note: Functionality should be accessed via the Public and Extension APIs. While the Internal API is intended specifically for internal use, it has been exposed for edge cases. Sizzle internally caches compiled selector functions and tokenization objects. The length of these caches defaults to 50, but can be set to any positive integer by assigning to this property. This method compiles a selector function and caches it for later use. For example, calling returns(Function): The compiled function to be used when filtering the set of possibly matching elements Parameters selector: A CSS selector Special thanks goes out to the following. Without their contributions to the open source community, Sizzle would not be what it is today.
Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |