jquery.autocomplete.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. // Type definitions for jQuery-Autocomplete 1.2.25
  2. // Project: https://www.devbridge.com/sourcery/components/jquery-autocomplete/
  3. // Definitions by: John Gouigouix <https://github.com/orchestra-ts/DefinitelyTyped/>
  4. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  5. /// <reference types="jquery"/>
  6. interface AutocompleteSuggestion {
  7. value: string;
  8. data: any;
  9. }
  10. interface AutocompleteResponse {
  11. suggestions: AutocompleteSuggestion[];
  12. }
  13. interface JQueryAutocompleteOptions {
  14. //----------------o AJAX SETTINGS
  15. /**
  16. * Server side URL or callback function that returns serviceUrl string. Optional if local lookup data is provided.
  17. */
  18. serviceUrl?: string;
  19. /**
  20. * Ajax request type to get suggestions.
  21. * @default "GET"
  22. */
  23. type?: string;
  24. /**
  25. * type of data returned from server. Either text, json or jsonp, which will cause the autocomplete to use jsonp.
  26. * You may return a json object in your callback when using jsonp.
  27. * @default "text"
  28. */
  29. dataType?: "text" | "json" | "jsonp";
  30. /**
  31. * The name of the request parameter that contains the query.
  32. * @default "query"
  33. */
  34. paramName?: string;
  35. /**
  36. * Additional parameters to pass with the request, optional.
  37. */
  38. params?: Object;
  39. /**
  40. * Number of miliseconds to defer ajax request.
  41. * @default 0
  42. */
  43. deferRequestBy?: number;
  44. /**
  45. * Any additional Ajax Settings that configure the jQuery Ajax request.
  46. */
  47. ajaxSettings?: JQueryAjaxSettings;
  48. //----------------o CONFIG SETTINGS
  49. /**
  50. * Boolean value indicating whether to cache suggestion results.
  51. * @default false
  52. */
  53. noCache?: boolean;
  54. /**
  55. * That splits input value and takes last part to as query for suggestions.
  56. * Useful when for example you need to fill list of coma separated values.
  57. */
  58. delimiter?: string | RegExp;
  59. /**
  60. * Called before ajax request. this is bound to input element.
  61. * @param query
  62. */
  63. onSearchStart? (query: string): void;
  64. /**
  65. * Called after ajax response is processed. this is bound to input element.
  66. * Suggestions is an array containing the results.
  67. * @param query
  68. * @param suggestions
  69. */
  70. onSearchComplete? (query: string, suggestions: AutocompleteSuggestion[]): void;
  71. /**
  72. * Called if ajax request fails. this is bound to input element.
  73. * @param query
  74. * @param jqXHR
  75. * @param textStatus
  76. * @param errorThrown
  77. */
  78. onSearchError? (query: string, jqXHR: JQueryXHR, textStatus: string, errorThrown: any): void;
  79. /**
  80. * Called after the result of the query is ready. Converts the result into response.suggestions format.
  81. * @param response
  82. * @param originalQuery
  83. */
  84. transformResult? (response: any, originalQuery: string): AutocompleteResponse;
  85. /**
  86. * Callback function invoked when user selects suggestion from the list.
  87. * This inside callback refers to input HtmlElement.
  88. * @param suggestion
  89. */
  90. onSelect? (suggestion: AutocompleteSuggestion): void;
  91. /**
  92. * Minimum number of characters required to trigger autosuggest.
  93. * @default 1
  94. */
  95. minChars?: number;
  96. /**
  97. * Number of maximum results to display for local lookup.
  98. * @default no limit
  99. */
  100. lookupLimit?: number;
  101. /**
  102. * Callback function or lookup array for the suggestions. It may be array of strings or suggestion object literals.
  103. * -> suggestion: An object literal with the following format: { value: 'string', data: any }.
  104. */
  105. lookup?: { (query: string, done: { (results: AutocompleteResponse): void }): void } | string[] | AutocompleteSuggestion[];
  106. /**
  107. * Filter function for local lookups. By default it does partial string match (case insensitive).
  108. * @param suggestion
  109. * @param query
  110. * @param queryLowercase
  111. */
  112. lookupFilter? (suggestion: AutocompleteSuggestion, query: string, queryLowercase: string): any;
  113. /**
  114. * Boolean value indicating if select should be triggered if it matches suggestion.
  115. * @default true
  116. */
  117. triggerSelectOnValidInput?: boolean;
  118. /**
  119. * Boolean value indicating if it shoud prevent future ajax requests for queries with the same root if no results were returned.
  120. * E.g. if Jam returns no suggestions, it will not fire for any future query that starts with Jam.
  121. * @default true
  122. */
  123. preventBadQueries?: boolean;
  124. /**
  125. * If set to true, first item will be selected when showing suggestions.
  126. * @default false
  127. */
  128. autoSelectFirst?: boolean;
  129. /**
  130. * Called before container will be hidden
  131. * @param container
  132. */
  133. onHide? (container: any): void;
  134. //----------------o PRESENTATION SETTINGS
  135. /**
  136. * Called before displaying the suggestions. You may manipulate suggestions DOM before it is displayed.
  137. * @param container
  138. */
  139. beforeRender? (container: any): void;
  140. /**
  141. * Custom function to format suggestion entry inside suggestions container, optional.
  142. * @param suggestion
  143. * @param currentValue
  144. */
  145. formatResult? (suggestion: AutocompleteSuggestion, currentValue: string): string;
  146. /**
  147. * Property name of the suggestion data object, by which results should be grouped.
  148. */
  149. groupBy?: string;
  150. /**
  151. * Maximum height of the suggestions container in pixels.
  152. * @default 300
  153. */
  154. maxHeight?: number;
  155. /**
  156. * Suggestions container width in pixels, e.g.: 300. takes input field width.
  157. * @default "auto"
  158. */
  159. width?: string | number;
  160. /**
  161. * 'z-index' for suggestions container.
  162. * @default 9999
  163. */
  164. zIndex?: number;
  165. /**
  166. * Container where suggestions will be appended. Can be jQuery object, selector or html element.
  167. * Make sure to set position: absolute or position: relative for that element.
  168. * @default document.body
  169. */
  170. appendTo?: any;
  171. /**
  172. * Suggestions are automatically positioned when their container is appended to body (look at appendTo option),
  173. * in other cases suggestions are rendered but no positioning is applied.
  174. * Set this option to force auto positioning in other cases.
  175. * @default false
  176. */
  177. forceFixPosition?: boolean;
  178. /**
  179. * Vertical orientation of the displayed suggestions, available values are auto, top, bottom.
  180. * If set to auto, the suggestions will be orientated it the way that place them closer to middle of the view port.
  181. * @default "bottom"
  182. */
  183. orientation?: "bottom" | "auto" | "top"
  184. /**
  185. * If true, input value stays the same when navigating over suggestions.
  186. * @default false
  187. */
  188. preserveInput?: boolean;
  189. /**
  190. * When no matching results, display a notification label.
  191. * @default false
  192. */
  193. showNoSuggestionNotice?: boolean;
  194. /**
  195. * Text or htmlString or Element or jQuery object for no matching results label.
  196. * @default "No results"
  197. */
  198. noSuggestionNotice?: string | Element | JQuery;
  199. /**
  200. * Called when input is altered after selection has been made. this is bound to input element.
  201. */
  202. onInvalidateSelection? (): void;
  203. /**
  204. * Set to true to leave the cursor in the input field after the user tabs to select a suggestion.
  205. * @default false
  206. */
  207. tabDisabled?: boolean;
  208. }
  209. interface AutocompleteInstance {
  210. /**
  211. * you may update any option at any time. Options are listed above.
  212. * @param options
  213. */
  214. setOptions(options: JQueryAutocompleteOptions): void;
  215. /**
  216. * clears suggestion cache and current suggestions suggestions.
  217. */
  218. clear(): void;
  219. /**
  220. * clears suggestion cache.
  221. */
  222. clearCache(): void;
  223. /**
  224. * deactivate autocomplete.
  225. */
  226. disable(): void;
  227. /**
  228. * activates autocomplete if it was deactivated before.
  229. */
  230. enable(): void;
  231. /**
  232. * hides suggestions.
  233. */
  234. hide(): void;
  235. /**
  236. * destroys autocomplete instance. All events are detached and suggestion containers removed.
  237. */
  238. dispose(): void;
  239. }
  240. interface JQuery {
  241. /**
  242. * Create Autocomplete component
  243. */
  244. autocomplete(options?: JQueryAutocompleteOptions): AutocompleteInstance;
  245. /**
  246. * Trigger non-specialized signature method
  247. * @param methodName
  248. * @param arg
  249. */
  250. autocomplete(methodName: string, ...arg: any[]): any;
  251. /**
  252. * You may update any option at any time. Options are listed above.
  253. * @param methodName The name of the method
  254. * @param options
  255. */
  256. autocomplete(methodName: "setOptions", options: JQueryAutocompleteOptions): AutocompleteInstance;
  257. /**
  258. * Clears suggestion cache and current suggestions suggestions.
  259. * @param methodName The name of the method
  260. */
  261. autocomplete(methodName: "clear"): AutocompleteInstance;
  262. /**
  263. * Clears suggestion cache.
  264. * @param methodName The name of the method
  265. */
  266. autocomplete(methodName: "clearCache"): AutocompleteInstance;
  267. /**
  268. * Deactivate autocomplete.
  269. * @param methodName The name of the method
  270. */
  271. autocomplete(methodName: "disable"): AutocompleteInstance;
  272. /**
  273. * Activates autocomplete if it was deactivated before.
  274. * @param methodName The name of the method
  275. */
  276. autocomplete(methodName: "enable"): AutocompleteInstance;
  277. /**
  278. * Hides suggestions.
  279. * @param methodName The name of the method
  280. */
  281. autocomplete(methodName: "hide"): AutocompleteInstance;
  282. /**
  283. * Destroys autocomplete instance. All events are detached and suggestion containers removed.
  284. * @param methodName The name of the method
  285. */
  286. autocomplete(methodName: "dispose"): AutocompleteInstance;
  287. /**
  288. * Create Autocomplete component via plugin alias
  289. */
  290. devbridgeAutocomplete(options?: JQueryAutocompleteOptions): AutocompleteInstance;
  291. /**
  292. * Trigger non-specialized signature method
  293. * @param methodName
  294. * @param arg
  295. */
  296. devbridgeAutocomplete(methodName: string, ...arg: any[]): any;
  297. /**
  298. * You may update any option at any time. Options are listed above.
  299. * @param methodName The name of the method
  300. * @param options
  301. */
  302. devbridgeAutocomplete(methodName: "setOptions", options: JQueryAutocompleteOptions): AutocompleteInstance;
  303. /**
  304. * Clears suggestion cache and current suggestions suggestions.
  305. * @param methodName The name of the method
  306. */
  307. devbridgeAutocomplete(methodName: "clear"): AutocompleteInstance;
  308. /**
  309. * Clears suggestion cache.
  310. * @param methodName The name of the method
  311. */
  312. devbridgeAutocomplete(methodName: "clearCache"): AutocompleteInstance;
  313. /**
  314. * Deactivate autocomplete.
  315. * @param methodName The name of the method
  316. */
  317. devbridgeAutocomplete(methodName: "disable"): AutocompleteInstance;
  318. /**
  319. * Activates autocomplete if it was deactivated before.
  320. * @param methodName The name of the method
  321. */
  322. devbridgeAutocomplete(methodName: "enable"): AutocompleteInstance;
  323. /**
  324. * Hides suggestions.
  325. * @param methodName The name of the method
  326. */
  327. devbridgeAutocomplete(methodName: "hide"): AutocompleteInstance;
  328. /**
  329. * Destroys autocomplete instance. All events are detached and suggestion containers removed.
  330. * @param methodName The name of the method
  331. */
  332. devbridgeAutocomplete(methodName: "dispose"): AutocompleteInstance;
  333. }