Skip to content

Instantly share code, notes, and snippets.

@Inviz
Created April 19, 2011 11:21
Show Gist options
  • Save Inviz/927160 to your computer and use it in GitHub Desktop.
Save Inviz/927160 to your computer and use it in GitHub Desktop.
var reSingularCombinator = /^\!?[>+^]$/; // "+", ">", "^"
local.matchNodeR = function(node, selector, needle){
var parsed = this.Slick.parse(selector);
if (!parsed) return true;
parsed = parsed.reverse();
for (var i = 0, expression, expressions, built, length, multiple; expression = parsed.expressions[i]; i++) {
var first = expression[0];
if (local.matchSelector(node, first.tag.toUpperCase(), first.id, first.classes, first.attributes, first.pseudos)) { // matching first selector against element
if ((length = expression.length) == 1) continue;
if (!built) built = {Slick: true, expressions: [], length: 0};
built.expressions.push(expressions = []);
built.length++;
for (var j = 1; j < length; j++) expressions.push(expression[j]);
if (!multiple) multiple = !expression[expression.length - 1].combinator.match(reSingularCombinator);
} else return false;
}
var found = built ? this.search(node, built, null, !(multiple && needle)) : node;
return needle ? (multiple ? found.indexOf(needle) > -1 : found == needle) : !!found;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment