Sha256: 2635f4141c39984ac5baf88bc8ce2b2db57b7162150de2829478af54516e805a

Contents?: true

Size: 1.56 KB

Versions: 50

Compression:

Stored size: 1.56 KB

Contents

# Disable
#
#= require ./prepare
#
# Disables clicked buttons with text in `data-disable-with`.
#
# ### Markup
#
# `<input type=submit>` or `<button type=submit>`
#
# ``` definition-table
# Attribute - Description
#
# `data-disable-with` - Message to set `<input>` value or `<button>` innerHTML to.
# ```
#
#     <input type="submit" data-disable-with="Submitting...">

$(document).on 'submit:prepare', 'form', ->
  for input in $(this).find 'input[type=submit][data-disable-with]'
    input = $ input
    # Get current value, default to 'Submit' text otherwise
    input.attr 'data-enable-with', input.val() or 'Submit'
    # If the text is empty, don't change anything
    if value = input.attr 'data-disable-with'
      input.val value
    input[0].disabled = true

  for button in $(this).find 'button[type=submit][data-disable-with]'
    button = $ button
    # Get button text, default to '' text otherwise
    button.attr 'data-enable-with', button.html() or ''
    # If the text is empty, don't change anything
    if value = button.attr 'data-disable-with'
      button.html value
    button[0].disabled = true

  return

# Renable controls when AJAX request finishes
$(document).on 'ajaxComplete', 'form', ->
  # Find all submit inputs to re-enable
  for input in $(this).find 'input[type=submit][data-enable-with]'
    $(input).val $(input).attr 'data-enable-with'
    input.disabled = false

  # Find submit buttons to re-enable
  for button in $(this).find 'button[type=submit][data-enable-with]'
    $(button).html $(button).attr 'data-enable-with'
    button.disabled = false

  return

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
wrgem-0.0.11 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.10 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.9 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.8 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.7 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.6 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.4 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.3 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.2 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.1 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee