Sha256: 74b0cafd852e975bdd32cff5a0851421394929c77232cea347b5942b7f5a1a02

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

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='flash_close'>&times;</a>
        <span>#{message}</span>
      </div>
    """).appendTo("body")

  setTimeout ->
    $alert.addClass 'is_visible'
  , 0

  mousedOver = undefined
  timeoutExpired = undefined

  hide = ->
    $alert.removeClass 'is_visible'
    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', '.flash_close', ->
    mousedOver = undefined
    hide()

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dvl-core-0.1.0 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.12 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.11 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.10 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.9 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.8 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.7 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.6 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.5 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-core-0.0.4 vendor/assets/javascripts/dvl/components/flashes.coffee
dvl-flashes-0.0.4 vendor/assets/javascripts/dvl/flashes.coffee
dvl-flashes-0.0.3 vendor/assets/javascripts/dvl/flashes.coffee
dvl-flashes-0.0.2 vendor/assets/javascripts/dvl/flashes.coffee