Permalink
Browse files

Added Element.match. Element.prototype.match seems irrelevant, but I …

…left it just the same.
  • Loading branch information...
1 parent 05d548a commit ee365efe250fa5aed6f103faf1eb3ad8e9e5252e @mattmccray committed Dec 8, 2008
Showing with 11 additions and 0 deletions.
  1. +11 −0 selectors.rb
View
@@ -18,6 +18,17 @@
return (parsed) ? Selectors.Utils.filter(this, parsed, {}) : true;
};
+// Element.match
+Element.match = function(el, selector){
+ if (!selector) return true;
+ selector = selector.toString();
+ var tagid = Selectors.Utils.parseTagAndID(selector);
+ var tag = tagid[0], id = tagid[1];
+ if (!Selectors.Filters.byID(el, id) || !Selectors.Filters.byTag(el, tag)) return false;
+ var parsed = Selectors.Utils.parseSelector(selector);
+ return (parsed) ? Selectors.Utils.filter(el, parsed, {}) : true;
+};
+
// Provides polymorphic access to getElementById to Elements as well as documents, both of which
// can be passed into Selectors.Utils.search as location for searching for subelements.
Element.prototype.getElementById = function(id, nocash){

1 comment on commit ee365ef

trek commented on ee365ef Jan 15, 2009

hey matt,
you may want to check out the sizzle-enabled version of redshift. It obviates the need for this patch (because it no longer users the moo css selector library)

http://github.com/backtik/redshift/tree/sizzle

Please sign in to comment.