Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Fix cursor position on Android Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesreggio committed Feb 2, 2015
1 parent f4b85ae commit 008bf09
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/jquery.mobilePhoneNumber.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ $ = jQuery

supportSelectionEnd = 'selectionEnd' of document.createElement('input')

# Timeout to work around cursor bugs in Android Firefox
withTimeout = (fn) -> setTimeout(fn, 50)

formatForPhone_ = (phone, defaultPrefix = null) ->
if phone.indexOf('+') != 0 and defaultPrefix
phone = defaultPrefix + phone.replace(/[^0-9]/g, '')
Expand Down Expand Up @@ -84,11 +87,8 @@ restrictEventAndFormat_ = (e) ->
value = value.substring(0, @caret()) +
String.fromCharCode(e.which) +
value.substring(caretEnd, value.length)
selection = @caret()
selectionAtEnd = selection == @val().length
format_.call(@, value, e)
if !selectionAtEnd
@caret(@val().length)
withTimeout => @caret(@val().length)

formatUp_ = (e) ->
checkForCountryChange_.call(@)
Expand Down Expand Up @@ -118,7 +118,7 @@ format_ = (value, e) ->
e.preventDefault()
@val(phone)
if !selectionAtEnd
@caret(selection)
withTimeout => @caret(selection)

formattedPhone_ = (phone, lastChar) ->
if phone.indexOf('+') != 0 && @data('defaultPrefix')
Expand Down

0 comments on commit 008bf09

Please sign in to comment.