#12409 closed bug (fixed)
Back-compat issue with custom pseudo selectors
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.8.1 |
Component: | selector | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The API for adding a custom psuedo selector which accepts an argument changed in jQuery 1.8. Prior to 1.8, one could do the following in order to create an :icontains(text)
pseudo selector:
jQuery.expr[':'].icontains = function( obj, index, meta, stack ) { return ( obj.textContent || obj.innerText || jQuery(obj).text() || '' ).toLowerCase().indexOf(meta[3].toLowerCase()) >= 0; };
In jQuery 1.8 this triggers a TypeError as the function parameters have effectively changed and the meta
parameter is now undefined.
The API for creating a custom psuedo selector which accepts an argument is completely different in 1.8 and is not back-compatible with the method used for 1.7.
In my opinion, a change like this which is not back-compatible with the previous method is classed as a bug. A plugin which adds a pseudo-selector like this now must be updated for jQuery 1.8, and if it wishes to retain support for jQuery 1.7 will have to introduce logic to determine which method to use to add the pseudo selector.
Change History (7)
comment:1 Changed 10 years ago by
Component: | unfiled → selector |
---|---|
Priority: | undecided → low |
Resolution: | → wontfix |
Status: | new → closed |
comment:2 Changed 10 years ago by
Resolution: | wontfix → fixed |
---|
Sizzle: provide backwards-compatibility for creating custom pseudos with arguments. Fixes #12409.
Changeset: f15eb3ce5b3e7967f04cb1a6d57542bd6f9f9262
comment:5 Changed 10 years ago by
Milestone: | None → 1.8.1 |
---|
comment:7 Changed 10 years ago by
jQuery 1.8.2 - the backward compatible solution always returns 0 for the index, so it breaks some existing custom pseudos selectors that rely on this.
This demos the problem: http://jsfiddle.net/ttkaminski/8RdtA/ Switch between jQuery 1.8.2 and jQuery 1.7.2.
Thank you for contributing to the jQuery project!
The decision to break the API for creating custom pseudos with arguments was not taken lightly. Given the new selector compilation in Sizzle, backwards compatibility for this API would be more code and work than it's worth. We strongly recommend using the new API whenever possible because of its performance benefits and readability.
Having said that, a case-insensitve contains seems pretty common, so I've added an example implementation for this custom pseudo that will work across all versions of jQuery here: https://github.com/jquery/sizzle/wiki/Sizzle-Documentation#wiki-back-compat