Sha256: d554cec99607eb3515d54879640d1fbcd666eec574482aeed2c417b4004ef4f4

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

#= require_tree ../utils

{ fire, stopEverything } = Quails

Quails.handleConfirm = (e) ->
  stopEverything(e) unless allowAction(this)

# For 'data-confirm' attribute:
# - Fires `confirm` event
# - Shows the confirmation dialog
# - Fires the `confirm:complete` event
#
# Returns `true` if no function stops the chain and user chose yes `false` otherwise.
# Attaching a handler to the element's `confirm` event that returns a `falsy` value cancels the confirmation dialog.
# Attaching a handler to the element's `confirm:complete` event that returns a `falsy` value makes this function
# return false. The `confirm:complete` event is fired whether or not the user answered true or false to the dialog.
allowAction = (element) ->
  message = element.getAttribute('data-confirm')
  return true unless message

  answer = false
  if fire(element, 'confirm')
    try answer = confirm(message)
    callback = fire(element, 'confirm:complete', [answer])

  answer and callback

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-on-quails-0.1.0 actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee