TRANSITION_LENGTH = 300
FLASH_ALERT_LENGTH = 3500
# Grab alerts rendered by the server and apply our behavior to them
$ ->
$('.flash').each ->
DvlFlash $(@)
window.DvlFlash = (alertType, message, lengthInMilliseconds) ->
# Initialize from an existing alert
if alertType instanceof jQuery
$alert = alertType
else
$alert = $("""
""").appendTo("body")
setTimeout ( -> $alert.addClass 'in' ), 0
mousedOver = undefined
timeoutExpired = undefined
hide = ->
$alert.removeClass 'in'
setTimeout ( -> $alert.remove() ), TRANSITION_LENGTH
setTimeout ->
hide() unless mousedOver
timeoutExpired = true
, lengthInMilliseconds || FLASH_ALERT_LENGTH
$alert.on 'mouseover', ->
mousedOver = true
$alert.one 'mouseout', ->
mousedOver = undefined
hide() if timeoutExpired
$alert.on 'click', '.close', ->
mousedOver = undefined
hide()