Sha256: 00f6f46953962982ec9d9db71fb377904e5459ce2a5f3a99ba368eb9c36ed4f3

Contents?: true

Size: 1.08 KB

Versions: 47

Compression:

Stored size: 1.08 KB

Contents

#= require_tree ../utils

{ stopEverything } = Rails

# Handles "data-method" on links such as:
# <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
Rails.handleMethod = (e) ->
  link = this
  method = link.getAttribute('data-method')
  return unless method

  href = Rails.href(link)
  csrfToken = Rails.csrfToken()
  csrfParam = Rails.csrfParam()
  form = document.createElement('form')
  formContent = "<input name='_method' value='#{method}' type='hidden' />"

  if csrfParam? and csrfToken? and not Rails.isCrossDomain(href)
    formContent += "<input name='#{csrfParam}' value='#{csrfToken}' type='hidden' />"

  # Must trigger submit by click on a button, else "submit" event handler won't work!
  # https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
  formContent += '<input type="submit" />'

  form.method = 'post'
  form.action = href
  form.target = link.target
  form.innerHTML = formContent
  form.style.display = 'none'

  document.body.appendChild(form)
  form.querySelector('[type="submit"]').click()

  stopEverything(e)

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.9.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.9.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.14 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.13 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.12 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.11 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee
jets-1.8.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/features/method.coffee