Debian Codegraph @

closure-library/closure/goog/ui/ac/ac.js

raw
1 // Copyright 2012 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Utility methods supporting the autocomplete package.
17 *
18 * @author [email protected] (Adam Wos)
19 * @see ../../demos/autocomplete-basic.html
20 */
21
22 goog.provide('goog.ui.ac');
23
24 goog.require('goog.ui.ac.ArrayMatcher');
25 goog.require('goog.ui.ac.AutoComplete');
26 goog.require('goog.ui.ac.InputHandler');
27 goog.require('goog.ui.ac.Renderer');
28
29
30 /**
31 * Factory function for building a basic autocomplete widget that autocompletes
32 * an inputbox or text area from a data array.
33 * @param {Array<?>} data Data array.
34 * @param {Element} input Input element or text area.
35 * @param {boolean=} opt_multi Whether to allow multiple entries separated with
36 * semi-colons or commas.
37 * @param {boolean=} opt_useSimilar use similar matches. e.g. "gost" => "ghost".
38 * @return {!goog.ui.ac.AutoComplete} A new autocomplete object.
39 */
40 goog.ui.ac.createSimpleAutoComplete = function(
41 data, input, opt_multi, opt_useSimilar) {
42 var matcher = new goog.ui.ac.ArrayMatcher(data, !opt_useSimilar);
43 var renderer = new goog.ui.ac.Renderer();
44 var inputHandler = new goog.ui.ac.InputHandler(null, null, !!opt_multi);
45
46 var autoComplete =
47 new goog.ui.ac.AutoComplete(matcher, renderer, inputHandler);
48 inputHandler.attachAutoComplete(autoComplete);
49 inputHandler.attachInputs(input);
50 return autoComplete;
51 };