summaryrefslogtreecommitdiff
path: root/assets/js/mumi.js
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2023-01-01 17:13:22 +0100
committerRicardo Wurmus <rekado@elephly.net>2023-01-01 17:13:22 +0100
commit92f3e2b073801f8a7e5302c7f3af70639f84b3cd (patch)
treea7921b4c84097a7efa26609596dfad07a907a07f /assets/js/mumi.js
parent8e4342637e26770f396a98de8ff584d5a8d691aa (diff)
js: Move tokenizer code to function.
Diffstat (limited to 'assets/js/mumi.js')
-rw-r--r--assets/js/mumi.js28
1 files changed, 17 insertions, 11 deletions
diff --git a/assets/js/mumi.js b/assets/js/mumi.js
index 151cb43..b37b138 100644
--- a/assets/js/mumi.js
+++ b/assets/js/mumi.js
@@ -65,6 +65,22 @@ var mumi = (function () {
return result;
},
};
+
+ var tokenizeText = function (input, options, tokenInput) {
+ let items = input.value.split(queryTokenizer).filter(entry => entry.trim() != '');
+ let tokens = [];
+ for (item of items) {
+ if (possibleTokens.find(element => element.text == item)) {
+ tokens.push({text: item});
+ } else {
+ tokens.push(options.freeTextToken(item));
+ }
+ }
+ input.value = "";
+ var existing = tokenInput.getTokens () || [];
+ tokenInput.setTokens(existing.concat(tokens));
+ };
+
var initTokenInput = function () {
var inputElement = document.querySelector (".tokenInput input#query");
if (inputElement == null) {
@@ -125,17 +141,7 @@ var mumi = (function () {
/* tokenize existing input text */
if (inputElement.value.length > 0) {
- let items = inputElement.value.split(queryTokenizer).filter(entry => entry.trim() != '');
- let tokens = [];
- for (item of items) {
- if (possibleTokens.find(element => element.text == item)) {
- tokens.push({text: item});
- } else {
- tokens.push(options.freeTextToken(item));
- }
- }
- inputElement.value = "";
- tokenInput.setTokens(tokens);
+ tokenizeText (inputElement, options, tokenInput);
}
inputElement.style.visibility = 'visible';
};