-
-
Save ollym/3e66cc2510504cbbc3d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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... |
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
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.