Created
October 17, 2015 20:57
-
-
Save hrgdavor/37529ae8732108db3968 to your computer and use it in GitHub Desktop.
small, simple, matcher function factory for searching DOM nodes
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
/** any tag | |
- () - any alement that is a tag and not TextElement | |
- (func) - matching decided by the provided function | |
- (tag) - element with that tag | |
- (attr,value) - element with attribute and value for it | |
- (tag,attr,value) */ | |
function matcher(p1,p2,p3){ | |
if(typeof(p1) == 'function') return p1; | |
if(!p3){ | |
if(!p2){ | |
if(!p1) return function(e){ return e.tagName; }; | |
return function (e){ | |
return e.tagName == p1; | |
}; | |
}else{ | |
return function (e){ | |
return e.getAttribute && e.getAttribute(p1) == p2; | |
}; | |
} | |
}else{ | |
return function (e){ | |
return e.getAttribute && e.tagName == p1 && e.getAttribute(p2) == p3; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment