Sha256: fad499581404c03080a4d4be0a6fd2f3177a974c50f27866d324dc852781feea

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

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 = $("""
      <div class="flash flash_#{alertType}">
        <a class='close'>&times;</a>
        #{message}
      </div>
    """).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()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dvl-flashes-0.0.1 vendor/assets/javascripts/dvl/flashes.coffee