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.55 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.54 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.53 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.52 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.51 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.50 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.49 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.48 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.47 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.46 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.45 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.44 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.43 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.42 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.41 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.40 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.39 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.38 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.37 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee
wrgem-0.0.35 lib/generators/wrstart/template/vendor/assets/components/rails-behaviors/disable.coffee