Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added insertRule testing for older non IE browsers

  • Loading branch information...
commit b01d242343213cad3c205d2881905624373af96e 1 parent 87ccd77
@ryanseddon ryanseddon authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 modernizr.js
View
21 modernizr.js
@@ -139,7 +139,7 @@ window.Modernizr = (function( window, document, undefined ) {
*/
testSelector = function( selector ) {
- var ret = false, style, sheet, rules, cssText;
+ var ret = false, style, sheet, rules, cssText, insertRule;
qS = document.querySelector;
if(!!qS) {
@@ -151,18 +151,29 @@ window.Modernizr = (function( window, document, undefined ) {
return ret;
}
- ret = injectElementWithStyles(selector + '{}', function( node ) {
+ ret = injectElementWithStyles( selector + '{}', function( node ) {
style = node.lastChild;
sheet = style.sheet || style.styleSheet;
rules = sheet.cssRules || sheet.rules;
- cssText = sheet.cssRules && sheet.cssRules[0] ? rules[0].cssText : sheet.cssText || "";
+ insertRule = sheet.insertRule;
+ cssText = sheet.cssRules && sheet.cssRules[0] ? rules[0].cssText : sheet.cssText || '';
/* Easy way out for IE8+ and other browser that don't support querySelector */
if( sheet && !rules.length ) {
return false;
} else {
- // Some pseudo element properties that have equivilent pseudo classes e.g ::first-line will return false positive so do a indexOf check
- return !/unknown/i.test( cssText ) && !~~cssText.indexOf(selector);
+ // insertRule will work the same way as querySelector an invalid style will throw an exception
+ if( insertRule ) {
+ try {
+ sheet.insertRule( selector + '{}', 0 );
+ ret = true;
+ } catch(e){}
+
+ return ret;
+ } else {
+ // Some pseudo element properties that have equivilent pseudo classes e.g ::first-line will return false positive so do a indexOf check
+ return !/unknown/i.test( cssText ) && !~~cssText.indexOf( selector );
+ }
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.