/* * jQuery UI Autocomplete @VERSION * * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://docs.jquery.com/UI/Autocomplete * * Depends: * jquery.ui.core.js * jquery.ui.widget.js */ (function( $ ) { $.widget( "ui.autocomplete", { options: { minLength: 1, delay: 300 }, _create: function() { var self = this; this.element .attr( "autocomplete", "off" ) // TODO verify these actually work as intended .attr({ role: "textbox", "aria-autocomplete": "list", "aria-haspopup": "true" }) .bind( "keydown.autocomplete", function( event ) { 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: // when menu is open or has focus if ( self.menu && self.menu.active ) { event.preventDefault(); } case keyCode.TAB: if ( !self.menu || !self.menu.active ) { return; } self.menu.select(); break; case keyCode.ESCAPE: self.element.val( self.term ); self.close( event ); break; case 16: case 17: case 18: // ignore metakeys (shift, ctrl, alt) break; default: // keypress is triggered before the input value is changed clearTimeout( self.searching ); self.searching = setTimeout(function() { self.search( null, event ); }, self.options.delay ); break; } }) .bind( "focus.autocomplete", function() { self.previous = self.element.val(); }) .bind( "blur.autocomplete", function( event ) { clearTimeout( self.searching ); // clicks on the menu (or a button to trigger a search) will cause a blur event // TODO try to implement this without a timeout, see clearTimeout in search() self.closing = setTimeout(function() { self.close( event ); }, 150 ); }); this._initSource(); this.response = function() { return self._response.apply( self, arguments ); }; this.menu = $("