Skip to content

Instantly share code, notes, and snippets.

@dperini
Created July 25, 2010 14:13
Show Gist options
  • Save dperini/489591 to your computer and use it in GitHub Desktop.
Save dperini/489591 to your computer and use it in GitHub Desktop.
// 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