Permalink
Browse files

Mask: use setTimeout to work around Chrome caret positioning issue

  • Loading branch information...
1 parent 3f23f5e commit 5cacdcaebe1363c6434eae21f8c78925b5e11254 Zach Shepherd committed with jzaefferer Oct 16, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 ui/jquery.ui.mask.js
View
@@ -80,7 +80,16 @@ $.widget( "ui.mask", {
if ( begin !== undefined ) {
end = ( end === undefined ) ? begin : end;
if ( dom.setSelectionRange ) {
- dom.setSelectionRange( begin, end );
+ /* Chrome fires off the focus events before positioning the
+ cursor based on where the user clicked. This is annoying
+ because, in the case of tyring to position the cursor at
+ the beginning of an empty input, the eventual positioning
+ based on the user's click overrides whatever we do here.
+ There's no good fix for this except to wait until the
+ click processesing resolves and _then_ reposition things. */
+ setTimeout(function(){
+ dom.setSelectionRange( begin, end );
+ }, /* yes, zero is long enough */ 0);
} else if ( dom.createTextRange ) {
range = dom.createTextRange();
range.collapse( true );

0 comments on commit 5cacdca

Please sign in to comment.