Sha256: b6b69ecc8588a0ed1ec608117c97e157d57309f5d3313bdff5b5a7534083483d

Contents?: true

Size: 1.25 KB

Versions: 46

Compression:

Stored size: 1.25 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 $input.data('include-blank') && 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()

  unless $input.data('include-blank') && value == ''
    value = parseInt(value || 0)

  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

46 entries across 46 versions & 1 rubygems

Version Path
effective_bootstrap-0.2.3 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.2.2 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.2.1 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.2.0 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.12 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.11 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.10 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.9 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.8 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.7 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.6 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.5 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.4 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.3 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.2 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.1 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.1.0 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.29 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.28 app/assets/javascripts/effective_price/initialize.js.coffee
effective_bootstrap-0.0.27 app/assets/javascripts/effective_price/initialize.js.coffee