jquery.keyboard.extension-autocomplete.min.js 3.2 KB

12
  1. /*! jQuery UI Virtual Keyboard Autocomplete v1.11.4 */
  2. !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&"object"==typeof module.exports?module.exports=e(require("jquery")):e(jQuery)}(function(c){"use strict";c.fn.addAutocomplete=function(l){var u={position:{of:null,my:"right top",at:"left top",collision:"flip"},events:"autocomplete",data:""};return this.each(function(){var t,o,a=c(this).data("keyboard");a&&(o=a.namespace+"Autocomplete",a.autocomplete_namespace=o,a.extensionNamespace.push(o),a.autocomplete_init=function(){var e=(t=a.autocomplete_options=c.extend(!0,{},u,l)).events||t.data||"autocomplete";a.options.alwaysOpen&&a.isVisible()&&a.autocomplete_setup(),a.$el.unbind(o).bind(c.keyboard.events.kbVisible+o,function(){a.autocomplete_setup()}).bind(c.keyboard.events.kbHidden+o,function(){a.$el[t.data||"autocomplete"]("close")}).bind(c.keyboard.events.kbChange+o,function(){a.hasAutocomplete&&a.isVisible()&&a.$el.val(a.$preview.val())}).bind(e+"open"+o,function(){if(a.hasAutocomplete){var e=c.extend({},t.position);e.of=e.of||a.$keyboard,a.$autocomplete.menu.element.position(e)}}).bind(e+"select"+o,function(e,t){a.autocomplete_getVal(t.item)})},a.autocomplete_getVal=function(e){var t;switch(typeof e){case"string":t=e||"";break;case"object":t=e.label||e.value||"";break;default:t=a.preview&&a.preview.value||a.el.value}t=t.toString(),a.hasAutocomplete&&""!==t&&((a.$preview||a.$el).val(t).focus(),a.last.start=t.length,a.last.end=t.length,a.last.val=t)},a.autocomplete_update=function(e){clearTimeout(a.$autocomplete.searching),a.$autocomplete.searching=setTimeout(function(){a.$autocomplete.term!==a.$autocomplete.element.val()&&(a.$autocomplete.selectedItem=null,a.$autocomplete.search(null,e))},a.$autocomplete.options.delay)},a.autocomplete_navKeys={8:"backSpace",9:"tab",13:"enter",20:"capsLock",27:"escape",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete"},a.autocomplete_setup=function(){var t;if(a.$autocomplete=a.$el.data(a.autocomplete_options.data)||a.$el.data("uiAutocomplete")||a.$el.data("ui-autocomplete")||a.$el.data("autocomplete"),a.hasAutocomplete=void 0!==a.$autocomplete&&!a.$autocomplete.options.disabled,a.hasAutocomplete){a.$preview.bind("keydown"+o+" keypress"+o,function(e){a.$preview&&e.namespace!==a.$autocomplete.eventNamespace&&(e.namespace=a.$autocomplete.eventNamespace.slice(1),(t=a.autocomplete_navKeys[e.which])?a.el!==a.preview&&(a.$el.triggerHandler(e),"enter"===t&&setTimeout(function(){a.$autocomplete&&(a.$preview.val(a.$autocomplete.selectedItem.value),a.$preview.focus())},100)):a.autocomplete_update(e))});var e="mouseup mousedown mouseleave touchstart touchend touchcancel ".split(" ").join(o+" ");a.bindButton(e,function(e){a.autocomplete_update(e)})}a.escCloseCallback.autocomplete||(a.escCloseCallback.autocomplete=a.checkAutocompleteMenu)},a.checkAutocompleteMenu=function(e){return a.hasAutocomplete&&e.closest("ul").hasClass("ui-autocomplete")},a.autocomplete_destroy=function(){clearTimeout(a.$autocomplete.searching),a.hasAutocomplete=!1,a.$el.unbind(o),a.$preview&&(a.$preview.unbind(o),a.unbindButton(o)),delete a.$autocomplete},a.autocomplete_init())})}});