]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - inc/awesomplete-multiple-tags.js
faecb417858e3dd05487d5f3e7000f4d602a7bda
1 var awp
= Awesomplete
.$;
2 var autocompleteFields
= document
.querySelectorAll('input[data-multiple]');
3 [].forEach
.call(autocompleteFields
, function(autocompleteField
) {
4 awesomplete
= new Awesomplete(awp(autocompleteField
), {
5 filter: function (text
, input
) {
6 return Awesomplete
.FILTER_CONTAINS(text
, input
.match(/[^ ]*$/)[0]);
8 replace: function (text
) {
9 var before
= this.input
.value
.match(/^.+ \s
*|/)[0];
10 this.input
.value
= before
+ text
+ " ";
17 * Remove already selected items from autocompletion list.
18 * HTML list is never updated, so removing a tag will add it back to awesomplete.
20 * FIXME: This a workaround waiting for awesomplete to handle this.
21 * https://github.com/LeaVerou/awesomplete/issues/16749
23 function awesompleteUniqueTag(selector
) {
24 var input
= document
.querySelector(selector
);
25 input
.addEventListener('input', function()
27 proposedTags
= input
.getAttribute('data-list').replace(/,/g
, '').split(' ');
29 while((match
= reg
.exec(input
.value
)) !== null) {
30 id
= proposedTags
.indexOf(match
[1]);
32 proposedTags
.splice(id
, 1);
36 awesomplete
.list
= proposedTags
;