Permalink
Browse files

cleanup

  • Loading branch information...
1 parent f639ab7 commit 619f1d767dfe048e79d253cc82c9463730b95a41 @rwaldin rwaldin committed Oct 1, 2011
Showing with 67 additions and 15 deletions.
  1. +33 −7 qwery.js
  2. +1 −1 qwery.min.js
  3. +33 −7 src/qwery.js
View
@@ -167,19 +167,45 @@
// loop through all descendent tokens
for (j = 0, l = r.length, k = 0; j < l; j++) {
- p = r[j]
- // loop through each token backwards crawling up tree
- for (i = tokens.length; i--;) {
- // loop through parent nodes
- while (p = walker[dividedTokens[i]](p, r[j])) {
- if (found = interpret.apply(p, q(tokens[i]))) break;
- }
+ if (_ancestorMatch(r[j], tokens, dividedTokens)) {
+ ret[k++] = r[j];
}
found && (ret[k++] = r[j])
}
return ret
}
+ function is(el, selector, root) {
+ if (isNode(selector)) return el == selector
+
+ if (arrayLike(selector)) return !!~flatten(selector).indexOf(el) // if selector is an array, is el a member?
+
+ var selectors = selector.split(','), tokens, dividedTokens
+ while (selector = selectors.pop()) {
+ tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
+ dividedTokens = selector.match(dividers)
+ tokens = tokens.slice(0) // this makes a copy of the array so the cached original is not affected
+ if (interpret.apply(el, q(tokens.pop())) && (!tokens.length || _ancestorMatch(el, tokens, dividedTokens, root))) {
+ return true
+ }
+ }
+ }
+
+ function _ancestorMatch(el, tokens, dividedTokens, root) {
+ var p = el, found;
+ // loop through each token backwards crawling up tree
+ for (i = tokens.length; i--;) {
+ // loop through parent nodes
+ while (p = walker[dividedTokens[i]](p, el)) {
+ if (found = interpret.apply(p, q(tokens[i]))) break
+ }
+ }
+
+ if (root && found) found = isAncestor(found, root)
+
+ return !!found
+ }
+
function isNode(el) {
return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9))
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -160,19 +160,45 @@
// loop through all descendent tokens
for (j = 0, l = r.length, k = 0; j < l; j++) {
- p = r[j]
- // loop through each token backwards crawling up tree
- for (i = tokens.length; i--;) {
- // loop through parent nodes
- while (p = walker[dividedTokens[i]](p, r[j])) {
- if (found = interpret.apply(p, q(tokens[i]))) break;
- }
+ if (_ancestorMatch(r[j], tokens, dividedTokens)) {
+ ret[k++] = r[j];
}
found && (ret[k++] = r[j])
}
return ret
}
+ function is(el, selector, root) {
+ if (isNode(selector)) return el == selector
+
+ if (arrayLike(selector)) return !!~flatten(selector).indexOf(el) // if selector is an array, is el a member?
+
+ var selectors = selector.split(','), tokens, dividedTokens
+ while (selector = selectors.pop()) {
+ tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
+ dividedTokens = selector.match(dividers)
+ tokens = tokens.slice(0) // this makes a copy of the array so the cached original is not affected
+ if (interpret.apply(el, q(tokens.pop())) && (!tokens.length || _ancestorMatch(el, tokens, dividedTokens, root))) {
+ return true
+ }
+ }
+ }
+
+ function _ancestorMatch(el, tokens, dividedTokens, root) {
+ var p = el, found;
+ // loop through each token backwards crawling up tree
+ for (i = tokens.length; i--;) {
+ // loop through parent nodes
+ while (p = walker[dividedTokens[i]](p, el)) {
+ if (found = interpret.apply(p, q(tokens[i]))) break
+ }
+ }
+
+ if (root && found) found = isAncestor(found, root)
+
+ return !!found
+ }
+
function isNode(el) {
return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9))
}

0 comments on commit 619f1d7

Please sign in to comment.