Created
July 7, 2013 19:08
-
-
Save nosajio/5944550 to your computer and use it in GitHub Desktop.
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
// ================================================== | |
// 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