Skip to content

Instantly share code, notes, and snippets.

@nosajio
Created July 7, 2013 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nosajio/5944550 to your computer and use it in GitHub Desktop.
Save nosajio/5944550 to your computer and use it in GitHub Desktop.
// ==================================================
// Active media query listener / breakpoint manager
// @depends: Modernizr
// ==================================================
var breaker = function( breakpoints ) {
var exec = []
, self = this;
if (typeof breakpoints !== 'object') return false;
self.test = function() {
for ( point in breakpoints ) {
// On
if ( exec.indexOf( point ) === -1 && Modernizr.mq( point ) ) {
if ( typeof breakpoints[point].on === 'function' ) {
breakpoints[point].on();
}
exec.push( point );
}
// Off
if ( exec.indexOf( point ) > -1 && !Modernizr.mq( point ) ) {
if ( typeof breakpoints[point].off === 'function' ) {
breakpoints[point].off();
}
exec.splice( (exec.indexOf( point )), 1 );
}
}
};
window.onresize = function() {
self.test();
};
self.test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment