Created
June 4, 2012 12:58
-
-
Save ogorzalka/2868209 to your computer and use it in GitHub Desktop.
jQuery.media, a very lightweight plugin for media query testings
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
/* | |
jQuery.media, a very lightweight plugin for media query testings | |
Examples : | |
if ( $.media({'min-width' : '480px', 'max-width' : '768px'}) ) { | |
(...) | |
} | |
if ( $.media({'min-width' : 480) ) { | |
(...) | |
} | |
*/ | |
(function($) { | |
$.media = function(options){ | |
var settings = { | |
'max-width' : 99999999, // okay, it's ugly but hey ! | |
'min-width' : 0, | |
'max-height' : 99999999, // okay, it's ugly but hey ! | |
'min-height' : 0 | |
}; | |
opts = $.extend({}, settings, options); | |
var doc = document.documentElement, | |
windowWidth = doc.clientWidth; | |
windowHeight = doc.clientHeight; | |
for (key in opts) { | |
opts[key] = parseInt(opts[key]); | |
} | |
return opts['max-width'] > windowWidth + 1 && opts['min-width'] < windowWidth - 1 && opts['max-height'] > windowHeight + 1 && opts['min-height'] < windowHeight - 1; | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment