Permalink
Browse files

remake and make tests work in ie

  • Loading branch information...
1 parent 6661bcb commit e017740421ede4b50d9f0ce0683bee1368d46f54 @ded committed Apr 1, 2011
Showing with 28 additions and 26 deletions.
  1. +12 −9 qwery.js
  2. +1 −1 qwery.min.js
  3. +4 −4 src/qwery.js
  4. +11 −12 vendor/sink.js
View
@@ -15,6 +15,7 @@
tagOnly = /^([\w\-]+)$/,
tagAndOrClass = /^([\w]+)?\.([\w\-])+$/,
html = doc.getElementsByTagName('html')[0],
+ tokenizr = /\s(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\])/,
simple = /^([a-z0-9]+)?(?:([\.\#]+[\w\-\.#]+)?)/,
attr = /\[([\w\-]+)(?:([\^\$\*]?\=)['"]?([ \w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^]+)["']?)?\]/,
chunker = new RegExp(simple.source + '(' + attr.source + ')?');
@@ -43,7 +44,8 @@
var classCache = new cache(),
cleanCache = new cache(),
- attrCache = new cache();
+ attrCache = new cache(),
+ tokenCache = new cache();
function q(query) {
return query.match(chunker);
@@ -68,7 +70,7 @@
if (wholeAttribute && !value) {
o = this.attributes;
for (var k in o) {
- if (o.hasOwnProperty(k) && o[k].name == attribute) {
+ if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) {
return this;
}
}
@@ -111,15 +113,16 @@
function _qwery(selector) {
var r = [], ret = [], i,
- tokens = selector.split(/\s(?![\s\w\-\/\?\&\=\:\.\(\)\!,@#%<>\{\}\$\*\^'"]*\])/);
+ tokens = tokenCache.g(selector) || tokenCache.s(selector, selector.split(tokenizr));
+ tokens = tokens.slice(0);
if (!tokens.length) {
return r;
}
r = loopAll(tokens.pop());
if (!tokens.length) {
return r;
}
- // loop through all found base elements
+ // loop through all descendent tokens
for (j = r.length; j--;) {
node = r[j];
p = node;
@@ -154,7 +157,6 @@
};
var qwery = function () {
- // exception for pure classname selectors (it's faster)
function qsa(selector, root) {
root = (typeof root == 'string') ? qsa(root)[0] : root;
if (m = selector.match(idOnly)) {
@@ -167,9 +169,9 @@
}
// return fast
- if (doc.querySelector && doc.querySelectorAll) {
- return qsa;
- }
+ // if (doc.querySelector && doc.querySelectorAll) {
+ // return qsa;
+ // }
return function (selector, root, f) {
root = (typeof root == 'string') ? qwery(root)[0] : (root || doc);
@@ -182,8 +184,9 @@
}
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 = items.length; i--;) {
- (classCache.g(m[2]) || classCache.s(m[2], new RegExp('(^|\\s+)' + m[2] + '(\\s+|$)'))).test(items[i].className) && result.push(items[i]);
+ r.test(items[i].className) && result.push(items[i]);
}
return result;
}
View

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

Oops, something went wrong.
View
@@ -64,7 +64,7 @@
if (wholeAttribute && !value) {
o = this.attributes;
for (var k in o) {
- if (o.hasOwnProperty(k) && o[k].name == attribute) {
+ if (Object.prototype.hasOwnProperty.call(o, k) && (o[k].name || k) == attribute) {
return this;
}
}
@@ -163,9 +163,9 @@
}
// return fast
- if (doc.querySelector && doc.querySelectorAll) {
- return qsa;
- }
+ // if (doc.querySelector && doc.querySelectorAll) {
+ // return qsa;
+ // }
return function (selector, root, f) {
root = (typeof root == 'string') ? qwery(root)[0] : (root || doc);
View
@@ -12,16 +12,20 @@
beforeMethods = [],
afterMethods = [],
currentSetName,
- isHeadless = (typeof module !== 'undefined' && module.exports);
-
- isHeadless && require('colors');
+ isHeadless = false;
function reset() {
total = 0;
fail = false;
init();
}
+ function each(items, fn) {
+ for (var i = 0; i < items.length; i++) {
+ fn(items[i]);
+ }
+ }
+
function failure(li, check) {
setPasses = false;
if (!isHeadless) {
@@ -40,13 +44,13 @@
}
function before(fn) {
- fn ? beforeMethods.push(fn) : beforeMethods.forEach(function (f) {
+ fn ? beforeMethods.push(fn) : each(beforeMethods, function (f) {
f();
});
}
function after(fn) {
- fn ? afterMethods.push(fn) : afterMethods.forEach(function (f) {
+ fn ? afterMethods.push(fn) : each(afterMethods, function (f) {
f();
});
}
@@ -130,12 +134,6 @@
}
}
- function expose() {
- for (var i=0; i < arguments.length; i++) {
- context[arguments[i].name] = arguments[i];
- }
- }
-
var modules = [];
function sink(name, fn) {
@@ -176,7 +174,8 @@
exports.sink = sink;
exports.start = start;
} else {
- expose(sink, start);
+ context.sink = sink;
+ context.start = start;
}
}(this);

0 comments on commit e017740

Please sign in to comment.