Skip to content

Instantly share code, notes, and snippets.

@yusugomori
Created July 4, 2012 16:39
Show Gist options
  • Save yusugomori/3048228 to your computer and use it in GitHub Desktop.
Save yusugomori/3048228 to your computer and use it in GitHub Desktop.
ModalContainer.coffee
class _Modal
show: (options={}) ->
return false unless options.modalContainerId?
$modalContainer = $(options.modalContainerId)
$modal = $modalContainer.children('.modal')
$close = $modal.find('.close')
$('html, body').addClass 'noscroll'
$modalContainer.css
display: 'block'
WebkitTransform: 'none'
MozTransform: 'none'
_h = $modal.outerHeight()
_h = -1*_h /2
$modalContainer.addClass 'visible'
$modal.css
'margin-bottom': _h
# Bind event for hide()
$close.on 'click' (e) =>
e.preventDefault()
@hide(options)
$('.overlay').on 'click' (e) =>
e.preventDefault()
@hide(options)
return _h
hide: (options={}) ->
return false unless options.modalContainerId?
$modalContainer = $(options.modalContainerId)
$modal = $modalContainer.children('.modal')
$modal.addClass 'rotation'
$('html, body').removeClass 'noscroll'
$modalContainer.removeClass 'visible'
setTimeout =>
$modalContainer.css
display: 'none'
WebkitTransform: 'translateZ(0px)'
MozTransform: 'translateZ(0px)'
, 200
setTimeout =>
$modal.removeClass 'rotation'
, 300
Modal = new _Modal()
$ ->
$('a.trigger-modal-link').on 'click' (e) ->
e.preventDefault()
Modal.show({modalContainerId: '#modal_for_demo'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment