Skip to content

Instantly share code, notes, and snippets.

@k4200
Created September 4, 2011 03:17
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save k4200/1192189 to your computer and use it in GitHub Desktop.
Save k4200/1192189 to your computer and use it in GitHub Desktop.
jQuery UI Autocomplete for Japanese IME
// jQuery UI doesn't work with Japanese, Chinese and probably other
// languages' IMEs.
//
// This code snippet is a modified code of jQuery UI Autocomplete 1.8.16
// that works with Japanese IME. It's based on the code in the ticket below.
// http://bugs.jqueryui.com/ticket/5933
//
// I briefly tested it, and it seems ok.
// Any comments/feedback would be appreciated.
//
//
.bind( "keydown.autocomplete", function( event ) {
if ( self.options.disabled || self.element.propAttr( "readOnly" ) ) {
return;
}
suppressKeyPress = false;
var keyCode = $.ui.keyCode;
switch( event.keyCode ) {
case keyCode.PAGE_UP:
self._move( "previousPage", event );
break;
case keyCode.PAGE_DOWN:
self._move( "nextPage", event );
break;
case keyCode.UP:
self._move( "previous", event );
// prevent moving cursor to beginning of text field in some browsers
event.preventDefault();
break;
case keyCode.DOWN:
self._move( "next", event );
// prevent moving cursor to end of text field in some browsers
event.preventDefault();
break;
case keyCode.ENTER:
case keyCode.NUMPAD_ENTER:
// when menu is open and has focus
if ( self.menu.active ) {
// #6055 - Opera still allows the keypress to occur
// which causes forms to submit
suppressKeyPress = true;
event.preventDefault();
}
//passthrough - ENTER and TAB both select the current element
case keyCode.TAB:
if ( !self.menu.active ) {
return;
}
self.menu.select( event );
break;
case keyCode.ESCAPE:
self.element.val( self.term );
self.close( event );
break;
default:
break;
}
})
.bind( "keyup.autocomplete", function( event ) {
var keyCode = $.ui.keyCode;
switch (event.keyCode) {
case keyCode.PAGE_UP:
case keyCode.PAGE_DOWN:
case keyCode.UP:
case keyCode.DOWN:
case keyCode.NUMPAD_ENTER:
case keyCode.TAB:
case keyCode.ESCAPE:
case keyCode.LEFT:
case keyCode.RIGHT:
case keyCode.SHIFT:
case keyCode.CONTROL:
case keyCode.ALT:
case keyCode.COMMAND:
case keyCode.COMMAND_RIGHT:
case keyCode.INSERT:
case keyCode.CAPS_LOCK:
case keyCode.END:
case keyCode.HOME:
// ignore metakeys (shift, ctrl, alt)
break;
case keyCode.ENTER:
default:
// keypress is triggered before the input value is changed
clearTimeout( self.searching );
self.searching = setTimeout(function() {
// only search if the value has changed
if ( self.term != self.element.val() ) {
self.selectedItem = null;
self.search( null, event );
}
}, self.options.delay );
break;
}
})
@k4200
Copy link
Author

k4200 commented Jul 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment