Skip to content

Instantly share code, notes, and snippets.

@dperini
Created Jul 25, 2010
Embed
What would you like to do?
// TODO: should probably convert result to plain array (since different engines return different things -- arrays, nodelists, objects, etc.)
var query = (function() {
var engine, engines = 'NW.Dom.select,base2.dom.querySelectorAll,Sizzle,$$,$,YAHOO.util.Selector.query,dojo.query,Ext.DomQuery.select'.split(',');
while ((engine = engines.shift())) {
if (Function('try{return ' + engine + '}catch(e){}')()) {
return Function('cssExpr, ctx', 'ctx || (ctx = document);return ' + engine + '(' +
(engine.indexOf('base2') > -1 ? 'ctx, cssExpr' : 'cssExpr, ctx') + ')');
}
}
return 'querySelectorAll' in document ?
function(cssExpr, ctx) {
ctx || (ctx = document);
return ctx.querySelectorAll(cssExpr);
} : Function('return []');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment