Permalink
Browse files

refactor

  • Loading branch information...
1 parent 7c800e8 commit a7a28c5a82244e5df014754f2b0ee5a9ea968740 @chjj committed Mar 1, 2012
Showing with 28 additions and 23 deletions.
  1. +28 −23 lib/zest.js
View
@@ -18,8 +18,8 @@
var window = this
, document = this.document
, old = this.zest
- , subject
- , context;
+ , context = document
+ , subject;
/**
* Helpers
@@ -393,15 +393,15 @@ var selectors = {
':hover': function(el) {
throw new Error(':hover is not supported.');
},
+ ':active': function(el) {
+ throw new Error(':active is not supported.');
+ },
':link': function(el) {
throw new Error(':link is not supported.');
},
':visited': function(el) {
throw new Error(':visited is not supported.');
},
- ':active': function(el) {
- throw new Error(':active is not supported.');
- },
':column': function() {
throw new Error(':column is not supported.');
},
@@ -646,7 +646,6 @@ var compile = function(sel) {
}
filter.push(comb(makeSimple(buff)));
-
buff = [];
}
@@ -701,7 +700,7 @@ var compileGroup = function(sel) {
* Selection
*/
-var select = function(sel) {
+var find = function(sel) {
var results = []
, test = compile(sel)
, scope = context.getElementsByTagName(test.qname)
@@ -711,7 +710,7 @@ var select = function(sel) {
, l
, last;
- if (subject) {
+ if (subject === true) {
while (el = scope[i++]) {
if (test(el) && subject !== last) {
results.push(subject);
@@ -727,7 +726,7 @@ var select = function(sel) {
subject = null;
if (test.sel) {
- res = select(test.sel);
+ res = find(test.sel);
l = res.length;
i = 0;
@@ -745,13 +744,7 @@ var select = function(sel) {
* Compatibility
*/
-select = (function() {
- var _select = select;
-
- if (window.ZEST_DEBUG) {
- return _select;
- }
-
+var select = (function() {
var slice = (function() {
try {
Array.prototype.slice.call(document.getElementsByTagName('*'));
@@ -771,7 +764,7 @@ select = (function() {
try {
return slice.call(context.querySelectorAll(sel));
} catch(e) {
- return _select(sel);
+ return find(sel);
}
};
}
@@ -791,7 +784,7 @@ select = (function() {
} catch(e) {
;
}
- return _select(sel);
+ return find(sel);
};
})();
@@ -809,8 +802,8 @@ if (function() {
* Zest
*/
-var zest = function(sel, context_) {
- context = context_ || document;
+var zest = function(sel, con) {
+ context = con || document;
try {
sel = select(sel);
@@ -821,7 +814,7 @@ var zest = function(sel, context_) {
sel = [];
}
- context = null;
+ context = document;
return sel;
};
@@ -840,7 +833,7 @@ zest.matches = function(el, sel) {
};
zest.cache = function() {
- if (zest._cache) return;
+ if (compile.raw) return;
var raw = compile
, cache = {};
@@ -854,14 +847,26 @@ zest.cache = function() {
zest._cache = cache;
};
+zest.noCache = function() {
+ if (!compile.raw) return;
+ compile = compile.raw;
+ delete zest._cache;
+};
+
zest.noConflict = function() {
window.zest = old;
return zest;
};
+zest.noNative = function() {
+ select = find;
+};
+
window.zest = zest;
-if (!window.ZEST_DEBUG) {
+if (window.ZEST_DEBUG) {
+ zest.noNative();
+} else {
zest.cache();
}

0 comments on commit a7a28c5

Please sign in to comment.