Sha256: 2a8ca9e6ab71971457d28cb48392bbf39b8a13c5c0eecfa0fdce67098d22d73e

Contents?: true

Size: 1.47 KB

Versions: 261

Compression:

Stored size: 1.47 KB

Contents

# Prevent non-currency buttons from being pressed
$(document).on 'keydown', "input[type='text'].effective_price", (event) ->
  allowed = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ',', '.']

  if event.key && event.key.length == 1 && event.metaKey == false && allowed.indexOf(event.key) == -1
    event.preventDefault()

# Assign the hidden input a value of 100x value
$(document).on 'change keyup', "input[type='text'].effective_price", (event) ->
  $input = $(event.target)
  value = $input.val().replace(/,/g, '')

  unless value == ''
    value = (parseFloat(value || 0.00) * 100.00).toFixed(0)

  $input.siblings("input[type='hidden']").first().val(value)

# Format the value for display as currency (USD)
$(document).on 'change', "input[type='text'].effective_price", (event) ->
  $input = $(event.target)
  value = $input.siblings("input[type='hidden']").first().val()
  max = 2000000000

  unless value == ''
    value = parseInt(value || 0)

    if value > max # 20 million is our max value
      value = max
      $input.siblings("input[type='hidden']").first().val(max)

    if value < -max # -20 million is our min value
      value = -max
      $input.siblings("input[type='hidden']").first().val(-max)

  if isNaN(value) == false && value != ''
    value = (value / 100.0) if value != 0

    value = value.toFixed(2).toString()
    value = value.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2') while (/(\d+)(\d{3})/.test(value))
  else
    value = ''

  $input.val(value)

Version data entries

261 entries across 261 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.13 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.12 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.11 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.10 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.9 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.8 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.7 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.6 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.5 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.4 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.3 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.2 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.1 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.19.0 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.7 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.4 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.3 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.2 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.1 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-1.18.0 app/assets/javascripts/effective_price/initialize.js.coffee