User:Splarka/softfocus.js

/* Soft searchbox focuser, version [0.0.2a] Originally from: http://en.wikipedia.org/wiki/User:Splarka/softfocus.js

Notes:
 * Sets focus on the search box
 * Blurs focus during: home/end/pageup/pagedown and up/down/left/right and escape if textbox is empty
 * Allows said key to perform action it was performing
 * Not tested on any browsers but Mozilla/FF, but should work in theory
 * Might actually be necessary to use "onkeypress" in IE, not sure

if(!window.mwDisableSearchAutoFocus) addOnloadHook(function { var search = document.getElementById('searchInput');  if(!search || window.location.hash.indexOf( '#' ) != -1) return  search.focus;  addHandler(search,'keydown',searchFocusKeydown); });

function searchFocusKeydown(e) { var e = window.event || e; var key = e.charCode || e.keyCode; if(key == 27 || (key >= 32 && key <= 40)) { var search = document.getElementById('searchInput'); if(search && search.value == '') search.blur } return true; }