Skip to content

Instantly share code, notes, and snippets.

@donnywals
Created January 5, 2015 13:17
Show Gist options
  • Save donnywals/ec8a18d30ba0e188538b to your computer and use it in GitHub Desktop.
Save donnywals/ec8a18d30ba0e188538b to your computer and use it in GitHub Desktop.
/*
* see http://krijnhoetmer.nl/stuff/javascript/media-queries/
*/
var App = App || {};
(function(){
var screenSizeTest = function(mediaQuery){
return window.matchMedia(mediaQuery).matches;
}
var readSize = function() {
var pseudo = window.getComputedStyle(document.documentElement, ':before').getPropertyValue('content');
return pseudo ? pseudo.replace(/['"]/g, '') : false;
}
App.isSmallScreen = function() {
return parseInt(readSize()) === 1;
}
App.isMediumScreen = function() {
return parseInt(readSize()) === 2;
}
App.isLargeScreen = function() {
return parseInt(readSize()) === 3;
}
App.isXLargeScreen = function() {
return parseInt(readSize()) === 4;
}
/*
* Unfortunatly...
*/
App.isSmallerThanPortraitIpad = function() {
return screenSizeTest("(max-width: 768px)");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment