2016-03-11 10:11:11 -05:00
|
|
|
class @Breakpoints
|
2016-03-14 07:51:07 -04:00
|
|
|
instance = null;
|
2016-03-11 10:11:11 -05:00
|
|
|
|
2016-03-14 07:51:07 -04:00
|
|
|
class BreakpointInstance
|
|
|
|
BREAKPOINTS = ["xs", "sm", "md", "lg"]
|
2016-03-11 10:11:11 -05:00
|
|
|
|
2016-03-14 07:51:07 -04:00
|
|
|
constructor: ->
|
|
|
|
@setup()
|
2016-03-11 10:11:11 -05:00
|
|
|
|
2016-03-14 07:51:07 -04:00
|
|
|
setup: ->
|
|
|
|
allDeviceSelector = BREAKPOINTS.map (breakpoint) ->
|
|
|
|
".device-#{breakpoint}"
|
|
|
|
return if $(allDeviceSelector.join(",")).length
|
2016-03-11 10:11:11 -05:00
|
|
|
|
2016-03-14 07:51:07 -04:00
|
|
|
# Create all the elements
|
2016-03-14 09:02:40 -04:00
|
|
|
els = $.map BREAKPOINTS, (breakpoint) ->
|
|
|
|
"<div class='device-#{breakpoint} visible-#{breakpoint}'></div>"
|
|
|
|
$("body").append els.join('')
|
2016-03-11 10:11:11 -05:00
|
|
|
|
2016-03-14 23:23:30 -04:00
|
|
|
visibleDevice: ->
|
2016-03-14 07:51:07 -04:00
|
|
|
allDeviceSelector = BREAKPOINTS.map (breakpoint) ->
|
|
|
|
".device-#{breakpoint}"
|
2016-03-14 23:23:30 -04:00
|
|
|
$(allDeviceSelector.join(",")).filter(":visible")
|
2016-03-14 07:51:07 -04:00
|
|
|
|
2016-03-14 23:23:30 -04:00
|
|
|
getBreakpointSize: ->
|
|
|
|
$visibleDevice = @visibleDevice
|
|
|
|
# the page refreshed via turbolinks
|
|
|
|
if not $visibleDevice().length
|
|
|
|
@setup()
|
|
|
|
$visibleDevice = @visibleDevice()
|
2016-03-14 07:51:07 -04:00
|
|
|
return $visibleDevice.attr("class").split("visible-")[1]
|
|
|
|
|
|
|
|
@get: ->
|
|
|
|
return instance ?= new BreakpointInstance
|
|
|
|
|
2016-03-14 09:02:40 -04:00
|
|
|
$ =>
|
|
|
|
@bp = Breakpoints.get()
|