]>
Commit | Line | Data |
---|---|---|
0743287f | 1 | var $ = global.jquery = require('jquery'); |
19f2f11e | 2 | |
0743287f TC |
3 | jQuery(function ($) { |
4 | function split(val) { | |
5 | return val.split(/,\s*/); | |
19f2f11e | 6 | } |
0743287f TC |
7 | function extractLast(term) { |
8 | return split(term).pop(); | |
19f2f11e NL |
9 | } |
10 | ||
11 | ||
0743287f TC |
12 | $('#value').bind('keydown', function (event) { |
13 | if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) { | |
19f2f11e NL |
14 | event.preventDefault(); |
15 | } | |
16 | }).autocomplete({ | |
0743287f TC |
17 | source: function (request, response) { |
18 | $.getJSON('./?view=tags', { | |
19 | term: extractLast(request.term), | |
19f2f11e NL |
20 | //id: $(':hidden#entry_id').val() |
21 | }, response); | |
22 | }, | |
0743287f | 23 | search: function () { |
19f2f11e NL |
24 | // custom minLength |
25 | var term = extractLast(this.value); | |
26 | if (term.length < 1) { | |
27 | return false; | |
28 | } | |
29 | }, | |
0743287f | 30 | focus: function () { |
19f2f11e NL |
31 | // prevent value inserted on focus |
32 | return false; | |
33 | }, | |
0743287f | 34 | select: function (event, ui) { |
19f2f11e NL |
35 | var terms = split(this.value); |
36 | // remove the current input | |
37 | terms.pop(); | |
38 | // add the selected item | |
39 | terms.push(ui.item.value); | |
40 | // add placeholder to get the comma-and-space at the end | |
0743287f TC |
41 | terms.push(''); |
42 | this.value = terms.join(', '); | |
19f2f11e | 43 | return false; |
0743287f | 44 | }, |
19f2f11e | 45 | }); |
19f2f11e | 46 | }); |