diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-11-13 20:24:12 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2015-11-17 20:03:21 +0100 |
commit | b39b1bc2eeebcb52f37f33f63fa645db014130c3 (patch) | |
tree | 3a507ab718cb261f8ec2f4e27bded606a6e6b2e3 /inc | |
parent | 44d60adc5e2fa547bc49620f7e647794f0cad631 (diff) | |
download | Shaarli-b39b1bc2eeebcb52f37f33f63fa645db014130c3.tar.gz Shaarli-b39b1bc2eeebcb52f37f33f63fa645db014130c3.tar.zst Shaarli-b39b1bc2eeebcb52f37f33f63fa645db014130c3.zip |
Fixes #360 - Auto-complete more than one tag in tag filter field
* Group awesomplete for multi data in a single JS file.
* Use it in editlink and linklist.
* Move awesomplete JS lib at the end of page in editlink.
Diffstat (limited to 'inc')
-rw-r--r-- | inc/awesomplete-multiple-tags.js | 35 |
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.$; | ||
2 | awesomplete = 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 | */ | ||
20 | function 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 | } | ||