aboutsummaryrefslogtreecommitdiffstats
path: root/src/selector
Commit message (Collapse)AuthorAgeFilesLines
* Tests: Indicate Chrome 112 & Safari 16.4 pass the cssHas support testMichał Gołębiowski-Owczarek2023-04-051-2/+2
| | | | | | | | | | | Chrome 112 & Safari 16.4 introduce two changes: * `:has()` is non-forgiving * `CSS.supports( "selector(...)" )` parses everything in a non-forgiving way We no longer care about the latter but the former means the `cssHas` support test now passes. Closes gh-5225
* Selector: Stop relying on CSS.supports( "selector(...)" )Michał Gołębiowski-Owczarek2023-02-142-28/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | `CSS.supports( "selector(...)" )` has different semantics than selectors passed to `querySelectorAll`. Apart from the fact that the former returns `false` for unrecognized selectors and the latter throws, `qSA` is more forgiving and accepts some invalid selectors, auto-correcting them where needed - for example, mismatched brackers are auto-closed. This behavior difference is breaking for many users. To add to that, a recent CSSWG resolution made `:is()` & `:where()` the only pseudos with forgiving parsing; browsers are in the process of making `:has()` parsing unforgiving. Taking all that into account, we go back to our previous try-catch approach without relying on `CSS.supports( "selector(...)" )`. The only difference is we detect forgiving parsing in `:has()` and mark the selector as buggy. The PR also updates `playwright-webkit` so that we test against a version of WebKit that already has non-forgiving `:has()`. Fixes gh-5194 Closes gh-5206 Ref gh-5098 Ref gh-5107 Ref w3c/csswg-drafts#7676 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
* Selector: Backport jQuery selection context logic to selector-nativeMichał Gołębiowski-Owczarek2023-02-1318-0/+325
| | | | | | | | | | | | | | | | | | | | | | This makes: ```js $div.find("div > *") ``` no longer matching children of `$div`. Also, leading combinators now work, e.g.: ```js $div.find( "> *" ); ``` returns children of `$div`. As a result of that, a number of tests are no longer skipped in the `selector-native` mode. Also, rename `rcombinators` to `rleadingCombinator`. Fixes gh-5185 Closes gh-5186 Ref gh-5085
* Selector: Make selector lists work with `qSA` againMichał Gołębiowski-Owczarek2022-12-192-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | jQuery 3.6.2 started using `CSS.supports( "selector(SELECTOR)" )` before using `querySelectorAll` on the selector. This was to solve gh-5098 - some selectors, like `:has()`, now had their parameters parsed in a forgiving way, meaning that `:has(:fakepseudo)` no longer throws but just returns 0 results, breaking that jQuery mechanism. A recent spec change made `CSS.supports( "selector(SELECTOR)" )` always use non-forgiving parsing, allowing us to use this API for what we've used `try-catch` before. To solve the issue on the spec side for older jQuery versions, `:has()` parameters are no longer using forgiving parsing in the latest spec update but our new mechanism is more future-proof anyway. However, the jQuery implementation has a bug - in `CSS.supports( "selector(SELECTOR)" )`, `SELECTOR` needs to be a `<complex-selector>` and not a `<complex-selector-list>`. Which means that selector lists now skip `qSA` and go to the jQuery custom traversal: ```js CSS.supports("selector(div:valid, span)"); // false CSS.supports("selector(div:valid)"); // true CSS.supports("selector(span)"); // true ``` To solve this, this commit wraps the selector list passed to `CSS.supports( "selector(:is(SELECTOR))" )` with `:is`, making it a single selector again. See: * https://w3c.github.io/csswg-drafts/css-conditional-4/#at-supports-ext * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector * https://w3c.github.io/csswg-drafts/selectors-4/#typedef-complex-selector-list Fixes gh-5177 Closes gh-5178 Ref w3c/csswg-drafts#7280
* Core:Selector: Move jQuery.contains from the selector to the core moduleMichał Gołębiowski-Owczarek2022-12-121-15/+0
| | | | | | | The `jQuery.contains` method is quite simple in jQuery 4+. On the other side, it's a dependency of the core `isAttached` util which is not ideal; moving it from the `selector` the `core` module resolves the issue. Closes gh-5167
* Selector: Implement the `uniqueSort` chainable methodMichał Gołębiowski-Owczarek2022-11-281-0/+5
| | | | | | | | | Some APIs, like `.prevAll()`, return elements in the reversed order, causing confusing behavior when used with wrapping methods (see gh-5149 for more info) To provide an easy workaround, this commit implements a chainable `uniqueSort` method on jQuery objects, an equivalent of `jQuery.uniqueSort`. Fixes gh-5166 Closes gh-5168
* Tests: Indicate Firefox 106+ passes the `cssSupportsSelector` testMichał Gołębiowski-Owczarek2022-11-251-1/+1
| | | | | | Firefox 106 adjusted to the spec mandating that `CSS.supports("selector(...)")` uses non-forgiving parsing which makes it pass the relevant support test. Closes gh-5141
* Selector:Manipulation: Fix DOM manip within template contentsMichał Gołębiowski-Owczarek2022-11-141-4/+3
| | | | | | | | | | | | | | | | The `<template/>` element `contents` property is a document fragment that may have a `null` `documentElement`. In Safari 16 this happens in more cases due to recent spec changes - in particular, even if that document fragment is explicitly adopted into an outer document. We're testing both of those cases now. The crash used to happen in `jQuery.contains`. As it turns out, we don't need to query the supposed container `documentElement` if it has the `Node.DOCUMENT_NODE` (9) `nodeType`; we can call `.contains()` directly on the `document`. That avoids the crash. Fixes gh-5147 Closes gh-5158
* Selector: Use jQuery `:has` if `CSS.supports(selector(...))` non-compliantMichał Gołębiowski-Owczarek2022-09-192-11/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | jQuery has followed the following logic for selector handling for ages: 1. Modify the selector to adhere to scoping rules jQuery mandates. 2. Try `qSA` on the modified selector. If it succeeds, use the results. 3. If `qSA` threw an error, run the jQuery custom traversal instead. It worked fine so far but now CSS has a concept of forgiving selector lists that some selectors like `:is()` & `:has()` use. That means providing unrecognized selectors as parameters to `:is()` & `:has()` no longer throws an error, it will just return no results. That made browsers with native `:has()` support break selectors using jQuery extensions inside, e.g. `:has(:contains("Item"))`. Detecting support for selectors can also be done via: ```js CSS.supports( "selector(SELECTOR_TO_BE_TESTED)" ) ``` which returns a boolean. There was a recent spec change requiring this API to always use non-forgiving parsing: https://github.com/w3c/csswg-drafts/issues/7280#issuecomment-1143852187 However, no browsers have implemented this change so far. To solve this, two changes are being made: 1. In browsers supports the new spec change to `CSS.supports( "selector()" )`, use it before trying `qSA`. 2. Otherwise, add `:has` to the buggy selectors list. Fixes gh-5098 Closes gh-5107 Ref w3c/csswg-drafts#7676
* Core: Don't rely on splice being present on inputBruno PIERRE2022-01-241-1/+2
| | | | | | | | | | Without this fix calling `jQuery.uniqueSort` on an array-like can result in: TypeError: results.splice is not a function at Function.jQuery.uniqueSort (https://code.jquery.com/jquery-git.js:664:12) at jQuery.fn.init.find (https://code.jquery.com/jquery-git.js:2394:27) at gocusihafe.js:3:4 Closes gh-4986
* CSS: Trim whitespace surrounding CSS Custom Properties valuesfecore12021-09-232-3/+1
| | | | | | | | The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes gh-4926 Closes gh-4930
* Core: Drop support for Edge Legacy (i.e. non-Chromium Microsoft Edge)Michał Gołębiowski-Owczarek2020-09-223-38/+17
| | | | | | | | | | | | Drop support for Edge Legacy: the non-Chromium, EdgeHTML-based Microsoft Edge version. Also, restrict some workarounds that were applied unconditionally in all browsers to run only in IE now. This slightly increases the size but reduces the performance burden on modern browsers that don't need the workarounds. Also, clean up some comments & remove some obsolete workarounds. Fixes gh-4568 Closes gh-4792
* Selector: Remove the "a:enabled" workaround for Chrome <=77Michał Gołębiowski-Owczarek2019-12-161-9/+0
| | | | | | | Remove the workaround for a broken `:enabled` pseudo-class on anchor elements in Chrome <=77. These versions of Chrome considers anchor elements with the `href` attribute as matching `:enabled`. Closes gh-4569
* Selector: Make empty attribute selectors work in IE againMichał Gołębiowski-Owczarek2019-11-182-1/+17
| | | | | | | | | | qSA in IE 11/Edge often (but not always) don't find elements with an empty name attribute selector (`[name=""]`). Detect that & fall back to Sizzle traversal. Interestingly, IE 10 & older don't seem to have the issue. Fixes gh-4435 Closes gh-4510
* Core: Migrate from AMD to ES modules 🎉Michał Gołębiowski-Owczarek2019-11-185-41/+11
| | | | | | | | | | | | | | | | | | | | | | Migrate all source AMD modules to ECMAScript modules. The final bundle is compiled by a custom build process that uses Rollup under the hood. Test files themselves are still loaded via RequireJS as that has to work in IE 11. Tests can now be run in "Load as modules" mode which replaces the previous "Load with AMD" option. That option of running tests doesn't work in IE and Edge as it requires support for dynamic imports. Some of the changes required by the migration: * check `typeof` of `noGlobal` instead of using the variable directly as it's not available when modules are used * change the nonce module to be an object as ECMASscript module exports are immutable * remove some unused exports * import `./core/parseHTML.js` directly in `jquery.js` so that it's not being cut out when the `ajax` module is excluded in a custom compilation Closes gh-4541
* Selector: Use shallow document comparisons in uniqueSortMichał Gołębiowski-Owczarek2019-10-211-3/+16
| | | | | | | | | | | | | | IE/Edge sometimes crash when comparing documents between frames using the strict equality operator (`===` & `!==`). Funnily enough, shallow comparisons (`==` & `!=`) work without crashing. The change to shallow comparisons in `src/selector.js` was done in gh-4471 but relevant changes in `src/selector/uniqueSort.js` were missed. Those changes have landed in Sizzle in jquery/sizzle#459. Fixes gh-4441 Closes gh-4512 Ref gh-4471 Ref jquery/sizzle#459
* Core: Remove private copies of push, sort & splice from the jQuery prototypeMichał Gołębiowski-Owczarek2019-09-241-3/+4
| | | Closes gh-4473
* Selector: reduce size, simplify setDocumentMichał Gołębiowski-Owczarek2019-08-261-0/+30
| | | | | | | | | | | With new selector code doing less convoluted support tests, it was possible to extract a lot of logic out of setDocument & also reduce size. This commit also backports jquery/sizzle#439 that was reverted by mistake during a switch from JSHint + JSCS to ESLint. Closes gh-4462 Ref jquery/sizzle#442 Ref jquery/sizzle#439
* Selector: Leverage the :scope pseudo-class where possibleMichał Gołębiowski-Owczarek2019-08-191-0/+17
| | | | | | | | | | | | | | | | | | | The `:scope` pseudo-class[1] has surprisingly good browser support: Chrome, Firefox & Safari have supported if for a long time; only IE & Edge lack support. This commit leverages this pseudo-class to get rid of the ID hack in most cases. Adding a temporary ID may cause layout thrashing which was reported a few times in [the past. We can't completely eliminate the ID hack in modern browses as sibling selectors require us to change context to the parent and then `:scope` stops applying to what we'd like. But it'd still improve performance in the vast majority of cases. [1] https://developer.mozilla.org/en-US/docs/Web/CSS/:scope Fixes gh-4453 Closes gh-4454 Ref gh-4332 Ref jquery/sizzle#405
* Selector: Inline Sizzle into the selector moduleMichał Gołębiowski-Owczarek2019-07-293-0/+133
| | | | | | | | | | | | | | | | | | This commit removes Sizzle from jQuery, inlining its code & removing obsolete workarounds where applicable. The selector-native module has been removed. Further work on the selector module may decrease the size enough that it will no longer be necessary. If it turns out it's still useful, we'll reinstate it but the code will look different anyway as we'll want to share as much code as possible with the existing selector module. The Sizzle AUTHORS.txt file has been merged with the jQuery one - people are sorted by their first contributions to either of the two repositories. The commit reduces the gzipped jQuery size by 1460 bytes compared to master. Closes gh-4395
* Reorganzing the jQuery source (first phase).John Resig2007-09-082-634/+0
|
* Added a new :animated selector - only selects elements that are currently ↵John Resig2007-09-081-1/+4
| | | | being animated.
* Integration of Mike Alsup's excellent form serialization code. The benefits ↵John Resig2007-09-051-22/+22
| | | | | | | | | | | | | | | | | | are as follows: - New method: .serializeArray() This returns an array of name/value pairs representing the contents of a form, or individual input elements. - Enhancement: .serialize() The results are correct now (as opposed to the mess from before), and allows you to serializes forms directly (rather than just the input elements). - Enhancement: .val() This now returns the correct value when dealing wih selects. Additionally, when dealing with multiple selects, it returns an array of values. Based upon Mike's code: http://malsup.com/jquery/form/comp/form.js and test suite: http://malsup.com/jquery/form/comp/test.html
* Removed all deprecated functionality for jQuery 1.2. A full list of what was ↵John Resig2007-09-042-92/+43
| | | | removed can be found here: http://jquery.com/blog/2007/08/24/jquery-114-faster-more-tests-ready-for-12/
* Removed all inline documentation. The current version of all documentation ↵John Resig2007-09-041-36/+0
| | | | is stored online, on the wiki: http://docs.jquery.com/
* Added support for a new :header psuedo-selector (only selects H1-H6 elements).John Resig2007-08-312-2/+7
|
* Fixed the issue where $("body").find("div#foo") would ignore the specified ↵John Resig2007-08-272-2/+4
| | | | tag name. (Bug #1543)
* Marked all the appropriate methods as being deprecated for the 1.1.4 release ↵John Resig2007-08-241-0/+7
| | | | (in preparation for 1.2).
* Fixed use of eval() and new Function() to work within the correct scope (and ↵John Resig2007-08-221-1/+1
| | | | not throw errors).
* Added the new :has() selector (Bug #1521)John Resig2007-08-212-2/+6
|
* Fix for a selector speed regression (calling a simple selector many times ↵John Resig2007-08-211-5/+12
| | | | | | | | | | resulted in a significant speed down). This has been fixed by breaking the RegExps out into the global scope. This required that a closure be implemented around the full jQuery script (which is now the case). Some simple changes were made in addition to the RegExp one, allowing for some greater flexibility on our part - and hopefully better compression. Speed results: http://dev.jquery.com/~john/ticket/1351/ vs. http://dev.jquery.com/~john/ticket/1351/113.html vs. http://dev.jquery.com/~john/ticket/1351/112.html
* Added a fix for IE returning comment nodes in * queries. I put the logic in ↵John Resig2007-08-191-1/+6
| | | | $.merge() but added a conditional such that the speed hit only effects IE users. (Bug #1155)
* The test for underscore selectors broke under Opera, so the element is now ↵John Resig2007-07-301-3/+12
| | | | loaded via Ajax and tested. (bug #1084)
* Added a fix for Safari's broken CSS getComputedStyle accessing. ↵John Resig2007-07-291-1/+1
| | | | Additionally, added a fix for Safari mis-reporting @selected for display: none options. The test suite is now completely passing in Safari 3. (Bug #1349)
* Integrated the custom fx test suite into the main test suite. All tests are ↵John Resig2007-07-291-11/+11
| | | | now run automatically. Removed the old suite, as it was no longer needed.
* $("#foo", xml) would always return an empty set, fixed (bug #877). ↵John Resig2007-07-251-1/+1
| | | | Additionally, a bug in jQuery.isXMLDoc(xmlDoc) was discovered, if the element was, in fact, an XML document.
* Added a fix for relative // - $("//div",this) (bug #1418)John Resig2007-07-252-2/+3
|
* Added a fix for h1 + h2 not working. (Bug #1361)John Resig2007-07-201-1/+1
|
* Final fix for Safari crasher (bug #1331).John Resig2007-07-061-1/+1
|
* Fix for Safari 1.3 crash (bug #1331).John Resig2007-07-051-1/+1
|
* fix little typo in commentEd Engelhardt2007-07-051-1/+1
|
* Added fix for broken child selectors in XML documents, bug #1346.John Resig2007-07-051-2/+2
|
* Added a fix for bug #1331, which caused Safari 1.3 to crash.John Resig2007-07-041-1/+1
|
* Fixed bug that prevented $= from working on elements that didn't have the ↵John Resig2007-07-041-1/+1
| | | | specified attribute.
* Who am I kidding |= is useless.John Resig2007-06-291-2/+2
|
* Added minor support for |= and ~= selectors.John Resig2007-06-291-2/+2
|
* Added fix for :nth-child(n).John Resig2007-06-291-1/+1
|
* Added fix for broken :only-child.John Resig2007-06-291-1/+1
|
* Added extra last-child test.John Resig2007-06-291-1/+2
|
* Added massive speed improvements to selectors. Also added support for ↵John Resig2007-06-291-60/+98
| | | | :nth-child(An+B) syntax.