Sha256: b77c1dc9894553a465507a58720cc2d93f698c0810d4d17062e777ee115fa3ac

Contents?: true

Size: 969 Bytes

Versions: 47

Compression:

Stored size: 969 Bytes

Contents

#= require_tree ../utils

{ fire, stopEverything } = Rails

Rails.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

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.8.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.8.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.8.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.7.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.7.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.7.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.6.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.5.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.5.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.5.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee
jets-1.5.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/confirm.coffee