Skip to content

Commit

Permalink
consolidate formatForwardSlash and formatSpace into formatForwardSlas…
Browse files Browse the repository at this point in the history
…hAndSpace
  • Loading branch information
tyrantkhan committed Aug 13, 2014
1 parent 2d8d3c9 commit c6273b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
24 changes: 5 additions & 19 deletions lib/jquery.payment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions src/jquery.payment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,9 @@ formatForwardExpiry = (e) ->
if /^\d\d$/.test(val)
$target.val("#{val} / ")

formatForwardSlash = (e) ->
formatForwardSlashAndSpace = (e) ->
slash = String.fromCharCode(e.which)
return unless slash is '/'

$target = $(e.currentTarget)
val = $target.val()

if /^\d$/.test(val) and val isnt '0'
$target.val("0#{val} / ")

formatSpace = (e) ->
space = String.fromCharCode(e.which)
return unless space is ' '
return unless slash is '/' or slash is ' '

$target = $(e.currentTarget)
val = $target.val()
Expand Down Expand Up @@ -332,7 +322,7 @@ setCardType = (e) ->
val = $target.val()
cardType = $.payment.cardType(val) or 'unknown'

unless $target.hasClass(cardType)
unless $target.hasClasscd (cardType)
allTypes = (card.type for card in cards)

$target.removeClass('unknown')
Expand All @@ -355,8 +345,7 @@ $.payment.fn.formatCardExpiry = ->
@payment('restrictNumeric')
@on('keypress', restrictExpiry)
@on('keypress', formatExpiry)
@on('keypress', formatForwardSlash)
@on('keypress', formatSpace)
@on('keypress', formatForwardSlashAndSpace)
@on('keypress', formatForwardExpiry)
@on('keydown', formatBackExpiry)
@on('change', reFormatExpiry)
Expand Down

0 comments on commit c6273b9

Please sign in to comment.