Created
July 25, 2010 14:13
-
-
Save dperini/489591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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