@@ -301,7 +301,7 @@ $.TokenList = function (input, url_or_data, settings) {
301301 . hide ( )
302302 . val ( "" )
303303 . focus ( function ( ) {
304- input_box . focus ( ) ;
304+ focus_with_timeout ( input_box ) ;
305305 } )
306306 . blur ( function ( ) {
307307 input_box . blur ( ) ;
@@ -326,7 +326,7 @@ $.TokenList = function (input, url_or_data, settings) {
326326 }
327327
328328 // Focus input box
329- input_box . focus ( ) ;
329+ focus_with_timeout ( input_box ) ;
330330 }
331331 } )
332332 . mouseover ( function ( event ) {
@@ -540,7 +540,7 @@ $.TokenList = function (input, url_or_data, settings) {
540540 if ( found_existing_token ) {
541541 select_token ( found_existing_token ) ;
542542 input_token . insertAfter ( found_existing_token ) ;
543- input_box . focus ( ) ;
543+ focus_with_timeout ( input_box ) ;
544544 return ;
545545 }
546546 }
@@ -594,7 +594,7 @@ $.TokenList = function (input, url_or_data, settings) {
594594 }
595595
596596 // Show the input box and give it focus again
597- input_box . focus ( ) ;
597+ focus_with_timeout ( input_box ) ;
598598 }
599599
600600 // Toggle selection of a token in the token list
@@ -626,7 +626,7 @@ $.TokenList = function (input, url_or_data, settings) {
626626 selected_token = null ;
627627
628628 // Show the input box and give it focus again
629- input_box . focus ( ) ;
629+ focus_with_timeout ( input_box ) ;
630630
631631 // Remove this token from the saved list
632632 saved_tokens = saved_tokens . slice ( 0 , index ) . concat ( saved_tokens . slice ( index + 1 ) ) ;
@@ -640,8 +640,8 @@ $.TokenList = function (input, url_or_data, settings) {
640640 if ( settings . tokenLimit !== null ) {
641641 input_box
642642 . show ( )
643- . val ( "" )
644- . focus ( ) ;
643+ . val ( "" ) ;
644+ focus_with_timeout ( input_box ) ;
645645 }
646646
647647 // Execute the onDelete callback if defined
@@ -867,6 +867,16 @@ $.TokenList = function (input, url_or_data, settings) {
867867 }
868868 return url ;
869869 }
870+
871+ // Bring browser focus to the specified object.
872+ // Use of setTimeout is to get around an IE bug.
873+ // (See, e.g., http://stackoverflow.com/questions/2600186/focus-doesnt-work-in-ie)
874+ //
875+ // obj: a jQuery object to focus()
876+ function focus_with_timeout ( obj ) {
877+ setTimeout ( function ( ) { obj . focus ( ) ; } , 50 ) ;
878+ }
879+
870880} ;
871881
872882// Really basic cache for the results
0 commit comments