Opened 12 years ago
Closed 11 years ago
#7281 closed bug (invalid)
Sizzle Extension API is broken
Reported by: | Owned by: | timmywil | |
---|---|---|---|
Priority: | low | Milestone: | 1.8 |
Component: | selector | Version: | 1.4.3 |
Keywords: | sizzle extension api | Cc: | |
Blocked by: | Blocking: |
Description
Currently new selectors cannot be added via the extension API documented in the Sizzle wiki: http://github.com/jeresig/sizzle/wiki
The issue is the leftMatch
object-literal, which is filled by the follow code at initialization time:
for ( var type in Expr.match ) { Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); }
We need this code to be publicly exposed so that we can run it after adding new selectors via the extension API.
I've hacked around this by creating a new method (using Sizzle via jQuery):
Expr = $.expr; Expr.process = function(type) { Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, function(all, num){ return "\\" + (num - 0 + 1); })); };
which I use like this:
$.expr.match['WIDGET'] = /@((?:[\w\u00c0-\uFFFF\-]|\\.)+)/; $.expr.preFilter.WIDGET = function(match) { return match[1].replace(/\\/g, ""); }; $.expr.filter.WIDGET = function(elem, match) { return elem.getAttribute('data-widget') === match; }; $.expr.process('WIDGET');
Sizzle needs to expose the code that fills the leftMatch
object via a function that works something like the one I've shown here.
Change History (8)
comment:1 Changed 12 years ago by
Owner: | set to Ben Lambert <[email protected]…> |
---|---|
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → new |
---|
I'm not sure, I've not looked into the Sizzle source code before 1.4.3.
Presumably it was working at some point, like when the Sizzle API docs were written.
comment:3 Changed 12 years ago by
Component: | unfiled → selector |
---|---|
Keywords: | sizzle extension api added |
Priority: | undecided → low |
Status: | new → open |
comment:4 Changed 12 years ago by
Milestone: | → 1.next |
---|
comment:5 Changed 12 years ago by
Owner: | changed from Ben Lambert <[email protected]…> to john |
---|---|
Status: | open → assigned |
comment:7 Changed 11 years ago by
Owner: | changed from john to timmywil |
---|
comment:8 Changed 11 years ago by
Milestone: | 1.next → 1.8 |
---|---|
Resolution: | → invalid |
Status: | assigned → closed |
No longer applies
Is this broken in versions prior to 1.4.3?