Skip to content

Instantly share code, notes, and snippets.

@remy
Created January 22, 2010 00:23
Show Gist options
  • Save remy/283362 to your computer and use it in GitHub Desktop.
Save remy/283362 to your computer and use it in GitHub Desktop.
find: function(q, context) {
var ele = [], list, i, j, x;
this.cache = context;
// this doesn't feel quite right, we should be able to do [#foo,bar].querySelectorAll (or something) - TODO add loop
if (context == undefined && this.length == 1) {
return xui(q, this[0]); // results = [].slice.call(this)
} else if (context == undefined && this.length > 1) {
// do some sort of loop - maybe this:
/*
this.each(function () {
ele = [].slice.call(this, xui(q, this));
});
ele = this.reduce(ele);
*/
} else {
context = document;
}
// fast matching for pure ID selectors
if (typeof q == string && idExpr.test(q)) {
ele = [context.getElementById(q.substr(1))];
} else if (typeof q == string) {
// one selector
ele = [].slice.call(context.querySelectorAll(q));
} else {
// an element was passed in
ele = [q];
}
// disabling the append style, could be a plugin:
// xui.fn.add = function (q) { this.elements = this.elements.concat(this.reduce(xui(q).elements)); return this; }
this.length = 0;
[].push.apply(this, ele); // gotta love apply - works like a fucking charm!
return this;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment