Skip to content

Commit

Permalink
refactor ender binding
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Mar 3, 2012
1 parent 7c602e7 commit 23f756e
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions ext/zest.ender.js
Expand Up @@ -10,23 +10,20 @@
* https://github.com/ender-js
*/

// I try not to change the expected functionality here, however,
// these functions seem like they should belong in a dom library,
// not as part of the selector engine binding.

;(function() {
var window = this
, document = this.document
, zest = this.zest.noConflict();
var zest = this.zest.noConflict()
, document = this.document;

$._select = function(str, context) {
context = context || document;

if (/^\s*</.test(str)) {
context = context.nodeType === 9
? context : context.ownerDocument;
context = context.nodeType !== 9
? context.ownerDocument
: context;

var out = []
, el = context.createElement('div');
var el = context.createElement('div')
, out = [];

el.innerHTML = str;
el = el.firstChild;
Expand All @@ -37,32 +34,33 @@

return out;
}

return zest(str, context);
};

$.ender(function() {
var has = function(obj, el) {
var i = obj.length;
while (i--) {
if (obj[i] === el) return true;
}
};
return {
find: function(sel) {
var res = []
, i = this.length
, r
, k;
var has = function(obj, el) {
var i = obj.length;
while (i--) {
if (obj[i] === el) return true;
}
};

$.ender({
find: function(sel) {
var res = []
, i = this.length
, r
, k;

while (i--) {
r = zest(sel, this[i]);
k = r.length;
while (k--) {
if (!has(res, r[k])) res.push(r[k]);
}
while (i--) {
r = zest(sel, this[i]);
k = r.length;
while (k--) {
if (!has(res, r[k])) res.push(r[k]);
}
return $(res);
}
};
}());

return $(res);
}
});
}).call(this);

0 comments on commit 23f756e

Please sign in to comment.