aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/awesomplete-multiple-tags.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/inc/awesomplete-multiple-tags.js b/inc/awesomplete-multiple-tags.js
new file mode 100644
index 00000000..e0f889b1
--- /dev/null
+++ b/inc/awesomplete-multiple-tags.js
@@ -0,0 +1,35 @@
1$ = Awesomplete.$;
2awesomplete = new Awesomplete($('input[data-multiple]'), {
3 filter: function(text, input) {
4 return Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
5 },
6 replace: function(text) {
7 var before = this.input.value.match(/^.+ \s*|/)[0];
8 this.input.value = before + text + " ";
9 },
10 minChars: 1
11});
12
13/**
14 * Remove already selected items from autocompletion list.
15 * HTML list is never updated, so removing a tag will add it back to awesomplete.
16 *
17 * FIXME: This a workaround waiting for awesomplete to handle this.
18 * https://github.com/LeaVerou/awesomplete/issues/16749
19 */
20function awesompleteUniqueTag(selector) {
21 var input = document.querySelector(selector);
22 input.addEventListener('input', function()
23 {
24 proposedTags = input.getAttribute('data-list').replace(/,/g, '').split(' ');
25 reg = /(\w+) /g;
26 while((match = reg.exec(input.value)) !== null) {
27 id = proposedTags.indexOf(match[1]);
28 if(id != -1 ) {
29 proposedTags.splice(id, 1);
30 }
31 }
32
33 awesomplete.list = proposedTags;
34 });
35}