-
Gabriel Engel authoredGabriel Engel authored
modal.coffee 2.53 KiB
@Modal = (->
self = {}
win = $(window)
#mistérios da vida c.483: Pq a self.$window diz ter 100% da janela via css mas na verdade ocupa menos de 100% da tela?
#isso impede que o retorno da janela ao normal quando não mais necessária a classe fluid. (comportamento dançante)
focus = ->
if self.$modal
input = self.$modal.find "input[type='text']"
input.get(0).focus() if input.length
keydown = (e) ->
k = e.which
if k is 27
e.preventDefault()
e.stopImmediatePropagation()
close()
check = ->
if self.$modal and self.$modal.length
if win.height() < self.$window.outerHeight() + (win.height() * 0.10)
unless self.$modal.hasClass("fluid")
self.$modal.addClass("fluid")
#else
#if self.$modal.hasClass("fluid")
#self.$modal.removeClass("fluid")
open = (template, params) ->
params = params or {}
RocketChat.animeBack self.$modal, ->
focus()
self.opened = 1
startListening() if params.listening
setContent template, params.data if template?
self.$modal.addClass "opened"
self.$modal.removeClass "fluid"
setTimeout ->
focus()
,200
close = ->
self.$modal.addClass "closed"
win.unbind("keydown.modal")
# acionar no on-complete da animação
setTimeout ->
self.opened = 0
stopListening()
self.$modal.removeClass "opened closed"
, 300
setContent = (template, data) ->
self.$main.empty()
if template
if data
Blaze.renderWithData template, data, self.$main.get(0)
else
Blaze.render template, self.$main.get(0)
checkFooter()
check()
checkFooter = ->
if self.$footer and self.$footer.length
buttons = self.$footer.find "button"
buttons.each ->
btn = $(@)
if btn.html().match /fechar/ig
btn.click (e) ->
e.preventDefault()
close()