1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan GroveYUI().use('autocomplete', 'autocomplete-highlighters', 'autocomplete-filters', 'editor-base', 'escape', function(Y) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove var editorNode = Y.one('#editor'),
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove editor = new Y.EditorBase(),
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove inputNode: editorNode,
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove queryDelimiter: ' ',
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove resultHighlighter: 'startsWith',
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove resultFilters: 'startsWith',
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove source: 'select * from search.suggest where query="{query}"',
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove editor.after('dom:blur', function (e) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove ac._afterListInputBlur();
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove editor.after('dom:focus', function (e) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove ac._afterListInputFocus();
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove editor.after('nodeChange', function (e) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove if (type === 'keyup' || type === 'backspace' || type === 'delete') {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove newVal = e.changedNode.get('text');
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove if (newVal !== ac.get('value')) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove ac.set('value', newVal, {src: Y.AutoCompleteBase.UI_SRC});
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove ac.on('select', function (e) {
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove var query = ac.get('query'),
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove sel = new (editor.getInstance().Selection);
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove // Remove the portion of the result text that already exists in the
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove // editor so we don't insert it twice.
c3d4ffa22754509013d6f882408f246ce8a273f1Ryan Grove result = result.replace(new RegExp('^' + Y.Escape.regex(query), 'i'), '');