]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - inc/awesomplete-multiple-tags.js
Merge pull request #551 from ArthurHoaro/hotfix/timezone
[github/shaarli/Shaarli.git] / inc / awesomplete-multiple-tags.js
CommitLineData
69a1a90c 1var awp = Awesomplete.$;
2awesomplete = new Awesomplete(awp('input[data-multiple]'), {
b39b1bc2
A
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}