Skip to content

Instantly share code, notes, and snippets.

@terrencewood
Created April 27, 2014 20:48
Show Gist options
  • Save terrencewood/11355304 to your computer and use it in GitHub Desktop.
Save terrencewood/11355304 to your computer and use it in GitHub Desktop.
Parse CSS for and create mediaQueryListeners for found breakpoints
(function() {
var handleMediaQueryMatch = function(mql) {
console.log('%s : %s', mql.media, mql.matches);
};
var mediaQueryListeners = function() {
for(var i = -1, sheets = document.styleSheets, sheet; sheet = sheets[++i];) {
for(var j = -1, rules = sheet.cssRules, rule, mql; rule = rules[++j];) {
if(rule.media) {
mql = window.matchMedia(rule.media.mediaText);
mql.addListener(handleMediaQueryMatch);
handleMediaQueryMatch(mql);
}
}
}
}
mediaQueryListeners();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment