Skip to content

Instantly share code, notes, and snippets.

@ollym
Created December 10, 2011 13:32
Show Gist options
  • Save ollym/3e66cc2510504cbbc3d5 to your computer and use it in GitHub Desktop.
Save ollym/3e66cc2510504cbbc3d5 to your computer and use it in GitHub Desktop.
// In $.qsa:
var regex = /^([^:]+)([^\s]*)(?:\s)/;
for (var match; (match = query.split(regex)).length > 1; query = match[3])
context = $(match[1], context).filter(match[2]);
return context;
// In $.fn.filter or wherever the filter logic is (should be $.fn.is):
if (/^:(.+)$/.test(selector) && (RegExp.$1 in $.fn))
return this.filter(function(element) {
return $(element)[RegExp.$1]();
});
// Then add:
$.fn.visible = function() {
...
}
$.fn.hidden = function() {
return ! this.visible;
}
// and so on...
@patik
Copy link

patik commented Dec 10, 2011

How do you insert the first part into $.qsa? Looking at it line 104 here, it already returns something else, so I'm not sure where to put it.

@ollym
Copy link
Author

ollym commented Dec 10, 2011

It's more complicated than that - the filter function uses $.qsa so the code above will cause an infinite loop. It's mainly a proof a concept rather than actual code. In my humble opinion - the selector processing should go into the $.fn.is function, which would make the filter code more like:

[].filter.call(this, function(element) { return $(element).is(selector); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment