Skip to content

Instantly share code, notes, and snippets.

@ny0m
Last active December 18, 2015 09:59
Show Gist options
  • Save ny0m/5764961 to your computer and use it in GitHub Desktop.
Save ny0m/5764961 to your computer and use it in GitHub Desktop.
Some additions to REM-unit-polyfill to prevent it from cycling through styles enclosed in @media queries in browsers that don't support them.
// Test for Media Query support
mediaQuery = function() {
if (window.matchMedia || window.msMatchMedia) { return true; }
return false;
}
// Remove queries.
removeMediaQueries = function(css) {
if (!mediaQuery()) {
while (css.match(/@media/) !== null) { // If CSS syntax is correct there should always be a "@media" str matching a "}\s*}" string
var start = css.match(/@media/).index,
end = css.match(/\}\s*\}/);
css = css.substring(0, start) + css.substring(end.index + end[0].length);
}
}
return css;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment