Created
May 24, 2013 14:57
-
-
Save jesgundy/5644121 to your computer and use it in GitHub Desktop.
Vanilla JS detection module.
This file contains hidden or 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
// Vanilla JS tests for detecting HTML elements | |
define('detection', function() { | |
if (!document.querySelectorAll) { | |
var d=document, s=d.createStyleSheet(); | |
d.querySelectorAll = function(r, c, i, j, a) { | |
a=d.all, c=[], r = r.replace(/\[for\b/gi, '[htmlFor').split(','); | |
for (i=r.length; i--;) { | |
s.addRule(r[i], 'k:v'); | |
for (j=a.length; j--;) a[j].currentStyle.k && c.push(a[j]); | |
s.removeRule(0); | |
} | |
return c; | |
}; | |
} | |
return { | |
// "has()" api: tests for basic CSS selector queries. | |
find: function( selector ) { | |
return document.querySelectorAll(selector); | |
}, | |
has: function( selector ) { | |
return this.find(selector).length > 0; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment