aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-11-05 18:16:52 +0100
committerArthurHoaro <arthur@hoa.ro>2020-11-05 18:16:52 +0100
commitdf9aac5b6406bf192f2e4e0987e25d0de88480df (patch)
tree7c1f405bf336225bcda257d483a59b5af0e61026 /assets
parent67339338af74a53780cc05232461ec30ffb05ad9 (diff)
downloadShaarli-df9aac5b6406bf192f2e4e0987e25d0de88480df.tar.gz
Shaarli-df9aac5b6406bf192f2e4e0987e25d0de88480df.tar.zst
Shaarli-df9aac5b6406bf192f2e4e0987e25d0de88480df.zip
Tags separator: vintage theme compatibility
Diffstat (limited to 'assets')
-rw-r--r--assets/default/js/base.js2
-rw-r--r--assets/vintage/js/base.js45
2 files changed, 27 insertions, 20 deletions
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index e7bf4909..37069d69 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -217,7 +217,7 @@ function init(description) {
217(() => { 217(() => {
218 const basePath = document.querySelector('input[name="js_base_path"]').value; 218 const basePath = document.querySelector('input[name="js_base_path"]').value;
219 const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]'); 219 const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]');
220 const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || '\s' : '\s'; 220 const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || ' ' : ' ';
221 221
222 /** 222 /**
223 * Handle responsive menu. 223 * Handle responsive menu.
diff --git a/assets/vintage/js/base.js b/assets/vintage/js/base.js
index 66830b59..15b664ce 100644
--- a/assets/vintage/js/base.js
+++ b/assets/vintage/js/base.js
@@ -2,29 +2,36 @@ import Awesomplete from 'awesomplete';
2import 'awesomplete/awesomplete.css'; 2import 'awesomplete/awesomplete.css';
3 3
4(() => { 4(() => {
5 const awp = Awesomplete.$;
6 const autocompleteFields = document.querySelectorAll('input[data-multiple]'); 5 const autocompleteFields = document.querySelectorAll('input[data-multiple]');
6 const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]');
7 const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || " " : " ";
8
7 [...autocompleteFields].forEach((autocompleteField) => { 9 [...autocompleteFields].forEach((autocompleteField) => {
8 const awesomplete = new Awesomplete(awp(autocompleteField)); 10 const awesome = new Awesomplete(Awesomplete.$(autocompleteField));
9 awesomplete.filter = (text, input) => Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
10 awesomplete.replace = (text) => {
11 const before = awesomplete.input.value.match(/^.+ \s*|/)[0];
12 awesomplete.input.value = `${before}${text} `;
13 };
14 awesomplete.minChars = 1;
15 11
16 autocompleteField.addEventListener('input', () => { 12 // Tags are separated by separator
17 const proposedTags = autocompleteField.getAttribute('data-list').replace(/,/g, '').split(' '); 13 awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS(
18 const reg = /(\w+) /g; 14 text,
19 let match; 15 input.match(new RegExp(`[^${tagsSeparator}]*$`))[0])
20 while ((match = reg.exec(autocompleteField.value)) !== null) { 16 ;
21 const id = proposedTags.indexOf(match[1]); 17 // Insert new selected tag in the input
22 if (id !== -1) { 18 awesome.replace = (text) => {
23 proposedTags.splice(id, 1); 19 const before = awesome.input.value.match(new RegExp(`^.+${tagsSeparator}+|`))[0];
20 awesome.input.value = `${before}${text}${tagsSeparator}`;
21 };
22 // Highlight found items
23 awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]);
24 // Don't display already selected items
25 const reg = new RegExp(`/(\w+)${tagsSeparator}/g`);
26 let match;
27 awesome.data = (item, input) => {
28 while ((match = reg.exec(input))) {
29 if (item === match[1]) {
30 return '';
24 } 31 }
25 } 32 }
26 33 return item;
27 awesomplete.list = proposedTags; 34 };
28 }); 35 awesome.minChars = 1;
29 }); 36 });
30})(); 37})();