* (bug 14082) Fix for complex text input vs AJAX suggestions on some browsers
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 14 May 2008 16:09:18 +0000 (16:09 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 14 May 2008 16:09:18 +0000 (16:09 +0000)
The mwsuggest code was doing a blur(); focus() on the text field the first time a key was pressed, as a workaround for a problem with Firefox when the field was focused at page load time, as on Special:Search with no input given.

Disabling of the browser's autosuggestion wasn't taking effect in Firefox without this workaround; however the extra blur() and focus() in some cases interrupted complex text input methods (for instance for Korean and Japanese), making it difficult to type in text. [Easily reproduceable in Safari on Mac.]

Unfortunately there's no good way to check if a field is focused from JavaScript, so we can't just conditionally do the blur/focus.

I've changed how Special:Search does its focus() of the input field; now instead of happening in raw immediate JS, it's done as a body onload handler -- this will run *after* mwsuggest.js does its setup, so by the time the field is forced focused, native autosuggest will be disabled.

There might conceivably be a race condition if the user manages to manually focus the field while the page is still loading. Not sure what we can do about that. :D

RELEASE-NOTES
includes/SpecialSearch.php
skins/common/mwsuggest.js

index 39027e6..16065f8 100644 (file)
@@ -273,6 +273,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 14093) Do 'sysop' => 'protect' magic in Title::isValidMoveOperation
 * (bug 14063) Power search form missing <label> for redirects check
 * (bug 14111) Similar filename warning links now lead to correct page
+* (bug 14082) Fix for complex text input vs AJAX suggestions on some browsers
 
 
 === API changes in 1.13 ===
index c0b143f..45de482 100644 (file)
@@ -619,8 +619,11 @@ class SpecialSearch {
        }
 
        function powerSearchFocus() {
-               return "<script type='text/javascript'>" .
-                       "document.getElementById('powerSearchText').focus();" .
+               global $wgJsMimeType;
+               return "<script type=\"$wgJsMimeType\">" .
+                       "hookEvent(\"load\", function(){" .
+                               "document.getElementById('powerSearchText').focus();" .
+                       "});" .
                        "</script>";
        }
 
index e755166..d7d03f9 100644 (file)
@@ -31,8 +31,6 @@ var os_autoload_forms = new Array('searchform', 'searchform2', 'powersearch', 's
 var os_is_stopped = false;
 // max lines to show in suggest table
 var os_max_lines_per_suggest = 7;
-// if we are about to focus the searchbox for the first time
-var os_first_focus = true;
 
 /** Timeout timer class that will fetch the results */ 
 function os_Timer(id,r,query){
@@ -534,12 +532,6 @@ function os_eventKeydown(e){
                return; // not our event
                        
        os_mouse_moved = false;
-               
-       if(os_first_focus){
-               // firefox bug, focus&defocus to make autocomplete=off valid
-               targ.blur(); targ.focus();
-               os_first_focus = false;
-       }
 
        os_cur_keypressed = (window.Event) ? e.which : e.keyCode;
        os_last_keypress = 0;
@@ -548,8 +540,6 @@ function os_eventKeydown(e){
 
 /** Event: loss of focus of input box */
 function os_eventBlur(e){      
-       if(os_first_focus)
-               return; // we are focusing/defocusing
        var targ = os_getTarget(e);
        var r = os_map[targ.id];
        if(r == null)
@@ -559,9 +549,8 @@ function os_eventBlur(e){
 }
 
 /** Event: focus (catch only when stopped) */
-function os_eventFocus(e){     
-       if(os_first_focus)
-               return; // we are focusing/defocusing
+function os_eventFocus(e){
+       // nothing happens here?
 }