Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- dev environment cleanup

- remove git submodules (blaaaaaaaaaa)
- add new flags to jsHint
- remake
- bump package version
  • Loading branch information...
commit 510999f13789399578632c631aa10880898e9dca 1 parent b54a0e2
@ded authored
View
3  .gitignore
@@ -1,6 +1,3 @@
*~
.DS_store
-tmp/
-tmp/qwery.js
-tmp/qwery.min.js
node_modules
View
6 .gitmodules
@@ -1,6 +0,0 @@
-[submodule "build/smoosh"]
- path = build/smoosh
- url = git://github.com/fat/smoosh.git
-[submodule "build/sink"]
- path = build/sink
- url = git://github.com/ded/sink-test.git
View
4 README.md
@@ -78,9 +78,11 @@ Qwery attempts to stay up to date with Yahoo's [Grade A Browser Support](http://
- Firefox 2, 3, 4, 5, Aurora
- Opera
-Tests
+Dev Env & Testing
-----
+ $ npm install --dev
+ $ make
$ open tests/index.html
Note
1  build/sink
@@ -1 +0,0 @@
-Subproject commit 5b82553c81a3561b6525e72468caeeb3557687d4
1  build/smoosh
@@ -1 +0,0 @@
-Subproject commit 0b4115e739a46f2b2c8b3340e0cce427e1804b8a
View
50 config/smoosh.json
@@ -1,29 +1,31 @@
{
"JAVASCRIPT": {
- "DIST_DIR": "./",
- "qwery": [
- "./src/copyright.js",
- "./src/qwery.js"
- ],
- "qwery-mobile": [
- "./src/copyright.js",
- "./mobile/qwery-mobile.js"
+ "DIST_DIR": "./"
+ , "qwery": [
+ "./src/copyright.js"
+ , "./src/qwery.js"
]
- },
- "JSHINT_OPTS": {
- "boss": true,
- "forin": false,
- "curly": false,
- "debug": false,
- "devel": false,
- "evil": false,
- "regexp": false,
- "undef": false,
- "sub": true,
- "white": false,
- "indent": 2,
- "whitespace": true,
- "asi": true,
- "laxbreak": true
+ , "qwery-mobile": [
+ "./src/copyright.js"
+ , "./mobile/qwery-mobile.js"
+ ]
+ }
+ , "JSHINT_OPTS": {
+ "boss": true
+ , "forin": false
+ , "curly": false
+ , "debug": false
+ , "devel": false
+ , "evil": false
+ , "regexp": false
+ , "undef": false
+ , "sub": true
+ , "white": false
+ , "indent": 2
+ , "whitespace": true
+ , "asi": true
+ , "laxbreak": true
+ , "eqeqeq": false
+ , "eqnull": true
}
}
View
17 package.json
@@ -1,14 +1,19 @@
{
"name": "qwery"
- , "description": "blazing fast CSS1|2|3 query selector engine"
- , "version": "2.2.2"
+ , "description": "blazing fast CSS3 query selector engine"
+ , "version": "2.2.3"
, "homepage": "https://github.com/ded/qwery"
, "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
- , "repository": {
- "type": "git"
- , "url": "https://github.com/ded/qwery.git"
- }
+ , "contributors": ["Jacob Thornton <> (https://github.com/fat)"]
, "main": "./qwery.js"
, "keywords": ["ender", "query", "css", "selector engine"]
, "ender": "./src/ender.js"
+ , "repository": {
+ "type": "git"
+ , "url": "https://github.com/ded/qwery.git"
+ }
+ , "devDependencies": {
+ "sink-test": ">= 0.0.9"
+ , "smoosh": ">= 0.3.0"
+ }
}
View
2  qwery-mobile.min.js
@@ -4,4 +4,4 @@
* copyright Dustin Diaz & Jacob Thornton 2011
* MIT License
*/
-!function(a,b,c){function j(a,e,i){var k=typeof e=="string"?j(e)[0]:e||b;if(!k||!a)return[];if(b.getElementsByClassName&&a=="string"&&(i=a.match(d)))return g(k.getElementsByClassName(i[1]));if(a==c||a==b){a=a==b?b:c;return e?[null]:[a]}if(h(a))return!k||f(a,k)?[a]:[];return g(k.querySelectorAll(a))}function i(a){var b=[],c,d;label:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue label;b[b.length]=a[c]}return b}function h(a){return a&&a.nodeType&&(a.nodeType==1||a.nodeType==9)||a===window}function g(a){return[].slice.call(a,0)}var d=/^\.([\w\-]+)$/,e=b.documentElement,f="compareDocumentPosition"in e?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:function(a,c){c=c==b||c==window?e:c;return c!==a&&c.contains(a)};j.uniq=i;var k=a.qwery;j.noConflict=function(){a.qwery=k;return this},a.qwery=j}(this,document,window)
+!function(a,b,c){function g(a){return[].slice.call(a,0)}function h(a){return a&&a.nodeType&&(a.nodeType==1||a.nodeType==9)||a===window}function i(a){var b=[],c,d;e:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue e;b[b.length]=a[c]}return b}function j(a,e,i){var k=typeof e=="string"?j(e)[0]:e||b;return!k||!a?[]:b.getElementsByClassName&&a=="string"&&(i=a.match(d))?g(k.getElementsByClassName(i[1])):a==c||a==b?(a=a==b?b:c,e?[null]:[a]):h(a)?!k||f(a,k)?[a]:[]:g(k.querySelectorAll(a))}var d=/^\.([\w\-]+)$/,e=b.documentElement,f="compareDocumentPosition"in e?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:function(a,c){return c=c==b||c==window?e:c,c!==a&&c.contains(a)};j.uniq=i;var k=a.qwery;j.noConflict=function(){return a.qwery=k,this},a.qwery=j}(this,document,window)
View
296 qwery.js
@@ -7,72 +7,72 @@
!function (context, doc) {
- var c, i, j, k, l, m, o, p, r, v,
- el, node, found, classes, item, items, token,
- html = doc.documentElement,
- id = /#([\w\-]+)/,
- clas = /\.[\w\-]+/g,
- idOnly = /^#([\w\-]+$)/,
- classOnly = /^\.([\w\-]+)$/,
- tagOnly = /^([\w\-]+)$/,
- tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/,
- normalizr = /\s*([\s\+\~>])\s*/g,
- splitters = /[\s\>\+\~]/,
- splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,
- dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g'),
- tokenizr = new RegExp(splitters.source + splittersMore.source),
- specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g,
- simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,
- attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,
- pseudo = /:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,
- chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?'),
- walker = {
- ' ': function (node) {
- return node && node !== html && node.parentNode
- },
- '>': function (node, contestant) {
- return node && node.parentNode == contestant.parentNode && node.parentNode;
- },
- '~': function (node) {
- return node && node.previousSibling;
- },
- '+': function (node, contestant, p1, p2) {
- if (!node) {
- return false;
+ var c, i, j, k, l, m, o, p, r, v
+ , el, node, found, classes, item, items, token
+ , html = doc.documentElement
+ , id = /#([\w\-]+)/
+ , clas = /\.[\w\-]+/g
+ , idOnly = /^#([\w\-]+$)/
+ , classOnly = /^\.([\w\-]+)$/
+ , tagOnly = /^([\w\-]+)$/
+ , tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/
+ , normalizr = /\s*([\s\+\~>])\s*/g
+ , splitters = /[\s\>\+\~]/
+ , splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/
+ , specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g
+ , simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/
+ , attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/
+ , pseudo = /:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/
+ , dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g')
+ , tokenizr = new RegExp(splitters.source + splittersMore.source)
+ , chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?')
+ , walker = {
+ ' ': function (node) {
+ return node && node !== html && node.parentNode
}
- p1 = previous(node);
- p2 = previous(contestant);
- return p1 && p2 && p1 == p2 && p1;
- }
- };
+ , '>': function (node, contestant) {
+ return node && node.parentNode == contestant.parentNode && node.parentNode;
+ }
+ , '~': function (node) {
+ return node && node.previousSibling;
+ }
+ , '+': function (node, contestant, p1, p2) {
+ if (!node) {
+ return false;
+ }
+ p1 = previous(node);
+ p2 = previous(contestant);
+ return p1 && p2 && p1 == p2 && p1;
+ }
+ }
function cache() {
- this.c = {};
+ this.c = {}
}
cache.prototype = {
- g: function (k) {
- return this.c[k] || undefined;
- },
- s: function (k, v) {
- this.c[k] = v;
- return v;
- }
- };
+ g: function (k) {
+ return this.c[k] || undefined
+ }
+ , s: function (k, v) {
+ this.c[k] = v
+ return v
+ }
+ }
- var classCache = new cache(),
- cleanCache = new cache(),
- attrCache = new cache(),
- tokenCache = new cache();
+ var classCache = new cache()
+ , cleanCache = new cache()
+ , attrCache = new cache()
+ , tokenCache = new cache()
function flatten(ar) {
- r = [];
+ r = []
for (i = 0, l = ar.length; i < l; i++) {
if (arrayLike(ar[i])) {
- r = r.concat(ar[i]);
+ r = r.concat(ar[i])
} else {
- r.push(ar[i]);
+ r.push(ar[i])
}
}
- return r;
+ return r
}
function previous(n) {
@@ -85,7 +85,7 @@
}
function q(query) {
- return query.match(chunker);
+ return query.match(chunker)
}
// this next method expect at most these args
@@ -96,108 +96,99 @@
function interpret(whole, tag, idsAndClasses, wholeAttribute, attribute, qualifier, value, wholePseudo, pseudo, wholePseudoVal, pseudoVal) {
var m, c, k;
if (tag && this.tagName.toLowerCase() !== tag) {
- return false;
+ return false
}
if (idsAndClasses && (m = idsAndClasses.match(id)) && m[1] !== this.id) {
- return false;
+ return false
}
if (idsAndClasses && (classes = idsAndClasses.match(clas))) {
for (i = classes.length; i--;) {
- c = classes[i].slice(1);
+ c = classes[i].slice(1)
if (!(classCache.g(c) || classCache.s(c, new RegExp('(^|\\s+)' + c + '(\\s+|$)'))).test(this.className)) {
- return false;
+ return false
}
}
}
if (pseudo && qwery.pseudos[pseudo] && !qwery.pseudos[pseudo](this, pseudoVal)) {
- return false;
+ return false
}
if (wholeAttribute && !value) {
- o = this.attributes;
+ o = this.attributes
for (k in o) {
if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) {
- return this;
+ return this
}
}
}
if (wholeAttribute && !checkAttr(qualifier, this.getAttribute(attribute) || '', value)) {
- return false;
+ return false
}
- return this;
+ return this
}
function clean(s) {
- return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1'));
+ return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1'))
}
function checkAttr(qualify, actual, val) {
switch (qualify) {
case '=':
- return actual == val;
+ return actual == val
case '^=':
- return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val))));
+ return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val))))
case '$=':
- return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$')));
+ return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$')))
case '*=':
- return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val))));
+ return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val))))
case '~=':
- return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)')));
+ return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)')))
case '|=':
- return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)')));
+ return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)')))
}
- return 0;
+ return 0
}
function _qwery(selector) {
- var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children,
- tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr)),
- dividedTokens = selector.match(dividers), dividedToken;
- tokens = tokens.slice(0); // this makes a copy of the array so the cached original is not effected
- if (!tokens.length) {
- return r;
- }
+ var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children
+ , tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
+ , dividedTokens = selector.match(dividers), dividedToken
+ tokens = tokens.slice(0) // this makes a copy of the array so the cached original is not effected
- token = tokens.pop();
- root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc;
- if (!root) {
- return r;
- }
- intr = q(token);
+ if (!tokens.length) return r
+
+ token = tokens.pop()
+ root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc
+
+ if (!root) return r
+
+ intr = q(token)
els = dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ? function (r) {
while (root = root.nextSibling) {
root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && r.push(root)
}
return r
}([]) :
- root.getElementsByTagName(intr[1] || '*');
- for (i = 0, l = els.length; i < l; i++) {
- if (item = interpret.apply(els[i], intr)) {
- r[j++] = item;
- }
- }
- if (!tokens.length) {
- return r;
- }
+ root.getElementsByTagName(intr[1] || '*')
+ for (i = 0, l = els.length; i < l; i++) if (item = interpret.apply(els[i], intr)) r[j++] = item
+ if (!tokens.length) return r
// loop through all descendent tokens
for (j = 0, l = r.length, k = 0; j < l; j++) {
- p = r[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 (found = interpret.apply(p, q(tokens[i]))) break;
}
}
- found && (ret[k++] = r[j]);
+ found && (ret[k++] = r[j])
}
- return ret;
+ return ret
}
function isNode(el) {
- return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9));
+ return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9))
}
function uniq(ar) {
@@ -209,47 +200,33 @@
continue label;
}
}
- a[a.length] = ar[i];
+ a[a.length] = ar[i]
}
- return a;
+ return a
}
function arrayLike(o) {
- return (typeof o === 'object' && isFinite(o.length));
+ return (typeof o === 'object' && isFinite(o.length))
}
function normalizeRoot(root) {
- if (!root) {
- return doc;
- }
- if (typeof root == 'string') {
- return qwery(root)[0];
- }
- if (arrayLike(root)) {
- return root[0];
- }
- return root;
+ if (!root) return doc
+ if (typeof root == 'string') return qwery(root)[0]
+ if (arrayLike(root)) return root[0]
+ return root
}
function qwery(selector, _root) {
- var root = normalizeRoot(_root);
+ var root = normalizeRoot(_root)
- if (!root || !selector) {
- return [];
- }
+ if (!root || !selector) return []
if (selector === window || isNode(selector)) {
- return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : [];
+ return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : []
}
- if (selector && arrayLike(selector)) {
- return flatten(selector);
- }
- if (m = selector.match(idOnly)) {
- return (el = doc.getElementById(m[1])) ? [el] : [];
- }
- if (m = selector.match(tagOnly)) {
- return flatten(root.getElementsByTagName(m[1]));
- }
- return select(selector, root);
+ if (selector && arrayLike(selector)) return flatten(selector)
+ if (m = selector.match(idOnly)) return (el = doc.getElementById(m[1])) ? [el] : []
+ if (m = selector.match(tagOnly)) return flatten(root.getElementsByTagName(m[1]))
+ return select(selector, root)
}
var isAncestor = 'compareDocumentPosition' in html ?
@@ -257,71 +234,64 @@
return (container.compareDocumentPosition(element) & 16) == 16;
} : 'contains' in html ?
function (element, container) {
- container = container == doc || container == window ? html : container;
- return container !== element && container.contains(element);
+ container = container == doc || container == window ? html : container
+ return container !== element && container.contains(element)
} :
function (element, container) {
- while (element = element.parentNode) {
- if (element === container) {
- return 1;
- }
- }
- return 0;
+ while (element = element.parentNode) if (element === container) return 1
+ return 0
},
- supportsCSS3 = (function () {
- if (!doc.querySelector || !doc.querySelectorAll) return false;
-
- try {
- return (doc.querySelectorAll(':nth-of-type(1)').length > 0);
- } catch (e) {
- return false;
- }
- })(),
+ supportsCSS3 = function () {
+ if (!doc.querySelector || !doc.querySelectorAll) return false
+
+ try { return (doc.querySelectorAll(':nth-of-type(1)').length > 0) }
+ catch (e) { return false }
+ }(),
select = supportsCSS3 ?
function (selector, root) {
if (doc.getElementsByClassName && (m = selector.match(classOnly))) {
return flatten((root).getElementsByClassName(m[1]));
}
- return flatten((root).querySelectorAll(selector));
+ return flatten((root).querySelectorAll(selector))
} :
function (selector, root) {
- selector = selector.replace(normalizr, '$1');
- var result = [], element, collection, collections = [], i;
+ selector = selector.replace(normalizr, '$1')
+ var result = [], element, collection, collections = [], i
if (m = selector.match(tagAndOrClass)) {
items = root.getElementsByTagName(m[1] || '*');
r = classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)'));
for (i = 0, l = items.length, j = 0; i < l; i++) {
r.test(items[i].className) && (result[j++] = items[i]);
}
- return result;
+ return result
}
for (i = 0, items = selector.split(','), l = items.length; i < l; i++) {
- collections[i] = _qwery(items[i]);
+ collections[i] = _qwery(items[i])
}
for (i = 0, l = collections.length; i < l && (collection = collections[i]); i++) {
- var ret = collection;
+ var ret = collection
if (root !== doc) {
- ret = [];
+ ret = []
for (j = 0, m = collection.length; j < m && (element = collection[j]); j++) {
// make sure element is a descendent of root
- isAncestor(element, root) && ret.push(element);
+ isAncestor(element, root) && ret.push(element)
}
}
- result = result.concat(ret);
+ result = result.concat(ret)
}
- return uniq(result);
- };
+ return uniq(result)
+ }
- qwery.uniq = uniq;
- qwery.pseudos = {};
+ qwery.uniq = uniq
+ qwery.pseudos = {}
- var oldQwery = context.qwery;
+ var old = context.qwery
qwery.noConflict = function () {
- context.qwery = oldQwery;
- return this;
- };
+ context.qwery = old
+ return this
+ }
if (typeof module !== 'undefined') module.exports = qwery; else context['qwery'] = qwery
View
2  qwery.min.js
@@ -4,4 +4,4 @@
* copyright Dustin Diaz & Jacob Thornton 2011
* MIT License
*/
-!function(a,b){function _(a,c){var d=$(c);if(!d||!a)return[];if(a===window||X(a))return!c||a!==window&&X(d)&&ba(a,d)?[a]:[];if(a&&Z(a))return Q(a);if(h=a.match(w))return(m=b.getElementById(h[1]))?[m]:[];if(h=a.match(y))return Q(d.getElementsByTagName(h[1]));return bc(a,d)}function $(a){if(!a)return b;if(typeof a=="string")return _(a)[0];if(Z(a))return a[0];return a}function Z(a){return typeof a=="object"&&isFinite(a.length)}function Y(a){var b=[],c,d;label:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue label;b[b.length]=a[c]}return b}function X(a){return a&&a.nodeType&&(a.nodeType==1||a.nodeType==9)}function W(a){var c=[],d=[],e,f=0,g,h,i,j,k,l,m,n,p,q,r,s=P.g(a)||P.s(a,a.split(E)),t=a.match(D),u;s=s.slice(0);if(!s.length)return c;k=s.pop(),n=s.length&&(i=s[s.length-1].match(w))?b.getElementById(i[1]):b;if(!n)return c;p=S(k),m=t&&/^[+~]$/.test(t[t.length-1])?function(a){while(n=n.nextSibling)n.nodeType==1&&(p[1]?p[1]==n.tagName.toLowerCase():1)&&a.push(n);return a}([]):n.getElementsByTagName(p[1]||"*");for(e=0,h=m.length;e<h;e++)if(q=T.apply(m[e],p))c[f++]=q;if(!s.length)return c;for(f=0,h=c.length,g=0;f<h;f++){j=c[f];for(e=s.length;e--;)while(j=K[t[e]](j,c[f]))if(o=T.apply(j,S(s[e])))break;o&&(d[g++]=c[f])}return d}function V(a,b,c){switch(a){case"=":return b==c;case"^=":return b.match(O.g("^="+c)||O.s("^="+c,new RegExp("^"+U(c))));case"$=":return b.match(O.g("$="+c)||O.s("$="+c,new RegExp(U(c)+"$")));case"*=":return b.match(O.g(c)||O.s(c,new RegExp(U(c))));case"~=":return b.match(O.g("~="+c)||O.s("~="+c,new RegExp("(?:^|\\s+)"+U(c)+"(?:\\s+|$)")));case"|=":return b.match(O.g("|="+c)||O.s("|="+c,new RegExp("^"+U(c)+"(-|$)")))}return 0}function U(a){return N.g(a)||N.s(a,a.replace(F,"\\$1"))}function T(a,b,c,e,f,g,h,j,k,l,m){var n,o,q;if(b&&this.tagName.toLowerCase()!==b)return!1;if(c&&(n=c.match(u))&&n[1]!==this.id)return!1;if(c&&(p=c.match(v)))for(d=p.length;d--;){o=p[d].slice(1);if(!(M.g(o)||M.s(o,new RegExp("(^|\\s+)"+o+"(\\s+|$)"))).test(this.className))return!1}if(k&&_.pseudos[k]&&!_.pseudos[k](this,m))return!1;if(e&&!h){i=this.attributes;for(q in i)if(Object.prototype.hasOwnProperty.call(i,q)&&(i[q].name||q)==f)return this}if(e&&!V(g,this.getAttribute(f)||"",h))return!1;return this}function S(a){return a.match(J)}function R(a){while(a=a.previousSibling)if(a.nodeType==1)break;return a}function Q(a){k=[];for(d=0,g=a.length;d<g;d++)Z(a[d])?k=k.concat(a[d]):k.push(a[d]);return k}function L(){this.c={}}var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t=b.documentElement,u=/#([\w\-]+)/,v=/\.[\w\-]+/g,w=/^#([\w\-]+$)/,x=/^\.([\w\-]+)$/,y=/^([\w\-]+)$/,z=/^([\w]+)?\.([\w\-]+)$/,A=/\s*([\s\+\~>])\s*/g,B=/[\s\>\+\~]/,C=/(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,D=new RegExp("("+B.source+")"+C.source,"g"),E=new RegExp(B.source+C.source),F=/([.*+?\^=!:${}()|\[\]\/\\])/g,G=/^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,H=/\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,I=/:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,J=new RegExp(G.source+"("+H.source+")?"+"("+I.source+")?"),K={" ":function(a){return a&&a!==t&&a.parentNode},">":function(a,b){return a&&a.parentNode==b.parentNode&&a.parentNode},"~":function(a){return a&&a.previousSibling},"+":function(a,b,c,d){if(!a)return!1;c=R(a),d=R(b);return c&&d&&c==d&&c}};L.prototype={g:function(a){return this.c[a]||undefined},s:function(a,b){this.c[a]=b;return b}};var M=new L,N=new L,O=new L,P=new L,ba="compareDocumentPosition"in t?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:"contains"in t?function(a,c){c=c==b||c==window?t:c;return c!==a&&c.contains(a)}:function(a,b){while(a=a.parentNode)if(a===b)return 1;return 0},bb=function(){if(!b.querySelector||!b.querySelectorAll)return!1;try{return b.querySelectorAll(":nth-of-type(1)").length>0}catch(a){return!1}}(),bc=bb?function(a,c){if(b.getElementsByClassName&&(h=a.match(x)))return Q(c.getElementsByClassName(h[1]));return Q(c.querySelectorAll(a))}:function(a,c){a=a.replace(A,"$1");var d=[],f,i,j=[],l;if(h=a.match(z)){r=c.getElementsByTagName(h[1]||"*"),k=M.g(h[2])||M.s(h[2],new RegExp("(^|\\s+)"+h[2]+"(\\s+|$)"));for(l=0,g=r.length,e=0;l<g;l++)k.test(r[l].className)&&(d[e++]=r[l]);return d}for(l=0,r=a.split(","),g=r.length;l<g;l++)j[l]=W(r[l]);for(l=0,g=j.length;l<g&&(i=j[l]);l++){var m=i;if(c!==b){m=[];for(e=0,h=i.length;e<h&&(f=i[e]);e++)ba(f,c)&&m.push(f)}d=d.concat(m)}return Y(d)};_.uniq=Y,_.pseudos={};var bd=a.qwery;_.noConflict=function(){a.qwery=bd;return this},typeof module!="undefined"?module.exports=_:a.qwery=_}(this,document)
+!function(a,b){function L(){this.c={}}function Q(a){k=[];for(d=0,g=a.length;d<g;d++)Z(a[d])?k=k.concat(a[d]):k.push(a[d]);return k}function R(a){while(a=a.previousSibling)if(a.nodeType==1)break;return a}function S(a){return a.match(J)}function T(a,b,c,e,f,g,h,j,k,l,m){var n,o,q;if(b&&this.tagName.toLowerCase()!==b)return!1;if(c&&(n=c.match(u))&&n[1]!==this.id)return!1;if(c&&(p=c.match(v)))for(d=p.length;d--;){o=p[d].slice(1);if(!(M.g(o)||M.s(o,new RegExp("(^|\\s+)"+o+"(\\s+|$)"))).test(this.className))return!1}if(k&&_.pseudos[k]&&!_.pseudos[k](this,m))return!1;if(e&&!h){i=this.attributes;for(q in i)if(Object.prototype.hasOwnProperty.call(i,q)&&(i[q].name||q)==f)return this}return e&&!V(g,this.getAttribute(f)||"",h)?!1:this}function U(a){return N.g(a)||N.s(a,a.replace(D,"\\$1"))}function V(a,b,c){switch(a){case"=":return b==c;case"^=":return b.match(O.g("^="+c)||O.s("^="+c,new RegExp("^"+U(c))));case"$=":return b.match(O.g("$="+c)||O.s("$="+c,new RegExp(U(c)+"$")));case"*=":return b.match(O.g(c)||O.s(c,new RegExp(U(c))));case"~=":return b.match(O.g("~="+c)||O.s("~="+c,new RegExp("(?:^|\\s+)"+U(c)+"(?:\\s+|$)")));case"|=":return b.match(O.g("|="+c)||O.s("|="+c,new RegExp("^"+U(c)+"(-|$)")))}return 0}function W(a){var c=[],d=[],e,f=0,g,h,i,j,k,l,m,n,p,q,r,s=P.g(a)||P.s(a,a.split(I)),t=a.match(H),u;s=s.slice(0);if(!s.length)return c;k=s.pop(),n=s.length&&(i=s[s.length-1].match(w))?b.getElementById(i[1]):b;if(!n)return c;p=S(k),m=t&&/^[+~]$/.test(t[t.length-1])?function(a){while(n=n.nextSibling)n.nodeType==1&&(p[1]?p[1]==n.tagName.toLowerCase():1)&&a.push(n);return a}([]):n.getElementsByTagName(p[1]||"*");for(e=0,h=m.length;e<h;e++)if(q=T.apply(m[e],p))c[f++]=q;if(!s.length)return c;for(f=0,h=c.length,g=0;f<h;f++){j=c[f];for(e=s.length;e--;)while(j=K[t[e]](j,c[f]))if(o=T.apply(j,S(s[e])))break;o&&(d[g++]=c[f])}return d}function X(a){return a&&a.nodeType&&(a.nodeType==1||a.nodeType==9)}function Y(a){var b=[],c,d;e:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue e;b[b.length]=a[c]}return b}function Z(a){return typeof a=="object"&&isFinite(a.length)}function $(a){return a?typeof a=="string"?_(a)[0]:Z(a)?a[0]:a:b}function _(a,c){var d=$(c);return!d||!a?[]:a===window||X(a)?!c||a!==window&&X(d)&&ba(a,d)?[a]:[]:a&&Z(a)?Q(a):(h=a.match(w))?(m=b.getElementById(h[1]))?[m]:[]:(h=a.match(y))?Q(d.getElementsByTagName(h[1])):bc(a,d)}var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t=b.documentElement,u=/#([\w\-]+)/,v=/\.[\w\-]+/g,w=/^#([\w\-]+$)/,x=/^\.([\w\-]+)$/,y=/^([\w\-]+)$/,z=/^([\w]+)?\.([\w\-]+)$/,A=/\s*([\s\+\~>])\s*/g,B=/[\s\>\+\~]/,C=/(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,D=/([.*+?\^=!:${}()|\[\]\/\\])/g,E=/^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,F=/\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,G=/:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,H=new RegExp("("+B.source+")"+C.source,"g"),I=new RegExp(B.source+C.source),J=new RegExp(E.source+"("+F.source+")?"+"("+G.source+")?"),K={" ":function(a){return a&&a!==t&&a.parentNode},">":function(a,b){return a&&a.parentNode==b.parentNode&&a.parentNode},"~":function(a){return a&&a.previousSibling},"+":function(a,b,c,d){return a?(c=R(a),d=R(b),c&&d&&c==d&&c):!1}};L.prototype={g:function(a){return this.c[a]||undefined},s:function(a,b){return this.c[a]=b,b}};var M=new L,N=new L,O=new L,P=new L,ba="compareDocumentPosition"in t?function(a,b){return(b.compareDocumentPosition(a)&16)==16}:"contains"in t?function(a,c){return c=c==b||c==window?t:c,c!==a&&c.contains(a)}:function(a,b){while(a=a.parentNode)if(a===b)return 1;return 0},bb=function(){if(!b.querySelector||!b.querySelectorAll)return!1;try{return b.querySelectorAll(":nth-of-type(1)").length>0}catch(a){return!1}}(),bc=bb?function(a,c){return b.getElementsByClassName&&(h=a.match(x))?Q(c.getElementsByClassName(h[1])):Q(c.querySelectorAll(a))}:function(a,c){a=a.replace(A,"$1");var d=[],f,i,j=[],l;if(h=a.match(z)){r=c.getElementsByTagName(h[1]||"*"),k=M.g(h[2])||M.s(h[2],new RegExp("(^|\\s+)"+h[2]+"(\\s+|$)"));for(l=0,g=r.length,e=0;l<g;l++)k.test(r[l].className)&&(d[e++]=r[l]);return d}for(l=0,r=a.split(","),g=r.length;l<g;l++)j[l]=W(r[l]);for(l=0,g=j.length;l<g&&(i=j[l]);l++){var m=i;if(c!==b){m=[];for(e=0,h=i.length;e<h&&(f=i[e]);e++)ba(f,c)&&m.push(f)}d=d.concat(m)}return Y(d)};_.uniq=Y,_.pseudos={};var bd=a.qwery;_.noConflict=function(){return a.qwery=bd,this},typeof module!="undefined"?module.exports=_:a.qwery=_}(this,document)
View
91 src/pseudos.js
@@ -1,91 +1,76 @@
!function () {
- var pseudos = qwery.pseudos, i, l, p, r, nodes, m, nthPattern = /\s*((?:\+|\-)?(\d*))n\s*((?:\+|\-)\s*\d+)?\s*/;
+ var pseudos = qwery.pseudos, i, l, p, r, nodes, m, nthPattern = /\s*((?:\+|\-)?(\d*))n\s*((?:\+|\-)\s*\d+)?\s*/
function children(node, ofType) {
- nodes = node.childNodes, r = [];
-
+ nodes = node.childNodes, r = []
+
for (i = 0, l = nodes.length; i < l; i++) {
- if (nodes[i].nodeType == 1 && (!ofType || nodes[i].nodeName == ofType)) {
- r.push(nodes[i]);
- }
+ if (nodes[i].nodeType == 1 && (!ofType || nodes[i].nodeName == ofType)) r.push(nodes[i])
}
- return r;
+ return r
}
-
+
function checkNthExpr(el, nodes, a, b) {
- if (!a) return (nodes[b-1] == el);
- for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) {
- if (el == nodes[i-1]) return true;
- }
- return false;
+ if (!a) return (nodes[b-1] == el)
+ for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i-1]) return true
+ return false
}
-
+
function checkNth(el, nodes, val) {
- if (isFinite(val)) {
- return nodes[val - 1] == el;
- } else if (val == 'odd') {
- return checkNthExpr(el, nodes, 2, 1);
- } else if (val == 'even') {
- return checkNthExpr(el, nodes, 2, 0);
- } else if (m = nthPattern.exec(val)) {
+ if (isFinite(val)) return nodes[val - 1] == el
+ else if (val == 'odd') return checkNthExpr(el, nodes, 2, 1)
+ else if (val == 'even') return checkNthExpr(el, nodes, 2, 0)
+ else if (m = nthPattern.exec(val))
return checkNthExpr(el, nodes,
(m[2] ? parseInt(m[1]) : parseInt(m[1] + '1')), // Check case where coefficient is omitted
- (m[3] ? parseInt(m[3].replace(/\s*/, '')) : 0)); // Check case where constant is omitted
- }
- return false;
+ (m[3] ? parseInt(m[3].replace(/\s*/, '')) : 0)) // Check case where constant is omitted
+
+ return false
}
pseudos['nth-child'] = function (el, val) {
- if (!val || !(p = el.parentNode)) return false;
+ if (!val || !(p = el.parentNode)) return false
return checkNth(el, children(p), val)
- };
+ }
pseudos['nth-last-child'] = function (el, val) {
- if (!val || !(p = el.parentNode)) return false;
+ if (!val || !(p = el.parentNode)) return false
return checkNth(el, children(p).reverse(), val)
- };
+ }
pseudos['nth-of-type'] = function (el, val) {
- if (!val || !(p = el.parentNode)) return false;
+ if (!val || !(p = el.parentNode)) return false
return checkNth(el, children(p, el.nodeName), val)
- };
+ }
pseudos['nth-last-of-type'] = function (el, val) {
- if (!val || !(p = el.parentNode)) return false;
+ if (!val || !(p = el.parentNode)) return false
return checkNth(el, children(p, el.nodeName).reverse(), val)
- };
+ }
- pseudos['first-child'] = function (el) { return pseudos['nth-child'](el, 1); };
- pseudos['last-child'] = function (el) { return pseudos['nth-last-child'](el, 1); };
- pseudos['first-of-type'] = function (el) { return pseudos['nth-of-type'](el, 1); };
- pseudos['last-of-type'] = function (el) { return pseudos['nth-last-of-type'](el, 1); };
+ pseudos['first-child'] = function (el) { return pseudos['nth-child'](el, 1) }
+ pseudos['last-child'] = function (el) { return pseudos['nth-last-child'](el, 1) }
+ pseudos['first-of-type'] = function (el) { return pseudos['nth-of-type'](el, 1) }
+ pseudos['last-of-type'] = function (el) { return pseudos['nth-last-of-type'](el, 1) }
pseudos['only-child'] = function (el) {
- return (p = el.parentNode) && (nodes = children(p)) && (nodes.length == 1) && (el == nodes[0]);
+ return (p = el.parentNode) && (nodes = children(p)) && (nodes.length == 1) && (el == nodes[0])
};
-
+
pseudos['only-of-type'] = function (el) {
- return (p = el.parentNode) && (nodes = children(p, el.nodeName)) && (nodes.length == 1) && (el == nodes[0]);
+ return (p = el.parentNode) && (nodes = children(p, el.nodeName)) && (nodes.length == 1) && (el == nodes[0])
};
pseudos.target = function (el) {
- return (el.getAttribute('id') == location.hash.substr(1));
- };
+ return (el.getAttribute('id') == location.hash.substr(1))
+ }
- pseudos.checked = function (el) {
- return el.checked;
- };
+ pseudos.checked = function (el) { return el.checked }
- pseudos.enabled = function (el) {
- return !el.disabled;
- };
+ pseudos.enabled = function (el) { return !el.disabled }
- pseudos.disabled = function (el) {
- return el.disabled;
- };
+ pseudos.disabled = function (el) { return el.disabled }
- pseudos.empty = function (el) {
- return !el.childNodes.length;
- };
+ pseudos.empty = function (el) { return !el.childNodes.length }
}();
View
296 src/qwery.js
@@ -1,71 +1,71 @@
!function (context, doc) {
- var c, i, j, k, l, m, o, p, r, v,
- el, node, found, classes, item, items, token,
- html = doc.documentElement,
- id = /#([\w\-]+)/,
- clas = /\.[\w\-]+/g,
- idOnly = /^#([\w\-]+$)/,
- classOnly = /^\.([\w\-]+)$/,
- tagOnly = /^([\w\-]+)$/,
- tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/,
- normalizr = /\s*([\s\+\~>])\s*/g,
- splitters = /[\s\>\+\~]/,
- splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/,
- dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g'),
- tokenizr = new RegExp(splitters.source + splittersMore.source),
- specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g,
- simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,
- attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,
- pseudo = /:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/,
- chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?'),
- walker = {
- ' ': function (node) {
- return node && node !== html && node.parentNode
- },
- '>': function (node, contestant) {
- return node && node.parentNode == contestant.parentNode && node.parentNode;
- },
- '~': function (node) {
- return node && node.previousSibling;
- },
- '+': function (node, contestant, p1, p2) {
- if (!node) {
- return false;
+ var c, i, j, k, l, m, o, p, r, v
+ , el, node, found, classes, item, items, token
+ , html = doc.documentElement
+ , id = /#([\w\-]+)/
+ , clas = /\.[\w\-]+/g
+ , idOnly = /^#([\w\-]+$)/
+ , classOnly = /^\.([\w\-]+)$/
+ , tagOnly = /^([\w\-]+)$/
+ , tagAndOrClass = /^([\w]+)?\.([\w\-]+)$/
+ , normalizr = /\s*([\s\+\~>])\s*/g
+ , splitters = /[\s\>\+\~]/
+ , splittersMore = /(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\]|[\s\w\+\-]*\))/
+ , specialChars = /([.*+?\^=!:${}()|\[\]\/\\])/g
+ , simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/
+ , attr = /\[([\w\-]+)(?:([\|\^\$\*\~]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/
+ , pseudo = /:([\w\-]+)(\(['"]?([\s\w\+\-]+)['"]?\))?/
+ , dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g')
+ , tokenizr = new RegExp(splitters.source + splittersMore.source)
+ , chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?')
+ , walker = {
+ ' ': function (node) {
+ return node && node !== html && node.parentNode
}
- p1 = previous(node);
- p2 = previous(contestant);
- return p1 && p2 && p1 == p2 && p1;
- }
- };
+ , '>': function (node, contestant) {
+ return node && node.parentNode == contestant.parentNode && node.parentNode;
+ }
+ , '~': function (node) {
+ return node && node.previousSibling;
+ }
+ , '+': function (node, contestant, p1, p2) {
+ if (!node) {
+ return false;
+ }
+ p1 = previous(node);
+ p2 = previous(contestant);
+ return p1 && p2 && p1 == p2 && p1;
+ }
+ }
function cache() {
- this.c = {};
+ this.c = {}
}
cache.prototype = {
- g: function (k) {
- return this.c[k] || undefined;
- },
- s: function (k, v) {
- this.c[k] = v;
- return v;
- }
- };
+ g: function (k) {
+ return this.c[k] || undefined
+ }
+ , s: function (k, v) {
+ this.c[k] = v
+ return v
+ }
+ }
- var classCache = new cache(),
- cleanCache = new cache(),
- attrCache = new cache(),
- tokenCache = new cache();
+ var classCache = new cache()
+ , cleanCache = new cache()
+ , attrCache = new cache()
+ , tokenCache = new cache()
function flatten(ar) {
- r = [];
+ r = []
for (i = 0, l = ar.length; i < l; i++) {
if (arrayLike(ar[i])) {
- r = r.concat(ar[i]);
+ r = r.concat(ar[i])
} else {
- r.push(ar[i]);
+ r.push(ar[i])
}
}
- return r;
+ return r
}
function previous(n) {
@@ -78,7 +78,7 @@
}
function q(query) {
- return query.match(chunker);
+ return query.match(chunker)
}
// this next method expect at most these args
@@ -89,108 +89,99 @@
function interpret(whole, tag, idsAndClasses, wholeAttribute, attribute, qualifier, value, wholePseudo, pseudo, wholePseudoVal, pseudoVal) {
var m, c, k;
if (tag && this.tagName.toLowerCase() !== tag) {
- return false;
+ return false
}
if (idsAndClasses && (m = idsAndClasses.match(id)) && m[1] !== this.id) {
- return false;
+ return false
}
if (idsAndClasses && (classes = idsAndClasses.match(clas))) {
for (i = classes.length; i--;) {
- c = classes[i].slice(1);
+ c = classes[i].slice(1)
if (!(classCache.g(c) || classCache.s(c, new RegExp('(^|\\s+)' + c + '(\\s+|$)'))).test(this.className)) {
- return false;
+ return false
}
}
}
if (pseudo && qwery.pseudos[pseudo] && !qwery.pseudos[pseudo](this, pseudoVal)) {
- return false;
+ return false
}
if (wholeAttribute && !value) {
- o = this.attributes;
+ o = this.attributes
for (k in o) {
if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) {
- return this;
+ return this
}
}
}
if (wholeAttribute && !checkAttr(qualifier, this.getAttribute(attribute) || '', value)) {
- return false;
+ return false
}
- return this;
+ return this
}
function clean(s) {
- return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1'));
+ return cleanCache.g(s) || cleanCache.s(s, s.replace(specialChars, '\\$1'))
}
function checkAttr(qualify, actual, val) {
switch (qualify) {
case '=':
- return actual == val;
+ return actual == val
case '^=':
- return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val))));
+ return actual.match(attrCache.g('^=' + val) || attrCache.s('^=' + val, new RegExp('^' + clean(val))))
case '$=':
- return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$')));
+ return actual.match(attrCache.g('$=' + val) || attrCache.s('$=' + val, new RegExp(clean(val) + '$')))
case '*=':
- return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val))));
+ return actual.match(attrCache.g(val) || attrCache.s(val, new RegExp(clean(val))))
case '~=':
- return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)')));
+ return actual.match(attrCache.g('~=' + val) || attrCache.s('~=' + val, new RegExp('(?:^|\\s+)' + clean(val) + '(?:\\s+|$)')))
case '|=':
- return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)')));
+ return actual.match(attrCache.g('|=' + val) || attrCache.s('|=' + val, new RegExp('^' + clean(val) + '(-|$)')))
}
- return 0;
+ return 0
}
function _qwery(selector) {
- var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children,
- tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr)),
- dividedTokens = selector.match(dividers), dividedToken;
- tokens = tokens.slice(0); // this makes a copy of the array so the cached original is not effected
- if (!tokens.length) {
- return r;
- }
+ var r = [], ret = [], i, j = 0, k, l, m, p, token, tag, els, root, intr, item, children
+ , tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr))
+ , dividedTokens = selector.match(dividers), dividedToken
+ tokens = tokens.slice(0) // this makes a copy of the array so the cached original is not effected
- token = tokens.pop();
- root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc;
- if (!root) {
- return r;
- }
- intr = q(token);
+ if (!tokens.length) return r
+
+ token = tokens.pop()
+ root = tokens.length && (m = tokens[tokens.length - 1].match(idOnly)) ? doc.getElementById(m[1]) : doc
+
+ if (!root) return r
+
+ intr = q(token)
els = dividedTokens && /^[+~]$/.test(dividedTokens[dividedTokens.length - 1]) ? function (r) {
while (root = root.nextSibling) {
root.nodeType == 1 && (intr[1] ? intr[1] == root.tagName.toLowerCase() : 1) && r.push(root)
}
return r
}([]) :
- root.getElementsByTagName(intr[1] || '*');
- for (i = 0, l = els.length; i < l; i++) {
- if (item = interpret.apply(els[i], intr)) {
- r[j++] = item;
- }
- }
- if (!tokens.length) {
- return r;
- }
+ root.getElementsByTagName(intr[1] || '*')
+ for (i = 0, l = els.length; i < l; i++) if (item = interpret.apply(els[i], intr)) r[j++] = item
+ if (!tokens.length) return r
// loop through all descendent tokens
for (j = 0, l = r.length, k = 0; j < l; j++) {
- p = r[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 (found = interpret.apply(p, q(tokens[i]))) break;
}
}
- found && (ret[k++] = r[j]);
+ found && (ret[k++] = r[j])
}
- return ret;
+ return ret
}
function isNode(el) {
- return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9));
+ return (el && el.nodeType && (el.nodeType == 1 || el.nodeType == 9))
}
function uniq(ar) {
@@ -202,47 +193,33 @@
continue label;
}
}
- a[a.length] = ar[i];
+ a[a.length] = ar[i]
}
- return a;
+ return a
}
function arrayLike(o) {
- return (typeof o === 'object' && isFinite(o.length));
+ return (typeof o === 'object' && isFinite(o.length))
}
function normalizeRoot(root) {
- if (!root) {
- return doc;
- }
- if (typeof root == 'string') {
- return qwery(root)[0];
- }
- if (arrayLike(root)) {
- return root[0];
- }
- return root;
+ if (!root) return doc
+ if (typeof root == 'string') return qwery(root)[0]
+ if (arrayLike(root)) return root[0]
+ return root
}
function qwery(selector, _root) {
- var root = normalizeRoot(_root);
+ var root = normalizeRoot(_root)
- if (!root || !selector) {
- return [];
- }
+ if (!root || !selector) return []
if (selector === window || isNode(selector)) {
- return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : [];
+ return !_root || (selector !== window && isNode(root) && isAncestor(selector, root)) ? [selector] : []
}
- if (selector && arrayLike(selector)) {
- return flatten(selector);
- }
- if (m = selector.match(idOnly)) {
- return (el = doc.getElementById(m[1])) ? [el] : [];
- }
- if (m = selector.match(tagOnly)) {
- return flatten(root.getElementsByTagName(m[1]));
- }
- return select(selector, root);
+ if (selector && arrayLike(selector)) return flatten(selector)
+ if (m = selector.match(idOnly)) return (el = doc.getElementById(m[1])) ? [el] : []
+ if (m = selector.match(tagOnly)) return flatten(root.getElementsByTagName(m[1]))
+ return select(selector, root)
}
var isAncestor = 'compareDocumentPosition' in html ?
@@ -250,71 +227,64 @@
return (container.compareDocumentPosition(element) & 16) == 16;
} : 'contains' in html ?
function (element, container) {
- container = container == doc || container == window ? html : container;
- return container !== element && container.contains(element);
+ container = container == doc || container == window ? html : container
+ return container !== element && container.contains(element)
} :
function (element, container) {
- while (element = element.parentNode) {
- if (element === container) {
- return 1;
- }
- }
- return 0;
+ while (element = element.parentNode) if (element === container) return 1
+ return 0
},
- supportsCSS3 = (function () {
- if (!doc.querySelector || !doc.querySelectorAll) return false;
-
- try {
- return (doc.querySelectorAll(':nth-of-type(1)').length > 0);
- } catch (e) {
- return false;
- }
- })(),
+ supportsCSS3 = function () {
+ if (!doc.querySelector || !doc.querySelectorAll) return false
+
+ try { return (doc.querySelectorAll(':nth-of-type(1)').length > 0) }
+ catch (e) { return false }
+ }(),
select = supportsCSS3 ?
function (selector, root) {
if (doc.getElementsByClassName && (m = selector.match(classOnly))) {
return flatten((root).getElementsByClassName(m[1]));
}
- return flatten((root).querySelectorAll(selector));
+ return flatten((root).querySelectorAll(selector))
} :
function (selector, root) {
- selector = selector.replace(normalizr, '$1');
- var result = [], element, collection, collections = [], i;
+ selector = selector.replace(normalizr, '$1')
+ var result = [], element, collection, collections = [], i
if (m = selector.match(tagAndOrClass)) {
items = root.getElementsByTagName(m[1] || '*');
r = classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)'));
for (i = 0, l = items.length, j = 0; i < l; i++) {
r.test(items[i].className) && (result[j++] = items[i]);
}
- return result;
+ return result
}
for (i = 0, items = selector.split(','), l = items.length; i < l; i++) {
- collections[i] = _qwery(items[i]);
+ collections[i] = _qwery(items[i])
}
for (i = 0, l = collections.length; i < l && (collection = collections[i]); i++) {
- var ret = collection;
+ var ret = collection
if (root !== doc) {
- ret = [];
+ ret = []
for (j = 0, m = collection.length; j < m && (element = collection[j]); j++) {
// make sure element is a descendent of root
- isAncestor(element, root) && ret.push(element);
+ isAncestor(element, root) && ret.push(element)
}
}
- result = result.concat(ret);
+ result = result.concat(ret)
}
- return uniq(result);
- };
+ return uniq(result)
+ }
- qwery.uniq = uniq;
- qwery.pseudos = {};
+ qwery.uniq = uniq
+ qwery.pseudos = {}
- var oldQwery = context.qwery;
+ var old = context.qwery
qwery.noConflict = function () {
- context.qwery = oldQwery;
- return this;
- };
+ context.qwery = old
+ return this
+ }
if (typeof module !== 'undefined') module.exports = qwery; else context['qwery'] = qwery
View
12 tests/index.html
@@ -9,18 +9,18 @@
top: -9999px;
}
</style>
- <link rel="stylesheet" href="../build/sink/src/sink.css" type="text/css">
- <script src="../build/sink/src/sink.js"></script>
+ <link rel="stylesheet" href="../node_modules/sink-test/src/sink.css" type="text/css">
+ <script src="../node_modules/sink-test/src/sink.js"></script>
<script type="text/javascript">
// test for noConflict()
- var qwery = function () {
- return 'success';
- };
+ function qwery() {
+ return 'success'
+ }
</script>
<script src="../src/qwery.js"></script>
<script src="../src/pseudos.js"></script>
<script type="text/javascript">
- var Q = qwery.noConflict();
+ var Q = qwery.noConflict()
</script>
</head>
<body>

0 comments on commit 510999f

Please sign in to comment.
Something went wrong with that request. Please try again.