Skip to content

Instantly share code, notes, and snippets.

@ridgehkr
Last active August 29, 2015 14:01
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 ridgehkr/3a69c685847c8e472eb7 to your computer and use it in GitHub Desktop.
Save ridgehkr/3a69c685847c8e472eb7 to your computer and use it in GitHub Desktop.
Enquire.js w/ Foundation breakpoint classes
# Breakpoint class
# provides a way to manage and access breakpoint values for use in media queries
# read in more detail about this at https://medium.com/@caleb.pierce/coffeescript-for-responsive-websites-3398abd5e2bd
class Breakpoint
constructor: (@lower_bound, @upper_bound = "") ->
@screen = "only screen"
# returns a min-width style media query breakpoint
up: ->
result = @screen
if @lower_bound != "0em"
result += " and (min-width:#{@lower_bound})"
return result
# returns a min-width and max-width style media query breakpoint
only: ->
result = @screen
if @lower_bound != "0em"
result += " and (min-width:#{@lower_bound})"
if @upper_bound != ""
result += " and (max-width:#{@upper_bound})"
return result
# instantiate all the Foundation breakpoints
mq =
small: new Breakpoint("0em", "40em")
medium: new Breakpoint("40.063em", "64em")
large: new Breakpoint("64.063em", "90em")
xlarge: new Breakpoint("90.063em", "120em")
xxlarge: new Breakpoint("120.063em")
# then, whenever you need to listen for breakpoints...
enquire.register mq.medium.up(), {
match : ->
# prepare desktop-size components
unmatch : ->
# prepare mobile-size components
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment