Created
April 27, 2014 20:48
-
-
Save terrencewood/11355304 to your computer and use it in GitHub Desktop.
Parse CSS for and create mediaQueryListeners for found breakpoints
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
(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