Side navigation
#7281 closed bug (invalid)
Opened October 22, 2010 05:44AM UTC
Closed July 03, 2012 02:20AM UTC
Sizzle Extension API is broken
Reported by: | Ben Lambert <ben.nagoya@gmail.com> | 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
leftMatchobject-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.
Attachments (0)
Change History (8)
Changed October 23, 2010 08:11AM UTC by comment:1
owner: | → Ben Lambert <ben.nagoya@gmail.com> |
---|---|
status: | new → pending |
Changed October 29, 2010 07:50AM UTC by comment:2
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.
Changed October 29, 2010 02:28PM UTC by comment:3
component: | unfiled → selector |
---|---|
keywords: | → sizzle extension api |
priority: | undecided → low |
status: | new → open |
Changed March 31, 2011 01:57AM UTC by comment:4
milestone: | → 1.next |
---|
Changed July 11, 2011 05:44PM UTC by comment:5
owner: | Ben Lambert <ben.nagoya@gmail.com> → john |
---|---|
status: | open → assigned |
Changed July 12, 2011 04:36PM UTC by comment:6
Confirmed in bug triage.
Changed June 19, 2012 06:06AM UTC by comment:7
owner: | john → timmywil |
---|
Changed July 03, 2012 02:20AM UTC by comment:8
milestone: | 1.next → 1.8 |
---|---|
resolution: | → invalid |
status: | assigned → closed |
No longer applies
Is this broken in versions prior to 1.4.3?