]> git.immae.eu Git - github/wallabag/wallabag.git/blob - app/Resources/static/themes/baggy/js/autoCompleteTags.js
clean & lint stuff
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / js / autoCompleteTags.js
1 var $ = global.jquery = require('jquery');
2
3 jQuery(function ($) {
4 function split(val) {
5 return val.split(/,\s*/);
6 }
7 function extractLast(term) {
8 return split(term).pop();
9 }
10
11
12 $('#value').bind('keydown', function (event) {
13 if (event.keyCode === $.ui.keyCode.TAB && $(this).data('ui-autocomplete').menu.active) {
14 event.preventDefault();
15 }
16 }).autocomplete({
17 source: function (request, response) {
18 $.getJSON('./?view=tags', {
19 term: extractLast(request.term),
20 //id: $(':hidden#entry_id').val()
21 }, response);
22 },
23 search: function () {
24 // custom minLength
25 var term = extractLast(this.value);
26 if (term.length < 1) {
27 return false;
28 }
29 },
30 focus: function () {
31 // prevent value inserted on focus
32 return false;
33 },
34 select: function (event, ui) {
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
41 terms.push('');
42 this.value = terms.join(', ');
43 return false;
44 },
45 });
46 });